From 963114e118a2263f4ee449cc07b0f6f7e5104bc1 Mon Sep 17 00:00:00 2001 From: Shishir Date: Mon, 18 Sep 2023 20:37:35 -0700 Subject: [PATCH] feat(cli): support adding all components via CLI (#1033) * feat: support adding all components via CLI `shadcn-ui add --all` This was manually tested to work as expected. * chore: run prettier * fix(cli): rename to all * chore: add changeset --------- Co-authored-by: shadcn --- .changeset/perfect-walls-dress.md | 5 +++++ packages/cli/src/commands/add.ts | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .changeset/perfect-walls-dress.md diff --git a/.changeset/perfect-walls-dress.md b/.changeset/perfect-walls-dress.md new file mode 100644 index 0000000000..33fdb7f125 --- /dev/null +++ b/.changeset/perfect-walls-dress.md @@ -0,0 +1,5 @@ +--- +"shadcn-ui": minor +--- + +add --all option diff --git a/packages/cli/src/commands/add.ts b/packages/cli/src/commands/add.ts index 01a1e30efc..bd33a94119 100644 --- a/packages/cli/src/commands/add.ts +++ b/packages/cli/src/commands/add.ts @@ -24,6 +24,7 @@ const addOptionsSchema = z.object({ yes: z.boolean(), overwrite: z.boolean(), cwd: z.string(), + all: z.boolean(), path: z.string().optional(), }) @@ -38,6 +39,7 @@ export const add = new Command() "the working directory. defaults to the current directory.", process.cwd() ) + .option("-a, --all", "add all available components", false) .option("-p, --path ", "the path to add the component to.") .action(async (components, opts) => { try { @@ -65,8 +67,10 @@ export const add = new Command() const registryIndex = await getRegistryIndex() - let selectedComponents = options.components - if (!options.components?.length) { + let selectedComponents = options.all + ? registryIndex.map((entry) => entry.name) + : options.components + if (!options.components?.length && !options.all) { const { components } = await prompts({ type: "multiselect", name: "components", @@ -76,6 +80,9 @@ export const add = new Command() choices: registryIndex.map((entry) => ({ title: entry.name, value: entry.name, + selected: options.all + ? true + : options.components?.includes(entry.name), })), }) selectedComponents = components