Skip to content

Commit

Permalink
feat(cli): add overwrite confirmation for existing components (#973)
Browse files Browse the repository at this point in the history
* feat(cli):  add overwrite confirmation for existing components

* fix(cli): handle overwrite for multiple items

* chore: add changeset

---------

Co-authored-by: shadcn <[email protected]>
  • Loading branch information
plbstl and shadcn authored Sep 19, 2023
1 parent 963114e commit 58d012e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-cows-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"shadcn-ui": minor
---

ask for overwrite
28 changes: 20 additions & 8 deletions packages/cli/src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,27 @@ 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(
"--overwrite"
)} to overwrite.`
)
process.exit(1)
}
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"
)} flag.`
)
continue
}

continue
spinner.start(`Installing ${item.name}...`)
} else {
continue
}
}

for (const file of item.files) {
Expand Down

0 comments on commit 58d012e

Please sign in to comment.