UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

29 lines (27 loc) 1.1 kB
import { bosContract } from "../contract.mjs"; import { cliCommandMeta } from "../contract.meta.mjs"; //#region src/cli/catalog.ts function splitCamelCase(value) { return value.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/\s+/).map((part) => part.trim()).filter(Boolean).map((part) => part.toLowerCase()); } const commandCatalog = Object.entries(bosContract).map(([key, procedure]) => { const meta = cliCommandMeta[key] ?? { summary: splitCamelCase(String(key)).join(" ") }; return { key, commandPath: meta.commandPath ?? splitCamelCase(String(key)), summary: meta.summary, meta, procedure }; }); function findCommandDescriptor(args) { const sorted = [...commandCatalog].sort((a, b) => b.commandPath.length - a.commandPath.length); for (const descriptor of sorted) if (args.slice(0, descriptor.commandPath.length).map((part) => part.toLowerCase()).join(" ") === descriptor.commandPath.join(" ")) return { descriptor, consumed: descriptor.commandPath.length }; return null; } //#endregion export { commandCatalog, findCommandDescriptor }; //# sourceMappingURL=catalog.mjs.map