@shell-shock/core 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/components/docs.d.cts +5 -5
  2. package/dist/components/docs.d.mts +5 -5
  3. package/dist/components/index.cjs +2 -0
  4. package/dist/components/index.d.cts +2 -2
  5. package/dist/components/index.d.mts +2 -2
  6. package/dist/components/index.mjs +2 -2
  7. package/dist/components/options-parser-logic.cjs +111 -10
  8. package/dist/components/options-parser-logic.cjs.map +1 -1
  9. package/dist/components/options-parser-logic.d.cts +39 -8
  10. package/dist/components/options-parser-logic.d.cts.map +1 -1
  11. package/dist/components/options-parser-logic.d.mts +32 -1
  12. package/dist/components/options-parser-logic.d.mts.map +1 -1
  13. package/dist/components/options-parser-logic.mjs +110 -11
  14. package/dist/components/options-parser-logic.mjs.map +1 -1
  15. package/dist/components/usage.cjs +6 -5
  16. package/dist/components/usage.cjs.map +1 -1
  17. package/dist/components/usage.d.cts +2 -4
  18. package/dist/components/usage.d.cts.map +1 -1
  19. package/dist/components/usage.d.mts +2 -4
  20. package/dist/components/usage.d.mts.map +1 -1
  21. package/dist/components/usage.mjs +6 -5
  22. package/dist/components/usage.mjs.map +1 -1
  23. package/dist/helpers/persistence.cjs +48 -3
  24. package/dist/helpers/persistence.cjs.map +1 -1
  25. package/dist/helpers/persistence.mjs +48 -3
  26. package/dist/helpers/persistence.mjs.map +1 -1
  27. package/dist/helpers/resolve-command.cjs +90 -29
  28. package/dist/helpers/resolve-command.cjs.map +1 -1
  29. package/dist/helpers/resolve-command.mjs +91 -30
  30. package/dist/helpers/resolve-command.mjs.map +1 -1
  31. package/dist/index.d.cts +2 -2
  32. package/dist/index.d.mts +2 -2
  33. package/dist/types/command.d.cts +272 -7
  34. package/dist/types/command.d.cts.map +1 -1
  35. package/dist/types/command.d.mts +272 -7
  36. package/dist/types/command.d.mts.map +1 -1
  37. package/dist/types/index.d.cts +2 -2
  38. package/dist/types/index.d.mts +2 -2
  39. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"usage.mjs","names":["code","Match","Switch","snakeCase","getDynamicPathSegmentName","isDynamicPathSegment","Usage","props","command","bin","packageManager","_$createComponent","children","when","_$memo","path","segments","map","segment","dynamics","name","variadic","join","Object","values","length"],"sources":["../../src/components/usage.tsx"],"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 { code, Match, Switch } from \"@alloy-js/core\";\nimport { snakeCase } from \"@stryke/string-format/snake-case\";\nimport {\n getDynamicPathSegmentName,\n isDynamicPathSegment\n} from \"../plugin-utils/context-helpers\";\nimport type { CommandTree } from \"../types/command\";\n\nexport interface UsageProps {\n /**\n * The command to generate help for.\n */\n command: CommandTree;\n\n /**\n * The package manager to generate the usage example for.\n *\n * @remarks\n * If not specified, examples for all supported package managers will be generated.\n *\n * @defaultValue \"npm\"\n */\n packageManager?: \"npm\" | \"yarn\" | \"pnpm\" | \"bun\";\n\n /**\n * The bin name to use in the usage display.\n */\n bin: string;\n}\n\n/**\n * A component that generates the usage display for a command.\n */\nexport function Usage(props: UsageProps) {\n const { command, bin, packageManager } = props;\n\n return (\n <>\n {code`$ `}\n <Switch>\n <Match when={packageManager === \"yarn\"}>{`yarn exec `}</Match>\n <Match when={packageManager === \"pnpm\"}>{`pnpm exec `}</Match>\n <Match when={packageManager === \"bun\"}>{`bun x `}</Match>\n <Match else>{`npx `}</Match>\n </Switch>\n {code`${bin} ${command.path.segments\n .map(segment =>\n isDynamicPathSegment(segment)\n ? `<${snakeCase(\n command.path.dynamics[segment]?.name ||\n getDynamicPathSegmentName(segment)\n )}${command.path.dynamics[segment]?.variadic ? \"...\" : \"\"}>`\n : segment\n )\n .join(\" \")}${\n Object.values(command.children).length > 0 ? \" [commands]\" : \"\"\n } [options]`}\n </>\n );\n}\n"],"mappings":";;;;;;;;;AAmDA,SAAgBM,MAAMC,OAAmB;CACvC,MAAM,EAAEC,SAASC,KAAKC,mBAAmBH;AAEzC,QAAA;EAEKP,IAAI;EAAIW,gBACRT,QAAM,EAAA,IAAAU,WAAA;AAAA,UAAA;IAAAD,gBACJV,OAAK;KAACY,MAAMH,mBAAmB;KAAME,UAAG;KAAY,CAAA;IAAAD,gBACpDV,OAAK;KAACY,MAAMH,mBAAmB;KAAME,UAAG;KAAY,CAAA;IAAAD,gBACpDV,OAAK;KAACY,MAAMH,mBAAmB;KAAKE,UAAG;KAAQ,CAAA;IAAAD,gBAC/CV,OAAK;KAAA,QAAA;KAAAW,UAAO;KAAM,CAAA;IAAA;KAAA,CAAA;EAAAE,WAEpBd,IAAI,GAAGS,IAAG,GAAID,QAAQO,KAAKC,SACzBC,KAAIC,YACHb,qBAAqBa,QAAQ,GACzB,IAAIf,UACFK,QAAQO,KAAKI,SAASD,UAAUE,QAC9BhB,0BAA0Bc,QAC9B,CAAC,GAAGV,QAAQO,KAAKI,SAASD,UAAUG,WAAW,QAAQ,GAAE,KACzDH,QACL,CACAI,KAAK,IAAI,GACVC,OAAOC,OAAOhB,QAAQI,SAAS,CAACa,SAAS,IAAI,gBAAgB,GAAE,YACrD;EAAA"}
1
+ {"version":3,"file":"usage.mjs","names":["code","Match","Switch","ReflectionKind","snakeCase","getDynamicPathSegmentName","isDynamicPathSegment","Usage","props","command","bin","packageManager","_$createComponent","children","when","_$memo","path","segments","length","map","segment","dynamics","name","variadic","join","Object","values","params","param","kind","string","number"],"sources":["../../src/components/usage.tsx"],"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 { code, Match, Switch } from \"@alloy-js/core\";\nimport { ReflectionKind } from \"@powerlines/deepkit/vendor/type\";\nimport { snakeCase } from \"@stryke/string-format/snake-case\";\nimport {\n getDynamicPathSegmentName,\n isDynamicPathSegment\n} from \"../plugin-utils/context-helpers\";\nimport type { CommandTree } from \"../types/command\";\n\nexport interface UsageProps {\n /**\n * The command to generate help for.\n */\n command: CommandTree;\n\n /**\n * The package manager to generate the usage example for.\n *\n * @remarks\n * If not specified, examples for all supported package managers will be generated.\n */\n packageManager?: \"npm\" | \"yarn\" | \"pnpm\" | \"bun\";\n\n /**\n * The bin name to use in the usage display.\n */\n bin: string;\n}\n\n/**\n * A component that generates the usage display for a command.\n */\nexport function Usage(props: UsageProps) {\n const { command, bin, packageManager } = props;\n\n return (\n <>\n {code`$ `}\n <Switch>\n <Match when={packageManager === \"npm\"}>{`npx `}</Match>\n <Match when={packageManager === \"yarn\"}>{`yarn exec `}</Match>\n <Match when={packageManager === \"pnpm\"}>{`pnpm exec `}</Match>\n <Match when={packageManager === \"bun\"}>{`bun x `}</Match>\n </Switch>\n {code`${bin}${\n command.path.segments.length > 0\n ? ` ${command.path.segments\n .map(segment =>\n isDynamicPathSegment(segment)\n ? `[${snakeCase(\n command.path.dynamics[segment]?.name ||\n getDynamicPathSegmentName(segment)\n )}${command.path.dynamics[segment]?.variadic ? \"...\" : \"\"}]`\n : segment\n )\n .join(\" \")}`\n : \"\"\n }${Object.values(command.children).length > 0 ? \" [commands]\" : \"\"}${\n command.params.length > 0\n ? ` ${command.params\n .map(\n param =>\n `<${snakeCase(param.name)}${\n (param.kind === ReflectionKind.string ||\n param.kind === ReflectionKind.number) &&\n param.variadic\n ? \"...\"\n : \"\"\n }>`\n )\n .join(\" \")}`\n : \"\"\n } [options]`}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AAkDA,SAAgBO,MAAMC,OAAmB;CACvC,MAAM,EAAEC,SAASC,KAAKC,mBAAmBH;AAEzC,QAAA;EAEKR,IAAI;EAAIY,gBACRV,QAAM,EAAA,IAAAW,WAAA;AAAA,UAAA;IAAAD,gBACJX,OAAK;KAACa,MAAMH,mBAAmB;KAAKE,UAAG;KAAM,CAAA;IAAAD,gBAC7CX,OAAK;KAACa,MAAMH,mBAAmB;KAAME,UAAG;KAAY,CAAA;IAAAD,gBACpDX,OAAK;KAACa,MAAMH,mBAAmB;KAAME,UAAG;KAAY,CAAA;IAAAD,gBACpDX,OAAK;KAACa,MAAMH,mBAAmB;KAAKE,UAAG;KAAQ,CAAA;IAAA;KAAA,CAAA;EAAAE,WAEjDf,IAAI,GAAGU,MACND,QAAQO,KAAKC,SAASC,SAAS,IAC3B,IAAIT,QAAQO,KAAKC,SACdE,KAAIC,YACHd,qBAAqBc,QAAQ,GACzB,IAAIhB,UACFK,QAAQO,KAAKK,SAASD,UAAUE,QAC9BjB,0BAA0Be,QAC9B,CAAC,GAAGX,QAAQO,KAAKK,SAASD,UAAUG,WAAW,QAAQ,GAAE,KACzDH,QACL,CACAI,KAAK,IAAI,KACZ,KACHC,OAAOC,OAAOjB,QAAQI,SAAS,CAACK,SAAS,IAAI,gBAAgB,KAC9DT,QAAQkB,OAAOT,SAAS,IACpB,IAAIT,QAAQkB,OACTR,KACCS,UACE,IAAIxB,UAAUwB,MAAMN,KAAK,IACtBM,MAAMC,SAAS1B,eAAe2B,UAC7BF,MAAMC,SAAS1B,eAAe4B,WAChCH,MAAML,WACF,QACA,GAAE,GAEX,CACAC,KAAK,IAAI,KACZ,GAAE,YACI;EAAA"}
@@ -1,16 +1,31 @@
1
1
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
2
  let __stryke_path_join_paths = require("@stryke/path/join-paths");
3
+ let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
4
+ let __stryke_helpers_omit = require("@stryke/helpers/omit");
3
5
 
4
6
  //#region src/helpers/persistence.ts
5
7
  function getCommandsPersistencePath(context) {
6
- return (0, __stryke_path_join_paths.joinPaths)(context.dataPath, `commands.json`);
8
+ return (0, __stryke_path_join_paths.joinPaths)(context.dataPath, "reflections", "commands.json");
7
9
  }
8
10
  function serializedCommandTree(commands) {
9
11
  const serialize = (node, parent = null) => {
10
12
  const serializedNode = {
11
13
  ...node,
14
+ options: Object.entries(node.options).reduce((ret, [key, option]) => {
15
+ ret[key] = { ...(0, __stryke_helpers_omit.omit)(option, ["reflection"]) };
16
+ return ret;
17
+ }, {}),
18
+ path: {
19
+ ...node.path,
20
+ dynamics: Object.entries(node.path.dynamics).reduce((ret, [key, dynamic]) => {
21
+ ret[key] = { ...(0, __stryke_helpers_omit.omit)(dynamic, ["reflection"]) };
22
+ return ret;
23
+ }, {})
24
+ },
25
+ params: node.params.map((param) => ({ ...(0, __stryke_helpers_omit.omit)(param, ["reflection"]) })),
12
26
  parent,
13
- children: {}
27
+ children: {},
28
+ reflection: node.reflection ? (0, __powerlines_deepkit_vendor_type.serializeType)(node.reflection.type) : void 0
14
29
  };
15
30
  for (const [key, child] of Object.entries(node.children || {})) serializedNode.children[key] = serialize(child, node.id);
16
31
  return serializedNode;
@@ -21,10 +36,40 @@ function serializedCommandTree(commands) {
21
36
  }
22
37
  function deserializeCommandTree(serializedCommands) {
23
38
  const deserialize = (node, parent = null) => {
39
+ const type = (0, __powerlines_deepkit_vendor_type.deserializeType)(node.reflection);
40
+ if (type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.function) throw new Error(`Failed to deserialize persisted data - invalid command handler reflection type for command ${node.id}`);
41
+ const reflection = new __powerlines_deepkit_vendor_type.ReflectionFunction(type);
42
+ let optionsReflection;
43
+ if (reflection.getParameters().length > 0 && reflection.getParameters()[0]) {
44
+ const optionsType = reflection.getParameters()[0].type;
45
+ if (optionsType.kind === __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral) optionsReflection = (0, __powerlines_deepkit_vendor_type.resolveClassType)(optionsType);
46
+ }
24
47
  const deserializedNode = {
25
48
  ...node,
49
+ options: optionsReflection ? Object.entries(node.options).reduce((ret, [key, option]) => {
50
+ ret[key] = {
51
+ ...option,
52
+ reflection: optionsReflection.getProperty(option.name)
53
+ };
54
+ return ret;
55
+ }, {}) : {},
56
+ path: {
57
+ ...node.path,
58
+ dynamics: Object.entries(node.path.dynamics).reduce((ret, [key, dynamic]) => {
59
+ ret[key] = {
60
+ ...dynamic,
61
+ reflection: reflection.getParameter(dynamic.name)
62
+ };
63
+ return ret;
64
+ }, {})
65
+ },
66
+ params: node.params.map((param) => ({
67
+ ...param,
68
+ reflection: reflection.getParameter(param.name)
69
+ })),
26
70
  parent,
27
- children: {}
71
+ children: {},
72
+ reflection
28
73
  };
29
74
  for (const [key, child] of Object.entries(node.children || {})) deserializedNode.children[key] = deserialize(child, deserializedNode);
30
75
  return deserializedNode;
@@ -1 +1 @@
1
- {"version":3,"file":"persistence.cjs","names":["joinPaths","getCommandsPersistencePath","context","dataPath","serializedCommandTree","commands","serialize","node","parent","serializedNode","children","key","child","Object","entries","id","result","deserializeCommandTree","serializedCommands","deserialize","deserializedNode","readCommandsPersistence","reflections","fs","read","length","Error","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 { joinPaths } from \"@stryke/path/join-paths\";\nimport type { CommandTree, SerializedCommandTree } from \"../types\";\nimport type { Context } from \"../types/context\";\n\nexport function getCommandsPersistencePath(context: Context): string {\n return joinPaths(context.dataPath, `commands.json`);\n}\n\nfunction 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 parent,\n children: {}\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\nfunction 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 deserializedNode: CommandTree = {\n ...node,\n parent,\n children: {}\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 serializedComm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uBU,KAAKC,MAAMN,YAAY,CAAC;;AAGpE,eAAsBO,yBAAyB3B,SAAkB;CAC/D,MAAM4B,WAAW7B,2BAA2BC,QAAQ;AAEpD,OAAMA,QAAQqB,GAAGQ,MACfD,UACAH,KAAKK,UACH5B,sBAAsBF,QAAQG,SAAS,EACvC,MACAH,QAAQ+B,OAAOC,SAAS,gBAAgB,IAAI,EAEhD,CAAC"}
1
+ {"version":3,"file":"persistence.cjs","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,gDAAiBA,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,KAA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J,YAAY,CAAC;;AAGpE,eAAsBK,yBAAyBjD,SAAkB;CAC/D,MAAMkD,WAAWnD,2BAA2BC,QAAQ;AAEpD,OAAMA,QAAQ6C,GAAGM,MACfD,UACAH,KAAKK,UACHlD,sBAAsBF,QAAQG,SAAS,EACvC,MACAH,QAAQqD,OAAOC,SAAS,gBAAgB,IAAI,EAEhD,CAAC"}
@@ -1,15 +1,30 @@
1
1
  import { joinPaths } from "@stryke/path/join-paths";
2
+ import { ReflectionFunction, ReflectionKind, deserializeType, resolveClassType, serializeType } from "@powerlines/deepkit/vendor/type";
3
+ import { omit } from "@stryke/helpers/omit";
2
4
 
3
5
  //#region src/helpers/persistence.ts
4
6
  function getCommandsPersistencePath(context) {
5
- return joinPaths(context.dataPath, `commands.json`);
7
+ return joinPaths(context.dataPath, "reflections", "commands.json");
6
8
  }
7
9
  function serializedCommandTree(commands) {
8
10
  const serialize = (node, parent = null) => {
9
11
  const serializedNode = {
10
12
  ...node,
13
+ options: Object.entries(node.options).reduce((ret, [key, option]) => {
14
+ ret[key] = { ...omit(option, ["reflection"]) };
15
+ return ret;
16
+ }, {}),
17
+ path: {
18
+ ...node.path,
19
+ dynamics: Object.entries(node.path.dynamics).reduce((ret, [key, dynamic]) => {
20
+ ret[key] = { ...omit(dynamic, ["reflection"]) };
21
+ return ret;
22
+ }, {})
23
+ },
24
+ params: node.params.map((param) => ({ ...omit(param, ["reflection"]) })),
11
25
  parent,
12
- children: {}
26
+ children: {},
27
+ reflection: node.reflection ? serializeType(node.reflection.type) : void 0
13
28
  };
14
29
  for (const [key, child] of Object.entries(node.children || {})) serializedNode.children[key] = serialize(child, node.id);
15
30
  return serializedNode;
@@ -20,10 +35,40 @@ function serializedCommandTree(commands) {
20
35
  }
21
36
  function deserializeCommandTree(serializedCommands) {
22
37
  const deserialize = (node, parent = null) => {
38
+ const type = deserializeType(node.reflection);
39
+ if (type.kind !== ReflectionKind.function) throw new Error(`Failed to deserialize persisted data - invalid command handler reflection type for command ${node.id}`);
40
+ const reflection = new ReflectionFunction(type);
41
+ let optionsReflection;
42
+ if (reflection.getParameters().length > 0 && reflection.getParameters()[0]) {
43
+ const optionsType = reflection.getParameters()[0].type;
44
+ if (optionsType.kind === ReflectionKind.objectLiteral) optionsReflection = resolveClassType(optionsType);
45
+ }
23
46
  const deserializedNode = {
24
47
  ...node,
48
+ options: optionsReflection ? Object.entries(node.options).reduce((ret, [key, option]) => {
49
+ ret[key] = {
50
+ ...option,
51
+ reflection: optionsReflection.getProperty(option.name)
52
+ };
53
+ return ret;
54
+ }, {}) : {},
55
+ path: {
56
+ ...node.path,
57
+ dynamics: Object.entries(node.path.dynamics).reduce((ret, [key, dynamic]) => {
58
+ ret[key] = {
59
+ ...dynamic,
60
+ reflection: reflection.getParameter(dynamic.name)
61
+ };
62
+ return ret;
63
+ }, {})
64
+ },
65
+ params: node.params.map((param) => ({
66
+ ...param,
67
+ reflection: reflection.getParameter(param.name)
68
+ })),
25
69
  parent,
26
- children: {}
70
+ children: {},
71
+ reflection
27
72
  };
28
73
  for (const [key, child] of Object.entries(node.children || {})) deserializedNode.children[key] = deserialize(child, deserializedNode);
29
74
  return deserializedNode;
@@ -1 +1 @@
1
- {"version":3,"file":"persistence.mjs","names":["joinPaths","getCommandsPersistencePath","context","dataPath","serializedCommandTree","commands","serialize","node","parent","serializedNode","children","key","child","Object","entries","id","result","deserializeCommandTree","serializedCommands","deserialize","deserializedNode","readCommandsPersistence","reflections","fs","read","length","Error","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 { joinPaths } from \"@stryke/path/join-paths\";\nimport type { CommandTree, SerializedCommandTree } from \"../types\";\nimport type { Context } from \"../types/context\";\n\nexport function getCommandsPersistencePath(context: Context): string {\n return joinPaths(context.dataPath, `commands.json`);\n}\n\nfunction 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 parent,\n children: {}\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\nfunction 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 deserializedNode: CommandTree = {\n ...node,\n parent,\n children: {}\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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AGpE,eAAsBO,yBAAyB3B,SAAkB;CAC/D,MAAM4B,WAAW7B,2BAA2BC,QAAQ;AAEpD,OAAMA,QAAQqB,GAAGQ,MACfD,UACAH,KAAKK,UACH5B,sBAAsBF,QAAQG,SAAS,EACvC,MACAH,QAAQ+B,OAAOC,SAAS,gBAAgB,IAAI,EAEhD,CAAC"}
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,Q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uBmB,KAAKC,MAAMJ,YAAY,CAAC;;AAGpE,eAAsBK,yBAAyBjD,SAAkB;CAC/D,MAAMkD,WAAWnD,2BAA2BC,QAAQ;AAEpD,OAAMA,QAAQ6C,GAAGM,MACfD,UACAH,KAAKK,UACHlD,sBAAsBF,QAAQG,SAAS,EACvC,MACAH,QAAQqD,OAAOC,SAAS,gBAAgB,IAAI,EAEhD,CAAC"}
@@ -30,6 +30,19 @@ let powerlines_lib_utilities_resolve = require("powerlines/lib/utilities/resolve
30
30
  function resolveCommandOptionDescription(kind, optional, name, title, defaultValue) {
31
31
  return `A${optional && !defaultValue ? "n optional" : ""} ${kind === __powerlines_deepkit_vendor_type.ReflectionKind.boolean ? "flag provided via the command-line" : "command-line option"} that allows the user to ${kind === __powerlines_deepkit_vendor_type.ReflectionKind.boolean ? "set the" : kind === __powerlines_deepkit_vendor_type.ReflectionKind.array ? "specify custom" : "specify a custom"} ${title?.trim() || (0, __stryke_string_format_title_case.titleCase)(name)} ${kind === __powerlines_deepkit_vendor_type.ReflectionKind.boolean ? "indicator" : `${kind === __powerlines_deepkit_vendor_type.ReflectionKind.number ? "numeric" : "string"} value${kind === __powerlines_deepkit_vendor_type.ReflectionKind.array ? "s" : ""}`} that will be used in the application.`;
32
32
  }
33
+ /**
34
+ * Resolves the description for a command parameter based on its reflection.
35
+ *
36
+ * @param kind - The reflection kind of the command parameter.
37
+ * @param optional - Whether the command parameter is optional.
38
+ * @param name - The name of the command parameter.
39
+ * @param title - The title of the command parameter, if any.
40
+ * @param defaultValue - The default value of the command parameter, if any.
41
+ * @returns The resolved description for the command parameter.
42
+ */
43
+ function resolveCommandParameterDescription(kind, optional, name, title, defaultValue) {
44
+ return `A${optional && !defaultValue ? "n optional" : ""} command-line positional parameter that allows the user to ${kind === __powerlines_deepkit_vendor_type.ReflectionKind.boolean ? "set the" : kind === __powerlines_deepkit_vendor_type.ReflectionKind.array ? "specify custom" : "specify a custom"} ${title?.trim() || (0, __stryke_string_format_title_case.titleCase)(name)} ${kind === __powerlines_deepkit_vendor_type.ReflectionKind.boolean ? "indicator" : `${kind === __powerlines_deepkit_vendor_type.ReflectionKind.number ? "numeric" : "string"} value${kind === __powerlines_deepkit_vendor_type.ReflectionKind.array ? "s" : ""}`} that will be used in the application.`;
45
+ }
33
46
  function resolveCommandId(context, file) {
34
47
  return (0, __stryke_path_replace.replacePath)((0, __stryke_path_file_path_fns.findFilePath)(file), context.commandsPath).split("/").filter((p) => Boolean(p) && !require_plugin_utils_context_helpers.isDynamicPathSegment(p)).join("/").replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "").replaceAll("/", "-");
35
48
  }
@@ -65,44 +78,48 @@ function findCommandsRoot(context) {
65
78
  * @returns The extracted command option information.
66
79
  */
67
80
  function extractCommandOption(command, reflection) {
68
- const propertyType = reflection.getType();
81
+ const type = reflection.getType();
69
82
  const option = {
70
83
  name: reflection.getNameAsString(),
71
84
  alias: reflection.getTags().alias ?? [],
72
85
  title: reflection.getTags().title?.trim() || (0, __stryke_string_format_title_case.titleCase)(reflection.getNameAsString()),
73
86
  description: reflection.getDescription() || resolveCommandOptionDescription(reflection.getKind(), reflection.isOptional(), reflection.getNameAsString(), reflection.getTags().title, reflection.getDefaultValue()),
74
87
  env: (0, __stryke_string_format_constant_case.constantCase)(reflection.getNameAsString()),
75
- kind: propertyType.kind,
88
+ kind: type.kind,
76
89
  optional: reflection.isOptional(),
77
90
  default: reflection.getDefaultValue(),
78
- variadic: false
91
+ variadic: reflection.isArray(),
92
+ reflection
79
93
  };
80
- if (propertyType.kind === __powerlines_deepkit_vendor_type.ReflectionKind.array) if (propertyType.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || propertyType.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number) {
94
+ if (reflection.isArray()) if (type.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || type.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number) {
81
95
  option.variadic = true;
82
- option.kind = propertyType.type.kind;
83
- } else throw new Error(`Unsupported array type for option "${reflection.getNameAsString()}" in command "${command.name}". Only string[] and number[] are supported.`);
84
- else if (propertyType.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.boolean && propertyType.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.string && propertyType.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.number) throw new Error(`Unsupported type for option "${reflection.getNameAsString()}" in command "${command.name}". Only string, number, boolean, string[] and number[] are supported, received ${(0, __powerlines_deepkit_vendor_type.stringifyType)(propertyType).trim().replaceAll(" | ", ", or ")}.`);
96
+ option.kind = type.type.kind;
97
+ } else throw new Error(`Unsupported array type for option "${reflection.getNameAsString()}" in command "${command.name}". Only string[] and number[] are supported, received ${(0, __powerlines_deepkit_vendor_type.stringifyType)(type).trim().replaceAll(" | ", ", or ")}.`);
98
+ else if (type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.boolean && type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.string && type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.number) throw new Error(`Unsupported type for option "${reflection.getNameAsString()}" in command "${command.name}". Only string, number, boolean, string[] and number[] are supported, received ${(0, __powerlines_deepkit_vendor_type.stringifyType)(type).trim().replaceAll(" | ", ", or ")}.`);
85
99
  return option;
86
100
  }
87
101
  /**
88
- * Extracts command parameter information from a type parameter reflection.
102
+ * Extracts command dynamic path segment information from a type parameter reflection.
89
103
  *
90
104
  * @param command - The command tree to which the parameter belongs.
91
105
  * @param segment - The command path segment corresponding to the parameter.
92
106
  * @param reflection - The type parameter reflection to extract information from.
93
- * @returns The extracted command option information.
107
+ * @returns The extracted command dynamic segment information.
94
108
  */
95
109
  function extractCommandDynamicSegment(command, segment, reflection) {
96
- if (reflection.type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.string && !(reflection.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.array && reflection.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)(reflection.type).trim().replaceAll(" | ", ", or ")}.`);
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 ")}.`);
97
112
  const option = {
98
- name: segment,
99
- title: (0, __stryke_string_format_title_case.titleCase)(segment),
100
- description: reflection.description || resolveCommandOptionDescription(__powerlines_deepkit_vendor_type.ReflectionKind.string, !!reflection.optional, segment, (0, __stryke_string_format_title_case.titleCase)(segment), reflection.default),
101
- optional: reflection.optional,
102
- default: reflection.default,
103
- catchAll: command.path.segments.some((seg) => require_plugin_utils_context_helpers.getDynamicPathSegmentName(segment) === seg && require_plugin_utils_context_helpers.isCatchAllPathSegment(seg))
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
104
121
  };
105
- if (reflection.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.array) {
122
+ if (type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.array) {
106
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.`);
107
124
  option.variadic = true;
108
125
  }
@@ -113,6 +130,32 @@ function extractCommandDynamicSegment(command, segment, reflection) {
113
130
  return option;
114
131
  }
115
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) {
140
+ const type = reflection.getType();
141
+ 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
+ const option = {
143
+ name: reflection.getName(),
144
+ title: (0, __stryke_string_format_title_case.titleCase)(reflection.getName()),
145
+ description: reflection.parameter.description || resolveCommandParameterDescription(type.kind, !!reflection.isOptional(), reflection.getName(), (0, __stryke_string_format_title_case.titleCase)(reflection.getName()), reflection.getDefaultValue()),
146
+ env: (0, __stryke_string_format_constant_case.constantCase)(reflection.getName()),
147
+ optional: reflection.isOptional(),
148
+ default: reflection.getDefaultValue(),
149
+ reflection
150
+ };
151
+ if (type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.array) if (type.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || type.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number) {
152
+ option.variadic = true;
153
+ option.kind = type.type.kind;
154
+ } else throw new Error(`Unsupported array type for positional parameter "${reflection.getName()}" in command "${command.name}". Only string[] and number[] are supported, received ${(0, __powerlines_deepkit_vendor_type.stringifyType)(type).trim().replaceAll(" | ", ", or ")}.`);
155
+ else if (type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.boolean && type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.string && type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.number) throw new Error(`Unsupported type for positional parameter "${reflection.getName()}" in command "${command.name}". Only string, number, boolean, string[] and number[] are supported, received ${(0, __powerlines_deepkit_vendor_type.stringifyType)(type).trim().replaceAll(" | ", ", or ")}.`);
156
+ return option;
157
+ }
158
+ /**
116
159
  * Reflects the command tree for a given command input.
117
160
  *
118
161
  * @param context - The context in which the command is being reflected.
@@ -131,8 +174,10 @@ async function reflectCommandTree(context, command, parent) {
131
174
  dynamics: {}
132
175
  },
133
176
  options: require_utilities.getDefaultOptions(context, command),
177
+ params: [],
134
178
  parent: parent ?? null,
135
- children: {}
179
+ children: {},
180
+ reflection: null
136
181
  };
137
182
  if (!command.isVirtual) {
138
183
  if (!command.entry.input?.file || !context.fs.existsSync(command.entry.input.file)) throw new Error(`${!command.entry.input?.file ? "Missing" : "Non-existent"} command entry file for "${command.name}"`);
@@ -145,24 +190,27 @@ async function reflectCommandTree(context, command, parent) {
145
190
  if ((0, __stryke_type_checks_is_set_string.isSetString)(metadata.title)) tree.title = metadata.title;
146
191
  if ((0, __stryke_type_checks_is_set_string.isSetString)(metadata.description)) tree.description = metadata.description;
147
192
  if ((0, __stryke_type_checks_is_set_string.isSetString)(metadata.alias) || Array.isArray(metadata.alias) && metadata.alias.length > 0) tree.alias = (0, __stryke_convert_to_array.toArray)(metadata.alias);
193
+ if ((0, __stryke_type_checks_is_set_string.isSetString)(metadata.icon)) tree.icon = metadata.icon;
148
194
  const type = (0, __powerlines_deepkit_vendor_type.reflect)(resolved);
149
195
  if (type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.function) throw new Error(`The command entry file "${command.entry.input.file}" does not export a valid function.`);
150
- tree.description ??= command.description || type.description || `The ${tree.title} executable command-line interface.`;
151
- if (type.parameters.length > 0 && type.parameters[0]) {
152
- const firstParam = type.parameters[0];
153
- if (firstParam.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral || firstParam.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.class) {
154
- const optionsReflection = __powerlines_deepkit_vendor_type.ReflectionClass.from(firstParam.type);
196
+ tree.reflection = new __powerlines_deepkit_vendor_type.ReflectionFunction(type);
197
+ tree.description ??= command.description || type.description || `The ${tree.title} executable command line interface.`;
198
+ const parameters = tree.reflection.getParameters();
199
+ if (parameters.length > 0 && parameters[0]) {
200
+ if (parameters[0].type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral || parameters[0].type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.class) {
201
+ const optionsReflection = __powerlines_deepkit_vendor_type.ReflectionClass.from(parameters[0].type);
155
202
  for (const propertyReflection of optionsReflection.getProperties()) tree.options[propertyReflection.getNameAsString()] = extractCommandOption(command, propertyReflection);
156
- }
203
+ } 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.`);
157
204
  tree.path.dynamics = tree.path.segments.filter((segment) => require_plugin_utils_context_helpers.isDynamicPathSegment(segment)).reduce((obj, segment, index) => {
158
- if (type.parameters.length < index + 2 || !type.parameters[index + 1]) return obj;
205
+ if (parameters.length < index + 2 || !parameters[index + 1]) return obj;
159
206
  const paramName = require_plugin_utils_context_helpers.getDynamicPathSegmentName(segment);
160
- obj[paramName] = extractCommandDynamicSegment(command, paramName, type.parameters[index + 1]);
207
+ obj[paramName] = extractCommandDynamicSegment(command, paramName, parameters[index + 1]);
161
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.`;
162
209
  return obj;
163
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));
164
212
  }
165
- } 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.`;
213
+ } 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.`;
166
214
  if (context.env) {
167
215
  if ((0, __stryke_type_checks_is_set_object.isSetObject)(tree.options)) Object.values(tree.options).filter((option) => option.env !== false).forEach((option) => {
168
216
  context.env.types.env.addProperty({
@@ -170,18 +218,31 @@ async function reflectCommandTree(context, command, parent) {
170
218
  optional: option.optional ? true : void 0,
171
219
  description: option.description,
172
220
  visibility: __powerlines_deepkit_vendor_type.ReflectionVisibility.public,
173
- type: option.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || option.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number ? option.variadic ? {
221
+ type: option.reflection?.getType() ?? (option.variadic ? {
174
222
  kind: __powerlines_deepkit_vendor_type.ReflectionKind.array,
175
223
  type: { kind: option.kind }
176
- } : { kind: option.kind } : { kind: __powerlines_deepkit_vendor_type.ReflectionKind.boolean },
224
+ } : { kind: option.kind }),
177
225
  default: option.default,
178
226
  tags: {
227
+ ...option.reflection?.getTags(),
179
228
  title: option.title,
180
229
  alias: option.alias.filter((alias) => alias.length > 0).map((alias) => (0, __stryke_string_format_constant_case.constantCase)(alias)),
181
230
  domain: "cli"
182
231
  }
183
232
  });
184
233
  });
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,
238
+ visibility: __powerlines_deepkit_vendor_type.ReflectionVisibility.public,
239
+ type: param.reflection.getType(),
240
+ default: param.default,
241
+ tags: {
242
+ ...param.reflection.getTags(),
243
+ domain: "cli"
244
+ }
245
+ }));
185
246
  }
186
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);
187
248
  return tree;