From 58d012e342d2563b4c43ed2ac18879a6d5044980 Mon Sep 17 00:00:00 2001 From: Paul Ebose <49006567+plbstl@users.noreply.github.com> Date: Tue, 19 Sep 2023 12:57:19 +0100 Subject: [PATCH] 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 --- .changeset/tidy-cows-poke.md | 5 +++++ packages/cli/src/commands/add.ts | 28 ++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 .changeset/tidy-cows-poke.md diff --git a/.changeset/tidy-cows-poke.md b/.changeset/tidy-cows-poke.md new file mode 100644 index 00000000000..360edb64eb7 --- /dev/null +++ b/.changeset/tidy-cows-poke.md @@ -0,0 +1,5 @@ +--- +"shadcn-ui": minor +--- + +ask for overwrite diff --git a/packages/cli/src/commands/add.ts b/packages/cli/src/commands/add.ts index bd33a94119e..553e430de41 100644 --- a/packages/cli/src/commands/add.ts +++ b/packages/cli/src/commands/add.ts @@ -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) {