Skip to content

Commit

Permalink
feat(cli): support adding all components (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing authored Sep 20, 2023
1 parent f2d66d4 commit 08fa517
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/cli/src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const addOptionsSchema = z.object({
yes: z.boolean(),
overwrite: z.boolean(),
cwd: z.string(),
all: z.boolean(),
path: z.string().optional(),
})

Expand All @@ -39,6 +40,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 All @@ -64,8 +66,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: 'autocompleteMultiselect',
name: 'components',
Expand All @@ -75,6 +79,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 08fa517

Please sign in to comment.