feat(cli): add cli error logs (#235)

This commit is contained in:
pengzhanbo 2024-10-01 01:24:32 +08:00 committed by GitHub
parent ebef7e6031
commit 713e7bcc2a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,7 +20,13 @@ export async function run(mode: Mode, root?: string) {
const progress = spinner() const progress = spinner()
progress.start(t('spinner.start')) progress.start(t('spinner.start'))
try {
await generate(mode, data) 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, // Delay for some time, I/O may not be completed yet,
// executing subsequent tasks at this point may cause issues. // executing subsequent tasks at this point may cause issues.
@ -29,15 +35,27 @@ export async function run(mode: Mode, root?: string) {
const cwd = path.join(process.cwd(), data.root) const cwd = path.join(process.cwd(), data.root)
if (data.git) { if (data.git) {
progress.message(t('spinner.git')) progress.message(t('spinner.git'))
try {
await execaCommand('git init', { cwd }) await execaCommand('git init', { cwd })
} }
catch (e) {
console.error(`${colors.red('git init error: ')}\n`, e)
process.exit(1)
}
}
const pm = data.packageManager const pm = data.packageManager
if (data.install) { if (data.install) {
progress.message(t('spinner.install')) progress.message(t('spinner.install'))
try {
await execaCommand(pm === 'yarn' ? 'yarn' : `${pm} install`, { cwd }) 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}`) : '' const cdCommand = mode === Mode.create ? colors.green(`cd ${data.root}`) : ''
const runCommand = colors.green(pm === 'yarn' ? 'yarn docs:dev' : `${pm} run docs:dev`) const runCommand = colors.green(pm === 'yarn' ? 'yarn docs:dev' : `${pm} run docs:dev`)