diff --git a/index.ts b/index.ts index 4d77d0904..e7c44df34 100755 --- a/index.ts +++ b/index.ts @@ -101,6 +101,7 @@ type PromptResult = { e2eFramework?: 'cypress' | 'nightwatch' | 'playwright' experimentFeatures?: (typeof EXPERIMENTAL_FEATURE_OPTIONS)[number]['value'][] needsBareboneTemplates?: boolean + needsAutomaticallyInstallDependencies?: boolean } function isValidPackageName(projectName) { @@ -255,6 +256,8 @@ async function init() { // TODO: default to true sometime in the future needsBareboneTemplates: false, + // TODO: default to false sometime in the future + needsAutomaticallyInstallDependencies: false, } intro( @@ -680,12 +683,25 @@ async function init() { }), ) + if (!args.length) { + // skip snapshot pending prompts + result.needsAutomaticallyInstallDependencies = await unwrapPrompt( + confirm({ + message: language.needsAutomaticallyInstallDependencies.message, + // TODO: default to true sometime in the future + initialValue: false, + }), + ) + } + let outroMessage = `${language.infos.done}\n\n` if (root !== cwd) { const cdProjectName = path.relative(cwd, root) outroMessage += ` ${bold(green(`cd ${cdProjectName.includes(' ') ? `"${cdProjectName}"` : cdProjectName}`))}\n` } - outroMessage += ` ${bold(green(getCommand(packageManager, 'install')))}\n` + if (!result.needsAutomaticallyInstallDependencies) { + outroMessage += ` ${bold(green(getCommand(packageManager, 'install')))}\n` + } if (needsPrettier) { outroMessage += ` ${bold(green(getCommand(packageManager, 'format')))}\n` } @@ -693,12 +709,40 @@ async function init() { if (!dotGitDirectoryState.hasDotGitDirectory) { outroMessage += ` -${dim('|')} ${language.infos.optionalGitCommand} - - ${bold(green('git init && git add -A && git commit -m "initial commit"'))}` + ${dim('|')} ${language.infos.optionalGitCommand} + ${bold(green('git init && git add -A && git commit -m "initial commit"'))}` } - outro(outroMessage) + if (!result.needsAutomaticallyInstallDependencies) { + outro(outroMessage) + return + } + + console.log(`\n\nstarting installation...\n`) + const { spawn } = await import('node:child_process') + const installArgs = ['install'] + const child = spawn(packageManager, installArgs, { + cwd: root, + stdio: 'inherit', + shell: process.platform === 'win32', + }) + + child.on('close', (code) => { + if (code === 0) { + console.log(outroMessage) + } else { + console.error( + red(`\n${bold('Error:')} Dependency installation failed with exit code ${code}.`), + ) + console.error( + red( + 'Please check the output above for details and try running the install command manually:', + ), + ) + console.error(bold(green(getCommand(packageManager, 'install')))) + process.exit(code) + } + }) } init().catch((e) => { diff --git a/locales/en-US.json b/locales/en-US.json index 10a91068f..79cb13e27 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -69,6 +69,9 @@ "message": "Select experimental features to include in your project:", "hint": "(↑/↓ to navigate, space to select, a to toggle all, enter to confirm)" }, + "needsAutomaticallyInstallDependencies": { + "message": "Automatically install dependencies?" + }, "needsRolldownVite": { "message": "rolldown-vite (experimental)" }, diff --git a/locales/fr-FR.json b/locales/fr-FR.json index 1e2ff6895..12e34a9b1 100644 --- a/locales/fr-FR.json +++ b/locales/fr-FR.json @@ -69,6 +69,9 @@ "message": "Sélectionnez les fonctionnalités expérimentales à inclure\u00a0:", "hint": "(↑/↓ pour naviguer, espace pour sélectionner, a pour tout sélectionner, entrée pour confirmer)" }, + "needsAutomaticallyInstallDependencies": { + "message": "Installer automatiquement les dépendances\u00a0?" + }, "needsRolldownVite": { "message": "rolldown-vite (expérimental)" }, diff --git a/locales/tr-TR.json b/locales/tr-TR.json index 550cdcedd..9db5335c5 100644 --- a/locales/tr-TR.json +++ b/locales/tr-TR.json @@ -69,6 +69,9 @@ "message": "Dahil edilecek deneysel özellikleri seçin:", "hint": "(↑/↓ gezinmek için, boşluk seçmek için, a tümünü seçmek için, enter onaylamak için)" }, + "needsAutomaticallyInstallDependencies": { + "message": "Bağımlılıklar otomatik olarak yüklensin mi?" + }, "needsRolldownVite": { "message": "rolldown-vite (deneysel)" }, diff --git a/locales/zh-Hans.json b/locales/zh-Hans.json index 3f46cf5d5..9fe5b3c87 100644 --- a/locales/zh-Hans.json +++ b/locales/zh-Hans.json @@ -69,6 +69,9 @@ "message": "选择要包含的试验特性:", "hint": "(↑/↓ 切换,空格选择,a 全选,回车确认)" }, + "needsAutomaticallyInstallDependencies": { + "message": "是否自动安装依赖?" + }, "needsRolldownVite": { "message": "rolldown-vite(试验阶段)" }, diff --git a/locales/zh-Hant.json b/locales/zh-Hant.json index 98cc63b2d..15a32e6e2 100644 --- a/locales/zh-Hant.json +++ b/locales/zh-Hant.json @@ -69,6 +69,9 @@ "message": "請選擇要包含的試驗特性:", "hint": "(↑/↓ 切換,空格選擇,a 全選,enter 確認)" }, + "needsAutomaticallyInstallDependencies": { + "message": "是否自動安裝相依套件?" + }, "needsRolldownVite": { "message": "rolldown-vite(試驗性功能)" }, diff --git a/utils/getLanguage.ts b/utils/getLanguage.ts index 5d81d2a00..1fccdaa7c 100644 --- a/utils/getLanguage.ts +++ b/utils/getLanguage.ts @@ -42,6 +42,7 @@ interface Language { needsOxlint: LanguageItem needsRolldownVite: LanguageItem needsBareboneTemplates: LanguageItem + needsAutomaticallyInstallDependencies: LanguageItem errors: { operationCancelled: string }