feat(cli): add overwrite confirmation for existing components (#66)

This commit is contained in:
Dunqing 2023-09-20 16:50:42 +08:00 committed by GitHub
parent 05da2d82f3
commit f2d66d4632
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -128,15 +128,28 @@ export const add = new Command()
if (existingComponent.length && !options.overwrite) { if (existingComponent.length && !options.overwrite) {
if (selectedComponents.includes(item.name)) { if (selectedComponents.includes(item.name)) {
logger.warn( spinner.stop()
`Component ${item.name} already exists. Use ${chalk.green( const { overwrite } = await prompts({
'--overwrite', type: 'confirm',
)} to overwrite.`, name: 'overwrite',
) message: `Component ${item.name} already exists. Would you like to overwrite?`,
process.exit(1) initial: false,
} })
continue if (!overwrite) {
logger.info(
`Skipped ${item.name}. To overwrite, run with the ${chalk.green(
'--overwrite',
)} flag.`,
)
continue
}
spinner.start(`Installing ${item.name}...`)
}
else {
continue
}
} }
for (const file of item.files) { for (const file of item.files) {