@shell-shock/core 0.6.0 → 0.8.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/components/docs.cjs +1 -1
- 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/docs.mjs +1 -1
- package/dist/components/docs.mjs.map +1 -1
- package/dist/components/helpers.cjs +15 -0
- package/dist/components/helpers.cjs.map +1 -0
- package/dist/components/helpers.d.cts +13 -0
- package/dist/components/helpers.d.cts.map +1 -0
- package/dist/components/helpers.d.mts +13 -0
- package/dist/components/helpers.d.mts.map +1 -0
- package/dist/components/helpers.mjs +14 -0
- package/dist/components/helpers.mjs.map +1 -0
- package/dist/components/index.cjs +5 -1
- package/dist/components/index.d.cts +3 -2
- package/dist/components/index.d.mts +3 -2
- package/dist/components/index.mjs +3 -2
- package/dist/components/options-parser-logic.cjs +156 -31
- package/dist/components/options-parser-logic.cjs.map +1 -1
- package/dist/components/options-parser-logic.d.cts +47 -8
- package/dist/components/options-parser-logic.d.cts.map +1 -1
- package/dist/components/options-parser-logic.d.mts +53 -14
- package/dist/components/options-parser-logic.d.mts.map +1 -1
- package/dist/components/options-parser-logic.mjs +154 -31
- package/dist/components/options-parser-logic.mjs.map +1 -1
- package/dist/components/usage.cjs +38 -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 +40 -7
- package/dist/components/usage.mjs.map +1 -1
- package/dist/helpers/persistence.cjs +31 -3
- package/dist/helpers/persistence.cjs.map +1 -1
- package/dist/helpers/persistence.mjs +31 -3
- package/dist/helpers/persistence.mjs.map +1 -1
- package/dist/helpers/resolve-command.cjs +68 -47
- package/dist/helpers/resolve-command.cjs.map +1 -1
- package/dist/helpers/resolve-command.mjs +70 -49
- package/dist/helpers/resolve-command.mjs.map +1 -1
- package/dist/helpers/validations.cjs +13 -36
- package/dist/helpers/validations.cjs.map +1 -1
- package/dist/helpers/validations.mjs +12 -36
- package/dist/helpers/validations.mjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/plugin-utils/context-helpers.cjs +3 -45
- package/dist/plugin-utils/context-helpers.cjs.map +1 -1
- package/dist/plugin-utils/context-helpers.d.cts +1 -37
- package/dist/plugin-utils/context-helpers.d.cts.map +1 -1
- package/dist/plugin-utils/context-helpers.d.mts +1 -37
- package/dist/plugin-utils/context-helpers.d.mts.map +1 -1
- package/dist/plugin-utils/context-helpers.mjs +4 -44
- package/dist/plugin-utils/context-helpers.mjs.map +1 -1
- package/dist/plugin-utils/index.cjs +0 -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 +9 -15
- 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 +9 -15
- package/dist/plugin.mjs.map +1 -1
- package/dist/types/command.d.cts +206 -33
- package/dist/types/command.d.cts.map +1 -1
- package/dist/types/command.d.mts +206 -33
- package/dist/types/command.d.mts.map +1 -1
- package/dist/types/index.d.cts +3 -2
- package/dist/types/index.d.mts +3 -2
- package/dist/types/runtime.d.cts +5 -15
- package/dist/types/runtime.d.cts.map +1 -1
- package/dist/types/runtime.d.mts +5 -15
- package/dist/types/runtime.d.mts.map +1 -1
- package/package.json +25 -11
|
@@ -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","getDynamicPathSegmentName","isCatchAllPathSegment","isDynamicPathSegment","isOptionalCatchAllPathSegment","isPathSegmentGroup","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","resolveCommandDynamicPathSegments","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","extractCommandDynamicSegment","segment","catchAll","segments","some","seg","reflectCommandTree","parent","isVirtual","replace","tree","dynamics","options","children","input","fs","existsSync","debug","id","resolved","plugins","reflectionLevel","metadata","function","parameters","firstParam","objectLiteral","class","optionsReflection","from","propertyReflection","getProperties","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 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 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) && !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 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 extractCommandDynamicSegment(\n command: CommandInput,\n segment: string,\n reflection: TypeParameter\n): CommandDynamicSegment {\n if (\n reflection.type.kind !== ReflectionKind.string &&\n !(\n reflection.type.kind === ReflectionKind.array &&\n reflection.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 reflection.type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const option = {\n name: segment,\n title: titleCase(segment),\n description:\n reflection.description ||\n resolveCommandOptionDescription(\n ReflectionKind.string,\n !!reflection.optional,\n segment,\n titleCase(segment),\n reflection.default\n ),\n optional: reflection.optional,\n default: reflection.default,\n catchAll: command.path.segments.some(\n seg =>\n getDynamicPathSegmentName(segment) === seg && isCatchAllPathSegment(seg)\n )\n } as CommandDynamicSegment;\n\n if (reflection.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 * 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 dynamics: {}\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.dynamics = tree.path.segments\n .filter(segment => isDynamicPathSegment(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 = getDynamicPathSegmentName(segment);\n obj[paramName] = extractCommandDynamicSegment(\n command,\n paramName,\n type.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 } 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.dynamics).filter(option => option.env !== false)\n // .length > 0\n // ) {\n // Object.values(tree.path.dynamics)\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 => !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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,SAAgB0B,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,eAAe6B,UACpB,cACA,GAAGL,SAASxB,eAAegC,SAAS,YAAY,SAAQ,QACtDR,SAASxB,eAAe8B,QAAQ,MAAM,KACtC;;AAIV,SAAgBG,iBAAiBC,SAAkBC,MAAsB;AACvE,QAAO1B,YAAYH,aAAa6B,KAAK,EAAED,QAAQE,aAAa,CACzDC,MAAM,IAAI,CACVC,QAAOC,MAAKC,QAAQD,EAAE,IAAI,CAACpB,qBAAqBoB,EAAE,CAAC,CACnDE,KAAK,IAAI,CACTC,WAAW,SAAS,GAAG,CACvBA,WAAW,SAAS,GAAG,CACvBA,WAAW,KAAK,IAAI;;;;;;;;AASzB,SAAgBC,mBAAmBR,MAAc;CAC/C,IAAIS,OAAOtC,aAAa6B,KAAK;CAC7B,IAAIT,OAAOnB,eAAe4B,MAAM,EAC9BU,kBAAkB,MACn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":"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","isDynamicPathSegment","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","extractCommandArgument","getName","parameter","reflectCommandTree","parent","isVirtual","replace","tree","icon","options","arguments","children","input","fs","existsSync","debug","id","resolved","plugins","reflectionLevel","metadata","function","parameters","getParameters","objectLiteral","class","optionsReflection","from","propertyReflection","getProperties","slice","arg","Object","values","forEach","types","addProperty","undefined","visibility","public","tags","domain","inputs","segments","segment","every","value","index"],"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 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 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 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 kind: type.kind,\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 CommandArgument;\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 StringCommandArgument | NumberCommandArgument).variadic = true;\n (option as StringCommandArgument | NumberCommandArgument).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 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} 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 } 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.arguments)\n .filter(arg => arg.env !== false)\n .forEach(arg =>\n context.env.types.env.addProperty({\n name: constantCase(arg.name),\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 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,SAAgByB,gCACdC,MACAC,UACAC,MACAC,OACAC,cACQ;AACR,QAAO,IAAIH,YAAY,CAACG,eAAe,eAAe,GAAE,GACtDJ,SAAStB,eAAe2B,UACpB,uCACA,sBAAqB,2BAEzBL,SAAStB,eAAe2B,UACpB,YACAL,SAAStB,eAAe4B,QACtB,mBACA,mBAAkB,GACtBH,OAAOI,MAAM,IAAIjB,UAAUY,KAAK,CAAA,GAClCF,SAAStB,eAAe2B,UACpB,cACA,GAAGL,SAAStB,eAAe8B,SAAS,YAAY,SAAQ,QACtDR,SAAStB,eAAe4B,QAAQ,MAAM,KACtC;;;;;;;;;;;;AAcV,SAAgBG,mCACdT,MACAC,UACAC,MACAC,OACAC,cACQ;AACR,Q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,YAAYM,SAAS;KAC/BzC,OAAOsC,OAAOtC;KACdwC,OAAOF,OAAOE,MACX5B,QAAO4B,UAASA,MAAMT,SAAS,EAAE,CACjCT,KAAIkB,UAAStD,aAAasD,MAAM,CAAC;KACpCqD,QAAQ;KACV;IACD,CAAC;IACF;AAGNT,SAAOC,OAAO1B,KAAKG,UAAU,CAC1BlD,QAAOuE,QAAOA,IAAIpC,QAAQ,MAAM,CAChCuC,SAAQH,QACP3E,QAAQuC,IAAIwC,MAAMxC,IAAIyC,YAAY;GAChCzF,MAAMb,aAAaiG,IAAIpF,KAAK;GAC5BD,UAAUqF,IAAIrF,WAAW,OAAO2F;GAChC/C,aAAayC,IAAIzC;GACjBgD,YAAYlH,qBAAqBmH;GACjCvD,MAAM+C,IAAIhD,WAAWE,SAAS;GAC9BW,SAASmC,IAAInC;GACb4C,MAAM;IACJ,GAAGT,IAAIhD,WAAWM,SAAS;IAC3BoD,QAAQ;IACV;GACD,CACH,CAAC;;AAGL,MAAK,MAAM7B,SAASxD,QAAQsF,OAAOlF,QACjCoD,YACEA,QAAM+B,SAASnF,QAAOoF,YAAW,CAACvG,qBAAqBuG,QAAQ,CAAC,CAC7DjE,WACDG,QAAQ6D,SAASnF,QAAOoF,YAAW,CAACvG,qBAAqBuG,QAAQ,CAAC,CAC/DjE,SACD,KACJiC,QAAM+B,SACHb,MAAM,GAAGhD,QAAQ6D,SAAShE,OAAO,CACjCkE,OAAOC,OAAOC,UAAUD,UAAUhE,QAAQ6D,SAASI,OAC1D,CAAC,CACCxC,MAAKI,SAASC,MAAMjE,QAAQ,MAAMwD,mBAAmB/C,SAASwD,OAAOL,KAAK;AAG5E,QAAOA"}
|
|
@@ -1,42 +1,19 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
2
3
|
|
|
3
4
|
//#region src/helpers/validations.ts
|
|
4
|
-
function
|
|
5
|
+
function validateArguments(command) {
|
|
5
6
|
const failures = [];
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
dynamicPathSegmentNames.add(require_plugin_utils_context_helpers.getDynamicPathSegmentName(segment));
|
|
14
|
-
}
|
|
15
|
-
if (command.path.segments.filter(require_plugin_utils_context_helpers.isDynamicPathSegment).length !== Object.keys(command.path.dynamics ?? {}).length) failures.push({
|
|
16
|
-
code: "DYNAMIC_PATH_SEGMENT_MISMATCH",
|
|
17
|
-
details: `Mismatch between dynamic path segments and defined dynamic path segments in command (found ${command.path.segments.filter(require_plugin_utils_context_helpers.isDynamicPathSegment).length} dynamic path segments in the command folder path "${command.path.segments.join("/")}", but ${Object.keys(command.path.dynamics ?? {}).length} potential dynamic path segment(s) could be determined from the command's function signature).`
|
|
18
|
-
});
|
|
19
|
-
const missing = command.path.segments.filter(require_plugin_utils_context_helpers.isDynamicPathSegment).filter((segment) => Object.prototype.hasOwnProperty.call(command.path.dynamics ?? {}, require_plugin_utils_context_helpers.getDynamicPathSegmentName(segment)) === false);
|
|
20
|
-
if (missing.length > 0) failures.push({
|
|
21
|
-
code: "MISSING_DYNAMIC_PATH_SEGMENT_DEFINITION",
|
|
22
|
-
details: `${missing.length} dynamic path segment${missing.length > 1 ? "s" : ""} in the command folder path "${command.path.segments.join("/")}" do${missing.length > 1 ? "" : "es"} not have corresponding entr${missing.length > 1 ? "ies" : "y"} in the command's path dynamic segments: \n- ${missing.map((segment) => `"${require_plugin_utils_context_helpers.getDynamicPathSegmentName(segment)}"`).join("\n- ")}`
|
|
23
|
-
});
|
|
24
|
-
else {
|
|
25
|
-
for (const varName of Object.keys(command.path.dynamics ?? {})) if (!command.path.segments.filter(require_plugin_utils_context_helpers.isDynamicPathSegment).find((segment) => require_plugin_utils_context_helpers.getDynamicPathSegmentName(segment) === varName)) failures.push({
|
|
26
|
-
code: "UNUSED_DYNAMIC_PATH_SEGMENT",
|
|
27
|
-
details: `The dynamic path segment name "${varName}" defined in the command's path dynamic segments is not used in the command folder path "${command.path.segments.join("/")}".`
|
|
28
|
-
});
|
|
29
|
-
command.path.segments.forEach((segment, index) => {
|
|
30
|
-
if (require_plugin_utils_context_helpers.isDynamicPathSegment(segment) && command.path.dynamics[require_plugin_utils_context_helpers.getDynamicPathSegmentName(segment)]?.catchAll === true && index + 1 < command.path.segments.length && command.path.segments[index + 1] && command.path.dynamics[require_plugin_utils_context_helpers.getDynamicPathSegmentName(command.path.segments[index + 1])]?.catchAll === true) failures.push({
|
|
31
|
-
code: "MULTIPLE_CATCH_ALL_PATH_SEGMENTS",
|
|
32
|
-
details: `The catch-all path segment "${require_plugin_utils_context_helpers.getDynamicPathSegmentName(segment)}" in the command at path "${command.path.segments.join("/")}" is marked as catch-all, and it is followed by another catch-all dynamic path segment "${require_plugin_utils_context_helpers.getDynamicPathSegmentName(command.path.segments[index + 1])}". Only one catch-all path segment is allowed per command, and it must be the final path segment.`
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
7
|
+
let sequential = false;
|
|
8
|
+
for (const argument of command.arguments ?? []) if ((argument.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || argument.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number) && argument.variadic) if (!sequential) sequential = true;
|
|
9
|
+
else failures.push({
|
|
10
|
+
code: "SEQUENTIAL_VARIADIC_ARGUMENTS",
|
|
11
|
+
details: `Sequential variadic arguments are not allowed - since the argument preceding ${argument.name} is variadic, it must not also be variadic.`
|
|
12
|
+
});
|
|
13
|
+
else sequential = false;
|
|
37
14
|
return failures;
|
|
38
15
|
}
|
|
39
|
-
function
|
|
16
|
+
function validateOptions(command) {
|
|
40
17
|
const failures = [];
|
|
41
18
|
const optionNames = /* @__PURE__ */ new Set();
|
|
42
19
|
for (const option of Object.values(command.options ?? {})) {
|
|
@@ -57,9 +34,9 @@ function validateCommandOptions(command) {
|
|
|
57
34
|
}
|
|
58
35
|
function validateCommand(command) {
|
|
59
36
|
const results = [];
|
|
60
|
-
let failures =
|
|
37
|
+
let failures = validateOptions(command);
|
|
61
38
|
if (failures.length > 0) results.push(...failures);
|
|
62
|
-
failures =
|
|
39
|
+
failures = validateArguments(command);
|
|
63
40
|
if (failures.length > 0) results.push(...failures);
|
|
64
41
|
return results;
|
|
65
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validations.cjs","names":["
|
|
1
|
+
{"version":3,"file":"validations.cjs","names":["ReflectionKind","validateArguments","command","failures","sequential","argument","arguments","kind","string","number","variadic","push","code","details","name","validateOptions","optionNames","Set","option","Object","values","options","has","add","alias","validateCommand","results","length"],"sources":["../../src/helpers/validations.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 { ReflectionKind } from \"@powerlines/deepkit/vendor/type\";\nimport type { CommandTree } from \"../types\";\n\nexport interface ValidationFailure {\n code: string;\n details: string;\n}\n\nexport function validateArguments(command: CommandTree): ValidationFailure[] {\n const failures: ValidationFailure[] = [];\n\n let sequential = false;\n for (const argument of command.arguments ?? []) {\n if (\n (argument.kind === ReflectionKind.string ||\n argument.kind === ReflectionKind.number) &&\n argument.variadic\n ) {\n if (!sequential) {\n sequential = true;\n } else {\n failures.push({\n code: \"SEQUENTIAL_VARIADIC_ARGUMENTS\",\n details: `Sequential variadic arguments are not allowed - since the argument preceding ${argument.name} is variadic, it must not also be variadic.`\n });\n }\n } else {\n sequential = false;\n }\n }\n\n return failures;\n}\n\nexport function validateOptions(command: CommandTree): ValidationFailure[] {\n const failures: ValidationFailure[] = [];\n\n const optionNames = new Set<string>();\n for (const option of Object.values(command.options ?? {})) {\n if (optionNames.has(option.name)) {\n failures.push({\n code: \"DUPLICATE_OPTION_NAME\",\n details: `Duplicate option name \"${option.name}\" found in command.`\n });\n }\n optionNames.add(option.name);\n\n for (const alias of option.alias) {\n if (optionNames.has(alias)) {\n failures.push({\n code: \"DUPLICATE_OPTION_ALIAS\",\n details: `Duplicate option name \"${alias}\" (an alias of \"${\n option.name\n }\") found in command.`\n });\n }\n optionNames.add(alias);\n }\n }\n\n return failures;\n}\n\nexport function validateCommand(command: CommandTree): ValidationFailure[] {\n const results: ValidationFailure[] = [];\n\n let failures = validateOptions(command);\n if (failures.length > 0) {\n results.push(...failures);\n }\n\n failures = validateArguments(command);\n if (failures.length > 0) {\n results.push(...failures);\n }\n\n return results;\n}\n"],"mappings":";;;;AA0BA,SAAgBC,kBAAkBC,SAA2C;CAC3E,MAAMC,WAAgC,EAAE;CAExC,IAAIC,aAAa;AACjB,MAAK,MAAMC,YAAYH,QAAQI,aAAa,EAAE,CAC5C,MACGD,SAASE,SAASP,gDAAeQ,UAChCH,SAASE,SAASP,gDAAeS,WACnCJ,SAASK,SAET,KAAI,CAACN,WACHA,cAAa;KAEbD,UAASQ,KAAK;EACZC,MAAM;EACNC,SAAS,gFAAgFR,SAASS,KAAI;EACvG,CAAC;KAGJV,cAAa;AAIjB,QAAOD;;AAGT,SAAgBY,gBAAgBb,SAA2C;CACzE,MAAMC,WAAgC,EAAE;CAExC,MAAMa,8BAAc,IAAIC,KAAa;AACrC,MAAK,MAAMC,UAAUC,OAAOC,OAAOlB,QAAQmB,WAAW,EAAE,CAAC,EAAE;AACzD,MAAIL,YAAYM,IAAIJ,OAAOJ,KAAK,CAC9BX,UAASQ,KAAK;GACZC,MAAM;GACNC,SAAS,0BAA0BK,OAAOJ,KAAI;GAC/C,CAAC;AAEJE,cAAYO,IAAIL,OAAOJ,KAAK;AAE5B,OAAK,MAAMU,SAASN,OAAOM,OAAO;AAChC,OAAIR,YAAYM,IAAIE,MAAM,CACxBrB,UAASQ,KAAK;IACZC,MAAM;IACNC,SAAS,0BAA0BW,MAAK,kBACtCN,OAAOJ,KAAI;IAEd,CAAC;AAEJE,eAAYO,IAAIC,MAAM;;;AAI1B,QAAOrB;;AAGT,SAAgBsB,gBAAgBvB,SAA2C;CACzE,MAAMwB,UAA+B,EAAE;CAEvC,IAAIvB,WAAWY,gBAAgBb,QAAQ;AACvC,KAAIC,SAASwB,SAAS,EACpBD,SAAQf,KAAK,GAAGR,SAAS;AAG3BA,YAAWF,kBAAkBC,QAAQ;AACrC,KAAIC,SAASwB,SAAS,EACpBD,SAAQf,KAAK,GAAGR,SAAS;AAG3B,QAAOuB"}
|
|
@@ -1,42 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
|
|
2
2
|
|
|
3
3
|
//#region src/helpers/validations.ts
|
|
4
|
-
function
|
|
4
|
+
function validateArguments(command) {
|
|
5
5
|
const failures = [];
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
dynamicPathSegmentNames.add(getDynamicPathSegmentName(segment));
|
|
14
|
-
}
|
|
15
|
-
if (command.path.segments.filter(isDynamicPathSegment).length !== Object.keys(command.path.dynamics ?? {}).length) failures.push({
|
|
16
|
-
code: "DYNAMIC_PATH_SEGMENT_MISMATCH",
|
|
17
|
-
details: `Mismatch between dynamic path segments and defined dynamic path segments in command (found ${command.path.segments.filter(isDynamicPathSegment).length} dynamic path segments in the command folder path "${command.path.segments.join("/")}", but ${Object.keys(command.path.dynamics ?? {}).length} potential dynamic path segment(s) could be determined from the command's function signature).`
|
|
18
|
-
});
|
|
19
|
-
const missing = command.path.segments.filter(isDynamicPathSegment).filter((segment) => Object.prototype.hasOwnProperty.call(command.path.dynamics ?? {}, getDynamicPathSegmentName(segment)) === false);
|
|
20
|
-
if (missing.length > 0) failures.push({
|
|
21
|
-
code: "MISSING_DYNAMIC_PATH_SEGMENT_DEFINITION",
|
|
22
|
-
details: `${missing.length} dynamic path segment${missing.length > 1 ? "s" : ""} in the command folder path "${command.path.segments.join("/")}" do${missing.length > 1 ? "" : "es"} not have corresponding entr${missing.length > 1 ? "ies" : "y"} in the command's path dynamic segments: \n- ${missing.map((segment) => `"${getDynamicPathSegmentName(segment)}"`).join("\n- ")}`
|
|
23
|
-
});
|
|
24
|
-
else {
|
|
25
|
-
for (const varName of Object.keys(command.path.dynamics ?? {})) if (!command.path.segments.filter(isDynamicPathSegment).find((segment) => getDynamicPathSegmentName(segment) === varName)) failures.push({
|
|
26
|
-
code: "UNUSED_DYNAMIC_PATH_SEGMENT",
|
|
27
|
-
details: `The dynamic path segment name "${varName}" defined in the command's path dynamic segments is not used in the command folder path "${command.path.segments.join("/")}".`
|
|
28
|
-
});
|
|
29
|
-
command.path.segments.forEach((segment, index) => {
|
|
30
|
-
if (isDynamicPathSegment(segment) && command.path.dynamics[getDynamicPathSegmentName(segment)]?.catchAll === true && index + 1 < command.path.segments.length && command.path.segments[index + 1] && command.path.dynamics[getDynamicPathSegmentName(command.path.segments[index + 1])]?.catchAll === true) failures.push({
|
|
31
|
-
code: "MULTIPLE_CATCH_ALL_PATH_SEGMENTS",
|
|
32
|
-
details: `The catch-all path segment "${getDynamicPathSegmentName(segment)}" in the command at path "${command.path.segments.join("/")}" is marked as catch-all, and it is followed by another catch-all dynamic path segment "${getDynamicPathSegmentName(command.path.segments[index + 1])}". Only one catch-all path segment is allowed per command, and it must be the final path segment.`
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
6
|
+
let sequential = false;
|
|
7
|
+
for (const argument of command.arguments ?? []) if ((argument.kind === ReflectionKind.string || argument.kind === ReflectionKind.number) && argument.variadic) if (!sequential) sequential = true;
|
|
8
|
+
else failures.push({
|
|
9
|
+
code: "SEQUENTIAL_VARIADIC_ARGUMENTS",
|
|
10
|
+
details: `Sequential variadic arguments are not allowed - since the argument preceding ${argument.name} is variadic, it must not also be variadic.`
|
|
11
|
+
});
|
|
12
|
+
else sequential = false;
|
|
37
13
|
return failures;
|
|
38
14
|
}
|
|
39
|
-
function
|
|
15
|
+
function validateOptions(command) {
|
|
40
16
|
const failures = [];
|
|
41
17
|
const optionNames = /* @__PURE__ */ new Set();
|
|
42
18
|
for (const option of Object.values(command.options ?? {})) {
|
|
@@ -57,9 +33,9 @@ function validateCommandOptions(command) {
|
|
|
57
33
|
}
|
|
58
34
|
function validateCommand(command) {
|
|
59
35
|
const results = [];
|
|
60
|
-
let failures =
|
|
36
|
+
let failures = validateOptions(command);
|
|
61
37
|
if (failures.length > 0) results.push(...failures);
|
|
62
|
-
failures =
|
|
38
|
+
failures = validateArguments(command);
|
|
63
39
|
if (failures.length > 0) results.push(...failures);
|
|
64
40
|
return results;
|
|
65
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validations.mjs","names":["
|
|
1
|
+
{"version":3,"file":"validations.mjs","names":["ReflectionKind","validateArguments","command","failures","sequential","argument","arguments","kind","string","number","variadic","push","code","details","name","validateOptions","optionNames","Set","option","Object","values","options","has","add","alias","validateCommand","results","length"],"sources":["../../src/helpers/validations.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 { ReflectionKind } from \"@powerlines/deepkit/vendor/type\";\nimport type { CommandTree } from \"../types\";\n\nexport interface ValidationFailure {\n code: string;\n details: string;\n}\n\nexport function validateArguments(command: CommandTree): ValidationFailure[] {\n const failures: ValidationFailure[] = [];\n\n let sequential = false;\n for (const argument of command.arguments ?? []) {\n if (\n (argument.kind === ReflectionKind.string ||\n argument.kind === ReflectionKind.number) &&\n argument.variadic\n ) {\n if (!sequential) {\n sequential = true;\n } else {\n failures.push({\n code: \"SEQUENTIAL_VARIADIC_ARGUMENTS\",\n details: `Sequential variadic arguments are not allowed - since the argument preceding ${argument.name} is variadic, it must not also be variadic.`\n });\n }\n } else {\n sequential = false;\n }\n }\n\n return failures;\n}\n\nexport function validateOptions(command: CommandTree): ValidationFailure[] {\n const failures: ValidationFailure[] = [];\n\n const optionNames = new Set<string>();\n for (const option of Object.values(command.options ?? {})) {\n if (optionNames.has(option.name)) {\n failures.push({\n code: \"DUPLICATE_OPTION_NAME\",\n details: `Duplicate option name \"${option.name}\" found in command.`\n });\n }\n optionNames.add(option.name);\n\n for (const alias of option.alias) {\n if (optionNames.has(alias)) {\n failures.push({\n code: \"DUPLICATE_OPTION_ALIAS\",\n details: `Duplicate option name \"${alias}\" (an alias of \"${\n option.name\n }\") found in command.`\n });\n }\n optionNames.add(alias);\n }\n }\n\n return failures;\n}\n\nexport function validateCommand(command: CommandTree): ValidationFailure[] {\n const results: ValidationFailure[] = [];\n\n let failures = validateOptions(command);\n if (failures.length > 0) {\n results.push(...failures);\n }\n\n failures = validateArguments(command);\n if (failures.length > 0) {\n results.push(...failures);\n }\n\n return results;\n}\n"],"mappings":";;;AA0BA,SAAgBC,kBAAkBC,SAA2C;CAC3E,MAAMC,WAAgC,EAAE;CAExC,IAAIC,aAAa;AACjB,MAAK,MAAMC,YAAYH,QAAQI,aAAa,EAAE,CAC5C,MACGD,SAASE,SAASP,eAAeQ,UAChCH,SAASE,SAASP,eAAeS,WACnCJ,SAASK,SAET,KAAI,CAACN,WACHA,cAAa;KAEbD,UAASQ,KAAK;EACZC,MAAM;EACNC,SAAS,gFAAgFR,SAASS,KAAI;EACvG,CAAC;KAGJV,cAAa;AAIjB,QAAOD;;AAGT,SAAgBY,gBAAgBb,SAA2C;CACzE,MAAMC,WAAgC,EAAE;CAExC,MAAMa,8BAAc,IAAIC,KAAa;AACrC,MAAK,MAAMC,UAAUC,OAAOC,OAAOlB,QAAQmB,WAAW,EAAE,CAAC,EAAE;AACzD,MAAIL,YAAYM,IAAIJ,OAAOJ,KAAK,CAC9BX,UAASQ,KAAK;GACZC,MAAM;GACNC,SAAS,0BAA0BK,OAAOJ,KAAI;GAC/C,CAAC;AAEJE,cAAYO,IAAIL,OAAOJ,KAAK;AAE5B,OAAK,MAAMU,SAASN,OAAOM,OAAO;AAChC,OAAIR,YAAYM,IAAIE,MAAM,CACxBrB,UAASQ,KAAK;IACZC,MAAM;IACNC,SAAS,0BAA0BW,MAAK,kBACtCN,OAAOJ,KAAI;IAEd,CAAC;AAEJE,eAAYO,IAAIC,MAAM;;;AAI1B,QAAOrB;;AAGT,SAAgBsB,gBAAgBvB,SAA2C;CACzE,MAAMwB,UAA+B,EAAE;CAEvC,IAAIvB,WAAWY,gBAAgBb,QAAQ;AACvC,KAAIC,SAASwB,SAAS,EACpBD,SAAQf,KAAK,GAAGR,SAAS;AAG3BA,YAAWF,kBAAkBC,QAAQ;AACrC,KAAIC,SAASwB,SAAS,EACpBD,SAAQf,KAAK,GAAGR,SAAS;AAG3B,QAAOuB"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseCommandParameter, BooleanCommandArgument, BooleanCommandOption, BooleanCommandParameter, CommandArgument, CommandBase, CommandInput, CommandModule, CommandOption, CommandTree, Metadata, NumberCommandArgument, NumberCommandOption, NumberCommandParameter, SerializedCommandArgument, SerializedCommandOption, SerializedCommandTree, StringCommandArgument, StringCommandOption, StringCommandParameter } from "./types/command.cjs";
|
|
2
2
|
import { Context, UnresolvedContext } from "./types/context.cjs";
|
|
3
3
|
import { BaseConfig, Options, OutputConfig, ResolvedConfig, UserConfig } from "./types/config.cjs";
|
|
4
4
|
import { ShellShockAPI, createShellShock } from "./api.cjs";
|
|
5
5
|
import { defineConfig } from "./config.cjs";
|
|
6
6
|
import { BaseCommandOptions } from "./types/options.cjs";
|
|
7
|
+
import { CommandContext } from "./types/runtime.cjs";
|
|
7
8
|
import "./types/index.cjs";
|
|
8
9
|
import plugin from "./plugin.cjs";
|
|
9
|
-
export {
|
|
10
|
+
export { BaseCommandOptions, BaseCommandParameter, BaseConfig, BooleanCommandArgument, BooleanCommandOption, BooleanCommandParameter, CommandArgument, CommandBase, CommandContext, CommandInput, CommandModule, CommandOption, CommandTree, Context, Metadata, NumberCommandArgument, NumberCommandOption, NumberCommandParameter, Options, OutputConfig, ResolvedConfig, SerializedCommandArgument, SerializedCommandOption, SerializedCommandTree, ShellShockAPI, ShellShockAPI as default, StringCommandArgument, StringCommandOption, StringCommandParameter, UnresolvedContext, UserConfig, createShellShock, defineConfig, plugin, plugin as shellShock };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseCommandParameter, BooleanCommandArgument, BooleanCommandOption, BooleanCommandParameter, CommandArgument, CommandBase, CommandInput, CommandModule, CommandOption, CommandTree, Metadata, NumberCommandArgument, NumberCommandOption, NumberCommandParameter, SerializedCommandArgument, SerializedCommandOption, SerializedCommandTree, StringCommandArgument, StringCommandOption, StringCommandParameter } from "./types/command.mjs";
|
|
2
2
|
import { Context, UnresolvedContext } from "./types/context.mjs";
|
|
3
3
|
import { BaseConfig, Options, OutputConfig, ResolvedConfig, UserConfig } from "./types/config.mjs";
|
|
4
4
|
import { ShellShockAPI, createShellShock } from "./api.mjs";
|
|
5
5
|
import { defineConfig } from "./config.mjs";
|
|
6
6
|
import { BaseCommandOptions } from "./types/options.mjs";
|
|
7
|
+
import { CommandContext } from "./types/runtime.mjs";
|
|
7
8
|
import "./types/index.mjs";
|
|
8
9
|
import plugin from "./plugin.mjs";
|
|
9
|
-
export {
|
|
10
|
+
export { BaseCommandOptions, BaseCommandParameter, BaseConfig, BooleanCommandArgument, BooleanCommandOption, BooleanCommandParameter, CommandArgument, CommandBase, CommandContext, CommandInput, CommandModule, CommandOption, CommandTree, Context, Metadata, NumberCommandArgument, NumberCommandOption, NumberCommandParameter, Options, OutputConfig, ResolvedConfig, SerializedCommandArgument, SerializedCommandOption, SerializedCommandTree, ShellShockAPI, ShellShockAPI as default, StringCommandArgument, StringCommandOption, StringCommandParameter, UnresolvedContext, UserConfig, createShellShock, defineConfig, plugin, plugin as shellShock };
|
|
@@ -63,8 +63,6 @@ function getAppBin(context) {
|
|
|
63
63
|
* ```typescript
|
|
64
64
|
* isDynamicPathSegment("[user]"); // true
|
|
65
65
|
* isDynamicPathSegment("user"); // false
|
|
66
|
-
* isDynamicPathSegment("[[...user]]"); // true
|
|
67
|
-
* isDynamicPathSegment("[...user]"); // true
|
|
68
66
|
* ```
|
|
69
67
|
*
|
|
70
68
|
* @param path - The command path segment to check.
|
|
@@ -74,52 +72,18 @@ function isDynamicPathSegment(path) {
|
|
|
74
72
|
return path.startsWith("[") && path.endsWith("]");
|
|
75
73
|
}
|
|
76
74
|
/**
|
|
77
|
-
* Determines if a given command path segment is an optional catch-all segment (enclosed in square brackets with a leading ellipsis).
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```typescript
|
|
81
|
-
* isOptionalCatchAllPathSegment("[[...user]]"); // true
|
|
82
|
-
* isOptionalCatchAllPathSegment("[...user]"); // false
|
|
83
|
-
* isOptionalCatchAllPathSegment("[user]"); // false
|
|
84
|
-
* ```
|
|
85
|
-
*
|
|
86
|
-
* @param path - The command path segment to check.
|
|
87
|
-
* @returns True if the path is an optional catch-all segment, false otherwise.
|
|
88
|
-
*/
|
|
89
|
-
function isOptionalCatchAllPathSegment(path) {
|
|
90
|
-
return path.startsWith("[[...") && path.endsWith("]]");
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Determines if a given command path segment is an optional catch-all segment (enclosed in square brackets with a leading ellipsis).
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```typescript
|
|
97
|
-
* isCatchAllPathSegment("[[...user]]"); // true
|
|
98
|
-
* isCatchAllPathSegment("[...user]"); // true
|
|
99
|
-
* isCatchAllPathSegment("[user]"); // false
|
|
100
|
-
* ```
|
|
101
|
-
*
|
|
102
|
-
* @param path - The command path segment to check.
|
|
103
|
-
* @returns True if the path is a catch-all segment, false otherwise.
|
|
104
|
-
*/
|
|
105
|
-
function isCatchAllPathSegment(path) {
|
|
106
|
-
return path.startsWith("[...") && path.endsWith("]") || isOptionalCatchAllPathSegment(path);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
75
|
* Extracts the variable name from a command path segment by removing enclosing square brackets.
|
|
110
76
|
*
|
|
111
77
|
* @example
|
|
112
78
|
* ```typescript
|
|
113
79
|
* getDynamicPathSegmentName("[user]"); // "user"
|
|
114
|
-
* getDynamicPathSegmentName("[[...user]]"); // "user"
|
|
115
|
-
* getDynamicPathSegmentName("[...user]"); // "user"
|
|
116
80
|
* ```
|
|
117
81
|
*
|
|
118
82
|
* @param path - The command path segment.
|
|
119
83
|
* @returns The variable name without square brackets.
|
|
120
84
|
*/
|
|
121
85
|
function getDynamicPathSegmentName(path) {
|
|
122
|
-
return path.replaceAll(/^\[
|
|
86
|
+
return path.replaceAll(/^\[+/g, "").replaceAll(/\]+$/g, "");
|
|
123
87
|
}
|
|
124
88
|
/**
|
|
125
89
|
* Determines if a given command path segment is a path segment group (enclosed in parentheses).
|
|
@@ -127,8 +91,6 @@ function getDynamicPathSegmentName(path) {
|
|
|
127
91
|
* @example
|
|
128
92
|
* ```typescript
|
|
129
93
|
* isPathSegmentGroup("(user)"); // true
|
|
130
|
-
* isPathSegmentGroup("[[...user]]"); // false
|
|
131
|
-
* isPathSegmentGroup("[...user]"); // false
|
|
132
94
|
* isPathSegmentGroup("[user]"); // false
|
|
133
95
|
* isPathSegmentGroup("user"); // false
|
|
134
96
|
* ```
|
|
@@ -137,7 +99,7 @@ function getDynamicPathSegmentName(path) {
|
|
|
137
99
|
* @returns True if the path is a path segment group, false otherwise.
|
|
138
100
|
*/
|
|
139
101
|
function isPathSegmentGroup(path) {
|
|
140
|
-
return path.startsWith("(") && path.endsWith(")");
|
|
102
|
+
return path.startsWith("(") && path.endsWith(")") || path.startsWith("_");
|
|
141
103
|
}
|
|
142
104
|
/**
|
|
143
105
|
* Extracts the group name from a command path segment by removing enclosing parentheses.
|
|
@@ -152,7 +114,7 @@ function isPathSegmentGroup(path) {
|
|
|
152
114
|
* @returns The group name without parentheses.
|
|
153
115
|
*/
|
|
154
116
|
function getPathSegmentGroupName(path) {
|
|
155
|
-
return path.replaceAll(/^\(+/g, "").replaceAll(/\)+$/g, "");
|
|
117
|
+
return path.replaceAll(/^\(+/g, "").replaceAll(/\)+$/g, "").replaceAll(/^_+/g, "");
|
|
156
118
|
}
|
|
157
119
|
/**
|
|
158
120
|
* Extracts the variable name from a command path segment by removing enclosing square brackets.
|
|
@@ -160,8 +122,6 @@ function getPathSegmentGroupName(path) {
|
|
|
160
122
|
* @example
|
|
161
123
|
* ```typescript
|
|
162
124
|
* getDynamicPathSegmentName("[user]"); // "user"
|
|
163
|
-
* getDynamicPathSegmentName("[[...user]]"); // "user"
|
|
164
|
-
* getDynamicPathSegmentName("[...user]"); // "user"
|
|
165
125
|
* ```
|
|
166
126
|
*
|
|
167
127
|
* @param path - The command path segment.
|
|
@@ -179,9 +139,7 @@ exports.getAppTitle = getAppTitle;
|
|
|
179
139
|
exports.getDynamicPathSegmentName = getDynamicPathSegmentName;
|
|
180
140
|
exports.getPathSegmentGroupName = getPathSegmentGroupName;
|
|
181
141
|
exports.getPathSegmentName = getPathSegmentName;
|
|
182
|
-
exports.isCatchAllPathSegment = isCatchAllPathSegment;
|
|
183
142
|
exports.isDynamicPathSegment = isDynamicPathSegment;
|
|
184
|
-
exports.isOptionalCatchAllPathSegment = isOptionalCatchAllPathSegment;
|
|
185
143
|
exports.isPathSegmentGroup = isPathSegmentGroup;
|
|
186
144
|
exports.sortArgAliases = sortArgAliases;
|
|
187
145
|
//# sourceMappingURL=context-helpers.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-helpers.cjs","names":["kebabCase","titleCase","isSetObject","isSetString","sortArgAliases","aliases","length","result","filter","alias","push","sort","a","b","localeCompare","getAppName","context","config","name","bin","Array","isArray","packageJson","Error","getAppTitle","title","getAppDescription","description","getAppBin","Object","keys","isDynamicPathSegment","path","startsWith","endsWith","isOptionalCatchAllPathSegment","isCatchAllPathSegment","getDynamicPathSegmentName","replaceAll","isPathSegmentGroup","getPathSegmentGroupName","getPathSegmentName"],"sources":["../../src/plugin-utils/context-helpers.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 { kebabCase } from \"@stryke/string-format/kebab-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 type { Context, UnresolvedContext } from \"../types\";\n\n/**\n * Sorts command argument aliases, placing single-character aliases first, followed by multi-character aliases, and then sorting them alphabetically.\n *\n * @param aliases - An array of argument aliases to sort.\n * @returns A new array of sorted aliases.\n */\nexport function sortArgAliases(aliases: string[]): string[] {\n if (aliases.length === 0) {\n return [];\n }\n\n const result = aliases.filter(alias => alias.length === 1);\n result.push(...aliases.filter(alias => alias.length > 1));\n\n return result.sort((a, b) => a.localeCompare(b));\n}\n\n/**\n * Retrieves the application name from the context and configuration.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The application name in kebab-case format.\n * @throws An error if no valid application name is found.\n */\nexport function getAppName(context: UnresolvedContext | Context): string {\n const result =\n context.config.name ||\n (isSetString(context.config.bin) ||\n (Array.isArray(context.config.bin) &&\n context.config.bin.length > 0 &&\n isSetString(context.config.bin[0]))\n ? isSetString(context.config.bin)\n ? context.config.bin\n : context.config.bin[0]\n : context.packageJson?.name);\n if (!isSetString(result)) {\n throw new Error(\n \"No application name found. Please provide a 'bin' option in the configuration or ensure the package.json has a valid 'name' field.\"\n );\n }\n\n return kebabCase(result);\n}\n\n/**\n * Retrieves the application title from the context and configuration.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The application title in title-case format.\n */\nexport function getAppTitle(context: UnresolvedContext | Context): string {\n return (\n context.config.title ||\n titleCase(context.config.name || getAppName(context))\n );\n}\n\n/**\n * Retrieves the application description from the context and configuration.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The application description.\n */\nexport function getAppDescription(\n context: UnresolvedContext | Context\n): string {\n return (\n context.config.description ||\n context.packageJson?.description ||\n `The ${getAppTitle(context)} command-line interface application.`\n );\n}\n\n/**\n * Retrieves the primary binary name for the application.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The primary binary name as a string.\n */\nexport function getAppBin(context: Context): string {\n return isSetObject(context.config.bin)\n ? Object.keys(context.config.bin)[0]!\n : kebabCase(getAppName(context));\n}\n\n/**\n * Determines if a given command path segment is variable (enclosed in square brackets).\n *\n * @example\n * ```typescript\n * isDynamicPathSegment(\"[user]\"); // true\n * isDynamicPathSegment(\"user\"); // false\n * isDynamicPathSegment(\"[[...user]]\"); // true\n * isDynamicPathSegment(\"[...user]\"); // true\n * ```\n *\n * @param path - The command path segment to check.\n * @returns True if the path is variable, false otherwise.\n */\nexport function isDynamicPathSegment(path: string): boolean {\n return path.startsWith(\"[\") && path.endsWith(\"]\");\n}\n\n/**\n * Determines if a given command path segment is an optional catch-all segment (enclosed in square brackets with a leading ellipsis).\n *\n * @example\n * ```typescript\n * isOptionalCatchAllPathSegment(\"[[...user]]\"); // true\n * isOptionalCatchAllPathSegment(\"[...user]\"); // false\n * isOptionalCatchAllPathSegment(\"[user]\"); // false\n * ```\n *\n * @param path - The command path segment to check.\n * @returns True if the path is an optional catch-all segment, false otherwise.\n */\nexport function isOptionalCatchAllPathSegment(path: string): boolean {\n return path.startsWith(\"[[...\") && path.endsWith(\"]]\");\n}\n\n/**\n * Determines if a given command path segment is an optional catch-all segment (enclosed in square brackets with a leading ellipsis).\n *\n * @example\n * ```typescript\n * isCatchAllPathSegment(\"[[...user]]\"); // true\n * isCatchAllPathSegment(\"[...user]\"); // true\n * isCatchAllPathSegment(\"[user]\"); // false\n * ```\n *\n * @param path - The command path segment to check.\n * @returns True if the path is a catch-all segment, false otherwise.\n */\nexport function isCatchAllPathSegment(path: string): boolean {\n return (\n (path.startsWith(\"[...\") && path.endsWith(\"]\")) ||\n isOptionalCatchAllPathSegment(path)\n );\n}\n\n/**\n * Extracts the variable name from a command path segment by removing enclosing square brackets.\n *\n * @example\n * ```typescript\n * getDynamicPathSegmentName(\"[user]\"); // \"user\"\n * getDynamicPathSegmentName(\"[[...user]]\"); // \"user\"\n * getDynamicPathSegmentName(\"[...user]\"); // \"user\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The variable name without square brackets.\n */\nexport function getDynamicPathSegmentName(path: string): string {\n return path.replaceAll(/^\\[+(?:\\.\\.\\.)*/g, \"\").replaceAll(/\\]+$/g, \"\");\n}\n\n/**\n * Determines if a given command path segment is a path segment group (enclosed in parentheses).\n *\n * @example\n * ```typescript\n * isPathSegmentGroup(\"(user)\"); // true\n * isPathSegmentGroup(\"[[...user]]\"); // false\n * isPathSegmentGroup(\"[...user]\"); // false\n * isPathSegmentGroup(\"[user]\"); // false\n * isPathSegmentGroup(\"user\"); // false\n * ```\n *\n * @param path - The command path segment to check.\n * @returns True if the path is a path segment group, false otherwise.\n */\nexport function isPathSegmentGroup(path: string): boolean {\n return path.startsWith(\"(\") && path.endsWith(\")\");\n}\n\n/**\n * Extracts the group name from a command path segment by removing enclosing parentheses.\n *\n * @example\n * ```typescript\n * getPathSegmentGroupName(\"(admin)\"); // \"admin\"\n * getPathSegmentGroupName(\"((group))\"); // \"group\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The group name without parentheses.\n */\nexport function getPathSegmentGroupName(path: string): string {\n return path.replaceAll(/^\\(+/g, \"\").replaceAll(/\\)+$/g, \"\");\n}\n\n/**\n * Extracts the variable name from a command path segment by removing enclosing square brackets.\n *\n * @example\n * ```typescript\n * getDynamicPathSegmentName(\"[user]\"); // \"user\"\n * getDynamicPathSegmentName(\"[[...user]]\"); // \"user\"\n * getDynamicPathSegmentName(\"[...user]\"); // \"user\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The variable name without square brackets.\n */\nexport function getPathSegmentName(path: string): string {\n return getPathSegmentGroupName(getDynamicPathSegmentName(path));\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,SAAgBI,eAAeC,SAA6B;AAC1D,KAAIA,QAAQC,WAAW,EACrB,QAAO,EAAE;CAGX,MAAMC,SAASF,QAAQG,QAAOC,UAASA,MAAMH,WAAW,EAAE;AAC1DC,QAAOG,KAAK,GAAGL,QAAQG,QAAOC,UAASA,MAAMH,SAAS,EAAE,CAAC;AAEzD,QAAOC,OAAOI,MAAMC,GAAGC,MAAMD,EAAEE,cAAcD,EAAE,CAAC;;;;;;;;;AAUlD,SAAgBE,WAAWC,SAA8C;CACvE,MAAMT,SACJS,QAAQC,OAAOC,6DACFF,QAAQC,OAAOE,IAAI,IAC/BC,MAAMC,QAAQL,QAAQC,OAAOE,IAAI,IAChCH,QAAQC,OAAOE,IAAIb,SAAS,yDAChBU,QAAQC,OAAOE,IAAI,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SAAS,GAAG,CAACA,WAAW,SAAS,GAAG;;;;;;;;;;;;;;;AAgB7D,SAAgBG,mBAAmBT,MAAsB;AACvD,QAAOQ,wBAAwBH,0BAA0BL,KAAK,CAAC"}
|
|
1
|
+
{"version":3,"file":"context-helpers.cjs","names":["kebabCase","titleCase","isSetObject","isSetString","sortArgAliases","aliases","length","result","filter","alias","push","sort","a","b","localeCompare","getAppName","context","config","name","bin","Array","isArray","packageJson","Error","getAppTitle","title","getAppDescription","description","getAppBin","Object","keys","isDynamicPathSegment","path","startsWith","endsWith","getDynamicPathSegmentName","replaceAll","isPathSegmentGroup","getPathSegmentGroupName","getPathSegmentName"],"sources":["../../src/plugin-utils/context-helpers.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 { kebabCase } from \"@stryke/string-format/kebab-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 type { Context, UnresolvedContext } from \"../types\";\n\n/**\n * Sorts command argument aliases, placing single-character aliases first, followed by multi-character aliases, and then sorting them alphabetically.\n *\n * @param aliases - An array of argument aliases to sort.\n * @returns A new array of sorted aliases.\n */\nexport function sortArgAliases(aliases: string[]): string[] {\n if (aliases.length === 0) {\n return [];\n }\n\n const result = aliases.filter(alias => alias.length === 1);\n result.push(...aliases.filter(alias => alias.length > 1));\n\n return result.sort((a, b) => a.localeCompare(b));\n}\n\n/**\n * Retrieves the application name from the context and configuration.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The application name in kebab-case format.\n * @throws An error if no valid application name is found.\n */\nexport function getAppName(context: UnresolvedContext | Context): string {\n const result =\n context.config.name ||\n (isSetString(context.config.bin) ||\n (Array.isArray(context.config.bin) &&\n context.config.bin.length > 0 &&\n isSetString(context.config.bin[0]))\n ? isSetString(context.config.bin)\n ? context.config.bin\n : context.config.bin[0]\n : context.packageJson?.name);\n if (!isSetString(result)) {\n throw new Error(\n \"No application name found. Please provide a 'bin' option in the configuration or ensure the package.json has a valid 'name' field.\"\n );\n }\n\n return kebabCase(result);\n}\n\n/**\n * Retrieves the application title from the context and configuration.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The application title in title-case format.\n */\nexport function getAppTitle(context: UnresolvedContext | Context): string {\n return (\n context.config.title ||\n titleCase(context.config.name || getAppName(context))\n );\n}\n\n/**\n * Retrieves the application description from the context and configuration.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The application description.\n */\nexport function getAppDescription(\n context: UnresolvedContext | Context\n): string {\n return (\n context.config.description ||\n context.packageJson?.description ||\n `The ${getAppTitle(context)} command-line interface application.`\n );\n}\n\n/**\n * Retrieves the primary binary name for the application.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The primary binary name as a string.\n */\nexport function getAppBin(context: Context): string {\n return isSetObject(context.config.bin)\n ? Object.keys(context.config.bin)[0]!\n : kebabCase(getAppName(context));\n}\n\n/**\n * Determines if a given command path segment is variable (enclosed in square brackets).\n *\n * @example\n * ```typescript\n * isDynamicPathSegment(\"[user]\"); // true\n * isDynamicPathSegment(\"user\"); // false\n * ```\n *\n * @param path - The command path segment to check.\n * @returns True if the path is variable, false otherwise.\n */\nexport function isDynamicPathSegment(path: string): boolean {\n return path.startsWith(\"[\") && path.endsWith(\"]\");\n}\n\n/**\n * Extracts the variable name from a command path segment by removing enclosing square brackets.\n *\n * @example\n * ```typescript\n * getDynamicPathSegmentName(\"[user]\"); // \"user\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The variable name without square brackets.\n */\nexport function getDynamicPathSegmentName(path: string): string {\n return path.replaceAll(/^\\[+/g, \"\").replaceAll(/\\]+$/g, \"\");\n}\n\n/**\n * Determines if a given command path segment is a path segment group (enclosed in parentheses).\n *\n * @example\n * ```typescript\n * isPathSegmentGroup(\"(user)\"); // true\n * isPathSegmentGroup(\"[user]\"); // false\n * isPathSegmentGroup(\"user\"); // false\n * ```\n *\n * @param path - The command path segment to check.\n * @returns True if the path is a path segment group, false otherwise.\n */\nexport function isPathSegmentGroup(path: string): boolean {\n return (path.startsWith(\"(\") && path.endsWith(\")\")) || path.startsWith(\"_\");\n}\n\n/**\n * Extracts the group name from a command path segment by removing enclosing parentheses.\n *\n * @example\n * ```typescript\n * getPathSegmentGroupName(\"(admin)\"); // \"admin\"\n * getPathSegmentGroupName(\"((group))\"); // \"group\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The group name without parentheses.\n */\nexport function getPathSegmentGroupName(path: string): string {\n return path\n .replaceAll(/^\\(+/g, \"\")\n .replaceAll(/\\)+$/g, \"\")\n .replaceAll(/^_+/g, \"\");\n}\n\n/**\n * Extracts the variable name from a command path segment by removing enclosing square brackets.\n *\n * @example\n * ```typescript\n * getDynamicPathSegmentName(\"[user]\"); // \"user\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The variable name without square brackets.\n */\nexport function getPathSegmentName(path: string): string {\n return getPathSegmentGroupName(getDynamicPathSegmentName(path));\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,SAAgBI,eAAeC,SAA6B;AAC1D,KAAIA,QAAQC,WAAW,EACrB,QAAO,EAAE;CAGX,MAAMC,SAASF,QAAQG,QAAOC,UAASA,MAAMH,WAAW,EAAE;AAC1DC,QAAOG,KAAK,GAAGL,QAAQG,QAAOC,UAASA,MAAMH,SAAS,EAAE,CAAC;AAEzD,QAAOC,OAAOI,MAAMC,GAAGC,MAAMD,EAAEE,cAAcD,EAAE,CAAC;;;;;;;;;AAUlD,SAA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