Skip to content

Commit

Permalink
feat(cli): support adding all components via CLI (#1033)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
sramam and shadcn committed Sep 19, 2023
1 parent 0a42865 commit 963114e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-walls-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"shadcn-ui": minor
---

add --all option
11 changes: 9 additions & 2 deletions packages/cli/src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const addOptionsSchema = z.object({
yes: z.boolean(),
overwrite: z.boolean(),
cwd: z.string(),
all: z.boolean(),
path: z.string().optional(),
})

Expand All @@ -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 <path>", "the path to add the component to.")
.action(async (components, opts) => {
try {
Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand Down

0 comments on commit 963114e

Please sign in to comment.