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 (selectedComponents.includes(item.name)) {
logger.warn(
`Component ${item.name} already exists. Use ${chalk.green(
spinner.stop()
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',
)} to overwrite.`,
)} flag.`,
)
process.exit(1)
continue
}
spinner.start(`Installing ${item.name}...`)
}
else {
continue
}
}
for (const file of item.files) {
const componentDir = path.resolve(targetDir, item.name)