@shell-shock/core 0.7.0 → 0.8.1

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.
Files changed (76) hide show
  1. package/README.md +1 -1
  2. package/dist/components/docs.cjs +1 -1
  3. package/dist/components/docs.cjs.map +1 -1
  4. package/dist/components/docs.d.mts +5 -5
  5. package/dist/components/docs.mjs +1 -1
  6. package/dist/components/docs.mjs.map +1 -1
  7. package/dist/components/helpers.cjs +15 -0
  8. package/dist/components/helpers.cjs.map +1 -0
  9. package/dist/components/helpers.d.cts +13 -0
  10. package/dist/components/helpers.d.cts.map +1 -0
  11. package/dist/components/helpers.d.mts +13 -0
  12. package/dist/components/helpers.d.mts.map +1 -0
  13. package/dist/components/helpers.mjs +14 -0
  14. package/dist/components/helpers.mjs.map +1 -0
  15. package/dist/components/index.cjs +4 -2
  16. package/dist/components/index.d.cts +3 -2
  17. package/dist/components/index.d.mts +3 -2
  18. package/dist/components/index.mjs +3 -2
  19. package/dist/components/options-parser-logic.cjs +121 -97
  20. package/dist/components/options-parser-logic.cjs.map +1 -1
  21. package/dist/components/options-parser-logic.d.cts +25 -17
  22. package/dist/components/options-parser-logic.d.cts.map +1 -1
  23. package/dist/components/options-parser-logic.d.mts +18 -10
  24. package/dist/components/options-parser-logic.d.mts.map +1 -1
  25. package/dist/components/options-parser-logic.mjs +120 -96
  26. package/dist/components/options-parser-logic.mjs.map +1 -1
  27. package/dist/components/usage.cjs +33 -1
  28. package/dist/components/usage.cjs.map +1 -1
  29. package/dist/components/usage.d.cts +2 -2
  30. package/dist/components/usage.d.mts +2 -2
  31. package/dist/components/usage.d.mts.map +1 -1
  32. package/dist/components/usage.mjs +35 -3
  33. package/dist/components/usage.mjs.map +1 -1
  34. package/dist/helpers/persistence.cjs +4 -21
  35. package/dist/helpers/persistence.cjs.map +1 -1
  36. package/dist/helpers/persistence.mjs +4 -21
  37. package/dist/helpers/persistence.mjs.map +1 -1
  38. package/dist/helpers/resolve-command.cjs +15 -55
  39. package/dist/helpers/resolve-command.cjs.map +1 -1
  40. package/dist/helpers/resolve-command.mjs +16 -56
  41. package/dist/helpers/resolve-command.mjs.map +1 -1
  42. package/dist/helpers/validations.cjs +13 -36
  43. package/dist/helpers/validations.cjs.map +1 -1
  44. package/dist/helpers/validations.mjs +12 -36
  45. package/dist/helpers/validations.mjs.map +1 -1
  46. package/dist/index.d.cts +3 -2
  47. package/dist/index.d.mts +3 -2
  48. package/dist/plugin-utils/context-helpers.cjs +3 -45
  49. package/dist/plugin-utils/context-helpers.cjs.map +1 -1
  50. package/dist/plugin-utils/context-helpers.d.cts +1 -37
  51. package/dist/plugin-utils/context-helpers.d.cts.map +1 -1
  52. package/dist/plugin-utils/context-helpers.d.mts +1 -37
  53. package/dist/plugin-utils/context-helpers.d.mts.map +1 -1
  54. package/dist/plugin-utils/context-helpers.mjs +4 -44
  55. package/dist/plugin-utils/context-helpers.mjs.map +1 -1
  56. package/dist/plugin-utils/index.cjs +0 -2
  57. package/dist/plugin-utils/index.d.cts +2 -2
  58. package/dist/plugin-utils/index.d.mts +2 -2
  59. package/dist/plugin-utils/index.mjs +2 -2
  60. package/dist/plugin.cjs +9 -15
  61. package/dist/plugin.cjs.map +1 -1
  62. package/dist/plugin.d.cts.map +1 -1
  63. package/dist/plugin.d.mts.map +1 -1
  64. package/dist/plugin.mjs +9 -15
  65. package/dist/plugin.mjs.map +1 -1
  66. package/dist/types/command.d.cts +26 -118
  67. package/dist/types/command.d.cts.map +1 -1
  68. package/dist/types/command.d.mts +26 -118
  69. package/dist/types/command.d.mts.map +1 -1
  70. package/dist/types/index.d.cts +3 -2
  71. package/dist/types/index.d.mts +3 -2
  72. package/dist/types/runtime.d.cts +5 -15
  73. package/dist/types/runtime.d.cts.map +1 -1
  74. package/dist/types/runtime.d.mts +5 -15
  75. package/dist/types/runtime.d.mts.map +1 -1
  76. package/package.json +24 -10
@@ -1 +1 @@
1
- {"version":3,"file":"persistence.mjs","names":["deserializeType","ReflectionFunction","ReflectionKind","resolveClassType","serializeType","omit","joinPaths","getCommandsPersistencePath","context","dataPath","serializedCommandTree","commands","serialize","node","parent","serializedNode","options","Object","entries","reduce","ret","key","option","path","dynamics","dynamic","params","map","param","children","reflection","type","undefined","child","id","result","deserializeCommandTree","serializedCommands","deserialize","kind","function","Error","optionsReflection","getParameters","length","optionsType","objectLiteral","deserializedNode","getProperty","name","getParameter","readCommandsPersistence","reflections","fs","read","JSON","parse","writeCommandsPersistence","filePath","write","stringify","config","mode"],"sources":["../../src/helpers/persistence.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 type { ReflectionClass } from \"@powerlines/deepkit/vendor/type\";\nimport {\n deserializeType,\n ReflectionFunction,\n ReflectionKind,\n resolveClassType,\n serializeType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport type {\n CommandDynamicSegment,\n CommandOption,\n CommandParameter,\n CommandTree,\n SerializedCommandDynamicSegment,\n SerializedCommandOption,\n SerializedCommandTree\n} from \"../types\";\nimport type { Context } from \"../types/context\";\n\nexport function getCommandsPersistencePath(context: Context): string {\n return joinPaths(context.dataPath, \"reflections\", \"commands.json\");\n}\n\nexport function serializedCommandTree(\n commands: Record<string, CommandTree>\n): Record<string, SerializedCommandTree> {\n const serialize = (\n node: CommandTree,\n parent: string | null = null\n ): SerializedCommandTree => {\n const serializedNode: SerializedCommandTree = {\n ...node,\n options: Object.entries(node.options).reduce(\n (ret, [key, option]) => {\n ret[key] = {\n ...omit(option, [\"reflection\"])\n };\n return ret;\n },\n {} as Record<string, SerializedCommandOption>\n ),\n path: {\n ...node.path,\n dynamics: Object.entries(node.path.dynamics).reduce(\n (ret, [key, dynamic]) => {\n ret[key] = {\n ...omit(dynamic, [\"reflection\"])\n };\n return ret;\n },\n {} as Record<string, SerializedCommandDynamicSegment>\n )\n },\n params: node.params.map(param => ({\n ...omit(param, [\"reflection\"])\n })),\n parent,\n children: {},\n reflection: node.reflection\n ? serializeType(node.reflection.type)\n : undefined\n };\n\n for (const [key, child] of Object.entries(node.children || {})) {\n serializedNode.children[key] = serialize(child, node.id);\n }\n\n return serializedNode;\n };\n\n const result: Record<string, SerializedCommandTree> = {};\n for (const [key, child] of Object.entries(commands)) {\n result[key] = serialize(child, null);\n }\n\n return result;\n}\n\nexport function deserializeCommandTree(\n serializedCommands: Record<string, SerializedCommandTree>\n): Record<string, CommandTree> {\n const deserialize = (\n node: SerializedCommandTree,\n parent: CommandTree | null = null\n ): CommandTree => {\n const type = deserializeType(node.reflection);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `Failed to deserialize persisted data - invalid command handler reflection type for command ${node.id}`\n );\n }\n\n const reflection = new ReflectionFunction(type);\n\n let optionsReflection: ReflectionClass<any> | undefined;\n if (\n reflection.getParameters().length > 0 &&\n reflection.getParameters()[0]\n ) {\n const optionsType = reflection.getParameters()[0]!.type;\n if (optionsType.kind === ReflectionKind.objectLiteral) {\n optionsReflection = resolveClassType(optionsType);\n }\n }\n\n const deserializedNode: CommandTree = {\n ...node,\n options: optionsReflection\n ? Object.entries(node.options).reduce(\n (ret, [key, option]) => {\n ret[key] = {\n ...option,\n reflection: optionsReflection.getProperty(option.name)\n } as CommandOption;\n return ret;\n },\n {} as Record<string, CommandOption>\n )\n : {},\n path: {\n ...node.path,\n dynamics: Object.entries(node.path.dynamics).reduce(\n (ret, [key, dynamic]) => {\n ret[key] = {\n ...dynamic,\n reflection: reflection.getParameter(dynamic.name)\n } as CommandDynamicSegment;\n return ret;\n },\n {} as Record<string, CommandDynamicSegment>\n )\n },\n params: node.params.map(param => ({\n ...param,\n reflection: reflection.getParameter(param.name)\n })) as CommandParameter[],\n parent,\n children: {},\n reflection\n };\n\n for (const [key, child] of Object.entries(node.children || {})) {\n deserializedNode.children[key] = deserialize(child, deserializedNode);\n }\n\n return deserializedNode;\n };\n\n const result: Record<string, CommandTree> = {};\n for (const [key, child] of Object.entries(serializedCommands)) {\n result[key] = deserialize(child, null);\n }\n\n return result;\n}\n\nexport async function readCommandsPersistence(context: Context) {\n const reflections = await context.fs.read(\n getCommandsPersistencePath(context)\n );\n if (!reflections || !reflections.length) {\n throw new Error(\n `CLI Command reflection file ${getCommandsPersistencePath(context)} is empty`\n );\n }\n\n context.commands = deserializeCommandTree(JSON.parse(reflections));\n}\n\nexport async function writeCommandsPersistence(context: Context) {\n const filePath = getCommandsPersistencePath(context);\n\n await context.fs.write(\n filePath,\n JSON.stringify(\n serializedCommandTree(context.commands),\n null,\n context.config.mode === \"development\" ? 2 : 0\n )\n );\n}\n"],"mappings":";;;;;AAuCA,SAAgBO,2BAA2BC,SAA0B;AACnE,QAAOF,UAAUE,QAAQC,UAAU,eAAe,gBAAgB;;AAGpE,SAAgBC,sBACdC,UACuC;CACvC,MAAMC,aACJC,MACAC,SAAwB,SACE;EAC1B,MAAMC,iBAAwC;GAC5C,GAAGF;GACHG,SAASC,OAAOC,QAAQL,KAAKG,QAAQ,CAACG,QACnCC,KAAK,CAACC,KAAKC,YAAY;AACtBF,QAAIC,OAAO,EACT,GAAGhB,KAAKiB,QAAQ,CAAC,aAAa,CAAA,EAC/B;AACD,WAAOF;MAET,EACF,CAAC;GACDG,MAAM;IACJ,GAAGV,KAAKU;IACRC,UAAUP,OAAOC,QAAQL,KAAKU,KAAKC,SAAS,CAACL,QAC1CC,KAAK,CAACC,KAAKI,aAAa;AACvBL,SAAIC,OAAO,EACT,GAAGhB,KAAKoB,S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 {"version":3,"file":"persistence.mjs","names":["deserializeType","ReflectionFunction","ReflectionKind","resolveClassType","serializeType","omit","joinPaths","getCommandsPersistencePath","context","dataPath","serializedCommandTree","commands","serialize","node","parent","serializedNode","options","Object","entries","reduce","ret","key","option","arguments","map","arg","children","reflection","type","undefined","child","id","result","deserializeCommandTree","serializedCommands","deserialize","kind","function","Error","optionsReflection","getParameters","length","optionsType","objectLiteral","deserializedNode","getProperty","name","i","getParameterOrUndefined","readCommandsPersistence","reflections","fs","read","JSON","parse","writeCommandsPersistence","filePath","write","stringify","config","mode"],"sources":["../../src/helpers/persistence.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 type { ReflectionClass } from \"@powerlines/deepkit/vendor/type\";\nimport {\n deserializeType,\n ReflectionFunction,\n ReflectionKind,\n resolveClassType,\n serializeType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport type {\n CommandArgument,\n CommandOption,\n CommandTree,\n SerializedCommandOption,\n SerializedCommandTree\n} from \"../types\";\nimport type { Context } from \"../types/context\";\n\nexport function getCommandsPersistencePath(context: Context): string {\n return joinPaths(context.dataPath, \"reflections\", \"commands.json\");\n}\n\nexport function serializedCommandTree(\n commands: Record<string, CommandTree>\n): Record<string, SerializedCommandTree> {\n const serialize = (\n node: CommandTree,\n parent: string | null = null\n ): SerializedCommandTree => {\n const serializedNode: SerializedCommandTree = {\n ...node,\n options: Object.entries(node.options).reduce(\n (ret, [key, option]) => {\n ret[key] = {\n ...omit(option, [\"reflection\"])\n };\n return ret;\n },\n {} as Record<string, SerializedCommandOption>\n ),\n arguments: node.arguments.map(arg => ({\n ...omit(arg, [\"reflection\"])\n })),\n parent,\n children: {},\n reflection: node.reflection\n ? serializeType(node.reflection.type)\n : undefined\n };\n\n for (const [key, child] of Object.entries(node.children || {})) {\n serializedNode.children[key] = serialize(child, node.id);\n }\n\n return serializedNode;\n };\n\n const result: Record<string, SerializedCommandTree> = {};\n for (const [key, child] of Object.entries(commands)) {\n result[key] = serialize(child, null);\n }\n\n return result;\n}\n\nexport function deserializeCommandTree(\n serializedCommands: Record<string, SerializedCommandTree>\n): Record<string, CommandTree> {\n const deserialize = (\n node: SerializedCommandTree,\n parent: CommandTree | null = null\n ): CommandTree => {\n const type = deserializeType(node.reflection);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `Failed to deserialize persisted data - invalid command handler reflection type for command ${node.id}`\n );\n }\n\n const reflection = new ReflectionFunction(type);\n\n let optionsReflection: ReflectionClass<any> | undefined;\n if (\n reflection.getParameters().length > 0 &&\n reflection.getParameters()[0]\n ) {\n const optionsType = reflection.getParameters()[0]!.type;\n if (optionsType.kind === ReflectionKind.objectLiteral) {\n optionsReflection = resolveClassType(optionsType);\n }\n }\n\n const deserializedNode: CommandTree = {\n ...node,\n options: optionsReflection\n ? Object.entries(node.options).reduce(\n (ret, [key, option]) => {\n ret[key] = {\n ...option,\n reflection: optionsReflection.getProperty(option.name)\n } as CommandOption;\n return ret;\n },\n {} as Record<string, CommandOption>\n )\n : {},\n arguments: node.arguments.map((arg, i) => ({\n ...arg,\n reflection:\n reflection.getParameters().length > i + 1\n ? reflection.getParameters()[i + 1]\n : reflection.getParameterOrUndefined(arg.name)\n })) as CommandArgument[],\n parent,\n children: {},\n reflection\n };\n\n for (const [key, child] of Object.entries(node.children || {})) {\n deserializedNode.children[key] = deserialize(child, deserializedNode);\n }\n\n return deserializedNode;\n };\n\n const result: Record<string, CommandTree> = {};\n for (const [key, child] of Object.entries(serializedCommands)) {\n result[key] = deserialize(child, null);\n }\n\n return result;\n}\n\nexport async function readCommandsPersistence(context: Context) {\n const reflections = await context.fs.read(\n getCommandsPersistencePath(context)\n );\n if (!reflections || !reflections.length) {\n throw new Error(\n `CLI Command reflection file ${getCommandsPersistencePath(context)} is empty`\n );\n }\n\n context.commands = deserializeCommandTree(JSON.parse(reflections));\n}\n\nexport async function writeCommandsPersistence(context: Context) {\n const filePath = getCommandsPersistencePath(context);\n\n await context.fs.write(\n filePath,\n JSON.stringify(\n serializedCommandTree(context.commands),\n null,\n context.config.mode === \"development\" ? 2 : 0\n )\n );\n}\n"],"mappings":";;;;;AAqCA,SAAgBO,2BAA2BC,SAA0B;AACnE,QAAOF,UAAUE,QAAQC,UAAU,eAAe,gBAAgB;;AAGpE,SAAgBC,sBACdC,UACuC;CACvC,MAAMC,aACJC,MACAC,SAAwB,SACE;EAC1B,MAAMC,iBAAwC;GAC5C,GAAGF;GACHG,SAASC,OAAOC,QAAQL,KAAKG,QAAQ,CAACG,QACnCC,KAAK,CAACC,KAAKC,YAAY;AACtBF,QAAIC,OAAO,EACT,GAAGhB,KAAKiB,QAAQ,CAAC,aAAa,CAAA,EAC/B;AACD,WAAOF;MAET,EACF,CAAC;GACDG,WAAWV,KAAKU,UAAUC,KAAIC,SAAQ,EACpC,GAAGpB,KAAKoB,KAAK,CAAC,aAAa,CAAA,EAC5B,EAAE;GACHX;GACAY,UAAU,EAAE;GACZC,YAAYd,KAAKc,aACbvB,cAAcS,KAAKc,WAAWC,KAAK,GACnCC;GACL;AAED,OAAK,MAAM,CAACR,KAAKS,UAAUb,OAAOC,QAAQL,KAAKa,YAAY,EAAE,CAAC,CAC5DX,gBAAeW,SAASL,OAAOT,UAAUkB,OAAOjB,KAAKkB,GAAG;AAG1D,SAAOhB;;CAGT,MAAMiB,SAAgD,EAAE;AACxD,MAAK,MAAM,CAACX,KAAKS,UAAUb,OAAOC,QA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,QAAQgB,mBAAmB,CAC3DF,QAAOX,OAAOc,YAAYL,OAAO,KAAK;AAGxC,QAAOE;;AAGT,eAAsBiB,wBAAwBzC,SAAkB;CAC9D,MAAM0C,cAAc,MAAM1C,QAAQ2C,GAAGC,KACnC7C,2BAA2BC,QAC7B,CAAC;AACD,KAAI,CAAC0C,eAAe,CAACA,YAAYT,OAC/B,OAAM,IAAIH,MACR,+BAA+B/B,2BAA2BC,QAAQ,CAAA,WACnE;AAGHA,SAAQG,WAAWsB,uBAAuBoB,KAAKC,MAAMJ,YAAY,CAAC;;AAGpE,eAAsBK,yBAAyB/C,SAAkB;CAC/D,MAAMgD,WAAWjD,2BAA2BC,QAAQ;AAEpD,OAAMA,QAAQ2C,GAAGM,MACfD,UACAH,KAAKK,UACHhD,sBAAsBF,QAAQG,SAAS,EACvC,MACAH,QAAQmD,OAAOC,SAAS,gBAAgB,IAAI,EAEhD,CAAC"}
@@ -99,48 +99,18 @@ function extractCommandOption(command, reflection) {
99
99
  return option;
100
100
  }
101
101
  /**
102
- * Extracts command dynamic path segment information from a type parameter reflection.
102
+ * Extracts command positional argument information from a type parameter reflection.
103
103
  *
104
104
  * @param command - The command tree to which the parameter belongs.
105
- * @param segment - The command path segment corresponding to the parameter.
106
105
  * @param reflection - The type parameter reflection to extract information from.
107
- * @returns The extracted command dynamic segment information.
106
+ * @returns The extracted command positional argument information.
108
107
  */
109
- function extractCommandDynamicSegment(command, segment, reflection) {
110
- const type = reflection.getType();
111
- if (type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.string && !(type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.array && type.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string)) throw new Error(`Unsupported type for dynamic path segment "${segment}" in command "${command.name}". Only string types (or an array of strings) are supported, received ${(0, __powerlines_deepkit_vendor_type.stringifyType)(type).trim().replaceAll(" | ", ", or ")}.`);
112
- const option = {
113
- name: reflection.getName(),
114
- segment,
115
- title: reflection.getTags().title || (0, __stryke_string_format_title_case.titleCase)(segment),
116
- description: reflection.parameter.description || resolveCommandOptionDescription(type.kind, !!reflection.isOptional(), segment, (0, __stryke_string_format_title_case.titleCase)(segment), reflection.getDefaultValue()),
117
- optional: reflection.isOptional(),
118
- default: reflection.getDefaultValue(),
119
- catchAll: command.path.segments.some((seg) => require_plugin_utils_context_helpers.getDynamicPathSegmentName(segment) === seg && require_plugin_utils_context_helpers.isCatchAllPathSegment(seg)),
120
- reflection
121
- };
122
- if (type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.array) {
123
- if (!option.catchAll) throw new Error(`Dynamic path segment "${segment}" in command "${command.name}" is an array type but is not defined as a catch-all segment. To use an array type for a dynamic path segment, it must be defined as a catch-all segment using the "[...segment]" syntax.`);
124
- option.variadic = true;
125
- }
126
- if (option.catchAll) {
127
- if (!option.optional && command.path.segments.some((seg) => require_plugin_utils_context_helpers.getDynamicPathSegmentName(segment) === seg && require_plugin_utils_context_helpers.isOptionalCatchAllPathSegment(seg))) throw new Error(`Dynamic path segment "${segment}" in command "${command.name}" is defined as a catch-all segment but is not optional. To define an optional catch-all segment, use the "[[...segment]]" syntax.`);
128
- else if (option.optional && !command.path.segments.some((seg) => require_plugin_utils_context_helpers.getDynamicPathSegmentName(segment) === seg && require_plugin_utils_context_helpers.isOptionalCatchAllPathSegment(seg))) throw new Error(`Dynamic path segment "${segment}" in command "${command.name}" is defined as an optional segment but is not defined as an optional catch-all segment. To define an optional catch-all segment, use the "[[...segment]]" syntax.`);
129
- }
130
- return option;
131
- }
132
- /**
133
- * Extracts command positional parameter information from a type parameter reflection.
134
- *
135
- * @param command - The command tree to which the parameter belongs.
136
- * @param reflection - The type parameter reflection to extract information from.
137
- * @returns The extracted command positional parameter information.
138
- */
139
- function extractCommandParameter(command, reflection) {
108
+ function extractCommandArgument(command, reflection) {
140
109
  const type = reflection.getType();
141
110
  if (type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.string && type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.number && type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.boolean && !(type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.array && (type.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || type.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number))) throw new Error(`Unsupported type for positional parameter "${reflection.getName()}" in command "${command.name}". Only string types (or an array of strings) are supported, received ${(0, __powerlines_deepkit_vendor_type.stringifyType)(type).trim().replaceAll(" | ", ", or ")}.`);
142
111
  const option = {
143
112
  name: reflection.getName(),
113
+ kind: type.kind,
144
114
  title: (0, __stryke_string_format_title_case.titleCase)(reflection.getName()),
145
115
  description: reflection.parameter.description || resolveCommandParameterDescription(type.kind, !!reflection.isOptional(), reflection.getName(), (0, __stryke_string_format_title_case.titleCase)(reflection.getName()), reflection.getDefaultValue()),
146
116
  env: (0, __stryke_string_format_constant_case.constantCase)(reflection.getName()),
@@ -167,14 +137,11 @@ async function reflectCommandTree(context, command, parent) {
167
137
  const title = command.title || `${parent?.title ? `${parent.isVirtual ? parent.title.replace(/ Commands$/, "") : parent.title} - ` : ""}${(0, __stryke_string_format_title_case.titleCase)(command.name)}${command.isVirtual ? " Commands" : ""}`;
168
138
  const tree = {
169
139
  alias: [],
140
+ icon: parent?.icon,
170
141
  ...command,
171
142
  title,
172
- path: {
173
- ...command.path,
174
- dynamics: {}
175
- },
176
143
  options: require_utilities.getDefaultOptions(context, command),
177
- params: [],
144
+ arguments: [],
178
145
  parent: parent ?? null,
179
146
  children: {},
180
147
  reflection: null
@@ -201,14 +168,7 @@ async function reflectCommandTree(context, command, parent) {
201
168
  const optionsReflection = __powerlines_deepkit_vendor_type.ReflectionClass.from(parameters[0].type);
202
169
  for (const propertyReflection of optionsReflection.getProperties()) tree.options[propertyReflection.getNameAsString()] = extractCommandOption(command, propertyReflection);
203
170
  } 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.`);
204
- tree.path.dynamics = tree.path.segments.filter((segment) => require_plugin_utils_context_helpers.isDynamicPathSegment(segment)).reduce((obj, segment, index) => {
205
- if (parameters.length < index + 2 || !parameters[index + 1]) return obj;
206
- const paramName = require_plugin_utils_context_helpers.getDynamicPathSegmentName(segment);
207
- obj[paramName] = extractCommandDynamicSegment(command, paramName, parameters[index + 1]);
208
- obj[paramName].description = obj[paramName].description || `The ${paramName} ${obj[paramName].catchAll ? `${obj[paramName].optional ? "optional " : ""}catch-all` : "dynamic "} segment for the ${command.name} command.`;
209
- return obj;
210
- }, {});
211
- if (parameters.length > Object.keys(tree.path.dynamics).length + 1) tree.params = parameters.slice(Object.keys(tree.path.dynamics).length + 1).map((param) => extractCommandParameter(command, param));
171
+ tree.arguments = parameters.slice(1).map((arg) => extractCommandArgument(command, arg));
212
172
  }
213
173
  } else tree.description ??= `A collection of available ${tree.title || (0, __stryke_string_format_title_case.titleCase)(tree.name)} commands that are included in the ${require_plugin_utils_context_helpers.getAppTitle(context)} command line application.`;
214
174
  if (context.env) {
@@ -231,20 +191,20 @@ async function reflectCommandTree(context, command, parent) {
231
191
  }
232
192
  });
233
193
  });
234
- Object.values(tree.params).filter((param) => param.env !== false).forEach((param) => context.env.types.env.addProperty({
235
- name: (0, __stryke_string_format_constant_case.constantCase)(param.name),
236
- optional: param.optional ? true : void 0,
237
- description: param.description,
194
+ Object.values(tree.arguments).filter((arg) => arg.env !== false).forEach((arg) => context.env.types.env.addProperty({
195
+ name: (0, __stryke_string_format_constant_case.constantCase)(arg.name),
196
+ optional: arg.optional ? true : void 0,
197
+ description: arg.description,
238
198
  visibility: __powerlines_deepkit_vendor_type.ReflectionVisibility.public,
239
- type: param.reflection.getType(),
240
- default: param.default,
199
+ type: arg.reflection.getType(),
200
+ default: arg.default,
241
201
  tags: {
242
- ...param.reflection.getTags(),
202
+ ...arg.reflection.getTags(),
243
203
  domain: "cli"
244
204
  }
245
205
  }));
246
206
  }
247
- for (const input of context.inputs.filter((input$1) => input$1.path.segments.filter((segment) => !require_plugin_utils_context_helpers.isDynamicPathSegment(segment)).length === command.path.segments.filter((segment) => !require_plugin_utils_context_helpers.isDynamicPathSegment(segment)).length + 1 && input$1.path.segments.slice(0, command.path.segments.length).every((value, index) => value === command.path.segments[index]))) tree.children[input.name] = await reflectCommandTree(context, input, tree);
207
+ for (const input of context.inputs.filter((input$1) => input$1.segments.filter((segment) => !require_plugin_utils_context_helpers.isDynamicPathSegment(segment)).length === command.segments.filter((segment) => !require_plugin_utils_context_helpers.isDynamicPathSegment(segment)).length + 1 && input$1.segments.slice(0, command.segments.length).every((value, index) => value === command.segments[index]))) tree.children[input.name] = await reflectCommandTree(context, input, tree);
248
208
  return tree;
249
209
  }
250
210
 
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-command.cjs","names":["esbuildPlugin","reflect","ReflectionClass","ReflectionFunction","ReflectionKind","ReflectionVisibility","stringifyType","toArray","appendPath","commonPath","findFilePath","findFolderName","stripStars","replacePath","resolveParentPath","constantCase","titleCase","isSetObject","isSetString","resolveModule","getAppTitle","getDynamicPathSegmentName","isCatchAllPathSegment","isDynamicPathSegment","isOptionalCatchAllPathSegment","isPathSegmentGroup","getDefaultOptions","resolveCommandOptionDescription","kind","optional","name","title","defaultValue","boolean","array","trim","number","resolveCommandParameterDescription","resolveCommandId","context","file","commandsPath","split","filter","p","Boolean","join","replaceAll","resolveCommandName","path","requireExtension","resolveCommandPath","resolveCommandDynamicPathSegments","map","findCommandsRoot","config","entry","projectRoot","workspaceConfig","workspaceRoot","Array","isArray","length","sourceRoot","extractCommandOption","command","reflection","type","getType","option","getNameAsString","alias","getTags","description","getDescription","getKind","isOptional","getDefaultValue","env","default","variadic","string","Error","extractCommandDynamicSegment","segment","getName","parameter","catchAll","segments","some","seg","extractCommandParameter","reflectCommandTree","parent","isVirtual","replace","tree","dynamics","options","params","children","input","fs","existsSync","debug","id","resolved","plugins","reflectionLevel","metadata","icon","function","parameters","getParameters","objectLiteral","class","optionsReflection","from","propertyReflection","getProperties","reduce","obj","index","paramName","Object","keys","slice","param","values","forEach","types","addProperty","undefined","visibility","public","tags","domain","inputs","every","value"],"sources":["../../src/helpers/resolve-command.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport type {\n ReflectionParameter,\n ReflectionProperty,\n TypeArray\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n reflect,\n ReflectionClass,\n ReflectionFunction,\n ReflectionKind,\n ReflectionVisibility,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { commonPath } from \"@stryke/path/common\";\nimport { findFilePath, findFolderName } from \"@stryke/path/file-path-fns\";\nimport { stripStars } from \"@stryke/path/normalize\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { resolveModule } from \"powerlines/lib/utilities/resolve\";\nimport {\n getAppTitle,\n getDynamicPathSegmentName,\n isCatchAllPathSegment,\n isDynamicPathSegment,\n isOptionalCatchAllPathSegment,\n isPathSegmentGroup\n} from \"../plugin-utils/context-helpers\";\nimport type {\n CommandDynamicSegment,\n CommandInput,\n CommandModule,\n CommandOption,\n CommandParameter,\n CommandTree,\n NumberCommandOption,\n NumberCommandParameter,\n StringCommandOption,\n StringCommandParameter\n} from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport { getDefaultOptions } from \"./utilities\";\n\n/**\n * Resolves the description for a command option based on its reflection.\n *\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param name - The name of the command option.\n * @param title - The title of the command option, if any.\n * @param defaultValue - The default value of the command option, if any.\n * @returns The resolved description for the command option.\n */\nexport function resolveCommandOptionDescription(\n kind: ReflectionKind,\n optional: boolean,\n name: string,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} ${\n kind === ReflectionKind.boolean\n ? \"flag provided via the command-line\"\n : \"command-line option\"\n } that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : kind === ReflectionKind.array\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.number ? \"numeric\" : \"string\"} value${\n kind === ReflectionKind.array ? \"s\" : \"\"\n }`\n } that will be used in the application.`;\n}\n\n/**\n * Resolves the description for a command parameter based on its reflection.\n *\n * @param kind - The reflection kind of the command parameter.\n * @param optional - Whether the command parameter is optional.\n * @param name - The name of the command parameter.\n * @param title - The title of the command parameter, if any.\n * @param defaultValue - The default value of the command parameter, if any.\n * @returns The resolved description for the command parameter.\n */\nexport function resolveCommandParameterDescription(\n kind: ReflectionKind,\n optional: boolean,\n name: string,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} command-line positional parameter that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : kind === ReflectionKind.array\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.number ? \"numeric\" : \"string\"} value${\n kind === ReflectionKind.array ? \"s\" : \"\"\n }`\n } that will be used in the application.`;\n}\n\nexport function resolveCommandId(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && !isDynamicPathSegment(p))\n .join(\"/\")\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .replaceAll(\"/\", \"-\");\n}\n\n/**\n * Finds the command name from the given file path.\n *\n * @param file - The file path to extract the command name from.\n * @returns The command name.\n */\nexport function resolveCommandName(file: string) {\n let path = findFilePath(file);\n let name = findFolderName(file, {\n requireExtension: true\n });\n\n while (isDynamicPathSegment(name)) {\n path = resolveParentPath(path);\n name = findFolderName(path, {\n requireExtension: true\n });\n }\n\n return name;\n}\n\nexport function resolveCommandPath(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .split(\"/\")\n .filter(path => path && !isPathSegmentGroup(path))\n .join(\"/\");\n}\n\nexport function resolveCommandDynamicPathSegments(\n context: Context,\n file: string\n): string[] {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(path => Boolean(path) && isDynamicPathSegment(path))\n .map(path => getDynamicPathSegmentName(path));\n}\n\nexport function findCommandsRoot(context: Context): string {\n if (isSetString(context.config.entry)) {\n return appendPath(\n appendPath(stripStars(context.config.entry), context.config.projectRoot),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n isSetObject(context.config.entry) &&\n \"file\" in context.config.entry\n ) {\n return appendPath(\n appendPath(\n stripStars(context.config.entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n Array.isArray(context.config.entry) &&\n context.config.entry.length > 0\n ) {\n return commonPath(\n context.config.entry.map(entry =>\n appendPath(\n appendPath(\n stripStars(isSetString(entry) ? entry : entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\n }\n\n return appendPath(\n context.config.sourceRoot || context.config.projectRoot,\n context.workspaceConfig.workspaceRoot\n );\n}\n\n/**\n * Extracts command parameter information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command option information.\n */\nexport function extractCommandOption(\n command: CommandInput,\n reflection: ReflectionProperty\n): CommandOption {\n const type = reflection.getType();\n\n const option = {\n name: reflection.getNameAsString(),\n alias: reflection.getTags().alias ?? [],\n title:\n reflection.getTags().title?.trim() ||\n titleCase(reflection.getNameAsString()),\n description:\n reflection.getDescription() ||\n resolveCommandOptionDescription(\n reflection.getKind(),\n reflection.isOptional(),\n reflection.getNameAsString(),\n reflection.getTags().title,\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getNameAsString()),\n kind: type.kind as\n | ReflectionKind.string\n | ReflectionKind.number\n | ReflectionKind.boolean,\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n variadic: reflection.isArray(),\n reflection\n } as CommandOption;\n\n if (reflection.isArray()) {\n if (\n (type as TypeArray).type.kind === ReflectionKind.string ||\n (type as TypeArray).type.kind === ReflectionKind.number\n ) {\n (option as StringCommandOption | NumberCommandOption).variadic = true;\n (option as StringCommandOption | NumberCommandOption).kind = (\n type as TypeArray\n ).type.kind as ReflectionKind.string | ReflectionKind.number;\n } else {\n throw new Error(\n `Unsupported array type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return option;\n}\n\n/**\n * Extracts command dynamic path segment information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param segment - The command path segment corresponding to the parameter.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command dynamic segment information.\n */\nexport function extractCommandDynamicSegment(\n command: CommandInput,\n segment: string,\n reflection: ReflectionParameter\n): CommandDynamicSegment {\n const type = reflection.getType();\n\n if (\n type.kind !== ReflectionKind.string &&\n !(\n type.kind === ReflectionKind.array &&\n type.type.kind === ReflectionKind.string\n )\n ) {\n throw new Error(\n `Unsupported type for dynamic path segment \"${segment}\" in command \"${\n command.name\n }\". Only string types (or an array of strings) are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const option = {\n name: reflection.getName(),\n segment,\n title: reflection.getTags().title || titleCase(segment),\n description:\n reflection.parameter.description ||\n resolveCommandOptionDescription(\n type.kind,\n !!reflection.isOptional(),\n segment,\n titleCase(segment),\n reflection.getDefaultValue()\n ),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n catchAll: command.path.segments.some(\n seg =>\n getDynamicPathSegmentName(segment) === seg && isCatchAllPathSegment(seg)\n ),\n reflection\n } as CommandDynamicSegment;\n\n if (type.kind === ReflectionKind.array) {\n if (!option.catchAll) {\n throw new Error(\n `Dynamic path segment \"${segment}\" in command \"${\n command.name\n }\" is an array type but is not defined as a catch-all segment. To use an array type for a dynamic path segment, it must be defined as a catch-all segment using the \"[...segment]\" syntax.`\n );\n }\n\n option.variadic = true;\n }\n\n if (option.catchAll) {\n if (\n !option.optional &&\n command.path.segments.some(\n seg =>\n getDynamicPathSegmentName(segment) === seg &&\n isOptionalCatchAllPathSegment(seg)\n )\n ) {\n throw new Error(\n `Dynamic path segment \"${segment}\" in command \"${\n command.name\n }\" is defined as a catch-all segment but is not optional. To define an optional catch-all segment, use the \"[[...segment]]\" syntax.`\n );\n } else if (\n option.optional &&\n !command.path.segments.some(\n seg =>\n getDynamicPathSegmentName(segment) === seg &&\n isOptionalCatchAllPathSegment(seg)\n )\n ) {\n throw new Error(\n `Dynamic path segment \"${segment}\" in command \"${\n command.name\n }\" is defined as an optional segment but is not defined as an optional catch-all segment. To define an optional catch-all segment, use the \"[[...segment]]\" syntax.`\n );\n }\n }\n\n return option;\n}\n\n/**\n * Extracts command positional parameter information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command positional parameter information.\n */\nexport function extractCommandParameter(\n command: CommandInput,\n reflection: ReflectionParameter\n): CommandParameter {\n const type = reflection.getType();\n\n if (\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number &&\n type.kind !== ReflectionKind.boolean &&\n !(\n type.kind === ReflectionKind.array &&\n (type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number)\n )\n ) {\n throw new Error(\n `Unsupported type for positional parameter \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string types (or an array of strings) are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const option = {\n name: reflection.getName(),\n title: titleCase(reflection.getName()),\n description:\n reflection.parameter.description ||\n resolveCommandParameterDescription(\n type.kind,\n !!reflection.isOptional(),\n reflection.getName(),\n titleCase(reflection.getName()),\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getName()),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n reflection\n } as CommandParameter;\n\n if (type.kind === ReflectionKind.array) {\n if (\n type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number\n ) {\n (option as StringCommandParameter | NumberCommandParameter).variadic =\n true;\n (option as StringCommandParameter | NumberCommandParameter).kind =\n type.type.kind;\n } else {\n throw new Error(\n `Unsupported array type for positional parameter \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for positional parameter \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return option;\n}\n\n/**\n * Reflects the command tree for a given command input.\n *\n * @param context - The context in which the command is being reflected.\n * @param command - The command input to reflect.\n * @param parent - The parent command tree, if any.\n * @returns The reflected command tree.\n */\nexport async function reflectCommandTree<TContext extends Context = Context>(\n context: TContext,\n command: CommandInput,\n parent?: CommandTree\n): Promise<CommandTree> {\n const title =\n command.title ||\n `${\n parent?.title\n ? `${\n parent.isVirtual\n ? parent.title.replace(/ Commands$/, \"\")\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const tree = {\n alias: [],\n ...command,\n title,\n path: {\n ...command.path,\n dynamics: {}\n },\n options: getDefaultOptions(context, command),\n params: [],\n parent: parent ?? null,\n children: {},\n reflection: null\n } as CommandTree;\n\n if (!command.isVirtual) {\n if (\n !command.entry.input?.file ||\n !context.fs.existsSync(command.entry.input.file)\n ) {\n throw new Error(\n `${\n !command.entry.input?.file ? \"Missing\" : \"Non-existent\"\n } command entry file for \"${command.name}\"`\n );\n }\n\n context.debug(\n `Adding reflection for user-defined command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n const resolved = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n reflectionLevel: \"verbose\"\n })\n ]\n }\n );\n\n const metadata = resolved.metadata ?? {};\n if (isSetString(metadata.title)) {\n tree.title = metadata.title;\n }\n if (isSetString(metadata.description)) {\n tree.description = metadata.description;\n }\n if (\n isSetString(metadata.alias) ||\n (Array.isArray(metadata.alias) && metadata.alias.length > 0)\n ) {\n tree.alias = toArray(metadata.alias);\n }\n if (isSetString(metadata.icon)) {\n tree.icon = metadata.icon;\n }\n\n const type = reflect(resolved);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `The command entry file \"${command.entry.input.file}\" does not export a valid function.`\n );\n }\n\n tree.reflection = new ReflectionFunction(type);\n tree.description ??=\n command.description ||\n type.description ||\n `The ${tree.title} executable command line interface.`;\n\n const parameters = tree.reflection.getParameters();\n if (parameters.length > 0 && parameters[0]) {\n if (\n parameters[0].type.kind === ReflectionKind.objectLiteral ||\n parameters[0].type.kind === ReflectionKind.class\n ) {\n const optionsReflection = ReflectionClass.from(parameters[0].type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n tree.options[propertyReflection.getNameAsString()] =\n extractCommandOption(command, propertyReflection);\n }\n } else {\n throw new Error(\n `The first parameter of the command handler function in \"${\n command.entry.input.file\n }\" must be an object literal or class type representing the command options.`\n );\n }\n\n tree.path.dynamics = tree.path.segments\n .filter(segment => isDynamicPathSegment(segment))\n .reduce(\n (obj, segment, index) => {\n if (parameters.length < index + 2 || !parameters[index + 1]) {\n return obj;\n }\n\n const paramName = getDynamicPathSegmentName(segment);\n obj[paramName] = extractCommandDynamicSegment(\n command,\n paramName,\n parameters[index + 1]!\n );\n\n obj[paramName].description =\n obj[paramName].description ||\n `The ${paramName} ${\n obj[paramName].catchAll\n ? `${obj[paramName].optional ? \"optional \" : \"\"}catch-all`\n : \"dynamic \"\n } segment for the ${command.name} command.`;\n\n return obj;\n },\n {} as Record<string, CommandDynamicSegment>\n );\n\n if (parameters.length > Object.keys(tree.path.dynamics).length + 1) {\n tree.params = parameters\n .slice(Object.keys(tree.path.dynamics).length + 1)\n .map(param => extractCommandParameter(command, param));\n }\n }\n } else {\n tree.description ??= `A collection of available ${\n tree.title || titleCase(tree.name)\n } commands that are included in the ${getAppTitle(\n context\n )} command line application.`;\n }\n\n if (context.env) {\n if (isSetObject(tree.options)) {\n Object.values(tree.options)\n .filter(option => option.env !== false)\n .forEach(option => {\n context.env.types.env.addProperty({\n name: option.env as string,\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type:\n option.reflection?.getType() ??\n ((option as StringCommandOption | NumberCommandOption).variadic\n ? { kind: ReflectionKind.array, type: { kind: option.kind } }\n : { kind: option.kind }),\n default: option.default,\n tags: {\n ...option.reflection?.getTags(),\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 0)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n Object.values(tree.params)\n .filter(param => param.env !== false)\n .forEach(param =>\n context.env.types.env.addProperty({\n name: constantCase(param.name),\n optional: param.optional ? true : undefined,\n description: param.description,\n visibility: ReflectionVisibility.public,\n type: param.reflection.getType(),\n default: param.default,\n tags: {\n ...param.reflection.getTags(),\n domain: \"cli\"\n }\n })\n );\n }\n\n for (const input of context.inputs.filter(\n input =>\n input.path.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n command.path.segments.filter(segment => !isDynamicPathSegment(segment))\n .length +\n 1 &&\n input.path.segments\n .slice(0, command.path.segments.length)\n .every((value, index) => value === command.path.segments[index])\n )) {\n tree.children[input.name] = await reflectCommandTree(context, input, tree);\n }\n\n return tree;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,SAAgB2B,gCACdC,MACAC,UACAC,MACAC,OACAC,cACQ;AACR,QAAO,IAAIH,YAAY,CAACG,eAAe,eAAe,GAAE,GACtDJ,SAASxB,gDAAe6B,UACpB,uCACA,sBAAqB,2BAEzBL,SAASxB,gDAAe6B,UACpB,YACAL,SAASxB,gDAAe8B,QACtB,mBACA,mBAAkB,GACtBH,OAAOI,MAAM,qDAAcL,KAAK,CAAA,GAClCF,SAASxB,gDAAe6B,UACpB,cACA,GAAGL,SAASxB,gDAAegC,SAAS,YAAY,SAAQ,QACtDR,SAASxB,gDAAe8B,QAAQ,MAAM,KACtC;;;;;;;;;;;;AAcV,SAAgBG,mCACdT,MACAC,UACAC,MACAC,OACAC,cACQ;AACR,QAAO,IA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C,CAClEtB,WACDG,QAAQhB,KAAKuC,SAAS7C,QAAOyC,YAAW,CAAC7D,0DAAqB6D,QAAQ,CAAC,CACpEtB,SACD,KACJuC,QAAMpD,KAAKuC,SACRsC,MAAM,GAAG7D,QAAQhB,KAAKuC,SAAS1B,OAAO,CACtC4E,OAAOC,OAAOjB,UAAUiB,UAAU1E,QAAQhB,KAAKuC,SAASkC,OAC/D,CAAC,CACC1B,MAAKI,SAASC,MAAMvE,QAAQ,MAAM8D,mBAAmBrD,SAAS8D,OAAOL,KAAK;AAG5E,QAAOA"}
1
+ {"version":3,"file":"resolve-command.cjs","names":["esbuildPlugin","reflect","ReflectionClass","ReflectionFunction","ReflectionKind","ReflectionVisibility","stringifyType","toArray","appendPath","commonPath","findFilePath","findFolderName","stripStars","replacePath","resolveParentPath","constantCase","titleCase","isSetObject","isSetString","resolveModule","getAppTitle","getDynamicPathSegmentName","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,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,EAAEA,MAAMyC,OAAOzC,MAAM;IAC3BmD,SAASV,OAAOU;IAChB4C,MAAM;KACJ,GAAGtD,OAAOH,YAAYM,SAAS;KAC/BzC,OAAOsC,OAAOtC;KACdwC,OAAOF,OAAOE,MACX5B,QAAO4B,UAASA,MAAMT,SAAS,EAAE,CACjCT,KAAIkB,iEAAsBA,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,6DAAmBoF,IAAIpF,KAAK;GAC5BD,UAAUqF,IAAIrF,WAAW,OAAO2F;GAChC/C,aAAayC,IAAIzC;GACjBgD,YAAYlH,sDAAqBmH;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,0DAAqBuG,QAAQ,CAAC,CAC7DjE,WACDG,QAAQ6D,SAASnF,QAAOoF,YAAW,CAACvG,0DAAqBuG,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,4 +1,4 @@
1
- import { getAppTitle, getDynamicPathSegmentName, isCatchAllPathSegment, isDynamicPathSegment, isOptionalCatchAllPathSegment, isPathSegmentGroup } from "../plugin-utils/context-helpers.mjs";
1
+ import { getAppTitle, isDynamicPathSegment, isPathSegmentGroup } from "../plugin-utils/context-helpers.mjs";
2
2
  import { getDefaultOptions } from "./utilities.mjs";
3
3
  import { toArray } from "@stryke/convert/to-array";
4
4
  import { appendPath } from "@stryke/path/append";
@@ -98,48 +98,18 @@ function extractCommandOption(command, reflection) {
98
98
  return option;
99
99
  }
100
100
  /**
101
- * Extracts command dynamic path segment information from a type parameter reflection.
101
+ * Extracts command positional argument information from a type parameter reflection.
102
102
  *
103
103
  * @param command - The command tree to which the parameter belongs.
104
- * @param segment - The command path segment corresponding to the parameter.
105
104
  * @param reflection - The type parameter reflection to extract information from.
106
- * @returns The extracted command dynamic segment information.
105
+ * @returns The extracted command positional argument information.
107
106
  */
108
- function extractCommandDynamicSegment(command, segment, reflection) {
109
- const type = reflection.getType();
110
- if (type.kind !== ReflectionKind.string && !(type.kind === ReflectionKind.array && type.type.kind === ReflectionKind.string)) throw new Error(`Unsupported type for dynamic path segment "${segment}" in command "${command.name}". Only string types (or an array of strings) are supported, received ${stringifyType(type).trim().replaceAll(" | ", ", or ")}.`);
111
- const option = {
112
- name: reflection.getName(),
113
- segment,
114
- title: reflection.getTags().title || titleCase(segment),
115
- description: reflection.parameter.description || resolveCommandOptionDescription(type.kind, !!reflection.isOptional(), segment, titleCase(segment), reflection.getDefaultValue()),
116
- optional: reflection.isOptional(),
117
- default: reflection.getDefaultValue(),
118
- catchAll: command.path.segments.some((seg) => getDynamicPathSegmentName(segment) === seg && isCatchAllPathSegment(seg)),
119
- reflection
120
- };
121
- if (type.kind === ReflectionKind.array) {
122
- if (!option.catchAll) throw new Error(`Dynamic path segment "${segment}" in command "${command.name}" is an array type but is not defined as a catch-all segment. To use an array type for a dynamic path segment, it must be defined as a catch-all segment using the "[...segment]" syntax.`);
123
- option.variadic = true;
124
- }
125
- if (option.catchAll) {
126
- if (!option.optional && command.path.segments.some((seg) => getDynamicPathSegmentName(segment) === seg && isOptionalCatchAllPathSegment(seg))) throw new Error(`Dynamic path segment "${segment}" in command "${command.name}" is defined as a catch-all segment but is not optional. To define an optional catch-all segment, use the "[[...segment]]" syntax.`);
127
- else if (option.optional && !command.path.segments.some((seg) => getDynamicPathSegmentName(segment) === seg && isOptionalCatchAllPathSegment(seg))) throw new Error(`Dynamic path segment "${segment}" in command "${command.name}" is defined as an optional segment but is not defined as an optional catch-all segment. To define an optional catch-all segment, use the "[[...segment]]" syntax.`);
128
- }
129
- return option;
130
- }
131
- /**
132
- * Extracts command positional parameter information from a type parameter reflection.
133
- *
134
- * @param command - The command tree to which the parameter belongs.
135
- * @param reflection - The type parameter reflection to extract information from.
136
- * @returns The extracted command positional parameter information.
137
- */
138
- function extractCommandParameter(command, reflection) {
107
+ function extractCommandArgument(command, reflection) {
139
108
  const type = reflection.getType();
140
109
  if (type.kind !== ReflectionKind.string && type.kind !== ReflectionKind.number && type.kind !== ReflectionKind.boolean && !(type.kind === ReflectionKind.array && (type.type.kind === ReflectionKind.string || type.type.kind === ReflectionKind.number))) throw new Error(`Unsupported type for positional parameter "${reflection.getName()}" in command "${command.name}". Only string types (or an array of strings) are supported, received ${stringifyType(type).trim().replaceAll(" | ", ", or ")}.`);
141
110
  const option = {
142
111
  name: reflection.getName(),
112
+ kind: type.kind,
143
113
  title: titleCase(reflection.getName()),
144
114
  description: reflection.parameter.description || resolveCommandParameterDescription(type.kind, !!reflection.isOptional(), reflection.getName(), titleCase(reflection.getName()), reflection.getDefaultValue()),
145
115
  env: constantCase(reflection.getName()),
@@ -166,14 +136,11 @@ async function reflectCommandTree(context, command, parent) {
166
136
  const title = command.title || `${parent?.title ? `${parent.isVirtual ? parent.title.replace(/ Commands$/, "") : parent.title} - ` : ""}${titleCase(command.name)}${command.isVirtual ? " Commands" : ""}`;
167
137
  const tree = {
168
138
  alias: [],
139
+ icon: parent?.icon,
169
140
  ...command,
170
141
  title,
171
- path: {
172
- ...command.path,
173
- dynamics: {}
174
- },
175
142
  options: getDefaultOptions(context, command),
176
- params: [],
143
+ arguments: [],
177
144
  parent: parent ?? null,
178
145
  children: {},
179
146
  reflection: null
@@ -200,14 +167,7 @@ async function reflectCommandTree(context, command, parent) {
200
167
  const optionsReflection = ReflectionClass.from(parameters[0].type);
201
168
  for (const propertyReflection of optionsReflection.getProperties()) tree.options[propertyReflection.getNameAsString()] = extractCommandOption(command, propertyReflection);
202
169
  } else throw new Error(`The first parameter of the command handler function in "${command.entry.input.file}" must be an object literal or class type representing the command options.`);
203
- tree.path.dynamics = tree.path.segments.filter((segment) => isDynamicPathSegment(segment)).reduce((obj, segment, index) => {
204
- if (parameters.length < index + 2 || !parameters[index + 1]) return obj;
205
- const paramName = getDynamicPathSegmentName(segment);
206
- obj[paramName] = extractCommandDynamicSegment(command, paramName, parameters[index + 1]);
207
- obj[paramName].description = obj[paramName].description || `The ${paramName} ${obj[paramName].catchAll ? `${obj[paramName].optional ? "optional " : ""}catch-all` : "dynamic "} segment for the ${command.name} command.`;
208
- return obj;
209
- }, {});
210
- if (parameters.length > Object.keys(tree.path.dynamics).length + 1) tree.params = parameters.slice(Object.keys(tree.path.dynamics).length + 1).map((param) => extractCommandParameter(command, param));
170
+ tree.arguments = parameters.slice(1).map((arg) => extractCommandArgument(command, arg));
211
171
  }
212
172
  } else tree.description ??= `A collection of available ${tree.title || titleCase(tree.name)} commands that are included in the ${getAppTitle(context)} command line application.`;
213
173
  if (context.env) {
@@ -230,20 +190,20 @@ async function reflectCommandTree(context, command, parent) {
230
190
  }
231
191
  });
232
192
  });
233
- Object.values(tree.params).filter((param) => param.env !== false).forEach((param) => context.env.types.env.addProperty({
234
- name: constantCase(param.name),
235
- optional: param.optional ? true : void 0,
236
- description: param.description,
193
+ Object.values(tree.arguments).filter((arg) => arg.env !== false).forEach((arg) => context.env.types.env.addProperty({
194
+ name: constantCase(arg.name),
195
+ optional: arg.optional ? true : void 0,
196
+ description: arg.description,
237
197
  visibility: ReflectionVisibility.public,
238
- type: param.reflection.getType(),
239
- default: param.default,
198
+ type: arg.reflection.getType(),
199
+ default: arg.default,
240
200
  tags: {
241
- ...param.reflection.getTags(),
201
+ ...arg.reflection.getTags(),
242
202
  domain: "cli"
243
203
  }
244
204
  }));
245
205
  }
246
- for (const input of context.inputs.filter((input$1) => input$1.path.segments.filter((segment) => !isDynamicPathSegment(segment)).length === command.path.segments.filter((segment) => !isDynamicPathSegment(segment)).length + 1 && input$1.path.segments.slice(0, command.path.segments.length).every((value, index) => value === command.path.segments[index]))) tree.children[input.name] = await reflectCommandTree(context, input, tree);
206
+ for (const input of context.inputs.filter((input$1) => input$1.segments.filter((segment) => !isDynamicPathSegment(segment)).length === command.segments.filter((segment) => !isDynamicPathSegment(segment)).length + 1 && input$1.segments.slice(0, command.segments.length).every((value, index) => value === command.segments[index]))) tree.children[input.name] = await reflectCommandTree(context, input, tree);
247
207
  return tree;
248
208
  }
249
209