@shell-shock/core 0.9.7 → 0.11.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/dist/api.cjs +1 -2
- package/dist/api.cjs.map +1 -1
- package/dist/api.d.cts +1 -1
- package/dist/api.d.mts +1 -1
- package/dist/api.mjs +1 -2
- package/dist/api.mjs.map +1 -1
- package/dist/components/docs.cjs +4 -4
- package/dist/components/docs.cjs.map +1 -1
- package/dist/components/docs.d.cts +5 -5
- package/dist/components/docs.d.mts +5 -5
- package/dist/components/helpers.d.cts +6 -6
- package/dist/components/helpers.d.mts +6 -6
- package/dist/components/helpers.d.mts.map +1 -1
- package/dist/components/index.cjs +1 -0
- 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 +31 -31
- package/dist/components/options-parser-logic.cjs.map +1 -1
- package/dist/components/options-parser-logic.d.cts +9 -9
- package/dist/components/options-parser-logic.d.cts.map +1 -1
- package/dist/components/options-parser-logic.d.mts +9 -9
- package/dist/components/options-parser-logic.d.mts.map +1 -1
- package/dist/components/options-parser-logic.mjs +26 -26
- package/dist/components/options-parser-logic.mjs.map +1 -1
- package/dist/components/usage.cjs +5 -5
- package/dist/components/usage.cjs.map +1 -1
- package/dist/components/usage.d.cts +2 -2
- package/dist/components/usage.d.cts.map +1 -1
- package/dist/components/usage.mjs +4 -4
- package/dist/components/usage.mjs.map +1 -1
- package/dist/components/utils-builtin.cjs +204 -0
- package/dist/components/utils-builtin.cjs.map +1 -1
- package/dist/components/utils-builtin.d.cts +13 -9
- package/dist/components/utils-builtin.d.cts.map +1 -1
- package/dist/components/utils-builtin.d.mts +13 -9
- package/dist/components/utils-builtin.d.mts.map +1 -1
- package/dist/components/utils-builtin.mjs +208 -5
- package/dist/components/utils-builtin.mjs.map +1 -1
- package/dist/contexts/options.cjs +2 -2
- package/dist/contexts/options.cjs.map +1 -1
- package/dist/contexts/options.d.cts +1 -1
- package/dist/contexts/options.d.cts.map +1 -1
- package/dist/contexts/options.d.mts +1 -1
- package/dist/contexts/options.d.mts.map +1 -1
- package/dist/contexts/options.mjs +4 -4
- package/dist/contexts/options.mjs.map +1 -1
- package/dist/helpers/automd.cjs +2 -2
- package/dist/helpers/automd.cjs.map +1 -1
- package/dist/helpers/automd.mjs.map +1 -1
- package/dist/helpers/docs-helpers.cjs +1 -1
- package/dist/helpers/docs-helpers.cjs.map +1 -1
- package/dist/helpers/docs-helpers.mjs +1 -1
- package/dist/helpers/docs-helpers.mjs.map +1 -1
- package/dist/helpers/paths.cjs +125 -0
- package/dist/helpers/paths.cjs.map +1 -0
- package/dist/helpers/paths.mjs +121 -0
- package/dist/helpers/paths.mjs.map +1 -0
- package/dist/helpers/persistence.cjs +68 -116
- package/dist/helpers/persistence.cjs.map +1 -1
- package/dist/helpers/persistence.mjs +68 -116
- package/dist/helpers/persistence.mjs.map +1 -1
- package/dist/helpers/update-package-json.cjs +5 -5
- package/dist/helpers/update-package-json.cjs.map +1 -1
- package/dist/helpers/update-package-json.mjs +1 -1
- package/dist/helpers/update-package-json.mjs.map +1 -1
- package/dist/helpers/utilities.cjs +1 -1
- package/dist/helpers/utilities.mjs +1 -1
- package/dist/helpers/validations.cjs +2 -3
- package/dist/helpers/validations.cjs.map +1 -1
- package/dist/helpers/validations.mjs +2 -2
- package/dist/helpers/validations.mjs.map +1 -1
- package/dist/index.cjs +14 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -4
- package/dist/index.d.mts +2 -4
- package/dist/index.mjs +3 -5
- package/dist/index.mjs.map +1 -1
- package/dist/plugin-utils/deepkit.cjs +72 -0
- package/dist/plugin-utils/deepkit.cjs.map +1 -0
- package/dist/plugin-utils/deepkit.d.cts +24 -0
- package/dist/plugin-utils/deepkit.d.cts.map +1 -0
- package/dist/plugin-utils/deepkit.d.mts +24 -0
- package/dist/plugin-utils/deepkit.d.mts.map +1 -0
- package/dist/plugin-utils/deepkit.mjs +70 -0
- package/dist/plugin-utils/deepkit.mjs.map +1 -0
- package/dist/plugin-utils/get-command-tree.cjs +2 -2
- package/dist/plugin-utils/get-command-tree.cjs.map +1 -1
- package/dist/plugin-utils/index.cjs +27 -18
- package/dist/plugin-utils/index.d.cts +3 -1
- package/dist/plugin-utils/index.d.mts +3 -1
- package/dist/plugin-utils/index.mjs +3 -1
- package/dist/plugin-utils/reflect.cjs +4 -5
- package/dist/plugin-utils/reflect.cjs.map +1 -1
- package/dist/plugin-utils/reflect.mjs +4 -4
- package/dist/plugin-utils/reflect.mjs.map +1 -1
- package/dist/plugin-utils/type-checks.cjs +89 -0
- package/dist/plugin-utils/type-checks.cjs.map +1 -0
- package/dist/plugin-utils/type-checks.d.cts +42 -0
- package/dist/plugin-utils/type-checks.d.cts.map +1 -0
- package/dist/plugin-utils/type-checks.d.mts +42 -0
- package/dist/plugin-utils/type-checks.d.mts.map +1 -0
- package/dist/plugin-utils/type-checks.mjs +84 -0
- package/dist/plugin-utils/type-checks.mjs.map +1 -0
- package/dist/plugin.cjs +48 -45
- 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 +30 -26
- package/dist/plugin.mjs.map +1 -1
- package/dist/resolver/deepkit.cjs +129 -0
- package/dist/resolver/deepkit.cjs.map +1 -0
- package/dist/resolver/deepkit.mjs +128 -0
- package/dist/resolver/deepkit.mjs.map +1 -0
- package/dist/resolver/helpers.cjs +173 -0
- package/dist/resolver/helpers.cjs.map +1 -0
- package/dist/resolver/helpers.mjs +168 -0
- package/dist/resolver/helpers.mjs.map +1 -0
- package/dist/resolver/module.cjs +144 -0
- package/dist/resolver/module.cjs.map +1 -0
- package/dist/resolver/module.mjs +143 -0
- package/dist/resolver/module.mjs.map +1 -0
- package/dist/resolver/resolve.cjs +209 -0
- package/dist/resolver/resolve.cjs.map +1 -0
- package/dist/resolver/resolve.mjs +208 -0
- package/dist/resolver/resolve.mjs.map +1 -0
- package/dist/types/command.cjs +131 -99
- package/dist/types/command.cjs.map +1 -1
- package/dist/types/command.d.cts +49 -75
- package/dist/types/command.d.cts.map +1 -1
- package/dist/types/command.d.mts +49 -75
- package/dist/types/command.d.mts.map +1 -1
- package/dist/types/command.mjs +119 -91
- package/dist/types/command.mjs.map +1 -1
- package/dist/types/config.cjs +1 -2
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.cts +2 -2
- package/dist/types/config.d.cts.map +1 -1
- package/dist/types/config.d.mts +2 -2
- package/dist/types/config.d.mts.map +1 -1
- package/dist/types/config.mjs +1 -2
- package/dist/types/config.mjs.map +1 -1
- package/dist/types/context.cjs +1 -1
- package/dist/types/context.cjs.map +1 -1
- package/dist/types/context.d.cts +3 -3
- package/dist/types/context.d.cts.map +1 -1
- package/dist/types/context.d.mts +3 -3
- package/dist/types/context.d.mts.map +1 -1
- package/dist/types/context.mjs +1 -1
- package/dist/types/context.mjs.map +1 -1
- package/dist/types/index.cjs +13 -9
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.mts +2 -2
- package/dist/types/index.mjs +2 -2
- package/package.json +34 -79
- package/dist/helpers/resolve-command.cjs +0 -410
- package/dist/helpers/resolve-command.cjs.map +0 -1
- package/dist/helpers/resolve-command.mjs +0 -405
- package/dist/helpers/resolve-command.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-command.cjs","names":[],"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 isDynamicPathSegment,\n isPathSegmentGroup\n} from \"../plugin-utils/context-helpers\";\nimport type {\n CommandArgument,\n CommandInput,\n CommandModule,\n CommandOption,\n CommandTree,\n NumberCommandArgument,\n NumberCommandOption,\n StringCommandArgument,\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 name - The name of the command option.\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param variadic - Whether the command option is variadic (i.e., an array).\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 name: string,\n kind: ReflectionKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} command-line ${\n kind === ReflectionKind.boolean ? \"flag\" : \"option\"\n } that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : variadic\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 variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\n/**\n * Resolves the description for a command argument based on its reflection.\n *\n * @param name - The name of the command argument.\n * @param kind - The reflection kind of the command argument.\n * @param optional - Whether the command argument is optional.\n * @param variadic - Whether the command argument is variadic (i.e., an array).\n * @param title - The title of the command argument, if any.\n * @param defaultValue - The default value of the command argument, if any.\n * @returns The resolved description for the command argument.\n */\nexport function resolveCommandArgumentDescription(\n name: string,\n kind: ReflectionKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `An${\n optional && !defaultValue ? \" optional\" : \"\"\n } argument that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : variadic\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 variadic ? \"s\" : \"\"\n }`\n }.`;\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.getNameAsString(),\n reflection.getKind(),\n reflection.isOptional(),\n reflection.isArray(),\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 positional argument 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 argument information.\n */\nexport function extractCommandArgument(\n command: CommandInput,\n reflection: ReflectionParameter\n): CommandArgument {\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 argument \"${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 argument = {\n name: reflection.getName(),\n alias: reflection.getAlias(),\n kind: type.kind,\n title: titleCase(reflection.getName()),\n description:\n reflection.parameter.description ||\n resolveCommandArgumentDescription(\n reflection.getName(),\n type.kind === ReflectionKind.array ? type.type.kind : type.kind,\n reflection.isOptional(),\n type.kind === ReflectionKind.array,\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 CommandArgument;\n\n if (type.kind === ReflectionKind.array) {\n if (\n type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number\n ) {\n (argument as StringCommandArgument | NumberCommandArgument).variadic =\n true;\n (argument as StringCommandArgument | NumberCommandArgument).kind =\n type.type.kind;\n } else {\n throw new Error(\n `Unsupported array type for argument \"${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 argument \"${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 argument;\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(/(?:c|C)ommands?$/, \"\").trim()\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const tree = {\n alias: [],\n icon: parent?.icon,\n ...command,\n title,\n options: getDefaultOptions(context, command),\n arguments: [],\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.replace(/(?:c|C)ommands?$/, \"\").trim()} 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.arguments = parameters\n .slice(1)\n .map(arg => extractCommandArgument(command, arg));\n\n // Ensure unique argument names by appending an index suffix to duplicates\n tree.arguments.forEach((argument, index) => {\n const found = tree.arguments.findIndex(\n arg => arg.name === argument.name\n );\n if (\n (found !== -1 && found !== index) ||\n tree.segments.some(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment) === argument.name\n )\n ) {\n argument.name += `_${\n tree.segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(/_\\d+$/, \"\") ===\n argument.name\n ).length +\n tree.arguments.filter(\n arg => arg.name.replace(/_\\d+$/, \"\") === argument.name\n ).length\n }`;\n argument.env = constantCase(argument.name);\n }\n });\n }\n } else {\n tree.description ??= `A collection of available ${\n tree.title.replace(/(?:c|C)ommands?$/, \"\").trim() || 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 > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n tree.arguments\n .filter(arg => arg.env !== false)\n .forEach(arg =>\n context.env.types.env.addProperty({\n name: arg.env as string,\n optional: arg.optional ? true : undefined,\n description: arg.description,\n visibility: ReflectionVisibility.public,\n type: arg.reflection.getType(),\n default: arg.default,\n tags: {\n ...arg.reflection.getTags(),\n alias: arg.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n })\n );\n }\n\n for (const input of context.inputs.filter(\n input =>\n input.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n command.segments.filter(segment => !isDynamicPathSegment(segment))\n .length +\n 1 &&\n input.segments\n .slice(0, command.segments.length)\n .every((value, index) => value === command.segments[index])\n )) {\n tree.children[input.name] = await reflectCommandTree(context, input, tree);\n }\n\n return tree;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAEA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;;;;;;;;;;;;AA8CX,SAAY,gCAAA,MAAA,MAAA,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACR,QAAO,IAAI,YAAE,CAAA,eAAA,eAAA,GAAA,gBAAA,SAAA,gDAAA,UAAA,SAAA,SAAA,2BAAA,SAAA,gDAAA,UACP,YACA,WACI,mBACD,mBAAA,GAAA,OAAA,MAAA,qDAAA,KAAA,CAAA,GAAA,SAAA,gDAAA,UACH,cACA,GAAG,SAAQ,gDAAA,SAAA,YAAA,SAAA,QAAA,WAAA,MAAA,KAAA;;AAErB,gCAAoB,SAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;AAYpB,SAAgB,kCAAkC,MAAM,MAAC,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACrD,QAAO,KAAK,YAAY,CAAC,eAAe,cAAc,GAAE,oCAAY,SAAA,gDAAA,UAC9D,YACR,WACY,mBACA,mBAAA,GAAA,OAAA,MAAA,qDAAA,KAAA,CAAA,GAAA,SAAA,gDAAA,UACJ,cACA,GAAG,SAAK,gDAAA,SAAA,YAAA,SAAA,QAAA,WAAA,MAAA,KAAA;;AAElB,kCAAgB,SAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AAChB,SAAgB,iBAAG,SAAA,MAAA;AACf,6FAAM,KAAA,EAAA,QAAA,aAAA,CACD,MAAM,IA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,IAAA,MAAA,IAAA,YAAA;GACA,MAAM,IAAI;GACV,UAAU,IAAA,WAAA,OAAA;GACX,aAAA,IAAA;GACC,YAAS,sDAAA;GACT,MAAM,IAAI,WAAW,SAAS;GAC9B,SAAS,IAAA;GACT,MAAM;IACL,GAAA,IAAA,WAAA,SAAA;IACL,OAAA,IAAA,MACQ,OAAA,cAAA,UAAA,MAAA,SAAA,GAAA;KAAA;KAAA;KAAA;KAAA,CAAA,CAAA,CACK,IAAI,cAAa,iEAAC,MAAA,EAAA;KAAA;KAAA;KAAA;KAAA,CAAA,CAAA;IAChC,QAAA;IACH;GACK,CAAC,EAAE;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;;AAER,MAAK,MAAM,SAAS,QAAQ,OAAO,OAAE,cAAA,YAAA,QAAA,SAAA,OAAA,cAAA,YAAA,CAAA,0DAAA,QAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAChC,WACL,QAAA,SAAA,OAAA,cAAA,YAAA,CAAA,0DAAA,QAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CACS,SACD,KACJ,QAAM,SACD,MAAM,GAAG,QAAQ,SAAS,OAAO,CACnC,MAAA,cAAA,OAAA,UAAA,UAAA,QAAA,SAAA,QAAA;EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CACL,MAAA,SAAA,MAAA,QAAA,MAAA,mBAAA,SAAA,OAAA,KAAA;AAEF,QAAO;;AAEX,mBAAE,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
|
|
@@ -1,405 +0,0 @@
|
|
|
1
|
-
import { getAppTitle, getDynamicPathSegmentName, isDynamicPathSegment, isPathSegmentGroup } from "../plugin-utils/context-helpers.mjs";
|
|
2
|
-
import { getDefaultOptions } from "./utilities.mjs";
|
|
3
|
-
import { toArray } from "@stryke/convert/to-array";
|
|
4
|
-
import { appendPath } from "@stryke/path/append";
|
|
5
|
-
import { findFilePath, findFolderName } from "@stryke/path/file-path-fns";
|
|
6
|
-
import { replacePath } from "@stryke/path/replace";
|
|
7
|
-
import { resolveParentPath } from "@stryke/path/resolve-parent-path";
|
|
8
|
-
import { constantCase } from "@stryke/string-format/constant-case";
|
|
9
|
-
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
10
|
-
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
11
|
-
import { titleCase } from "@stryke/string-format/title-case";
|
|
12
|
-
import { ReflectionClass, ReflectionFunction, ReflectionKind, ReflectionVisibility, __ΩReflectionKind, reflect, stringifyType } from "@powerlines/deepkit/vendor/type";
|
|
13
|
-
import { esbuildPlugin } from "@powerlines/deepkit/esbuild-plugin";
|
|
14
|
-
import { commonPath } from "@stryke/path/common";
|
|
15
|
-
import { stripStars } from "@stryke/path/normalize";
|
|
16
|
-
import { resolveModule } from "powerlines/lib/utilities/resolve";
|
|
17
|
-
|
|
18
|
-
//#region src/helpers/resolve-command.ts
|
|
19
|
-
function __assignType(fn, args) {
|
|
20
|
-
fn.__type = args;
|
|
21
|
-
return fn;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Resolves the description for a command option based on its reflection.
|
|
25
|
-
*
|
|
26
|
-
* @param name - The name of the command option.
|
|
27
|
-
* @param kind - The reflection kind of the command option.
|
|
28
|
-
* @param optional - Whether the command option is optional.
|
|
29
|
-
* @param variadic - Whether the command option is variadic (i.e., an array).
|
|
30
|
-
* @param title - The title of the command option, if any.
|
|
31
|
-
* @param defaultValue - The default value of the command option, if any.
|
|
32
|
-
* @returns The resolved description for the command option.
|
|
33
|
-
*/
|
|
34
|
-
function resolveCommandOptionDescription(name, kind, optional = false, variadic = false, title, defaultValue) {
|
|
35
|
-
return `A${optional && !defaultValue ? "n optional" : ""} command-line ${kind === ReflectionKind.boolean ? "flag" : "option"} that allows the user to ${kind === ReflectionKind.boolean ? "set the" : variadic ? "specify custom" : "specify a custom"} ${title?.trim() || titleCase(name)} ${kind === ReflectionKind.boolean ? "indicator" : `${kind === ReflectionKind.number ? "numeric" : "string"} value${variadic ? "s" : ""}`}.`;
|
|
36
|
-
}
|
|
37
|
-
resolveCommandOptionDescription.__type = [
|
|
38
|
-
"name",
|
|
39
|
-
() => __ΩReflectionKind,
|
|
40
|
-
"kind",
|
|
41
|
-
"optional",
|
|
42
|
-
"variadic",
|
|
43
|
-
"title",
|
|
44
|
-
"defaultValue",
|
|
45
|
-
"resolveCommandOptionDescription",
|
|
46
|
-
"P&2!n\"2#\"2$\"2%&2&8\"2'8&/("
|
|
47
|
-
];
|
|
48
|
-
/**
|
|
49
|
-
* Resolves the description for a command argument based on its reflection.
|
|
50
|
-
*
|
|
51
|
-
* @param name - The name of the command argument.
|
|
52
|
-
* @param kind - The reflection kind of the command argument.
|
|
53
|
-
* @param optional - Whether the command argument is optional.
|
|
54
|
-
* @param variadic - Whether the command argument is variadic (i.e., an array).
|
|
55
|
-
* @param title - The title of the command argument, if any.
|
|
56
|
-
* @param defaultValue - The default value of the command argument, if any.
|
|
57
|
-
* @returns The resolved description for the command argument.
|
|
58
|
-
*/
|
|
59
|
-
function resolveCommandArgumentDescription(name, kind, optional = false, variadic = false, title, defaultValue) {
|
|
60
|
-
return `An${optional && !defaultValue ? " optional" : ""} argument that allows the user to ${kind === ReflectionKind.boolean ? "set the" : variadic ? "specify custom" : "specify a custom"} ${title?.trim() || titleCase(name)} ${kind === ReflectionKind.boolean ? "indicator" : `${kind === ReflectionKind.number ? "numeric" : "string"} value${variadic ? "s" : ""}`}.`;
|
|
61
|
-
}
|
|
62
|
-
resolveCommandArgumentDescription.__type = [
|
|
63
|
-
"name",
|
|
64
|
-
() => __ΩReflectionKind,
|
|
65
|
-
"kind",
|
|
66
|
-
"optional",
|
|
67
|
-
"variadic",
|
|
68
|
-
"title",
|
|
69
|
-
"defaultValue",
|
|
70
|
-
"resolveCommandArgumentDescription",
|
|
71
|
-
"P&2!n\"2#\"2$\"2%&2&8\"2'8&/("
|
|
72
|
-
];
|
|
73
|
-
function resolveCommandId(context, file) {
|
|
74
|
-
return replacePath(findFilePath(file), context.commandsPath).split("/").filter(__assignType((p) => Boolean(p) && !isDynamicPathSegment(p), [
|
|
75
|
-
"p",
|
|
76
|
-
"",
|
|
77
|
-
"P\"2!\"/\""
|
|
78
|
-
])).join("/").replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "").replaceAll("/", "-");
|
|
79
|
-
}
|
|
80
|
-
resolveCommandId.__type = [
|
|
81
|
-
"Context",
|
|
82
|
-
"context",
|
|
83
|
-
"file",
|
|
84
|
-
"resolveCommandId",
|
|
85
|
-
"P\"w!2\"&2#&/$"
|
|
86
|
-
];
|
|
87
|
-
/**
|
|
88
|
-
* Finds the command name from the given file path.
|
|
89
|
-
*
|
|
90
|
-
* @param file - The file path to extract the command name from.
|
|
91
|
-
* @returns The command name.
|
|
92
|
-
*/
|
|
93
|
-
function resolveCommandName(file) {
|
|
94
|
-
let path = findFilePath(file);
|
|
95
|
-
let name = findFolderName(file, { requireExtension: true });
|
|
96
|
-
while (isDynamicPathSegment(name)) {
|
|
97
|
-
path = resolveParentPath(path);
|
|
98
|
-
name = findFolderName(path, { requireExtension: true });
|
|
99
|
-
}
|
|
100
|
-
return name;
|
|
101
|
-
}
|
|
102
|
-
resolveCommandName.__type = [
|
|
103
|
-
"file",
|
|
104
|
-
"resolveCommandName",
|
|
105
|
-
"P&2!\"/\""
|
|
106
|
-
];
|
|
107
|
-
function resolveCommandPath(context, file) {
|
|
108
|
-
return replacePath(findFilePath(file), context.commandsPath).replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "").split("/").filter(__assignType((path) => path && !isPathSegmentGroup(path), [
|
|
109
|
-
"path",
|
|
110
|
-
"",
|
|
111
|
-
"P\"2!\"/\""
|
|
112
|
-
])).join("/");
|
|
113
|
-
}
|
|
114
|
-
resolveCommandPath.__type = [
|
|
115
|
-
"Context",
|
|
116
|
-
"context",
|
|
117
|
-
"file",
|
|
118
|
-
"resolveCommandPath",
|
|
119
|
-
"P\"w!2\"&2#&/$"
|
|
120
|
-
];
|
|
121
|
-
function resolveCommandDynamicPathSegments(context, file) {
|
|
122
|
-
return replacePath(findFilePath(file), context.commandsPath).split("/").filter(__assignType((path) => Boolean(path) && isDynamicPathSegment(path), [
|
|
123
|
-
"path",
|
|
124
|
-
"",
|
|
125
|
-
"P\"2!\"/\""
|
|
126
|
-
])).map(__assignType((path) => getDynamicPathSegmentName(path), [
|
|
127
|
-
"path",
|
|
128
|
-
"",
|
|
129
|
-
"P\"2!\"/\""
|
|
130
|
-
]));
|
|
131
|
-
}
|
|
132
|
-
resolveCommandDynamicPathSegments.__type = [
|
|
133
|
-
"Context",
|
|
134
|
-
"context",
|
|
135
|
-
"file",
|
|
136
|
-
"resolveCommandDynamicPathSegments",
|
|
137
|
-
"P\"w!2\"&2#&F/$"
|
|
138
|
-
];
|
|
139
|
-
function findCommandsRoot(context) {
|
|
140
|
-
if (isSetString(context.config.entry)) return appendPath(appendPath(stripStars(context.config.entry), context.config.projectRoot), context.workspaceConfig.workspaceRoot);
|
|
141
|
-
else if (isSetObject(context.config.entry) && "file" in context.config.entry) return appendPath(appendPath(stripStars(context.config.entry.file), context.config.projectRoot), context.workspaceConfig.workspaceRoot);
|
|
142
|
-
else if (Array.isArray(context.config.entry) && context.config.entry.length > 0) return commonPath(context.config.entry.map(__assignType((entry) => appendPath(appendPath(stripStars(isSetString(entry) ? entry : entry.file), context.config.projectRoot), context.workspaceConfig.workspaceRoot), [
|
|
143
|
-
"entry",
|
|
144
|
-
"",
|
|
145
|
-
"P\"2!\"/\""
|
|
146
|
-
])));
|
|
147
|
-
return appendPath(context.config.sourceRoot || context.config.projectRoot, context.workspaceConfig.workspaceRoot);
|
|
148
|
-
}
|
|
149
|
-
findCommandsRoot.__type = [
|
|
150
|
-
"Context",
|
|
151
|
-
"context",
|
|
152
|
-
"findCommandsRoot",
|
|
153
|
-
"P\"w!2\"&/#"
|
|
154
|
-
];
|
|
155
|
-
/**
|
|
156
|
-
* Extracts command parameter information from a type parameter reflection.
|
|
157
|
-
*
|
|
158
|
-
* @param command - The command tree to which the parameter belongs.
|
|
159
|
-
* @param reflection - The type parameter reflection to extract information from.
|
|
160
|
-
* @returns The extracted command option information.
|
|
161
|
-
*/
|
|
162
|
-
function extractCommandOption(command, reflection) {
|
|
163
|
-
const type = reflection.getType();
|
|
164
|
-
const option = {
|
|
165
|
-
name: reflection.getNameAsString(),
|
|
166
|
-
alias: reflection.getTags().alias ?? [],
|
|
167
|
-
title: reflection.getTags().title?.trim() || titleCase(reflection.getNameAsString()),
|
|
168
|
-
description: reflection.getDescription() || resolveCommandOptionDescription(reflection.getNameAsString(), reflection.getKind(), reflection.isOptional(), reflection.isArray(), reflection.getTags().title, reflection.getDefaultValue()),
|
|
169
|
-
env: constantCase(reflection.getNameAsString()),
|
|
170
|
-
kind: type.kind,
|
|
171
|
-
optional: reflection.isOptional(),
|
|
172
|
-
default: reflection.getDefaultValue(),
|
|
173
|
-
variadic: reflection.isArray(),
|
|
174
|
-
reflection
|
|
175
|
-
};
|
|
176
|
-
if (reflection.isArray()) if (type.type.kind === ReflectionKind.string || type.type.kind === ReflectionKind.number) {
|
|
177
|
-
option.variadic = true;
|
|
178
|
-
option.kind = type.type.kind;
|
|
179
|
-
} 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 ")}.`);
|
|
180
|
-
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 ")}.`);
|
|
181
|
-
return option;
|
|
182
|
-
}
|
|
183
|
-
extractCommandOption.__type = [
|
|
184
|
-
"CommandInput",
|
|
185
|
-
"command",
|
|
186
|
-
"ReflectionProperty",
|
|
187
|
-
"reflection",
|
|
188
|
-
"CommandOption",
|
|
189
|
-
"extractCommandOption",
|
|
190
|
-
"P\"w!2\"\"w#2$\"w%/&"
|
|
191
|
-
];
|
|
192
|
-
/**
|
|
193
|
-
* Extracts command positional argument information from a type parameter reflection.
|
|
194
|
-
*
|
|
195
|
-
* @param command - The command tree to which the parameter belongs.
|
|
196
|
-
* @param reflection - The type parameter reflection to extract information from.
|
|
197
|
-
* @returns The extracted command positional argument information.
|
|
198
|
-
*/
|
|
199
|
-
function extractCommandArgument(command, reflection) {
|
|
200
|
-
const type = reflection.getType();
|
|
201
|
-
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 argument "${reflection.getName()}" in command "${command.name}". Only string types (or an array of strings) are supported, received ${stringifyType(type).trim().replaceAll(" | ", ", or ")}.`);
|
|
202
|
-
const argument = {
|
|
203
|
-
name: reflection.getName(),
|
|
204
|
-
alias: reflection.getAlias(),
|
|
205
|
-
kind: type.kind,
|
|
206
|
-
title: titleCase(reflection.getName()),
|
|
207
|
-
description: reflection.parameter.description || resolveCommandArgumentDescription(reflection.getName(), type.kind === ReflectionKind.array ? type.type.kind : type.kind, reflection.isOptional(), type.kind === ReflectionKind.array, titleCase(reflection.getName()), reflection.getDefaultValue()),
|
|
208
|
-
env: constantCase(reflection.getName()),
|
|
209
|
-
optional: reflection.isOptional(),
|
|
210
|
-
default: reflection.getDefaultValue(),
|
|
211
|
-
reflection
|
|
212
|
-
};
|
|
213
|
-
if (type.kind === ReflectionKind.array) if (type.type.kind === ReflectionKind.string || type.type.kind === ReflectionKind.number) {
|
|
214
|
-
argument.variadic = true;
|
|
215
|
-
argument.kind = type.type.kind;
|
|
216
|
-
} else throw new Error(`Unsupported array type for argument "${reflection.getName()}" in command "${command.name}". Only string[] and number[] are supported, received ${stringifyType(type).trim().replaceAll(" | ", ", or ")}.`);
|
|
217
|
-
else if (type.kind !== ReflectionKind.boolean && type.kind !== ReflectionKind.string && type.kind !== ReflectionKind.number) throw new Error(`Unsupported type for argument "${reflection.getName()}" in command "${command.name}". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(type).trim().replaceAll(" | ", ", or ")}.`);
|
|
218
|
-
return argument;
|
|
219
|
-
}
|
|
220
|
-
extractCommandArgument.__type = [
|
|
221
|
-
"CommandInput",
|
|
222
|
-
"command",
|
|
223
|
-
"ReflectionParameter",
|
|
224
|
-
"reflection",
|
|
225
|
-
"CommandArgument",
|
|
226
|
-
"extractCommandArgument",
|
|
227
|
-
"P\"w!2\"\"w#2$\"w%/&"
|
|
228
|
-
];
|
|
229
|
-
/**
|
|
230
|
-
* Reflects the command tree for a given command input.
|
|
231
|
-
*
|
|
232
|
-
* @param context - The context in which the command is being reflected.
|
|
233
|
-
* @param command - The command input to reflect.
|
|
234
|
-
* @param parent - The parent command tree, if any.
|
|
235
|
-
* @returns The reflected command tree.
|
|
236
|
-
*/
|
|
237
|
-
async function reflectCommandTree(context, command, parent) {
|
|
238
|
-
const title = command.title || `${parent?.title ? `${parent.isVirtual ? parent.title.replace(/(?:c|C)ommands?$/, "").trim() : parent.title} - ` : ""}${titleCase(command.name)}${command.isVirtual ? " Commands" : ""}`;
|
|
239
|
-
const tree = {
|
|
240
|
-
alias: [],
|
|
241
|
-
icon: parent?.icon,
|
|
242
|
-
...command,
|
|
243
|
-
title,
|
|
244
|
-
options: getDefaultOptions(context, command),
|
|
245
|
-
arguments: [],
|
|
246
|
-
parent: parent ?? null,
|
|
247
|
-
children: {},
|
|
248
|
-
reflection: null
|
|
249
|
-
};
|
|
250
|
-
if (!command.isVirtual) {
|
|
251
|
-
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}"`);
|
|
252
|
-
context.debug(`Adding reflection for user-defined command: ${command.id} (file: ${command.entry.input.file})`);
|
|
253
|
-
const resolved = await (resolveModule.Ω = [["CommandModule", "\"w!"]], resolveModule(context, command.entry.input, { plugins: [esbuildPlugin(context, {
|
|
254
|
-
reflection: "default",
|
|
255
|
-
reflectionLevel: "verbose"
|
|
256
|
-
})] }));
|
|
257
|
-
const metadata = resolved.metadata ?? {};
|
|
258
|
-
if (isSetString(metadata.title)) tree.title = metadata.title;
|
|
259
|
-
if (isSetString(metadata.description)) tree.description = metadata.description;
|
|
260
|
-
if (isSetString(metadata.alias) || Array.isArray(metadata.alias) && metadata.alias.length > 0) tree.alias = toArray(metadata.alias);
|
|
261
|
-
if (isSetString(metadata.icon)) tree.icon = metadata.icon;
|
|
262
|
-
const type = reflect(resolved);
|
|
263
|
-
if (type.kind !== ReflectionKind.function) throw new Error(`The command entry file "${command.entry.input.file}" does not export a valid function.`);
|
|
264
|
-
tree.reflection = new ReflectionFunction(type);
|
|
265
|
-
tree.description ??= command.description || type.description || `The ${tree.title.replace(/(?:c|C)ommands?$/, "").trim()} executable command-line interface.`;
|
|
266
|
-
const parameters = tree.reflection.getParameters();
|
|
267
|
-
if (parameters.length > 0 && parameters[0]) {
|
|
268
|
-
if (parameters[0].type.kind === ReflectionKind.objectLiteral || parameters[0].type.kind === ReflectionKind.class) {
|
|
269
|
-
const optionsReflection = ReflectionClass.from(parameters[0].type);
|
|
270
|
-
for (const propertyReflection of optionsReflection.getProperties()) tree.options[propertyReflection.getNameAsString()] = extractCommandOption(command, propertyReflection);
|
|
271
|
-
} 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.`);
|
|
272
|
-
tree.arguments = parameters.slice(1).map(__assignType((arg) => extractCommandArgument(command, arg), [
|
|
273
|
-
"arg",
|
|
274
|
-
"",
|
|
275
|
-
"P\"2!\"/\""
|
|
276
|
-
]));
|
|
277
|
-
tree.arguments.forEach(__assignType((argument, index) => {
|
|
278
|
-
const found = tree.arguments.findIndex(__assignType((arg) => arg.name === argument.name, [
|
|
279
|
-
"arg",
|
|
280
|
-
"",
|
|
281
|
-
"P\"2!\"/\""
|
|
282
|
-
]));
|
|
283
|
-
if (found !== -1 && found !== index || tree.segments.some(__assignType((segment) => isDynamicPathSegment(segment) && getDynamicPathSegmentName(segment) === argument.name, [
|
|
284
|
-
"segment",
|
|
285
|
-
"",
|
|
286
|
-
"P\"2!\"/\""
|
|
287
|
-
]))) {
|
|
288
|
-
argument.name += `_${tree.segments.filter(__assignType((segment) => isDynamicPathSegment(segment) && getDynamicPathSegmentName(segment).replace(/_\d+$/, "") === argument.name, [
|
|
289
|
-
"segment",
|
|
290
|
-
"",
|
|
291
|
-
"P\"2!\"/\""
|
|
292
|
-
])).length + tree.arguments.filter(__assignType((arg) => arg.name.replace(/_\d+$/, "") === argument.name, [
|
|
293
|
-
"arg",
|
|
294
|
-
"",
|
|
295
|
-
"P\"2!\"/\""
|
|
296
|
-
])).length}`;
|
|
297
|
-
argument.env = constantCase(argument.name);
|
|
298
|
-
}
|
|
299
|
-
}, [
|
|
300
|
-
"argument",
|
|
301
|
-
"index",
|
|
302
|
-
"",
|
|
303
|
-
"P\"2!\"2\"\"/#"
|
|
304
|
-
]));
|
|
305
|
-
}
|
|
306
|
-
} else tree.description ??= `A collection of available ${tree.title.replace(/(?:c|C)ommands?$/, "").trim() || titleCase(tree.name)} commands that are included in the ${getAppTitle(context)} command-line application.`;
|
|
307
|
-
if (context.env) {
|
|
308
|
-
if (isSetObject(tree.options)) Object.values(tree.options).filter(__assignType((option) => option.env !== false, [
|
|
309
|
-
"option",
|
|
310
|
-
"",
|
|
311
|
-
"P\"2!\"/\""
|
|
312
|
-
])).forEach(__assignType((option) => {
|
|
313
|
-
context.env.types.env.addProperty({
|
|
314
|
-
name: option.env,
|
|
315
|
-
optional: option.optional ? true : void 0,
|
|
316
|
-
description: option.description,
|
|
317
|
-
visibility: ReflectionVisibility.public,
|
|
318
|
-
type: option.reflection?.getType() ?? (option.variadic ? {
|
|
319
|
-
kind: ReflectionKind.array,
|
|
320
|
-
type: { kind: option.kind }
|
|
321
|
-
} : { kind: option.kind }),
|
|
322
|
-
default: option.default,
|
|
323
|
-
tags: {
|
|
324
|
-
...option.reflection?.getTags(),
|
|
325
|
-
title: option.title,
|
|
326
|
-
alias: option.alias.filter(__assignType((alias) => alias.length > 1, [
|
|
327
|
-
"alias",
|
|
328
|
-
"",
|
|
329
|
-
"P\"2!\"/\""
|
|
330
|
-
])).map(__assignType((alias) => constantCase(alias), [
|
|
331
|
-
"alias",
|
|
332
|
-
"",
|
|
333
|
-
"P\"2!\"/\""
|
|
334
|
-
])),
|
|
335
|
-
domain: "cli"
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
}, [
|
|
339
|
-
"option",
|
|
340
|
-
"",
|
|
341
|
-
"P\"2!\"/\""
|
|
342
|
-
]));
|
|
343
|
-
tree.arguments.filter(__assignType((arg) => arg.env !== false, [
|
|
344
|
-
"arg",
|
|
345
|
-
"",
|
|
346
|
-
"P\"2!\"/\""
|
|
347
|
-
])).forEach(__assignType((arg) => context.env.types.env.addProperty({
|
|
348
|
-
name: arg.env,
|
|
349
|
-
optional: arg.optional ? true : void 0,
|
|
350
|
-
description: arg.description,
|
|
351
|
-
visibility: ReflectionVisibility.public,
|
|
352
|
-
type: arg.reflection.getType(),
|
|
353
|
-
default: arg.default,
|
|
354
|
-
tags: {
|
|
355
|
-
...arg.reflection.getTags(),
|
|
356
|
-
alias: arg.alias.filter(__assignType((alias) => alias.length > 1, [
|
|
357
|
-
"alias",
|
|
358
|
-
"",
|
|
359
|
-
"P\"2!\"/\""
|
|
360
|
-
])).map(__assignType((alias) => constantCase(alias), [
|
|
361
|
-
"alias",
|
|
362
|
-
"",
|
|
363
|
-
"P\"2!\"/\""
|
|
364
|
-
])),
|
|
365
|
-
domain: "cli"
|
|
366
|
-
}
|
|
367
|
-
}), [
|
|
368
|
-
"arg",
|
|
369
|
-
"",
|
|
370
|
-
"P\"2!\"/\""
|
|
371
|
-
]));
|
|
372
|
-
}
|
|
373
|
-
for (const input of context.inputs.filter(__assignType((input$1) => input$1.segments.filter(__assignType((segment) => !isDynamicPathSegment(segment), [
|
|
374
|
-
"segment",
|
|
375
|
-
"",
|
|
376
|
-
"P\"2!\"/\""
|
|
377
|
-
])).length === command.segments.filter(__assignType((segment) => !isDynamicPathSegment(segment), [
|
|
378
|
-
"segment",
|
|
379
|
-
"",
|
|
380
|
-
"P\"2!\"/\""
|
|
381
|
-
])).length + 1 && input$1.segments.slice(0, command.segments.length).every(__assignType((value, index) => value === command.segments[index], [
|
|
382
|
-
"value",
|
|
383
|
-
"index",
|
|
384
|
-
"",
|
|
385
|
-
"P\"2!\"2\"\"/#"
|
|
386
|
-
])), [
|
|
387
|
-
"input",
|
|
388
|
-
"",
|
|
389
|
-
"P\"2!\"/\""
|
|
390
|
-
]))) tree.children[input.name] = await reflectCommandTree(context, input, tree);
|
|
391
|
-
return tree;
|
|
392
|
-
}
|
|
393
|
-
reflectCommandTree.__type = [
|
|
394
|
-
"context",
|
|
395
|
-
"CommandInput",
|
|
396
|
-
"command",
|
|
397
|
-
"CommandTree",
|
|
398
|
-
"parent",
|
|
399
|
-
"reflectCommandTree",
|
|
400
|
-
"P\"2!\"w\"2#\"w$2%8\"w$`/&"
|
|
401
|
-
];
|
|
402
|
-
|
|
403
|
-
//#endregion
|
|
404
|
-
export { findCommandsRoot, reflectCommandTree, resolveCommandId, resolveCommandName, resolveCommandPath };
|
|
405
|
-
//# sourceMappingURL=resolve-command.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-command.mjs","names":[],"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 isDynamicPathSegment,\n isPathSegmentGroup\n} from \"../plugin-utils/context-helpers\";\nimport type {\n CommandArgument,\n CommandInput,\n CommandModule,\n CommandOption,\n CommandTree,\n NumberCommandArgument,\n NumberCommandOption,\n StringCommandArgument,\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 name - The name of the command option.\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param variadic - Whether the command option is variadic (i.e., an array).\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 name: string,\n kind: ReflectionKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} command-line ${\n kind === ReflectionKind.boolean ? \"flag\" : \"option\"\n } that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : variadic\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 variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\n/**\n * Resolves the description for a command argument based on its reflection.\n *\n * @param name - The name of the command argument.\n * @param kind - The reflection kind of the command argument.\n * @param optional - Whether the command argument is optional.\n * @param variadic - Whether the command argument is variadic (i.e., an array).\n * @param title - The title of the command argument, if any.\n * @param defaultValue - The default value of the command argument, if any.\n * @returns The resolved description for the command argument.\n */\nexport function resolveCommandArgumentDescription(\n name: string,\n kind: ReflectionKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `An${\n optional && !defaultValue ? \" optional\" : \"\"\n } argument that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : variadic\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 variadic ? \"s\" : \"\"\n }`\n }.`;\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.getNameAsString(),\n reflection.getKind(),\n reflection.isOptional(),\n reflection.isArray(),\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 positional argument 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 argument information.\n */\nexport function extractCommandArgument(\n command: CommandInput,\n reflection: ReflectionParameter\n): CommandArgument {\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 argument \"${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 argument = {\n name: reflection.getName(),\n alias: reflection.getAlias(),\n kind: type.kind,\n title: titleCase(reflection.getName()),\n description:\n reflection.parameter.description ||\n resolveCommandArgumentDescription(\n reflection.getName(),\n type.kind === ReflectionKind.array ? type.type.kind : type.kind,\n reflection.isOptional(),\n type.kind === ReflectionKind.array,\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 CommandArgument;\n\n if (type.kind === ReflectionKind.array) {\n if (\n type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number\n ) {\n (argument as StringCommandArgument | NumberCommandArgument).variadic =\n true;\n (argument as StringCommandArgument | NumberCommandArgument).kind =\n type.type.kind;\n } else {\n throw new Error(\n `Unsupported array type for argument \"${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 argument \"${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 argument;\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(/(?:c|C)ommands?$/, \"\").trim()\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const tree = {\n alias: [],\n icon: parent?.icon,\n ...command,\n title,\n options: getDefaultOptions(context, command),\n arguments: [],\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.replace(/(?:c|C)ommands?$/, \"\").trim()} 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.arguments = parameters\n .slice(1)\n .map(arg => extractCommandArgument(command, arg));\n\n // Ensure unique argument names by appending an index suffix to duplicates\n tree.arguments.forEach((argument, index) => {\n const found = tree.arguments.findIndex(\n arg => arg.name === argument.name\n );\n if (\n (found !== -1 && found !== index) ||\n tree.segments.some(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment) === argument.name\n )\n ) {\n argument.name += `_${\n tree.segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(/_\\d+$/, \"\") ===\n argument.name\n ).length +\n tree.arguments.filter(\n arg => arg.name.replace(/_\\d+$/, \"\") === argument.name\n ).length\n }`;\n argument.env = constantCase(argument.name);\n }\n });\n }\n } else {\n tree.description ??= `A collection of available ${\n tree.title.replace(/(?:c|C)ommands?$/, \"\").trim() || 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 > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n tree.arguments\n .filter(arg => arg.env !== false)\n .forEach(arg =>\n context.env.types.env.addProperty({\n name: arg.env as string,\n optional: arg.optional ? true : undefined,\n description: arg.description,\n visibility: ReflectionVisibility.public,\n type: arg.reflection.getType(),\n default: arg.default,\n tags: {\n ...arg.reflection.getTags(),\n alias: arg.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n })\n );\n }\n\n for (const input of context.inputs.filter(\n input =>\n input.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n command.segments.filter(segment => !isDynamicPathSegment(segment))\n .length +\n 1 &&\n input.segments\n .slice(0, command.segments.length)\n .every((value, index) => value === command.segments[index])\n )) {\n tree.children[input.name] = await reflectCommandTree(context, input, tree);\n }\n\n return tree;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAEA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;;;;;;;;;;;;AA8CX,SAAY,gCAAA,MAAA,MAAA,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACR,QAAO,IAAI,YAAE,CAAA,eAAA,eAAA,GAAA,gBAAA,SAAA,eAAA,UAAA,SAAA,SAAA,2BAAA,SAAA,eAAA,UACP,YACA,WACI,mBACD,mBAAA,GAAA,OAAA,MAAA,IAAA,UAAA,KAAA,CAAA,GAAA,SAAA,eAAA,UACH,cACA,GAAG,SAAQ,eAAA,SAAA,YAAA,SAAA,QAAA,WAAA,MAAA,KAAA;;AAErB,gCAAoB,SAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;AAYpB,SAAgB,kCAAkC,MAAM,MAAC,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACrD,QAAO,KAAK,YAAY,CAAC,eAAe,cAAc,GAAE,oCAAY,SAAA,eAAA,UAC9D,YACR,WACY,mBACA,mBAAA,GAAA,OAAA,MAAA,IAAA,UAAA,KAAA,CAAA,GAAA,SAAA,eAAA,UACJ,cACA,GAAG,SAAK,eAAA,SAAA,YAAA,SAAA,QAAA,WAAA,MAAA,KAAA;;AAElB,kCAAgB,SAAA;CAAA;OAAA;CAAA;CAAA;CAAA;CAAA;CAAA;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