@shell-shock/core 0.5.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/components/docs.d.cts +5 -5
- package/dist/components/docs.d.mts +5 -5
- package/dist/components/index.cjs +3 -1
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.mts +2 -2
- package/dist/components/index.mjs +2 -2
- package/dist/components/options-parser-logic.cjs +127 -31
- package/dist/components/options-parser-logic.cjs.map +1 -1
- package/dist/components/options-parser-logic.d.cts +37 -10
- package/dist/components/options-parser-logic.d.cts.map +1 -1
- package/dist/components/options-parser-logic.d.mts +31 -4
- package/dist/components/options-parser-logic.d.mts.map +1 -1
- package/dist/components/options-parser-logic.mjs +126 -32
- package/dist/components/options-parser-logic.mjs.map +1 -1
- package/dist/components/usage.cjs +6 -5
- package/dist/components/usage.cjs.map +1 -1
- package/dist/components/usage.d.cts +2 -4
- package/dist/components/usage.d.cts.map +1 -1
- package/dist/components/usage.d.mts +2 -4
- package/dist/components/usage.d.mts.map +1 -1
- package/dist/components/usage.mjs +7 -6
- package/dist/components/usage.mjs.map +1 -1
- package/dist/helpers/persistence.cjs +48 -3
- package/dist/helpers/persistence.cjs.map +1 -1
- package/dist/helpers/persistence.mjs +48 -3
- package/dist/helpers/persistence.mjs.map +1 -1
- package/dist/helpers/resolve-command.cjs +103 -53
- package/dist/helpers/resolve-command.cjs.map +1 -1
- package/dist/helpers/resolve-command.mjs +105 -55
- package/dist/helpers/resolve-command.mjs.map +1 -1
- package/dist/helpers/validations.cjs +20 -20
- package/dist/helpers/validations.cjs.map +1 -1
- package/dist/helpers/validations.mjs +21 -21
- package/dist/helpers/validations.mjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/plugin-utils/context-helpers.cjs +105 -4
- package/dist/plugin-utils/context-helpers.cjs.map +1 -1
- package/dist/plugin-utils/context-helpers.d.cts +89 -3
- package/dist/plugin-utils/context-helpers.d.cts.map +1 -1
- package/dist/plugin-utils/context-helpers.d.mts +89 -3
- package/dist/plugin-utils/context-helpers.d.mts.map +1 -1
- package/dist/plugin-utils/context-helpers.mjs +99 -3
- package/dist/plugin-utils/context-helpers.mjs.map +1 -1
- package/dist/plugin-utils/get-command-tree.cjs +1 -1
- package/dist/plugin-utils/get-command-tree.cjs.map +1 -1
- package/dist/plugin-utils/get-command-tree.mjs +2 -2
- package/dist/plugin-utils/get-command-tree.mjs.map +1 -1
- package/dist/plugin-utils/index.cjs +7 -2
- package/dist/plugin-utils/index.d.cts +2 -2
- package/dist/plugin-utils/index.d.mts +2 -2
- package/dist/plugin-utils/index.mjs +2 -2
- package/dist/plugin.cjs +1 -1
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +2 -2
- package/dist/plugin.mjs.map +1 -1
- package/dist/types/command.d.cts +291 -9
- package/dist/types/command.d.cts.map +1 -1
- package/dist/types/command.d.mts +291 -9
- package/dist/types/command.d.mts.map +1 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.mts +2 -2
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-command.cjs","names":["esbuildPlugin","reflect","ReflectionClass","ReflectionKind","ReflectionVisibility","stringifyType","toArray","appendPath","commonPath","findFilePath","findFolderName","stripStars","replacePath","resolveParentPath","constantCase","titleCase","isSetObject","isSetString","resolveModule","getAppTitle","getPositionalCommandOptionName","isPositionalCommandOption","getDefaultOptions","resolveCommandOptionDescription","kind","optional","name","title","defaultValue","boolean","array","trim","number","resolveCommandId","context","file","commandsPath","split","filter","p","Boolean","join","replaceAll","resolveCommandName","path","requireExtension","resolveCommandPath","resolveCommandParams","map","findCommandsRoot","config","entry","projectRoot","workspaceConfig","workspaceRoot","Array","isArray","length","sourceRoot","extractCommandOption","command","reflection","propertyType","getType","option","getNameAsString","alias","getTags","description","getDescription","getKind","isOptional","getDefaultValue","env","default","variadic","type","string","Error","extractCommandPositionalOption","segment","reflectCommandTree","parent","isVirtual","replace","tree","positional","options","children","input","fs","existsSync","debug","id","resolved","plugins","reflectionLevel","metadata","function","parameters","firstParam","objectLiteral","class","optionsReflection","from","propertyReflection","getProperties","segments","reduce","obj","index","paramName","Object","values","forEach","types","addProperty","undefined","visibility","public","tags","domain","inputs","slice","every","value"],"sources":["../../src/helpers/resolve-command.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport type {\n ReflectionProperty,\n TypeParameter\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n reflect,\n ReflectionClass,\n ReflectionKind,\n ReflectionVisibility,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { commonPath } from \"@stryke/path/common\";\nimport { findFilePath, findFolderName } from \"@stryke/path/file-path-fns\";\nimport { stripStars } from \"@stryke/path/normalize\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { resolveModule } from \"powerlines/lib/utilities/resolve\";\nimport {\n getAppTitle,\n getPositionalCommandOptionName,\n isPositionalCommandOption\n} from \"../plugin-utils/context-helpers\";\nimport type {\n CommandInput,\n CommandModule,\n CommandOption,\n CommandPositionalOption,\n CommandTree,\n NumberCommandOption,\n StringCommandOption\n} from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport { getDefaultOptions } from \"./utilities\";\n\n/**\n * Resolves the description for a command option based on its reflection.\n *\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param name - The name of the command option.\n * @param title - The title of the command option, if any.\n * @param defaultValue - The default value of the command option, if any.\n * @returns The resolved description for the command option.\n */\nexport function resolveCommandOptionDescription(\n kind: ReflectionKind,\n optional: boolean,\n name: string,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} ${\n kind === ReflectionKind.boolean\n ? \"flag provided via the command-line\"\n : \"command-line option\"\n } that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : kind === ReflectionKind.array\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.number ? \"numeric\" : \"string\"} value${\n kind === ReflectionKind.array ? \"s\" : \"\"\n }`\n } that will be used in the application.`;\n}\n\nexport function resolveCommandId(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && !isPositionalCommandOption(p))\n .join(\"/\")\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .replaceAll(\"/\", \"-\");\n}\n\n/**\n * Finds the command name from the given file path.\n *\n * @param file - The file path to extract the command name from.\n * @returns The command name.\n */\nexport function resolveCommandName(file: string) {\n let path = findFilePath(file);\n let name = findFolderName(file, {\n requireExtension: true\n });\n\n while (isPositionalCommandOption(name)) {\n path = resolveParentPath(path);\n name = findFolderName(path, {\n requireExtension: true\n });\n }\n\n return name;\n}\n\nexport function resolveCommandPath(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\");\n}\n\nexport function resolveCommandParams(context: Context, file: string): string[] {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && isPositionalCommandOption(p))\n .map(p => p.replaceAll(/^\\[+/g, \"\").replaceAll(/\\]+$/g, \"\"));\n}\n\nexport function findCommandsRoot(context: Context): string {\n if (isSetString(context.config.entry)) {\n return appendPath(\n appendPath(stripStars(context.config.entry), context.config.projectRoot),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n isSetObject(context.config.entry) &&\n \"file\" in context.config.entry\n ) {\n return appendPath(\n appendPath(\n stripStars(context.config.entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n Array.isArray(context.config.entry) &&\n context.config.entry.length > 0\n ) {\n return commonPath(\n context.config.entry.map(entry =>\n appendPath(\n appendPath(\n stripStars(isSetString(entry) ? entry : entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\n }\n\n return appendPath(\n context.config.sourceRoot || context.config.projectRoot,\n context.workspaceConfig.workspaceRoot\n );\n}\n\n/**\n * Extracts command parameter information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command option information.\n */\nexport function extractCommandOption(\n command: CommandInput,\n reflection: ReflectionProperty\n): CommandOption {\n const propertyType = reflection.getType();\n\n const option = {\n name: reflection.getNameAsString(),\n alias: reflection.getTags().alias ?? [],\n title:\n reflection.getTags().title?.trim() ||\n titleCase(reflection.getNameAsString()),\n description:\n reflection.getDescription() ||\n resolveCommandOptionDescription(\n reflection.getKind(),\n reflection.isOptional(),\n reflection.getNameAsString(),\n reflection.getTags().title,\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getNameAsString()),\n kind: propertyType.kind as\n | ReflectionKind.string\n | ReflectionKind.number\n | ReflectionKind.boolean,\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n variadic: false\n } as CommandOption;\n if (propertyType.kind === ReflectionKind.array) {\n if (\n propertyType.type.kind === ReflectionKind.string ||\n propertyType.type.kind === ReflectionKind.number\n ) {\n (option as StringCommandOption | NumberCommandOption).variadic = true;\n (option as StringCommandOption | NumberCommandOption).kind =\n propertyType.type.kind;\n } else {\n throw new Error(\n `Unsupported array type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported.`\n );\n }\n } else if (\n propertyType.kind !== ReflectionKind.boolean &&\n propertyType.kind !== ReflectionKind.string &&\n propertyType.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n propertyType\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return option;\n}\n\n/**\n * Extracts command parameter information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param segment - The command path segment corresponding to the parameter.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command option information.\n */\nexport function extractCommandPositionalOption(\n command: CommandInput,\n segment: string,\n reflection: TypeParameter\n): CommandPositionalOption {\n if (\n reflection.type.kind !== ReflectionKind.string &&\n reflection.type.kind !== ReflectionKind.number &&\n !(\n reflection.type.kind === ReflectionKind.array &&\n (reflection.type.type.kind === ReflectionKind.string ||\n reflection.type.type.kind === ReflectionKind.number)\n )\n ) {\n throw new Error(\n `Unsupported type for positional option \"${segment}\" in command \"${\n command.name\n }\". Only string and number types (or string[] and number[]) are supported, received ${stringifyType(\n reflection.type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const option = {\n name: segment,\n alias: [],\n title: titleCase(segment),\n description:\n reflection.description ||\n resolveCommandOptionDescription(\n reflection.type.kind,\n !!reflection.optional,\n segment,\n titleCase(segment),\n reflection.default\n ),\n env: constantCase(segment),\n kind: reflection.type.kind,\n optional: reflection.optional,\n default: reflection.default,\n variadic: false\n } as CommandPositionalOption;\n\n if (reflection.type.kind === ReflectionKind.array) {\n if (\n reflection.type.type.kind === ReflectionKind.string ||\n reflection.type.type.kind === ReflectionKind.number\n ) {\n (option as StringCommandOption | NumberCommandOption).variadic = true;\n (option as StringCommandOption | NumberCommandOption).kind =\n reflection.type.type.kind;\n } else {\n throw new Error(\n `Unsupported array type for option \"${segment}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported.`\n );\n }\n }\n\n return option;\n}\n\n/**\n * Reflects the command tree for a given command input.\n *\n * @param context - The context in which the command is being reflected.\n * @param command - The command input to reflect.\n * @param parent - The parent command tree, if any.\n * @returns The reflected command tree.\n */\nexport async function reflectCommandTree<TContext extends Context = Context>(\n context: TContext,\n command: CommandInput,\n parent?: CommandTree\n): Promise<CommandTree> {\n const title =\n command.title ||\n `${parent?.title ? `${parent.isVirtual ? parent.title.replace(/ Commands$/, \"\") : parent.title} - ` : \"\"}${titleCase(command.name)}${\n command.isVirtual ? \" Commands\" : \"\"\n }`;\n\n const tree = {\n alias: [],\n ...command,\n title,\n path: {\n ...command.path,\n positional: {}\n },\n options: getDefaultOptions(context, command),\n parent: parent ?? null,\n children: {}\n } as CommandTree;\n\n if (!command.isVirtual) {\n if (\n !command.entry.input?.file ||\n !context.fs.existsSync(command.entry.input.file)\n ) {\n throw new Error(\n `${\n !command.entry.input?.file ? \"Missing\" : \"Non-existent\"\n } command entry file for \"${command.name}\"`\n );\n }\n\n context.debug(\n `Adding reflection for user-defined command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n const resolved = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n reflectionLevel: \"verbose\"\n })\n ]\n }\n );\n\n const metadata = resolved.metadata ?? {};\n if (isSetString(metadata.title)) {\n tree.title = metadata.title;\n }\n if (isSetString(metadata.description)) {\n tree.description = metadata.description;\n }\n if (\n isSetString(metadata.alias) ||\n (Array.isArray(metadata.alias) && metadata.alias.length > 0)\n ) {\n tree.alias = toArray(metadata.alias);\n }\n\n const type = reflect(resolved);\n\n // const type = await reflectType<TContext>(context, command.entry.input);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `The command entry file \"${command.entry.input.file}\" does not export a valid function.`\n );\n }\n\n tree.description ??=\n command.description ||\n type.description ||\n `The ${tree.title} executable command-line interface.`;\n\n if (type.parameters.length > 0 && type.parameters[0]) {\n const firstParam = type.parameters[0];\n if (\n firstParam.type.kind === ReflectionKind.objectLiteral ||\n firstParam.type.kind === ReflectionKind.class\n ) {\n const optionsReflection = ReflectionClass.from(firstParam.type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n tree.options[propertyReflection.getNameAsString()] =\n extractCommandOption(command, propertyReflection);\n }\n }\n\n tree.path.positional = tree.path.segments\n .filter(segment => isPositionalCommandOption(segment))\n .reduce(\n (obj, segment, index) => {\n if (\n type.parameters.length < index + 2 ||\n !type.parameters[index + 1]\n ) {\n return obj;\n }\n\n const paramName = getPositionalCommandOptionName(segment);\n obj[paramName] = extractCommandPositionalOption(\n command,\n paramName,\n type.parameters[index + 1]!\n );\n\n obj[paramName].description =\n obj[paramName].description ||\n `The ${paramName} positional option for the ${command.name} command.`;\n\n return obj;\n },\n {} as Record<string, CommandPositionalOption>\n );\n }\n } else {\n tree.description ??= `A collection of available ${\n tree.title || titleCase(tree.name)\n } commands that are included in the ${getAppTitle(\n context\n )} command-line application.`;\n }\n\n if (context.env) {\n if (isSetObject(tree.options)) {\n Object.values(tree.options)\n .filter(option => option.env !== false)\n .forEach(option => {\n context.env.types.env.addProperty({\n name: option.env as string,\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type:\n option.kind === ReflectionKind.string ||\n option.kind === ReflectionKind.number\n ? option.variadic\n ? { kind: ReflectionKind.array, type: { kind: option.kind } }\n : { kind: option.kind }\n : { kind: ReflectionKind.boolean },\n default: option.default,\n tags: {\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 0)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n if (\n Object.values(tree.path.positional).filter(option => option.env !== false)\n .length > 0\n ) {\n Object.values(tree.path.positional)\n .filter(option => option.env !== false)\n .forEach(option =>\n context.env.types.env.addProperty({\n name: constantCase(option.name),\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type: option.variadic\n ? {\n kind: ReflectionKind.array,\n type: { kind: ReflectionKind.string }\n }\n : { kind: ReflectionKind.string },\n default: option.default,\n tags: {\n domain: \"cli\"\n }\n })\n );\n }\n }\n\n for (const input of context.inputs.filter(\n input =>\n input.path.segments.filter(segment => !isPositionalCommandOption(segment))\n .length ===\n command.path.segments.filter(\n segment => !isPositionalCommandOption(segment)\n ).length +\n 1 &&\n input.path.segments\n .slice(0, command.path.segments.length)\n .every((value, index) => value === command.path.segments[index])\n )) {\n tree.children[input.name] = await reflectCommandTree(context, input, tree);\n }\n\n return tree;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqEA,SAAgBuB,gCACdC,MACAC,UACAC,MACAC,OACAC,cACQ;AACR,QAAO,IAAIH,YAAY,CAACG,eAAe,eAAe,GAAE,GACtDJ,SAASrB,gDAAe0B,UACpB,uCACA,sBAAqB,2BAEzBL,SAASrB,gDAAe0B,UACpB,YACAL,SAASrB,gDAAe2B,QACtB,mBACA,mBAAkB,GACtBH,OAAOI,MAAM,qDAAcL,KAAK,CAAA,GAClCF,SAASrB,gDAAe0B,UACpB,cACA,GAAGL,SAASrB,gDAAe6B,SAAS,YAAY,SAAQ,QACtDR,SAASrB,gDAAe2B,QAAQ,MAAM,KACtC;;AAIV,SAAgBG,iBAAiBC,SAAkBC,MAAsB;AACvE,6FAAgCA,KAAK,EAAED,QAAQE,aAAa,CACz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B2D,QACxC,CAAC,CAACvB,SACA,KACJgC,QAAM7C,KAAK+D,SACRgB,MAAM,GAAG/D,QAAQhB,KAAK+D,SAASlD,OAAO,CACtCmE,OAAOC,OAAOf,UAAUe,UAAUjE,QAAQhB,KAAK+D,SAASG,OAC/D,CAAC,CACCzB,MAAKG,SAASC,MAAM/D,QAAQ,MAAMuD,mBAAmB/C,SAASuD,OAAOJ,KAAK;AAG5E,QAAOA"}
|
|
1
|
+
{"version":3,"file":"resolve-command.cjs","names":["esbuildPlugin","reflect","ReflectionClass","ReflectionFunction","ReflectionKind","ReflectionVisibility","stringifyType","toArray","appendPath","commonPath","findFilePath","findFolderName","stripStars","replacePath","resolveParentPath","constantCase","titleCase","isSetObject","isSetString","resolveModule","getAppTitle","getDynamicPathSegmentName","isCatchAllPathSegment","isDynamicPathSegment","isOptionalCatchAllPathSegment","isPathSegmentGroup","getDefaultOptions","resolveCommandOptionDescription","kind","optional","name","title","defaultValue","boolean","array","trim","number","resolveCommandParameterDescription","resolveCommandId","context","file","commandsPath","split","filter","p","Boolean","join","replaceAll","resolveCommandName","path","requireExtension","resolveCommandPath","resolveCommandDynamicPathSegments","map","findCommandsRoot","config","entry","projectRoot","workspaceConfig","workspaceRoot","Array","isArray","length","sourceRoot","extractCommandOption","command","reflection","type","getType","option","getNameAsString","alias","getTags","description","getDescription","getKind","isOptional","getDefaultValue","env","default","variadic","string","Error","extractCommandDynamicSegment","segment","getName","parameter","catchAll","segments","some","seg","extractCommandParameter","reflectCommandTree","parent","isVirtual","replace","tree","dynamics","options","params","children","input","fs","existsSync","debug","id","resolved","plugins","reflectionLevel","metadata","icon","function","parameters","getParameters","objectLiteral","class","optionsReflection","from","propertyReflection","getProperties","reduce","obj","index","paramName","Object","keys","slice","param","values","forEach","types","addProperty","undefined","visibility","public","tags","domain","inputs","every","value"],"sources":["../../src/helpers/resolve-command.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport type {\n ReflectionParameter,\n ReflectionProperty,\n TypeArray\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n reflect,\n ReflectionClass,\n ReflectionFunction,\n ReflectionKind,\n ReflectionVisibility,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { commonPath } from \"@stryke/path/common\";\nimport { findFilePath, findFolderName } from \"@stryke/path/file-path-fns\";\nimport { stripStars } from \"@stryke/path/normalize\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { resolveModule } from \"powerlines/lib/utilities/resolve\";\nimport {\n getAppTitle,\n getDynamicPathSegmentName,\n isCatchAllPathSegment,\n isDynamicPathSegment,\n isOptionalCatchAllPathSegment,\n isPathSegmentGroup\n} from \"../plugin-utils/context-helpers\";\nimport type {\n CommandDynamicSegment,\n CommandInput,\n CommandModule,\n CommandOption,\n CommandParameter,\n CommandTree,\n NumberCommandOption,\n NumberCommandParameter,\n StringCommandOption,\n StringCommandParameter\n} from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport { getDefaultOptions } from \"./utilities\";\n\n/**\n * Resolves the description for a command option based on its reflection.\n *\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param name - The name of the command option.\n * @param title - The title of the command option, if any.\n * @param defaultValue - The default value of the command option, if any.\n * @returns The resolved description for the command option.\n */\nexport function resolveCommandOptionDescription(\n kind: ReflectionKind,\n optional: boolean,\n name: string,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} ${\n kind === ReflectionKind.boolean\n ? \"flag provided via the command-line\"\n : \"command-line option\"\n } that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : kind === ReflectionKind.array\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.number ? \"numeric\" : \"string\"} value${\n kind === ReflectionKind.array ? \"s\" : \"\"\n }`\n } that will be used in the application.`;\n}\n\n/**\n * Resolves the description for a command parameter based on its reflection.\n *\n * @param kind - The reflection kind of the command parameter.\n * @param optional - Whether the command parameter is optional.\n * @param name - The name of the command parameter.\n * @param title - The title of the command parameter, if any.\n * @param defaultValue - The default value of the command parameter, if any.\n * @returns The resolved description for the command parameter.\n */\nexport function resolveCommandParameterDescription(\n kind: ReflectionKind,\n optional: boolean,\n name: string,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} command-line positional parameter that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : kind === ReflectionKind.array\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.number ? \"numeric\" : \"string\"} value${\n kind === ReflectionKind.array ? \"s\" : \"\"\n }`\n } that will be used in the application.`;\n}\n\nexport function resolveCommandId(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && !isDynamicPathSegment(p))\n .join(\"/\")\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .replaceAll(\"/\", \"-\");\n}\n\n/**\n * Finds the command name from the given file path.\n *\n * @param file - The file path to extract the command name from.\n * @returns The command name.\n */\nexport function resolveCommandName(file: string) {\n let path = findFilePath(file);\n let name = findFolderName(file, {\n requireExtension: true\n });\n\n while (isDynamicPathSegment(name)) {\n path = resolveParentPath(path);\n name = findFolderName(path, {\n requireExtension: true\n });\n }\n\n return name;\n}\n\nexport function resolveCommandPath(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .split(\"/\")\n .filter(path => path && !isPathSegmentGroup(path))\n .join(\"/\");\n}\n\nexport function resolveCommandDynamicPathSegments(\n context: Context,\n file: string\n): string[] {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(path => Boolean(path) && isDynamicPathSegment(path))\n .map(path => getDynamicPathSegmentName(path));\n}\n\nexport function findCommandsRoot(context: Context): string {\n if (isSetString(context.config.entry)) {\n return appendPath(\n appendPath(stripStars(context.config.entry), context.config.projectRoot),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n isSetObject(context.config.entry) &&\n \"file\" in context.config.entry\n ) {\n return appendPath(\n appendPath(\n stripStars(context.config.entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n Array.isArray(context.config.entry) &&\n context.config.entry.length > 0\n ) {\n return commonPath(\n context.config.entry.map(entry =>\n appendPath(\n appendPath(\n stripStars(isSetString(entry) ? entry : entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\n }\n\n return appendPath(\n context.config.sourceRoot || context.config.projectRoot,\n context.workspaceConfig.workspaceRoot\n );\n}\n\n/**\n * Extracts command parameter information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command option information.\n */\nexport function extractCommandOption(\n command: CommandInput,\n reflection: ReflectionProperty\n): CommandOption {\n const type = reflection.getType();\n\n const option = {\n name: reflection.getNameAsString(),\n alias: reflection.getTags().alias ?? [],\n title:\n reflection.getTags().title?.trim() ||\n titleCase(reflection.getNameAsString()),\n description:\n reflection.getDescription() ||\n resolveCommandOptionDescription(\n reflection.getKind(),\n reflection.isOptional(),\n reflection.getNameAsString(),\n reflection.getTags().title,\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getNameAsString()),\n kind: type.kind as\n | ReflectionKind.string\n | ReflectionKind.number\n | ReflectionKind.boolean,\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n variadic: reflection.isArray(),\n reflection\n } as CommandOption;\n\n if (reflection.isArray()) {\n if (\n (type as TypeArray).type.kind === ReflectionKind.string ||\n (type as TypeArray).type.kind === ReflectionKind.number\n ) {\n (option as StringCommandOption | NumberCommandOption).variadic = true;\n (option as StringCommandOption | NumberCommandOption).kind = (\n type as TypeArray\n ).type.kind as ReflectionKind.string | ReflectionKind.number;\n } else {\n throw new Error(\n `Unsupported array type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return option;\n}\n\n/**\n * Extracts command dynamic path segment information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param segment - The command path segment corresponding to the parameter.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command dynamic segment information.\n */\nexport function extractCommandDynamicSegment(\n command: CommandInput,\n segment: string,\n reflection: ReflectionParameter\n): CommandDynamicSegment {\n const type = reflection.getType();\n\n if (\n type.kind !== ReflectionKind.string &&\n !(\n type.kind === ReflectionKind.array &&\n type.type.kind === ReflectionKind.string\n )\n ) {\n throw new Error(\n `Unsupported type for dynamic path segment \"${segment}\" in command \"${\n command.name\n }\". Only string types (or an array of strings) are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const option = {\n name: reflection.getName(),\n segment,\n title: reflection.getTags().title || titleCase(segment),\n description:\n reflection.parameter.description ||\n resolveCommandOptionDescription(\n type.kind,\n !!reflection.isOptional(),\n segment,\n titleCase(segment),\n reflection.getDefaultValue()\n ),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n catchAll: command.path.segments.some(\n seg =>\n getDynamicPathSegmentName(segment) === seg && isCatchAllPathSegment(seg)\n ),\n reflection\n } as CommandDynamicSegment;\n\n if (type.kind === ReflectionKind.array) {\n if (!option.catchAll) {\n throw new Error(\n `Dynamic path segment \"${segment}\" in command \"${\n command.name\n }\" is an array type but is not defined as a catch-all segment. To use an array type for a dynamic path segment, it must be defined as a catch-all segment using the \"[...segment]\" syntax.`\n );\n }\n\n option.variadic = true;\n }\n\n if (option.catchAll) {\n if (\n !option.optional &&\n command.path.segments.some(\n seg =>\n getDynamicPathSegmentName(segment) === seg &&\n isOptionalCatchAllPathSegment(seg)\n )\n ) {\n throw new Error(\n `Dynamic path segment \"${segment}\" in command \"${\n command.name\n }\" is defined as a catch-all segment but is not optional. To define an optional catch-all segment, use the \"[[...segment]]\" syntax.`\n );\n } else if (\n option.optional &&\n !command.path.segments.some(\n seg =>\n getDynamicPathSegmentName(segment) === seg &&\n isOptionalCatchAllPathSegment(seg)\n )\n ) {\n throw new Error(\n `Dynamic path segment \"${segment}\" in command \"${\n command.name\n }\" is defined as an optional segment but is not defined as an optional catch-all segment. To define an optional catch-all segment, use the \"[[...segment]]\" syntax.`\n );\n }\n }\n\n return option;\n}\n\n/**\n * Extracts command positional parameter information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command positional parameter information.\n */\nexport function extractCommandParameter(\n command: CommandInput,\n reflection: ReflectionParameter\n): CommandParameter {\n const type = reflection.getType();\n\n if (\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number &&\n type.kind !== ReflectionKind.boolean &&\n !(\n type.kind === ReflectionKind.array &&\n (type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number)\n )\n ) {\n throw new Error(\n `Unsupported type for positional parameter \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string types (or an array of strings) are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const option = {\n name: reflection.getName(),\n title: titleCase(reflection.getName()),\n description:\n reflection.parameter.description ||\n resolveCommandParameterDescription(\n type.kind,\n !!reflection.isOptional(),\n reflection.getName(),\n titleCase(reflection.getName()),\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getName()),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n reflection\n } as CommandParameter;\n\n if (type.kind === ReflectionKind.array) {\n if (\n type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number\n ) {\n (option as StringCommandParameter | NumberCommandParameter).variadic =\n true;\n (option as StringCommandParameter | NumberCommandParameter).kind =\n type.type.kind;\n } else {\n throw new Error(\n `Unsupported array type for positional parameter \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for positional parameter \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return option;\n}\n\n/**\n * Reflects the command tree for a given command input.\n *\n * @param context - The context in which the command is being reflected.\n * @param command - The command input to reflect.\n * @param parent - The parent command tree, if any.\n * @returns The reflected command tree.\n */\nexport async function reflectCommandTree<TContext extends Context = Context>(\n context: TContext,\n command: CommandInput,\n parent?: CommandTree\n): Promise<CommandTree> {\n const title =\n command.title ||\n `${\n parent?.title\n ? `${\n parent.isVirtual\n ? parent.title.replace(/ Commands$/, \"\")\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const tree = {\n alias: [],\n ...command,\n title,\n path: {\n ...command.path,\n dynamics: {}\n },\n options: getDefaultOptions(context, command),\n params: [],\n parent: parent ?? null,\n children: {},\n reflection: null\n } as CommandTree;\n\n if (!command.isVirtual) {\n if (\n !command.entry.input?.file ||\n !context.fs.existsSync(command.entry.input.file)\n ) {\n throw new Error(\n `${\n !command.entry.input?.file ? \"Missing\" : \"Non-existent\"\n } command entry file for \"${command.name}\"`\n );\n }\n\n context.debug(\n `Adding reflection for user-defined command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n const resolved = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n reflectionLevel: \"verbose\"\n })\n ]\n }\n );\n\n const metadata = resolved.metadata ?? {};\n if (isSetString(metadata.title)) {\n tree.title = metadata.title;\n }\n if (isSetString(metadata.description)) {\n tree.description = metadata.description;\n }\n if (\n isSetString(metadata.alias) ||\n (Array.isArray(metadata.alias) && metadata.alias.length > 0)\n ) {\n tree.alias = toArray(metadata.alias);\n }\n if (isSetString(metadata.icon)) {\n tree.icon = metadata.icon;\n }\n\n const type = reflect(resolved);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `The command entry file \"${command.entry.input.file}\" does not export a valid function.`\n );\n }\n\n tree.reflection = new ReflectionFunction(type);\n tree.description ??=\n command.description ||\n type.description ||\n `The ${tree.title} executable command line interface.`;\n\n const parameters = tree.reflection.getParameters();\n if (parameters.length > 0 && parameters[0]) {\n if (\n parameters[0].type.kind === ReflectionKind.objectLiteral ||\n parameters[0].type.kind === ReflectionKind.class\n ) {\n const optionsReflection = ReflectionClass.from(parameters[0].type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n tree.options[propertyReflection.getNameAsString()] =\n extractCommandOption(command, propertyReflection);\n }\n } else {\n throw new Error(\n `The first parameter of the command handler function in \"${\n command.entry.input.file\n }\" must be an object literal or class type representing the command options.`\n );\n }\n\n tree.path.dynamics = tree.path.segments\n .filter(segment => isDynamicPathSegment(segment))\n .reduce(\n (obj, segment, index) => {\n if (parameters.length < index + 2 || !parameters[index + 1]) {\n return obj;\n }\n\n const paramName = getDynamicPathSegmentName(segment);\n obj[paramName] = extractCommandDynamicSegment(\n command,\n paramName,\n parameters[index + 1]!\n );\n\n obj[paramName].description =\n obj[paramName].description ||\n `The ${paramName} ${\n obj[paramName].catchAll\n ? `${obj[paramName].optional ? \"optional \" : \"\"}catch-all`\n : \"dynamic \"\n } segment for the ${command.name} command.`;\n\n return obj;\n },\n {} as Record<string, CommandDynamicSegment>\n );\n\n if (parameters.length > Object.keys(tree.path.dynamics).length + 1) {\n tree.params = parameters\n .slice(Object.keys(tree.path.dynamics).length + 1)\n .map(param => extractCommandParameter(command, param));\n }\n }\n } else {\n tree.description ??= `A collection of available ${\n tree.title || titleCase(tree.name)\n } commands that are included in the ${getAppTitle(\n context\n )} command line application.`;\n }\n\n if (context.env) {\n if (isSetObject(tree.options)) {\n Object.values(tree.options)\n .filter(option => option.env !== false)\n .forEach(option => {\n context.env.types.env.addProperty({\n name: option.env as string,\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type:\n option.reflection?.getType() ??\n ((option as StringCommandOption | NumberCommandOption).variadic\n ? { kind: ReflectionKind.array, type: { kind: option.kind } }\n : { kind: option.kind }),\n default: option.default,\n tags: {\n ...option.reflection?.getTags(),\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 0)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n Object.values(tree.params)\n .filter(param => param.env !== false)\n .forEach(param =>\n context.env.types.env.addProperty({\n name: constantCase(param.name),\n optional: param.optional ? true : undefined,\n description: param.description,\n visibility: ReflectionVisibility.public,\n type: param.reflection.getType(),\n default: param.default,\n tags: {\n ...param.reflection.getTags(),\n domain: \"cli\"\n }\n })\n );\n }\n\n for (const input of context.inputs.filter(\n input =>\n input.path.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n command.path.segments.filter(segment => !isDynamicPathSegment(segment))\n .length +\n 1 &&\n input.path.segments\n .slice(0, command.path.segments.length)\n .every((value, index) => value === command.path.segments[index])\n )) {\n tree.children[input.name] = await reflectCommandTree(context, input, tree);\n }\n\n return tree;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,SAAgB2B,gCACdC,MACAC,UACAC,MACAC,OACAC,cACQ;AACR,QAAO,IAAIH,YAAY,CAACG,eAAe,eAAe,GAAE,GACtDJ,SAASxB,gDAAe6B,UACpB,uCACA,sBAAqB,2BAEzBL,SAASxB,gDAAe6B,UACpB,YACAL,SAASxB,gDAAe8B,QACtB,mBACA,mBAAkB,GACtBH,OAAOI,MAAM,qDAAcL,KAAK,CAAA,GAClCF,SAASxB,gDAAe6B,UACpB,cACA,GAAGL,SAASxB,gDAAegC,SAAS,YAAY,SAAQ,QACtDR,SAASxB,gDAAe8B,QAAQ,MAAM,KACtC;;;;;;;;;;;;AAcV,SAAgBG,mCACdT,MACAC,UACAC,MACAC,OACAC,cACQ;AACR,QAAO,IAAIH,YAAY,CAACG,eAAe,eAAe,GAAE,6DACtDJ,SAASxB,gDAAe6B,UACpB,YACAL,SAASxB,gDAAe8B,QACtB,mBACA,mBAAkB,GACtBH,OAAOI,MAAM,qDAAcL,KAAK,CAAA,GA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B,KAAKuC,SAAS1B,OAAO,CACtC4E,OAAOC,OAAOjB,UAAUiB,UAAU1E,QAAQhB,KAAKuC,SAASkC,OAC/D,CAAC,CACC1B,MAAKI,SAASC,MAAMvE,QAAQ,MAAM8D,mBAAmBrD,SAAS8D,OAAOL,KAAK;AAG5E,QAAOA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getAppTitle,
|
|
1
|
+
import { getAppTitle, getDynamicPathSegmentName, isCatchAllPathSegment, isDynamicPathSegment, isOptionalCatchAllPathSegment, isPathSegmentGroup } from "../plugin-utils/context-helpers.mjs";
|
|
2
2
|
import { getDefaultOptions } from "./utilities.mjs";
|
|
3
3
|
import { toArray } from "@stryke/convert/to-array";
|
|
4
4
|
import { appendPath } from "@stryke/path/append";
|
|
@@ -9,7 +9,7 @@ import { constantCase } from "@stryke/string-format/constant-case";
|
|
|
9
9
|
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
10
10
|
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
11
11
|
import { titleCase } from "@stryke/string-format/title-case";
|
|
12
|
-
import { ReflectionClass, ReflectionKind, ReflectionVisibility, reflect, stringifyType } from "@powerlines/deepkit/vendor/type";
|
|
12
|
+
import { ReflectionClass, ReflectionFunction, ReflectionKind, ReflectionVisibility, reflect, stringifyType } from "@powerlines/deepkit/vendor/type";
|
|
13
13
|
import { esbuildPlugin } from "@powerlines/deepkit/esbuild-plugin";
|
|
14
14
|
import { commonPath } from "@stryke/path/common";
|
|
15
15
|
import { stripStars } from "@stryke/path/normalize";
|
|
@@ -29,8 +29,21 @@ import { resolveModule } from "powerlines/lib/utilities/resolve";
|
|
|
29
29
|
function resolveCommandOptionDescription(kind, optional, name, title, defaultValue) {
|
|
30
30
|
return `A${optional && !defaultValue ? "n optional" : ""} ${kind === ReflectionKind.boolean ? "flag provided via the command-line" : "command-line option"} that allows the user to ${kind === ReflectionKind.boolean ? "set the" : kind === ReflectionKind.array ? "specify custom" : "specify a custom"} ${title?.trim() || titleCase(name)} ${kind === ReflectionKind.boolean ? "indicator" : `${kind === ReflectionKind.number ? "numeric" : "string"} value${kind === ReflectionKind.array ? "s" : ""}`} that will be used in the application.`;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Resolves the description for a command parameter based on its reflection.
|
|
34
|
+
*
|
|
35
|
+
* @param kind - The reflection kind of the command parameter.
|
|
36
|
+
* @param optional - Whether the command parameter is optional.
|
|
37
|
+
* @param name - The name of the command parameter.
|
|
38
|
+
* @param title - The title of the command parameter, if any.
|
|
39
|
+
* @param defaultValue - The default value of the command parameter, if any.
|
|
40
|
+
* @returns The resolved description for the command parameter.
|
|
41
|
+
*/
|
|
42
|
+
function resolveCommandParameterDescription(kind, optional, name, title, defaultValue) {
|
|
43
|
+
return `A${optional && !defaultValue ? "n optional" : ""} command-line positional parameter that allows the user to ${kind === ReflectionKind.boolean ? "set the" : kind === ReflectionKind.array ? "specify custom" : "specify a custom"} ${title?.trim() || titleCase(name)} ${kind === ReflectionKind.boolean ? "indicator" : `${kind === ReflectionKind.number ? "numeric" : "string"} value${kind === ReflectionKind.array ? "s" : ""}`} that will be used in the application.`;
|
|
44
|
+
}
|
|
32
45
|
function resolveCommandId(context, file) {
|
|
33
|
-
return replacePath(findFilePath(file), context.commandsPath).split("/").filter((p) => Boolean(p) && !
|
|
46
|
+
return replacePath(findFilePath(file), context.commandsPath).split("/").filter((p) => Boolean(p) && !isDynamicPathSegment(p)).join("/").replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "").replaceAll("/", "-");
|
|
34
47
|
}
|
|
35
48
|
/**
|
|
36
49
|
* Finds the command name from the given file path.
|
|
@@ -41,14 +54,14 @@ function resolveCommandId(context, file) {
|
|
|
41
54
|
function resolveCommandName(file) {
|
|
42
55
|
let path = findFilePath(file);
|
|
43
56
|
let name = findFolderName(file, { requireExtension: true });
|
|
44
|
-
while (
|
|
57
|
+
while (isDynamicPathSegment(name)) {
|
|
45
58
|
path = resolveParentPath(path);
|
|
46
59
|
name = findFolderName(path, { requireExtension: true });
|
|
47
60
|
}
|
|
48
61
|
return name;
|
|
49
62
|
}
|
|
50
63
|
function resolveCommandPath(context, file) {
|
|
51
|
-
return replacePath(findFilePath(file), context.commandsPath).replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "");
|
|
64
|
+
return replacePath(findFilePath(file), context.commandsPath).replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "").split("/").filter((path) => path && !isPathSegmentGroup(path)).join("/");
|
|
52
65
|
}
|
|
53
66
|
function findCommandsRoot(context) {
|
|
54
67
|
if (isSetString(context.config.entry)) return appendPath(appendPath(stripStars(context.config.entry), context.config.projectRoot), context.workspaceConfig.workspaceRoot);
|
|
@@ -64,50 +77,81 @@ function findCommandsRoot(context) {
|
|
|
64
77
|
* @returns The extracted command option information.
|
|
65
78
|
*/
|
|
66
79
|
function extractCommandOption(command, reflection) {
|
|
67
|
-
const
|
|
80
|
+
const type = reflection.getType();
|
|
68
81
|
const option = {
|
|
69
82
|
name: reflection.getNameAsString(),
|
|
70
83
|
alias: reflection.getTags().alias ?? [],
|
|
71
84
|
title: reflection.getTags().title?.trim() || titleCase(reflection.getNameAsString()),
|
|
72
85
|
description: reflection.getDescription() || resolveCommandOptionDescription(reflection.getKind(), reflection.isOptional(), reflection.getNameAsString(), reflection.getTags().title, reflection.getDefaultValue()),
|
|
73
86
|
env: constantCase(reflection.getNameAsString()),
|
|
74
|
-
kind:
|
|
87
|
+
kind: type.kind,
|
|
75
88
|
optional: reflection.isOptional(),
|
|
76
89
|
default: reflection.getDefaultValue(),
|
|
77
|
-
variadic:
|
|
90
|
+
variadic: reflection.isArray(),
|
|
91
|
+
reflection
|
|
78
92
|
};
|
|
79
|
-
if (
|
|
93
|
+
if (reflection.isArray()) if (type.type.kind === ReflectionKind.string || type.type.kind === ReflectionKind.number) {
|
|
80
94
|
option.variadic = true;
|
|
81
|
-
option.kind =
|
|
82
|
-
} else throw new Error(`Unsupported array type for option "${reflection.getNameAsString()}" in command "${command.name}". Only string[] and number[] are supported.`);
|
|
83
|
-
else if (
|
|
95
|
+
option.kind = type.type.kind;
|
|
96
|
+
} else throw new Error(`Unsupported array type for option "${reflection.getNameAsString()}" in command "${command.name}". Only string[] and number[] are supported, received ${stringifyType(type).trim().replaceAll(" | ", ", or ")}.`);
|
|
97
|
+
else if (type.kind !== ReflectionKind.boolean && type.kind !== ReflectionKind.string && type.kind !== ReflectionKind.number) throw new Error(`Unsupported type for option "${reflection.getNameAsString()}" in command "${command.name}". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(type).trim().replaceAll(" | ", ", or ")}.`);
|
|
84
98
|
return option;
|
|
85
99
|
}
|
|
86
100
|
/**
|
|
87
|
-
* Extracts command
|
|
101
|
+
* Extracts command dynamic path segment information from a type parameter reflection.
|
|
88
102
|
*
|
|
89
103
|
* @param command - The command tree to which the parameter belongs.
|
|
90
104
|
* @param segment - The command path segment corresponding to the parameter.
|
|
91
105
|
* @param reflection - The type parameter reflection to extract information from.
|
|
92
|
-
* @returns The extracted command
|
|
106
|
+
* @returns The extracted command dynamic segment information.
|
|
93
107
|
*/
|
|
94
|
-
function
|
|
95
|
-
|
|
108
|
+
function extractCommandDynamicSegment(command, segment, reflection) {
|
|
109
|
+
const type = reflection.getType();
|
|
110
|
+
if (type.kind !== ReflectionKind.string && !(type.kind === ReflectionKind.array && type.type.kind === ReflectionKind.string)) throw new Error(`Unsupported type for dynamic path segment "${segment}" in command "${command.name}". Only string types (or an array of strings) are supported, received ${stringifyType(type).trim().replaceAll(" | ", ", or ")}.`);
|
|
96
111
|
const option = {
|
|
97
|
-
name:
|
|
98
|
-
|
|
99
|
-
title: titleCase(segment),
|
|
100
|
-
description: reflection.description || resolveCommandOptionDescription(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
variadic: false
|
|
112
|
+
name: reflection.getName(),
|
|
113
|
+
segment,
|
|
114
|
+
title: reflection.getTags().title || titleCase(segment),
|
|
115
|
+
description: reflection.parameter.description || resolveCommandOptionDescription(type.kind, !!reflection.isOptional(), segment, titleCase(segment), reflection.getDefaultValue()),
|
|
116
|
+
optional: reflection.isOptional(),
|
|
117
|
+
default: reflection.getDefaultValue(),
|
|
118
|
+
catchAll: command.path.segments.some((seg) => getDynamicPathSegmentName(segment) === seg && isCatchAllPathSegment(seg)),
|
|
119
|
+
reflection
|
|
106
120
|
};
|
|
107
|
-
if (
|
|
121
|
+
if (type.kind === ReflectionKind.array) {
|
|
122
|
+
if (!option.catchAll) throw new Error(`Dynamic path segment "${segment}" in command "${command.name}" is an array type but is not defined as a catch-all segment. To use an array type for a dynamic path segment, it must be defined as a catch-all segment using the "[...segment]" syntax.`);
|
|
108
123
|
option.variadic = true;
|
|
109
|
-
|
|
110
|
-
|
|
124
|
+
}
|
|
125
|
+
if (option.catchAll) {
|
|
126
|
+
if (!option.optional && command.path.segments.some((seg) => getDynamicPathSegmentName(segment) === seg && isOptionalCatchAllPathSegment(seg))) throw new Error(`Dynamic path segment "${segment}" in command "${command.name}" is defined as a catch-all segment but is not optional. To define an optional catch-all segment, use the "[[...segment]]" syntax.`);
|
|
127
|
+
else if (option.optional && !command.path.segments.some((seg) => getDynamicPathSegmentName(segment) === seg && isOptionalCatchAllPathSegment(seg))) throw new Error(`Dynamic path segment "${segment}" in command "${command.name}" is defined as an optional segment but is not defined as an optional catch-all segment. To define an optional catch-all segment, use the "[[...segment]]" syntax.`);
|
|
128
|
+
}
|
|
129
|
+
return option;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Extracts command positional parameter information from a type parameter reflection.
|
|
133
|
+
*
|
|
134
|
+
* @param command - The command tree to which the parameter belongs.
|
|
135
|
+
* @param reflection - The type parameter reflection to extract information from.
|
|
136
|
+
* @returns The extracted command positional parameter information.
|
|
137
|
+
*/
|
|
138
|
+
function extractCommandParameter(command, reflection) {
|
|
139
|
+
const type = reflection.getType();
|
|
140
|
+
if (type.kind !== ReflectionKind.string && type.kind !== ReflectionKind.number && type.kind !== ReflectionKind.boolean && !(type.kind === ReflectionKind.array && (type.type.kind === ReflectionKind.string || type.type.kind === ReflectionKind.number))) throw new Error(`Unsupported type for positional parameter "${reflection.getName()}" in command "${command.name}". Only string types (or an array of strings) are supported, received ${stringifyType(type).trim().replaceAll(" | ", ", or ")}.`);
|
|
141
|
+
const option = {
|
|
142
|
+
name: reflection.getName(),
|
|
143
|
+
title: titleCase(reflection.getName()),
|
|
144
|
+
description: reflection.parameter.description || resolveCommandParameterDescription(type.kind, !!reflection.isOptional(), reflection.getName(), titleCase(reflection.getName()), reflection.getDefaultValue()),
|
|
145
|
+
env: constantCase(reflection.getName()),
|
|
146
|
+
optional: reflection.isOptional(),
|
|
147
|
+
default: reflection.getDefaultValue(),
|
|
148
|
+
reflection
|
|
149
|
+
};
|
|
150
|
+
if (type.kind === ReflectionKind.array) if (type.type.kind === ReflectionKind.string || type.type.kind === ReflectionKind.number) {
|
|
151
|
+
option.variadic = true;
|
|
152
|
+
option.kind = type.type.kind;
|
|
153
|
+
} else throw new Error(`Unsupported array type for positional parameter "${reflection.getName()}" in command "${command.name}". Only string[] and number[] are supported, received ${stringifyType(type).trim().replaceAll(" | ", ", or ")}.`);
|
|
154
|
+
else if (type.kind !== ReflectionKind.boolean && type.kind !== ReflectionKind.string && type.kind !== ReflectionKind.number) throw new Error(`Unsupported type for positional parameter "${reflection.getName()}" in command "${command.name}". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(type).trim().replaceAll(" | ", ", or ")}.`);
|
|
111
155
|
return option;
|
|
112
156
|
}
|
|
113
157
|
/**
|
|
@@ -126,11 +170,13 @@ async function reflectCommandTree(context, command, parent) {
|
|
|
126
170
|
title,
|
|
127
171
|
path: {
|
|
128
172
|
...command.path,
|
|
129
|
-
|
|
173
|
+
dynamics: {}
|
|
130
174
|
},
|
|
131
175
|
options: getDefaultOptions(context, command),
|
|
176
|
+
params: [],
|
|
132
177
|
parent: parent ?? null,
|
|
133
|
-
children: {}
|
|
178
|
+
children: {},
|
|
179
|
+
reflection: null
|
|
134
180
|
};
|
|
135
181
|
if (!command.isVirtual) {
|
|
136
182
|
if (!command.entry.input?.file || !context.fs.existsSync(command.entry.input.file)) throw new Error(`${!command.entry.input?.file ? "Missing" : "Non-existent"} command entry file for "${command.name}"`);
|
|
@@ -143,24 +189,27 @@ async function reflectCommandTree(context, command, parent) {
|
|
|
143
189
|
if (isSetString(metadata.title)) tree.title = metadata.title;
|
|
144
190
|
if (isSetString(metadata.description)) tree.description = metadata.description;
|
|
145
191
|
if (isSetString(metadata.alias) || Array.isArray(metadata.alias) && metadata.alias.length > 0) tree.alias = toArray(metadata.alias);
|
|
192
|
+
if (isSetString(metadata.icon)) tree.icon = metadata.icon;
|
|
146
193
|
const type = reflect(resolved);
|
|
147
194
|
if (type.kind !== ReflectionKind.function) throw new Error(`The command entry file "${command.entry.input.file}" does not export a valid function.`);
|
|
148
|
-
tree.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
195
|
+
tree.reflection = new ReflectionFunction(type);
|
|
196
|
+
tree.description ??= command.description || type.description || `The ${tree.title} executable command line interface.`;
|
|
197
|
+
const parameters = tree.reflection.getParameters();
|
|
198
|
+
if (parameters.length > 0 && parameters[0]) {
|
|
199
|
+
if (parameters[0].type.kind === ReflectionKind.objectLiteral || parameters[0].type.kind === ReflectionKind.class) {
|
|
200
|
+
const optionsReflection = ReflectionClass.from(parameters[0].type);
|
|
153
201
|
for (const propertyReflection of optionsReflection.getProperties()) tree.options[propertyReflection.getNameAsString()] = extractCommandOption(command, propertyReflection);
|
|
154
|
-
}
|
|
155
|
-
tree.path.
|
|
156
|
-
if (
|
|
157
|
-
const paramName =
|
|
158
|
-
obj[paramName] =
|
|
159
|
-
obj[paramName].description = obj[paramName].description || `The ${paramName}
|
|
202
|
+
} else throw new Error(`The first parameter of the command handler function in "${command.entry.input.file}" must be an object literal or class type representing the command options.`);
|
|
203
|
+
tree.path.dynamics = tree.path.segments.filter((segment) => isDynamicPathSegment(segment)).reduce((obj, segment, index) => {
|
|
204
|
+
if (parameters.length < index + 2 || !parameters[index + 1]) return obj;
|
|
205
|
+
const paramName = getDynamicPathSegmentName(segment);
|
|
206
|
+
obj[paramName] = extractCommandDynamicSegment(command, paramName, parameters[index + 1]);
|
|
207
|
+
obj[paramName].description = obj[paramName].description || `The ${paramName} ${obj[paramName].catchAll ? `${obj[paramName].optional ? "optional " : ""}catch-all` : "dynamic "} segment for the ${command.name} command.`;
|
|
160
208
|
return obj;
|
|
161
209
|
}, {});
|
|
210
|
+
if (parameters.length > Object.keys(tree.path.dynamics).length + 1) tree.params = parameters.slice(Object.keys(tree.path.dynamics).length + 1).map((param) => extractCommandParameter(command, param));
|
|
162
211
|
}
|
|
163
|
-
} else tree.description ??= `A collection of available ${tree.title || titleCase(tree.name)} commands that are included in the ${getAppTitle(context)} command
|
|
212
|
+
} else tree.description ??= `A collection of available ${tree.title || titleCase(tree.name)} commands that are included in the ${getAppTitle(context)} command line application.`;
|
|
164
213
|
if (context.env) {
|
|
165
214
|
if (isSetObject(tree.options)) Object.values(tree.options).filter((option) => option.env !== false).forEach((option) => {
|
|
166
215
|
context.env.types.env.addProperty({
|
|
@@ -168,32 +217,33 @@ async function reflectCommandTree(context, command, parent) {
|
|
|
168
217
|
optional: option.optional ? true : void 0,
|
|
169
218
|
description: option.description,
|
|
170
219
|
visibility: ReflectionVisibility.public,
|
|
171
|
-
type: option.
|
|
220
|
+
type: option.reflection?.getType() ?? (option.variadic ? {
|
|
172
221
|
kind: ReflectionKind.array,
|
|
173
222
|
type: { kind: option.kind }
|
|
174
|
-
} : { kind: option.kind }
|
|
223
|
+
} : { kind: option.kind }),
|
|
175
224
|
default: option.default,
|
|
176
225
|
tags: {
|
|
226
|
+
...option.reflection?.getTags(),
|
|
177
227
|
title: option.title,
|
|
178
228
|
alias: option.alias.filter((alias) => alias.length > 0).map((alias) => constantCase(alias)),
|
|
179
229
|
domain: "cli"
|
|
180
230
|
}
|
|
181
231
|
});
|
|
182
232
|
});
|
|
183
|
-
|
|
184
|
-
name: constantCase(
|
|
185
|
-
optional:
|
|
186
|
-
description:
|
|
233
|
+
Object.values(tree.params).filter((param) => param.env !== false).forEach((param) => context.env.types.env.addProperty({
|
|
234
|
+
name: constantCase(param.name),
|
|
235
|
+
optional: param.optional ? true : void 0,
|
|
236
|
+
description: param.description,
|
|
187
237
|
visibility: ReflectionVisibility.public,
|
|
188
|
-
type:
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
238
|
+
type: param.reflection.getType(),
|
|
239
|
+
default: param.default,
|
|
240
|
+
tags: {
|
|
241
|
+
...param.reflection.getTags(),
|
|
242
|
+
domain: "cli"
|
|
243
|
+
}
|
|
194
244
|
}));
|
|
195
245
|
}
|
|
196
|
-
for (const input of context.inputs.filter((input$1) => input$1.path.segments.filter((segment) => !
|
|
246
|
+
for (const input of context.inputs.filter((input$1) => input$1.path.segments.filter((segment) => !isDynamicPathSegment(segment)).length === command.path.segments.filter((segment) => !isDynamicPathSegment(segment)).length + 1 && input$1.path.segments.slice(0, command.path.segments.length).every((value, index) => value === command.path.segments[index]))) tree.children[input.name] = await reflectCommandTree(context, input, tree);
|
|
197
247
|
return tree;
|
|
198
248
|
}
|
|
199
249
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-command.mjs","names":["esbuildPlugin","reflect","ReflectionClass","ReflectionKind","ReflectionVisibility","stringifyType","toArray","appendPath","commonPath","findFilePath","findFolderName","stripStars","replacePath","resolveParentPath","constantCase","titleCase","isSetObject","isSetString","resolveModule","getAppTitle","getPositionalCommandOptionName","isPositionalCommandOption","getDefaultOptions","resolveCommandOptionDescription","kind","optional","name","title","defaultValue","boolean","array","trim","number","resolveCommandId","context","file","commandsPath","split","filter","p","Boolean","join","replaceAll","resolveCommandName","path","requireExtension","resolveCommandPath","resolveCommandParams","map","findCommandsRoot","config","entry","projectRoot","workspaceConfig","workspaceRoot","Array","isArray","length","sourceRoot","extractCommandOption","command","reflection","propertyType","getType","option","getNameAsString","alias","getTags","description","getDescription","getKind","isOptional","getDefaultValue","env","default","variadic","type","string","Error","extractCommandPositionalOption","segment","reflectCommandTree","parent","isVirtual","replace","tree","positional","options","children","input","fs","existsSync","debug","id","resolved","plugins","reflectionLevel","metadata","function","parameters","firstParam","objectLiteral","class","optionsReflection","from","propertyReflection","getProperties","segments","reduce","obj","index","paramName","Object","values","forEach","types","addProperty","undefined","visibility","public","tags","domain","inputs","slice","every","value"],"sources":["../../src/helpers/resolve-command.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport type {\n ReflectionProperty,\n TypeParameter\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n reflect,\n ReflectionClass,\n ReflectionKind,\n ReflectionVisibility,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { commonPath } from \"@stryke/path/common\";\nimport { findFilePath, findFolderName } from \"@stryke/path/file-path-fns\";\nimport { stripStars } from \"@stryke/path/normalize\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { resolveModule } from \"powerlines/lib/utilities/resolve\";\nimport {\n getAppTitle,\n getPositionalCommandOptionName,\n isPositionalCommandOption\n} from \"../plugin-utils/context-helpers\";\nimport type {\n CommandInput,\n CommandModule,\n CommandOption,\n CommandPositionalOption,\n CommandTree,\n NumberCommandOption,\n StringCommandOption\n} from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport { getDefaultOptions } from \"./utilities\";\n\n/**\n * Resolves the description for a command option based on its reflection.\n *\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param name - The name of the command option.\n * @param title - The title of the command option, if any.\n * @param defaultValue - The default value of the command option, if any.\n * @returns The resolved description for the command option.\n */\nexport function resolveCommandOptionDescription(\n kind: ReflectionKind,\n optional: boolean,\n name: string,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} ${\n kind === ReflectionKind.boolean\n ? \"flag provided via the command-line\"\n : \"command-line option\"\n } that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : kind === ReflectionKind.array\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.number ? \"numeric\" : \"string\"} value${\n kind === ReflectionKind.array ? \"s\" : \"\"\n }`\n } that will be used in the application.`;\n}\n\nexport function resolveCommandId(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && !isPositionalCommandOption(p))\n .join(\"/\")\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .replaceAll(\"/\", \"-\");\n}\n\n/**\n * Finds the command name from the given file path.\n *\n * @param file - The file path to extract the command name from.\n * @returns The command name.\n */\nexport function resolveCommandName(file: string) {\n let path = findFilePath(file);\n let name = findFolderName(file, {\n requireExtension: true\n });\n\n while (isPositionalCommandOption(name)) {\n path = resolveParentPath(path);\n name = findFolderName(path, {\n requireExtension: true\n });\n }\n\n return name;\n}\n\nexport function resolveCommandPath(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\");\n}\n\nexport function resolveCommandParams(context: Context, file: string): string[] {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && isPositionalCommandOption(p))\n .map(p => p.replaceAll(/^\\[+/g, \"\").replaceAll(/\\]+$/g, \"\"));\n}\n\nexport function findCommandsRoot(context: Context): string {\n if (isSetString(context.config.entry)) {\n return appendPath(\n appendPath(stripStars(context.config.entry), context.config.projectRoot),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n isSetObject(context.config.entry) &&\n \"file\" in context.config.entry\n ) {\n return appendPath(\n appendPath(\n stripStars(context.config.entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n Array.isArray(context.config.entry) &&\n context.config.entry.length > 0\n ) {\n return commonPath(\n context.config.entry.map(entry =>\n appendPath(\n appendPath(\n stripStars(isSetString(entry) ? entry : entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\n }\n\n return appendPath(\n context.config.sourceRoot || context.config.projectRoot,\n context.workspaceConfig.workspaceRoot\n );\n}\n\n/**\n * Extracts command parameter information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command option information.\n */\nexport function extractCommandOption(\n command: CommandInput,\n reflection: ReflectionProperty\n): CommandOption {\n const propertyType = reflection.getType();\n\n const option = {\n name: reflection.getNameAsString(),\n alias: reflection.getTags().alias ?? [],\n title:\n reflection.getTags().title?.trim() ||\n titleCase(reflection.getNameAsString()),\n description:\n reflection.getDescription() ||\n resolveCommandOptionDescription(\n reflection.getKind(),\n reflection.isOptional(),\n reflection.getNameAsString(),\n reflection.getTags().title,\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getNameAsString()),\n kind: propertyType.kind as\n | ReflectionKind.string\n | ReflectionKind.number\n | ReflectionKind.boolean,\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n variadic: false\n } as CommandOption;\n if (propertyType.kind === ReflectionKind.array) {\n if (\n propertyType.type.kind === ReflectionKind.string ||\n propertyType.type.kind === ReflectionKind.number\n ) {\n (option as StringCommandOption | NumberCommandOption).variadic = true;\n (option as StringCommandOption | NumberCommandOption).kind =\n propertyType.type.kind;\n } else {\n throw new Error(\n `Unsupported array type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported.`\n );\n }\n } else if (\n propertyType.kind !== ReflectionKind.boolean &&\n propertyType.kind !== ReflectionKind.string &&\n propertyType.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n propertyType\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return option;\n}\n\n/**\n * Extracts command parameter information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param segment - The command path segment corresponding to the parameter.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command option information.\n */\nexport function extractCommandPositionalOption(\n command: CommandInput,\n segment: string,\n reflection: TypeParameter\n): CommandPositionalOption {\n if (\n reflection.type.kind !== ReflectionKind.string &&\n reflection.type.kind !== ReflectionKind.number &&\n !(\n reflection.type.kind === ReflectionKind.array &&\n (reflection.type.type.kind === ReflectionKind.string ||\n reflection.type.type.kind === ReflectionKind.number)\n )\n ) {\n throw new Error(\n `Unsupported type for positional option \"${segment}\" in command \"${\n command.name\n }\". Only string and number types (or string[] and number[]) are supported, received ${stringifyType(\n reflection.type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const option = {\n name: segment,\n alias: [],\n title: titleCase(segment),\n description:\n reflection.description ||\n resolveCommandOptionDescription(\n reflection.type.kind,\n !!reflection.optional,\n segment,\n titleCase(segment),\n reflection.default\n ),\n env: constantCase(segment),\n kind: reflection.type.kind,\n optional: reflection.optional,\n default: reflection.default,\n variadic: false\n } as CommandPositionalOption;\n\n if (reflection.type.kind === ReflectionKind.array) {\n if (\n reflection.type.type.kind === ReflectionKind.string ||\n reflection.type.type.kind === ReflectionKind.number\n ) {\n (option as StringCommandOption | NumberCommandOption).variadic = true;\n (option as StringCommandOption | NumberCommandOption).kind =\n reflection.type.type.kind;\n } else {\n throw new Error(\n `Unsupported array type for option \"${segment}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported.`\n );\n }\n }\n\n return option;\n}\n\n/**\n * Reflects the command tree for a given command input.\n *\n * @param context - The context in which the command is being reflected.\n * @param command - The command input to reflect.\n * @param parent - The parent command tree, if any.\n * @returns The reflected command tree.\n */\nexport async function reflectCommandTree<TContext extends Context = Context>(\n context: TContext,\n command: CommandInput,\n parent?: CommandTree\n): Promise<CommandTree> {\n const title =\n command.title ||\n `${parent?.title ? `${parent.isVirtual ? parent.title.replace(/ Commands$/, \"\") : parent.title} - ` : \"\"}${titleCase(command.name)}${\n command.isVirtual ? \" Commands\" : \"\"\n }`;\n\n const tree = {\n alias: [],\n ...command,\n title,\n path: {\n ...command.path,\n positional: {}\n },\n options: getDefaultOptions(context, command),\n parent: parent ?? null,\n children: {}\n } as CommandTree;\n\n if (!command.isVirtual) {\n if (\n !command.entry.input?.file ||\n !context.fs.existsSync(command.entry.input.file)\n ) {\n throw new Error(\n `${\n !command.entry.input?.file ? \"Missing\" : \"Non-existent\"\n } command entry file for \"${command.name}\"`\n );\n }\n\n context.debug(\n `Adding reflection for user-defined command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n const resolved = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n reflectionLevel: \"verbose\"\n })\n ]\n }\n );\n\n const metadata = resolved.metadata ?? {};\n if (isSetString(metadata.title)) {\n tree.title = metadata.title;\n }\n if (isSetString(metadata.description)) {\n tree.description = metadata.description;\n }\n if (\n isSetString(metadata.alias) ||\n (Array.isArray(metadata.alias) && metadata.alias.length > 0)\n ) {\n tree.alias = toArray(metadata.alias);\n }\n\n const type = reflect(resolved);\n\n // const type = await reflectType<TContext>(context, command.entry.input);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `The command entry file \"${command.entry.input.file}\" does not export a valid function.`\n );\n }\n\n tree.description ??=\n command.description ||\n type.description ||\n `The ${tree.title} executable command-line interface.`;\n\n if (type.parameters.length > 0 && type.parameters[0]) {\n const firstParam = type.parameters[0];\n if (\n firstParam.type.kind === ReflectionKind.objectLiteral ||\n firstParam.type.kind === ReflectionKind.class\n ) {\n const optionsReflection = ReflectionClass.from(firstParam.type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n tree.options[propertyReflection.getNameAsString()] =\n extractCommandOption(command, propertyReflection);\n }\n }\n\n tree.path.positional = tree.path.segments\n .filter(segment => isPositionalCommandOption(segment))\n .reduce(\n (obj, segment, index) => {\n if (\n type.parameters.length < index + 2 ||\n !type.parameters[index + 1]\n ) {\n return obj;\n }\n\n const paramName = getPositionalCommandOptionName(segment);\n obj[paramName] = extractCommandPositionalOption(\n command,\n paramName,\n type.parameters[index + 1]!\n );\n\n obj[paramName].description =\n obj[paramName].description ||\n `The ${paramName} positional option for the ${command.name} command.`;\n\n return obj;\n },\n {} as Record<string, CommandPositionalOption>\n );\n }\n } else {\n tree.description ??= `A collection of available ${\n tree.title || titleCase(tree.name)\n } commands that are included in the ${getAppTitle(\n context\n )} command-line application.`;\n }\n\n if (context.env) {\n if (isSetObject(tree.options)) {\n Object.values(tree.options)\n .filter(option => option.env !== false)\n .forEach(option => {\n context.env.types.env.addProperty({\n name: option.env as string,\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type:\n option.kind === ReflectionKind.string ||\n option.kind === ReflectionKind.number\n ? option.variadic\n ? { kind: ReflectionKind.array, type: { kind: option.kind } }\n : { kind: option.kind }\n : { kind: ReflectionKind.boolean },\n default: option.default,\n tags: {\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 0)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n if (\n Object.values(tree.path.positional).filter(option => option.env !== false)\n .length > 0\n ) {\n Object.values(tree.path.positional)\n .filter(option => option.env !== false)\n .forEach(option =>\n context.env.types.env.addProperty({\n name: constantCase(option.name),\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type: option.variadic\n ? {\n kind: ReflectionKind.array,\n type: { kind: ReflectionKind.string }\n }\n : { kind: ReflectionKind.string },\n default: option.default,\n tags: {\n domain: \"cli\"\n }\n })\n );\n }\n }\n\n for (const input of context.inputs.filter(\n input =>\n input.path.segments.filter(segment => !isPositionalCommandOption(segment))\n .length ===\n command.path.segments.filter(\n segment => !isPositionalCommandOption(segment)\n ).length +\n 1 &&\n input.path.segments\n .slice(0, command.path.segments.length)\n .every((value, index) => value === command.path.segments[index])\n )) {\n tree.children[input.name] = await reflectCommandTree(context, input, tree);\n }\n\n return tree;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqEA,SAAgBuB,gCACdC,MACAC,UACAC,MACAC,OACAC,cACQ;AACR,QAAO,IAAIH,YAAY,CAACG,eAAe,eAAe,GAAE,GACtDJ,SAASrB,eAAe0B,UACpB,uCACA,sBAAqB,2BAEzBL,SAASrB,eAAe0B,UACpB,YACAL,SAASrB,eAAe2B,QACtB,mBACA,mBAAkB,GACtBH,OAAOI,MAAM,IAAIhB,UAAUW,KAAK,CAAA,GAClCF,SAASrB,eAAe0B,UACpB,cACA,GAAGL,SAASrB,eAAe6B,SAAS,YAAY,SAAQ,QACtDR,SAASrB,eAAe2B,QAAQ,MAAM,KACtC;;AAIV,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MAAMrB,eAAe0E,QAAO;IACrC,GACD,EAAErD,MAAMrB,eAAe0E,QAAQ;GACnCH,SAASV,OAAOU;GAChB8C,MAAM,EACJC,QAAQ,OACV;GACD,CACH,CAAC;;AAIP,MAAK,MAAMhC,SAASvD,QAAQwF,OAAOpF,QACjCmD,YACEA,QAAM7C,KAAK+D,SAASrE,QAAO0C,YAAW,CAAC3D,0BAA0B2D,QAAQ,CAAC,CACvEvB,WACDG,QAAQhB,KAAK+D,SAASrE,QACpB0C,YAAW,CAAC3D,0BAA0B2D,QACxC,CAAC,CAACvB,SACA,KACJgC,QAAM7C,KAAK+D,SACRgB,MAAM,GAAG/D,QAAQhB,KAAK+D,SAASlD,OAAO,CACtCmE,OAAOC,OAAOf,UAAUe,UAAUjE,QAAQhB,KAAK+D,SAASG,OAC/D,CAAC,CACCzB,MAAKG,SAASC,MAAM/D,QAAQ,MAAMuD,mBAAmB/C,SAASuD,OAAOJ,KAAK;AAG5E,QAAOA"}
|
|
1
|
+
{"version":3,"file":"resolve-command.mjs","names":["esbuildPlugin","reflect","ReflectionClass","ReflectionFunction","ReflectionKind","ReflectionVisibility","stringifyType","toArray","appendPath","commonPath","findFilePath","findFolderName","stripStars","replacePath","resolveParentPath","constantCase","titleCase","isSetObject","isSetString","resolveModule","getAppTitle","getDynamicPathSegmentName","isCatchAllPathSegment","isDynamicPathSegment","isOptionalCatchAllPathSegment","isPathSegmentGroup","getDefaultOptions","resolveCommandOptionDescription","kind","optional","name","title","defaultValue","boolean","array","trim","number","resolveCommandParameterDescription","resolveCommandId","context","file","commandsPath","split","filter","p","Boolean","join","replaceAll","resolveCommandName","path","requireExtension","resolveCommandPath","resolveCommandDynamicPathSegments","map","findCommandsRoot","config","entry","projectRoot","workspaceConfig","workspaceRoot","Array","isArray","length","sourceRoot","extractCommandOption","command","reflection","type","getType","option","getNameAsString","alias","getTags","description","getDescription","getKind","isOptional","getDefaultValue","env","default","variadic","string","Error","extractCommandDynamicSegment","segment","getName","parameter","catchAll","segments","some","seg","extractCommandParameter","reflectCommandTree","parent","isVirtual","replace","tree","dynamics","options","params","children","input","fs","existsSync","debug","id","resolved","plugins","reflectionLevel","metadata","icon","function","parameters","getParameters","objectLiteral","class","optionsReflection","from","propertyReflection","getProperties","reduce","obj","index","paramName","Object","keys","slice","param","values","forEach","types","addProperty","undefined","visibility","public","tags","domain","inputs","every","value"],"sources":["../../src/helpers/resolve-command.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport type {\n ReflectionParameter,\n ReflectionProperty,\n TypeArray\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n reflect,\n ReflectionClass,\n ReflectionFunction,\n ReflectionKind,\n ReflectionVisibility,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { commonPath } from \"@stryke/path/common\";\nimport { findFilePath, findFolderName } from \"@stryke/path/file-path-fns\";\nimport { stripStars } from \"@stryke/path/normalize\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { resolveModule } from \"powerlines/lib/utilities/resolve\";\nimport {\n getAppTitle,\n getDynamicPathSegmentName,\n isCatchAllPathSegment,\n isDynamicPathSegment,\n isOptionalCatchAllPathSegment,\n isPathSegmentGroup\n} from \"../plugin-utils/context-helpers\";\nimport type {\n CommandDynamicSegment,\n CommandInput,\n CommandModule,\n CommandOption,\n CommandParameter,\n CommandTree,\n NumberCommandOption,\n NumberCommandParameter,\n StringCommandOption,\n StringCommandParameter\n} from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport { getDefaultOptions } from \"./utilities\";\n\n/**\n * Resolves the description for a command option based on its reflection.\n *\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param name - The name of the command option.\n * @param title - The title of the command option, if any.\n * @param defaultValue - The default value of the command option, if any.\n * @returns The resolved description for the command option.\n */\nexport function resolveCommandOptionDescription(\n kind: ReflectionKind,\n optional: boolean,\n name: string,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} ${\n kind === ReflectionKind.boolean\n ? \"flag provided via the command-line\"\n : \"command-line option\"\n } that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : kind === ReflectionKind.array\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.number ? \"numeric\" : \"string\"} value${\n kind === ReflectionKind.array ? \"s\" : \"\"\n }`\n } that will be used in the application.`;\n}\n\n/**\n * Resolves the description for a command parameter based on its reflection.\n *\n * @param kind - The reflection kind of the command parameter.\n * @param optional - Whether the command parameter is optional.\n * @param name - The name of the command parameter.\n * @param title - The title of the command parameter, if any.\n * @param defaultValue - The default value of the command parameter, if any.\n * @returns The resolved description for the command parameter.\n */\nexport function resolveCommandParameterDescription(\n kind: ReflectionKind,\n optional: boolean,\n name: string,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} command-line positional parameter that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : kind === ReflectionKind.array\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.number ? \"numeric\" : \"string\"} value${\n kind === ReflectionKind.array ? \"s\" : \"\"\n }`\n } that will be used in the application.`;\n}\n\nexport function resolveCommandId(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && !isDynamicPathSegment(p))\n .join(\"/\")\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .replaceAll(\"/\", \"-\");\n}\n\n/**\n * Finds the command name from the given file path.\n *\n * @param file - The file path to extract the command name from.\n * @returns The command name.\n */\nexport function resolveCommandName(file: string) {\n let path = findFilePath(file);\n let name = findFolderName(file, {\n requireExtension: true\n });\n\n while (isDynamicPathSegment(name)) {\n path = resolveParentPath(path);\n name = findFolderName(path, {\n requireExtension: true\n });\n }\n\n return name;\n}\n\nexport function resolveCommandPath(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .split(\"/\")\n .filter(path => path && !isPathSegmentGroup(path))\n .join(\"/\");\n}\n\nexport function resolveCommandDynamicPathSegments(\n context: Context,\n file: string\n): string[] {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(path => Boolean(path) && isDynamicPathSegment(path))\n .map(path => getDynamicPathSegmentName(path));\n}\n\nexport function findCommandsRoot(context: Context): string {\n if (isSetString(context.config.entry)) {\n return appendPath(\n appendPath(stripStars(context.config.entry), context.config.projectRoot),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n isSetObject(context.config.entry) &&\n \"file\" in context.config.entry\n ) {\n return appendPath(\n appendPath(\n stripStars(context.config.entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n Array.isArray(context.config.entry) &&\n context.config.entry.length > 0\n ) {\n return commonPath(\n context.config.entry.map(entry =>\n appendPath(\n appendPath(\n stripStars(isSetString(entry) ? entry : entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\n }\n\n return appendPath(\n context.config.sourceRoot || context.config.projectRoot,\n context.workspaceConfig.workspaceRoot\n );\n}\n\n/**\n * Extracts command parameter information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command option information.\n */\nexport function extractCommandOption(\n command: CommandInput,\n reflection: ReflectionProperty\n): CommandOption {\n const type = reflection.getType();\n\n const option = {\n name: reflection.getNameAsString(),\n alias: reflection.getTags().alias ?? [],\n title:\n reflection.getTags().title?.trim() ||\n titleCase(reflection.getNameAsString()),\n description:\n reflection.getDescription() ||\n resolveCommandOptionDescription(\n reflection.getKind(),\n reflection.isOptional(),\n reflection.getNameAsString(),\n reflection.getTags().title,\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getNameAsString()),\n kind: type.kind as\n | ReflectionKind.string\n | ReflectionKind.number\n | ReflectionKind.boolean,\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n variadic: reflection.isArray(),\n reflection\n } as CommandOption;\n\n if (reflection.isArray()) {\n if (\n (type as TypeArray).type.kind === ReflectionKind.string ||\n (type as TypeArray).type.kind === ReflectionKind.number\n ) {\n (option as StringCommandOption | NumberCommandOption).variadic = true;\n (option as StringCommandOption | NumberCommandOption).kind = (\n type as TypeArray\n ).type.kind as ReflectionKind.string | ReflectionKind.number;\n } else {\n throw new Error(\n `Unsupported array type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return option;\n}\n\n/**\n * Extracts command dynamic path segment information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param segment - The command path segment corresponding to the parameter.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command dynamic segment information.\n */\nexport function extractCommandDynamicSegment(\n command: CommandInput,\n segment: string,\n reflection: ReflectionParameter\n): CommandDynamicSegment {\n const type = reflection.getType();\n\n if (\n type.kind !== ReflectionKind.string &&\n !(\n type.kind === ReflectionKind.array &&\n type.type.kind === ReflectionKind.string\n )\n ) {\n throw new Error(\n `Unsupported type for dynamic path segment \"${segment}\" in command \"${\n command.name\n }\". Only string types (or an array of strings) are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const option = {\n name: reflection.getName(),\n segment,\n title: reflection.getTags().title || titleCase(segment),\n description:\n reflection.parameter.description ||\n resolveCommandOptionDescription(\n type.kind,\n !!reflection.isOptional(),\n segment,\n titleCase(segment),\n reflection.getDefaultValue()\n ),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n catchAll: command.path.segments.some(\n seg =>\n getDynamicPathSegmentName(segment) === seg && isCatchAllPathSegment(seg)\n ),\n reflection\n } as CommandDynamicSegment;\n\n if (type.kind === ReflectionKind.array) {\n if (!option.catchAll) {\n throw new Error(\n `Dynamic path segment \"${segment}\" in command \"${\n command.name\n }\" is an array type but is not defined as a catch-all segment. To use an array type for a dynamic path segment, it must be defined as a catch-all segment using the \"[...segment]\" syntax.`\n );\n }\n\n option.variadic = true;\n }\n\n if (option.catchAll) {\n if (\n !option.optional &&\n command.path.segments.some(\n seg =>\n getDynamicPathSegmentName(segment) === seg &&\n isOptionalCatchAllPathSegment(seg)\n )\n ) {\n throw new Error(\n `Dynamic path segment \"${segment}\" in command \"${\n command.name\n }\" is defined as a catch-all segment but is not optional. To define an optional catch-all segment, use the \"[[...segment]]\" syntax.`\n );\n } else if (\n option.optional &&\n !command.path.segments.some(\n seg =>\n getDynamicPathSegmentName(segment) === seg &&\n isOptionalCatchAllPathSegment(seg)\n )\n ) {\n throw new Error(\n `Dynamic path segment \"${segment}\" in command \"${\n command.name\n }\" is defined as an optional segment but is not defined as an optional catch-all segment. To define an optional catch-all segment, use the \"[[...segment]]\" syntax.`\n );\n }\n }\n\n return option;\n}\n\n/**\n * Extracts command positional parameter information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command positional parameter information.\n */\nexport function extractCommandParameter(\n command: CommandInput,\n reflection: ReflectionParameter\n): CommandParameter {\n const type = reflection.getType();\n\n if (\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number &&\n type.kind !== ReflectionKind.boolean &&\n !(\n type.kind === ReflectionKind.array &&\n (type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number)\n )\n ) {\n throw new Error(\n `Unsupported type for positional parameter \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string types (or an array of strings) are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const option = {\n name: reflection.getName(),\n title: titleCase(reflection.getName()),\n description:\n reflection.parameter.description ||\n resolveCommandParameterDescription(\n type.kind,\n !!reflection.isOptional(),\n reflection.getName(),\n titleCase(reflection.getName()),\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getName()),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n reflection\n } as CommandParameter;\n\n if (type.kind === ReflectionKind.array) {\n if (\n type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number\n ) {\n (option as StringCommandParameter | NumberCommandParameter).variadic =\n true;\n (option as StringCommandParameter | NumberCommandParameter).kind =\n type.type.kind;\n } else {\n throw new Error(\n `Unsupported array type for positional parameter \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for positional parameter \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return option;\n}\n\n/**\n * Reflects the command tree for a given command input.\n *\n * @param context - The context in which the command is being reflected.\n * @param command - The command input to reflect.\n * @param parent - The parent command tree, if any.\n * @returns The reflected command tree.\n */\nexport async function reflectCommandTree<TContext extends Context = Context>(\n context: TContext,\n command: CommandInput,\n parent?: CommandTree\n): Promise<CommandTree> {\n const title =\n command.title ||\n `${\n parent?.title\n ? `${\n parent.isVirtual\n ? parent.title.replace(/ Commands$/, \"\")\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const tree = {\n alias: [],\n ...command,\n title,\n path: {\n ...command.path,\n dynamics: {}\n },\n options: getDefaultOptions(context, command),\n params: [],\n parent: parent ?? null,\n children: {},\n reflection: null\n } as CommandTree;\n\n if (!command.isVirtual) {\n if (\n !command.entry.input?.file ||\n !context.fs.existsSync(command.entry.input.file)\n ) {\n throw new Error(\n `${\n !command.entry.input?.file ? \"Missing\" : \"Non-existent\"\n } command entry file for \"${command.name}\"`\n );\n }\n\n context.debug(\n `Adding reflection for user-defined command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n const resolved = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n reflectionLevel: \"verbose\"\n })\n ]\n }\n );\n\n const metadata = resolved.metadata ?? {};\n if (isSetString(metadata.title)) {\n tree.title = metadata.title;\n }\n if (isSetString(metadata.description)) {\n tree.description = metadata.description;\n }\n if (\n isSetString(metadata.alias) ||\n (Array.isArray(metadata.alias) && metadata.alias.length > 0)\n ) {\n tree.alias = toArray(metadata.alias);\n }\n if (isSetString(metadata.icon)) {\n tree.icon = metadata.icon;\n }\n\n const type = reflect(resolved);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `The command entry file \"${command.entry.input.file}\" does not export a valid function.`\n );\n }\n\n tree.reflection = new ReflectionFunction(type);\n tree.description ??=\n command.description ||\n type.description ||\n `The ${tree.title} executable command line interface.`;\n\n const parameters = tree.reflection.getParameters();\n if (parameters.length > 0 && parameters[0]) {\n if (\n parameters[0].type.kind === ReflectionKind.objectLiteral ||\n parameters[0].type.kind === ReflectionKind.class\n ) {\n const optionsReflection = ReflectionClass.from(parameters[0].type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n tree.options[propertyReflection.getNameAsString()] =\n extractCommandOption(command, propertyReflection);\n }\n } else {\n throw new Error(\n `The first parameter of the command handler function in \"${\n command.entry.input.file\n }\" must be an object literal or class type representing the command options.`\n );\n }\n\n tree.path.dynamics = tree.path.segments\n .filter(segment => isDynamicPathSegment(segment))\n .reduce(\n (obj, segment, index) => {\n if (parameters.length < index + 2 || !parameters[index + 1]) {\n return obj;\n }\n\n const paramName = getDynamicPathSegmentName(segment);\n obj[paramName] = extractCommandDynamicSegment(\n command,\n paramName,\n parameters[index + 1]!\n );\n\n obj[paramName].description =\n obj[paramName].description ||\n `The ${paramName} ${\n obj[paramName].catchAll\n ? `${obj[paramName].optional ? \"optional \" : \"\"}catch-all`\n : \"dynamic \"\n } segment for the ${command.name} command.`;\n\n return obj;\n },\n {} as Record<string, CommandDynamicSegment>\n );\n\n if (parameters.length > Object.keys(tree.path.dynamics).length + 1) {\n tree.params = parameters\n .slice(Object.keys(tree.path.dynamics).length + 1)\n .map(param => extractCommandParameter(command, param));\n }\n }\n } else {\n tree.description ??= `A collection of available ${\n tree.title || titleCase(tree.name)\n } commands that are included in the ${getAppTitle(\n context\n )} command line application.`;\n }\n\n if (context.env) {\n if (isSetObject(tree.options)) {\n Object.values(tree.options)\n .filter(option => option.env !== false)\n .forEach(option => {\n context.env.types.env.addProperty({\n name: option.env as string,\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type:\n option.reflection?.getType() ??\n ((option as StringCommandOption | NumberCommandOption).variadic\n ? { kind: ReflectionKind.array, type: { kind: option.kind } }\n : { kind: option.kind }),\n default: option.default,\n tags: {\n ...option.reflection?.getTags(),\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 0)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n Object.values(tree.params)\n .filter(param => param.env !== false)\n .forEach(param =>\n context.env.types.env.addProperty({\n name: constantCase(param.name),\n optional: param.optional ? true : undefined,\n description: param.description,\n visibility: ReflectionVisibility.public,\n type: param.reflection.getType(),\n default: param.default,\n tags: {\n ...param.reflection.getTags(),\n domain: \"cli\"\n }\n })\n );\n }\n\n for (const input of context.inputs.filter(\n input =>\n input.path.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n command.path.segments.filter(segment => !isDynamicPathSegment(segment))\n .length +\n 1 &&\n input.path.segments\n .slice(0, command.path.segments.length)\n .every((value, index) => value === command.path.segments[index])\n )) {\n tree.children[input.name] = await reflectCommandTree(context, input, tree);\n }\n\n return tree;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,SAAgB2B,gCACdC,MACAC,UACAC,MACAC,OACAC,cACQ;AACR,QAAO,IAAIH,YAAY,CAACG,eAAe,eAAe,GAAE,GACtDJ,SAASxB,eAAe6B,UACpB,uCACA,sBAAqB,2BAEzBL,SAASxB,eAAe6B,UACpB,YACAL,SAASxB,eAAe8B,QACtB,mBACA,mBAAkB,GACtBH,OAAOI,MAAM,IAAInB,UAAUc,KAAK,CAAA,GAClCF,SAASxB,eAAe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