Skip to content

Commit 2bd51ee

Browse files
committed
feat: improve init command
1 parent 46fb3b0 commit 2bd51ee

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

src/commands/init.js

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ export async function init() {
2626
}
2727
]);
2828

29-
let jsFiles = [];
29+
let jsFiles = ['puter-sdk'];
30+
let jsDevFiles = [];
3031
let cssFiles = [];
32+
let jsExtraLibraries = [];
3133
let extraFiles = [];
3234
let bundlerAnswers = null;
3335
let frameworkAnswers = null;
@@ -73,14 +75,14 @@ export async function init() {
7375
content: `<template><h1>${answers.name}</h1></template>`
7476
});
7577
break;
76-
case FULLSTACK_FRAMEWORKS[2]:
78+
case FULLSTACK_FRAMEWORKS[2]:
7779
jsFiles.push('svelte@latest', 'sveltekit@latest');
7880
extraFiles.push({
7981
path: 'src/app.vue',
8082
content: `<template><h1>${answers.name}</h1></template>`
8183
});
8284
break;
83-
case FULLSTACK_FRAMEWORKS[3]:
85+
case FULLSTACK_FRAMEWORKS[3]:
8486
jsFiles.push('astro@latest', 'astro@latest');
8587
extraFiles.push({
8688
path: 'src/pages/index.astro',
@@ -117,6 +119,7 @@ export async function init() {
117119
break;
118120
case JS_LIBRARIES[1]:
119121
jsFiles.push('vue@latest');
122+
jsDevFiles.push('@vitejs/plugin-vue');
120123
const vueLibs = await inquirer.prompt([
121124
{
122125
type: 'checkbox',
@@ -126,10 +129,30 @@ export async function init() {
126129
}
127130
]);
128131
jsFiles.push(...vueLibs.vueLibraries);
129-
extraFiles.push({
132+
extraFiles.push(
133+
{
130134
path: 'src/App.vue',
131135
content: `<template><h1>${answers.name}</h1></template>`
132-
});
136+
},
137+
{
138+
path: 'vite.config.js',
139+
content: `import { defineConfig } from 'vite';
140+
import vue from '@vitejs/plugin-vue';
141+
142+
export default defineConfig({
143+
plugins: [vue()]
144+
})
145+
`},
146+
{
147+
path: 'main.js',
148+
content: `import { createApp } from 'vue'
149+
import './style.css';
150+
import App from './App.vue';
151+
152+
const app = createApp(App);
153+
app.mount('#app');
154+
`},
155+
);
133156
break;
134157
case JS_LIBRARIES[2]:
135158
jsFiles.push('@angular/core@latest');
@@ -196,15 +219,16 @@ export async function init() {
196219
case CSS_LIBRARIES[2]:
197220
cssFiles.push('https://cdn.tailwindcss.com');
198221
break;
199-
}
222+
}
200223
}
201224

225+
202226
const spinner = ora('Creating Puter app...').start();
203227

204228
try {
205229
const useBundler = answers.useBundler === 'Yes';
206230
// Create basic app structure
207-
await createAppStructure(answers.name, useBundler, bundlerAnswers, frameworkAnswers, jsFiles, cssFiles, extraFiles);
231+
await createAppStructure(answers.name, useBundler, bundlerAnswers, frameworkAnswers, jsFiles, jsDevFiles, cssFiles, extraFiles);
208232
spinner.succeed(chalk.green('Successfully created Puter app!'));
209233

210234
console.log('\nNext steps:');
@@ -221,7 +245,7 @@ export async function init() {
221245
}
222246
}
223247

224-
async function createAppStructure(name, useBundler, bundlerAnswers, frameworkAnswers, jsFiles, cssFiles, extraFiles) {
248+
async function createAppStructure(name, useBundler, bundlerAnswers, frameworkAnswers, jsFiles, jsDevFiles, cssFiles, extraFiles) {
225249
// Create project directory
226250
await fs.mkdir(name, { recursive: true });
227251

@@ -262,17 +286,23 @@ console.log('Puter app initialized!');`,
262286
const packageJson = {
263287
name: name,
264288
version: '1.0.0',
289+
type: 'module',
265290
scripts,
266291
dependencies: {},
267292
devDependencies: {}
268293
};
269294

295+
270296
jsFiles.forEach(lib => {
271297
if (!lib.startsWith('http')) {
272298
packageJson.dependencies[lib.split('@')[0].toString().toLowerCase()] = lib.split('@')[1] || 'latest';
273299
}
274300
});
275301

302+
jsDevFiles.forEach(lib => {
303+
packageJson.devDependencies[lib] = 'latest';
304+
});
305+
276306
packageJson.devDependencies[bundler] = 'latest';
277307

278308
await fs.writeFile(path.join(name, 'package.json'), JSON.stringify(packageJson, null, 2));

0 commit comments

Comments
 (0)