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,16 +128,29 @@ 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({
type: 'confirm',
name: 'overwrite',
message: `Component ${item.name} already exists. Would you like to overwrite?`,
initial: false,
})
if (!overwrite) {
logger.info(
`Skipped ${item.name}. To overwrite, run with the ${chalk.green(
'--overwrite', '--overwrite',
)} to overwrite.`, )} flag.`,
) )
process.exit(1) continue
} }
spinner.start(`Installing ${item.name}...`)
}
else {
continue continue
} }
}
for (const file of item.files) { for (const file of item.files) {
const componentDir = path.resolve(targetDir, item.name) const componentDir = path.resolve(targetDir, item.name)