feat(cli): add overwrite confirmation for existing components

This commit is contained in:
Dunqing 2023-09-20 15:35:08 +08:00
parent 686ac00cab
commit 6f84c9b441

View File

@ -128,19 +128,28 @@ export const add = new Command()
if (existingComponent.length && !options.overwrite) {
if (selectedComponents.includes(item.name)) {
logger.warn(
`\nComponent ${
item.name
} already exists. Use ${chalk.green(
'--overwrite',
)} to overwrite.`,
)
spinner.stop()
process.exitCode = 1
return
}
const { overwrite } = await prompts({
type: 'confirm',
name: 'overwrite',
message: `Component ${item.name} already exists. Would you like to overwrite?`,
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) {