feat(cli): support adding all components (#65)

This commit is contained in:
Dunqing 2023-09-20 16:52:14 +08:00 committed by GitHub
parent f2d66d4632
commit 08fa517eb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,6 +25,7 @@ const addOptionsSchema = z.object({
yes: z.boolean(), yes: z.boolean(),
overwrite: z.boolean(), overwrite: z.boolean(),
cwd: z.string(), cwd: z.string(),
all: z.boolean(),
path: z.string().optional(), path: z.string().optional(),
}) })
@ -39,6 +40,7 @@ export const add = new Command()
'the working directory. defaults to the current directory.', 'the working directory. defaults to the current directory.',
process.cwd(), process.cwd(),
) )
.option('-a, --all', 'add all available components', false)
.option('-p, --path <path>', 'the path to add the component to.') .option('-p, --path <path>', 'the path to add the component to.')
.action(async (components, opts) => { .action(async (components, opts) => {
try { try {
@ -64,8 +66,10 @@ export const add = new Command()
const registryIndex = await getRegistryIndex() const registryIndex = await getRegistryIndex()
let selectedComponents = options.components let selectedComponents = options.all
if (!options.components?.length) { ? registryIndex.map(entry => entry.name)
: options.components
if (!options.components?.length && !options.all) {
const { components } = await prompts({ const { components } = await prompts({
type: 'autocompleteMultiselect', type: 'autocompleteMultiselect',
name: 'components', name: 'components',
@ -75,6 +79,9 @@ export const add = new Command()
choices: registryIndex.map(entry => ({ choices: registryIndex.map(entry => ({
title: entry.name, title: entry.name,
value: entry.name, value: entry.name,
selected: options.all
? true
: options.components?.includes(entry.name),
})), })),
}) })
selectedComponents = components selectedComponents = components