pswui/packages/cli/src/helpers/registry.ts
p-sw 5f50d1d8f6 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.
2024-06-07 00:48:14 +09:00

33 lines
1.0 KiB
TypeScript

import {REGISTRY_URL, Registry} from '../const.js'
export async function getRegistry(): Promise<{ok: true; registry: Registry} | {ok: false; message: string}> {
const registryResponse = await fetch(REGISTRY_URL)
if (registryResponse.ok) {
return {
ok: true,
registry: (await registryResponse.json()) as Registry,
}
} else {
return {
ok: false,
message: `Error while fetching registry: ${registryResponse.status} ${registryResponse.statusText}`,
}
}
}
export async function getAvailableComponentNames(registry: Registry): Promise<string[]> {
return Object.keys(registry.components)
}
export async function getComponentURL(registry: Registry, componentName: string): Promise<string> {
return registry.base.replace('{componentName}', registry.components[componentName])
}
export async function getComponentRealname(
registry: Registry,
componentName: keyof Registry['components'],
): Promise<string> {
return registry.components[componentName].split('/').pop() ?? ''
}