From 91d9b9f9f3a11531b930844ddde0c0b5f533c7ab Mon Sep 17 00:00:00 2001 From: p-sw Date: Fri, 7 Jun 2024 19:00:50 +0900 Subject: [PATCH] refactor(cli): normalize component name input This change includes normalization of user input for component name by converting it to lowercase during the installation process. This is done to ensure that component names are not case sensitive and that any input will match the existing component names in the registry. --- packages/cli/src/commands/add.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/commands/add.ts b/packages/cli/src/commands/add.ts index 926283f..3703c00 100644 --- a/packages/cli/src/commands/add.ts +++ b/packages/cli/src/commands/add.ts @@ -31,6 +31,8 @@ export default class Add extends Command { this.error('No component name provided. Please provide name of component you want to be installed.') } + const name = args.name.toLowerCase() + const resolvedConfig = await validateConfig((message: string) => this.log(message), await loadConfig(flags.config)) const componentFolder = join(process.cwd(), resolvedConfig.paths.components) const sharedFile = join(process.cwd(), resolvedConfig.paths.shared) @@ -49,8 +51,8 @@ export default class Add extends Command { const componentNames = await getAvailableComponentNames(registry) loadRegistryOra.succeed(`Successfully fetched registry! (${componentNames.length} components)`) - if (!componentNames.includes(args.name)) { - this.error(`Component with name ${args.name} does not exists in registry. Please provide correct name.`) + if (!componentNames.includes(name)) { + this.error(`Component with name ${name} does not exists in registry. Please provide correct name.`) } const sharedFileOra = ora('Installing shared module...').start() @@ -69,12 +71,12 @@ export default class Add extends Command { sharedFileOra.succeed('Shared module is already installed!') } - const componentFileOra = ora(`Installing ${args.name} component...`).start() - const componentFile = join(componentFolder, registry.components[args.name]) + const componentFileOra = ora(`Installing ${name} component...`).start() + const componentFile = join(componentFolder, registry.components[name]) if (existsSync(componentFile) && !flags.force) { componentFileOra.succeed(`Component is already installed! (${componentFile})`) } else { - const componentFileContentResponse = await fetch(await getComponentURL(registry, args.name)) + const componentFileContentResponse = await fetch(await getComponentURL(registry, name)) if (!componentFileContentResponse.ok) { componentFileOra.fail( `Error while fetching component file content: ${componentFileContentResponse.status} ${componentFileContentResponse.statusText}`,