Skip to content

Commit 58d012e

Browse files
plbstlshadcn
andauthored
feat(cli): add overwrite confirmation for existing components (#973)
* feat(cli): add overwrite confirmation for existing components * fix(cli): handle overwrite for multiple items * chore: add changeset --------- Co-authored-by: shadcn <m@shadcn.com>
1 parent 963114e commit 58d012e

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

.changeset/tidy-cows-poke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"shadcn-ui": minor
3+
---
4+
5+
ask for overwrite

packages/cli/src/commands/add.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,27 @@ export const add = new Command()
138138

139139
if (existingComponent.length && !options.overwrite) {
140140
if (selectedComponents.includes(item.name)) {
141-
logger.warn(
142-
`Component ${item.name} already exists. Use ${chalk.green(
143-
"--overwrite"
144-
)} to overwrite.`
145-
)
146-
process.exit(1)
147-
}
141+
spinner.stop()
142+
const { overwrite } = await prompts({
143+
type: "confirm",
144+
name: "overwrite",
145+
message: `Component ${item.name} already exists. Would you like to overwrite?`,
146+
initial: false,
147+
})
148+
149+
if (!overwrite) {
150+
logger.info(
151+
`Skipped ${item.name}. To overwrite, run with the ${chalk.green(
152+
"--overwrite"
153+
)} flag.`
154+
)
155+
continue
156+
}
148157

149-
continue
158+
spinner.start(`Installing ${item.name}...`)
159+
} else {
160+
continue
161+
}
150162
}
151163

152164
for (const file of item.files) {

0 commit comments

Comments
 (0)