Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add cli error logs #235

Merged
merged 1 commit into from
Sep 30, 2024
Merged
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
24 changes: 21 additions & 3 deletions cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ export async function run(mode: Mode, root?: string) {
const progress = spinner()
progress.start(t('spinner.start'))

await generate(mode, data)
try {
await generate(mode, data)
}
catch (e) {
console.error(`${colors.red('generate files error: ')}\n`, e)
process.exit(1)
}

// Delay for some time, I/O may not be completed yet,
// executing subsequent tasks at this point may cause issues.
Expand All @@ -29,14 +35,26 @@ export async function run(mode: Mode, root?: string) {
const cwd = path.join(process.cwd(), data.root)
if (data.git) {
progress.message(t('spinner.git'))
await execaCommand('git init', { cwd })
try {
await execaCommand('git init', { cwd })
}
catch (e) {
console.error(`${colors.red('git init error: ')}\n`, e)
process.exit(1)
}
}

const pm = data.packageManager

if (data.install) {
progress.message(t('spinner.install'))
await execaCommand(pm === 'yarn' ? 'yarn' : `${pm} install`, { cwd })
try {
await execaCommand(pm === 'yarn' ? 'yarn' : `${pm} install`, { cwd })
}
catch (e) {
console.error(`${colors.red('install dependencies error: ')}\n`, e)
process.exit(1)
}
}

const cdCommand = mode === Mode.create ? colors.green(`cd ${data.root}`) : ''
Expand Down