Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 49 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type PromptResult = {
e2eFramework?: 'cypress' | 'nightwatch' | 'playwright'
experimentFeatures?: (typeof EXPERIMENTAL_FEATURE_OPTIONS)[number]['value'][]
needsBareboneTemplates?: boolean
needsAutomaticallyInstallDependencies?: boolean
}

function isValidPackageName(projectName) {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -680,25 +683,66 @@ 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`
}
outroMessage += ` ${bold(green(getCommand(packageManager, 'dev')))}\n`

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) => {
Expand Down
3 changes: 3 additions & 0 deletions locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
},
Expand Down
3 changes: 3 additions & 0 deletions locales/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
},
Expand Down
3 changes: 3 additions & 0 deletions locales/tr-TR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
},
Expand Down
3 changes: 3 additions & 0 deletions locales/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
"message": "选择要包含的试验特性:",
"hint": "(↑/↓ 切换,空格选择,a 全选,回车确认)"
},
"needsAutomaticallyInstallDependencies": {
"message": "是否自动安装依赖?"
},
"needsRolldownVite": {
"message": "rolldown-vite(试验阶段)"
},
Expand Down
3 changes: 3 additions & 0 deletions locales/zh-Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
"message": "請選擇要包含的試驗特性:",
"hint": "(↑/↓ 切換,空格選擇,a 全選,enter 確認)"
},
"needsAutomaticallyInstallDependencies": {
"message": "是否自動安裝相依套件?"
},
"needsRolldownVite": {
"message": "rolldown-vite(試驗性功能)"
},
Expand Down
1 change: 1 addition & 0 deletions utils/getLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface Language {
needsOxlint: LanguageItem
needsRolldownVite: LanguageItem
needsBareboneTemplates: LanguageItem
needsAutomaticallyInstallDependencies: LanguageItem
errors: {
operationCancelled: string
}
Expand Down
Loading