From 5f50d1d8f6680f2e399a2fcc8d74d3ecd9bf3599 Mon Sep 17 00:00:00 2001 From: p-sw Date: Fri, 7 Jun 2024 00:48:14 +0900 Subject: [PATCH] feat(cli): add realname resolution for components The update enhances the CLI functionality by introducing the realname resolution for components. This is done in the 'list.ts' file, through a new helper function 'getComponentRealName' that is called whenever list of installed components is required. This ensures the correct identifiers are always considered, regardless of them being aliases or actual names. --- packages/cli/src/commands/list.ts | 9 ++++++--- packages/cli/src/helpers/registry.ts | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/commands/list.ts b/packages/cli/src/commands/list.ts index 894f795..ea45423 100644 --- a/packages/cli/src/commands/list.ts +++ b/packages/cli/src/commands/list.ts @@ -1,5 +1,5 @@ import {Command, Flags} from '@oclif/core' -import {getAvailableComponentNames, getRegistry, getComponentURL} from '../helpers/registry.js' +import {getAvailableComponentNames, getRegistry, getComponentURL, getComponentRealname} from '../helpers/registry.js' import ora from 'ora' import treeify from 'treeify' import {CONFIG_DEFAULT_PATH} from '../const.js' @@ -36,12 +36,15 @@ export default class List extends Command { const names = await getAvailableComponentNames(registry) getInstalledSpinner.start() - const installedNames = await getComponentsInstalled(names, loadedConfig) + const installedNames = await getComponentsInstalled( + await Promise.all(names.map(async (name) => await getComponentRealname(registry, name))), + loadedConfig, + ) getInstalledSpinner.succeed(`Got ${installedNames.length} installed components.`) let final: Record = {} for (const name of names) { - const installed = installedNames.includes(name) ? 'yes' : 'no' + const installed = installedNames.includes(await getComponentRealname(registry, name)) ? 'yes' : 'no' if (flags.url) { const url = await getComponentURL(registry, name) final = {...final, [name]: {URL: url, installed}} diff --git a/packages/cli/src/helpers/registry.ts b/packages/cli/src/helpers/registry.ts index 9b84611..b6cd780 100644 --- a/packages/cli/src/helpers/registry.ts +++ b/packages/cli/src/helpers/registry.ts @@ -23,3 +23,10 @@ export async function getAvailableComponentNames(registry: Registry): Promise { return registry.base.replace('{componentName}', registry.components[componentName]) } + +export async function getComponentRealname( + registry: Registry, + componentName: keyof Registry['components'], +): Promise { + return registry.components[componentName].split('/').pop() ?? '' +}