@shell-shock/core 0.17.8 → 0.17.10

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 (141) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -1
  2. package/dist/api.cjs +148 -1
  3. package/dist/api.d.cts +6 -6
  4. package/dist/api.d.cts.map +1 -1
  5. package/dist/api.d.mts +6 -6
  6. package/dist/api.d.mts.map +1 -1
  7. package/dist/api.mjs +145 -1
  8. package/dist/api.mjs.map +1 -1
  9. package/dist/components/command-validation-logic.cjs +292 -1
  10. package/dist/components/command-validation-logic.mjs +289 -1
  11. package/dist/components/command-validation-logic.mjs.map +1 -1
  12. package/dist/components/docs.cjs +265 -1
  13. package/dist/components/docs.mjs +256 -1
  14. package/dist/components/docs.mjs.map +1 -1
  15. package/dist/components/exec-builtin.cjs +429 -13
  16. package/dist/components/exec-builtin.mjs +425 -13
  17. package/dist/components/exec-builtin.mjs.map +1 -1
  18. package/dist/components/helpers.cjs +120 -1
  19. package/dist/components/helpers.mjs +112 -1
  20. package/dist/components/helpers.mjs.map +1 -1
  21. package/dist/components/index.cjs +58 -1
  22. package/dist/components/index.mjs +10 -1
  23. package/dist/components/options-parser-logic.cjs +960 -5
  24. package/dist/components/options-parser-logic.d.cts +1 -1
  25. package/dist/components/options-parser-logic.mjs +945 -5
  26. package/dist/components/options-parser-logic.mjs.map +1 -1
  27. package/dist/components/state-builtin.cjs +629 -8
  28. package/dist/components/state-builtin.mjs +622 -8
  29. package/dist/components/state-builtin.mjs.map +1 -1
  30. package/dist/components/usage.cjs +117 -1
  31. package/dist/components/usage.mjs +114 -1
  32. package/dist/components/usage.mjs.map +1 -1
  33. package/dist/components/utils-builtin.cjs +838 -33
  34. package/dist/components/utils-builtin.mjs +828 -33
  35. package/dist/components/utils-builtin.mjs.map +1 -1
  36. package/dist/config.cjs +31 -1
  37. package/dist/config.mjs +29 -1
  38. package/dist/config.mjs.map +1 -1
  39. package/dist/contexts/command.cjs +26 -1
  40. package/dist/contexts/command.mjs +23 -1
  41. package/dist/contexts/command.mjs.map +1 -1
  42. package/dist/contexts/index.cjs +9 -1
  43. package/dist/contexts/index.mjs +4 -1
  44. package/dist/contexts/options.cjs +63 -1
  45. package/dist/contexts/options.mjs +58 -1
  46. package/dist/contexts/options.mjs.map +1 -1
  47. package/dist/helpers/automd.cjs +71 -1
  48. package/dist/helpers/automd.mjs +70 -1
  49. package/dist/helpers/automd.mjs.map +1 -1
  50. package/dist/helpers/docs-helpers.cjs +23 -1
  51. package/dist/helpers/docs-helpers.mjs +22 -1
  52. package/dist/helpers/docs-helpers.mjs.map +1 -1
  53. package/dist/helpers/paths.cjs +137 -1
  54. package/dist/helpers/paths.mjs +133 -1
  55. package/dist/helpers/paths.mjs.map +1 -1
  56. package/dist/helpers/persistence.cjs +115 -1
  57. package/dist/helpers/persistence.mjs +112 -1
  58. package/dist/helpers/persistence.mjs.map +1 -1
  59. package/dist/helpers/update-package-json.cjs +65 -1
  60. package/dist/helpers/update-package-json.mjs +63 -1
  61. package/dist/helpers/update-package-json.mjs.map +1 -1
  62. package/dist/helpers/utilities.cjs +95 -1
  63. package/dist/helpers/utilities.mjs +93 -1
  64. package/dist/helpers/utilities.mjs.map +1 -1
  65. package/dist/helpers/validations.cjs +71 -1
  66. package/dist/helpers/validations.mjs +71 -1
  67. package/dist/helpers/validations.mjs.map +1 -1
  68. package/dist/index.cjs +53 -1
  69. package/dist/index.d.cts +3 -3
  70. package/dist/index.d.mts +3 -3
  71. package/dist/index.mjs +7 -1
  72. package/dist/plugin-utils/compute-bin.cjs +50 -1
  73. package/dist/plugin-utils/compute-bin.mjs +49 -1
  74. package/dist/plugin-utils/compute-bin.mjs.map +1 -1
  75. package/dist/plugin-utils/context-helpers.cjs +231 -1
  76. package/dist/plugin-utils/context-helpers.mjs +221 -1
  77. package/dist/plugin-utils/context-helpers.mjs.map +1 -1
  78. package/dist/plugin-utils/deepkit.cjs +71 -1
  79. package/dist/plugin-utils/deepkit.mjs +69 -1
  80. package/dist/plugin-utils/deepkit.mjs.map +1 -1
  81. package/dist/plugin-utils/description-helpers.cjs +111 -2
  82. package/dist/plugin-utils/description-helpers.mjs +107 -2
  83. package/dist/plugin-utils/description-helpers.mjs.map +1 -1
  84. package/dist/plugin-utils/get-command-tree.cjs +117 -1
  85. package/dist/plugin-utils/get-command-tree.mjs +114 -1
  86. package/dist/plugin-utils/get-command-tree.mjs.map +1 -1
  87. package/dist/plugin-utils/index.cjs +39 -1
  88. package/dist/plugin-utils/index.mjs +10 -1
  89. package/dist/plugin-utils/reflect.cjs +52 -1
  90. package/dist/plugin-utils/reflect.mjs +52 -1
  91. package/dist/plugin-utils/reflect.mjs.map +1 -1
  92. package/dist/plugin-utils/traverse-command-tree.cjs +64 -1
  93. package/dist/plugin-utils/traverse-command-tree.mjs +62 -1
  94. package/dist/plugin-utils/traverse-command-tree.mjs.map +1 -1
  95. package/dist/plugin-utils/type-checks.cjs +93 -1
  96. package/dist/plugin-utils/type-checks.mjs +88 -1
  97. package/dist/plugin-utils/type-checks.mjs.map +1 -1
  98. package/dist/plugin.cjs +471 -4
  99. package/dist/plugin.d.cts.map +1 -1
  100. package/dist/plugin.d.mts.map +1 -1
  101. package/dist/plugin.mjs +465 -4
  102. package/dist/plugin.mjs.map +1 -1
  103. package/dist/resolver/deepkit.cjs +135 -1
  104. package/dist/resolver/deepkit.mjs +134 -1
  105. package/dist/resolver/deepkit.mjs.map +1 -1
  106. package/dist/resolver/helpers.cjs +173 -1
  107. package/dist/resolver/helpers.mjs +168 -1
  108. package/dist/resolver/helpers.mjs.map +1 -1
  109. package/dist/resolver/module.cjs +145 -1
  110. package/dist/resolver/module.mjs +144 -1
  111. package/dist/resolver/module.mjs.map +1 -1
  112. package/dist/resolver/resolve.cjs +222 -1
  113. package/dist/resolver/resolve.mjs +221 -1
  114. package/dist/resolver/resolve.mjs.map +1 -1
  115. package/dist/types/command.cjs +441 -1
  116. package/dist/types/command.d.cts +1 -1
  117. package/dist/types/command.d.mts +2 -2
  118. package/dist/types/command.mjs +405 -1
  119. package/dist/types/command.mjs.map +1 -1
  120. package/dist/types/config.cjs +134 -1
  121. package/dist/types/config.d.cts +10 -8
  122. package/dist/types/config.d.cts.map +1 -1
  123. package/dist/types/config.d.mts +10 -8
  124. package/dist/types/config.d.mts.map +1 -1
  125. package/dist/types/config.mjs +127 -1
  126. package/dist/types/config.mjs.map +1 -1
  127. package/dist/types/context.cjs +37 -1
  128. package/dist/types/context.mjs +34 -1
  129. package/dist/types/context.mjs.map +1 -1
  130. package/dist/types/env.cjs +52 -1
  131. package/dist/types/env.d.cts +1 -1
  132. package/dist/types/env.d.mts +1 -1
  133. package/dist/types/env.mjs +50 -1
  134. package/dist/types/env.mjs.map +1 -1
  135. package/dist/types/index.cjs +50 -1
  136. package/dist/types/index.d.cts +2 -2
  137. package/dist/types/index.d.mts +2 -2
  138. package/dist/types/index.mjs +6 -1
  139. package/dist/types/options.cjs +12 -1
  140. package/dist/types/options.mjs +10 -1
  141. package/package.json +22 -21
@@ -1 +1,222 @@
1
- require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../plugin-utils/context-helpers.cjs`),t=require(`../plugin-utils/deepkit.cjs`),n=require(`../helpers/utilities.cjs`),r=require(`./helpers.cjs`),i=require(`./deepkit.cjs`),a=require(`./module.cjs`);let o=require(`@powerlines/deepkit/vendor/type`),s=require(`@stryke/string-format/constant-case`),c=require(`@stryke/string-format/title-case`),l=require(`@stryke/type-checks/is-set-object`),u=require(`@powerlines/deepkit/esbuild-plugin`),d=require(`@powerlines/plugin-esbuild/helpers/resolve`);function f(e,t){return e.__type=t,e}async function p(e){let{context:t,command:r,parent:i}=e,a=r.title||`${i?.title?`${i.isVirtual?i.title.replace(/(?:c|C)ommands?$/,``).trim():i.title} - `:``}${(0,c.titleCase)(r.name)}${r.isVirtual?` Commands`:``}`,o={input:e,output:{alias:[],icon:i?.icon,tags:i?.tags??[],source:`file`,...r,title:a,options:i===null?n.getGlobalOptions(t,r):{},args:[],parent:i??null,children:{}}};if(!r.isVirtual){if(!r.entry.input?.file||!t.fs.existsSync(r.entry.input.file))throw Error(`${r.entry.input?.file?`Non-existent`:`Missing`} command entry file for "${r.name}"`);t.debug(`Adding reflection for CLI command: ${r.id} (file: ${r.entry.input.file})`),o.module=await(d.resolveModule.Ω=[[`CommandModule`,`"w!`]],(0,d.resolveModule)(t,r.entry.input,{name:r.title||(0,c.titleCase)(r.name),treeShaking:!0,resolve:{skipNodeModulesBundle:!0},plugins:[(0,u.esbuildPlugin)(t,{reflection:`default`,level:`all`})]}))}return o}p.__type=[`ResolverInput`,`input`,`ResolverContext`,`initialize`,'P"w!2""w#`/$'];async function m(n){return n.output.options=r.applyOptionsDefaults(n),n.output.args=r.applyArgsDefaults(n),n.output.args.forEach(f((t,r)=>{let i=n.output.args.findIndex(f(e=>e.name===t.name,[`a`,``,`P"2!"/"`]));(i!==-1&&i!==r||n.output.segments.some(f(n=>e.isDynamicPathSegment(n)&&e.getDynamicPathSegmentName(n)===t.name,[`segment`,``,`P"2!"/"`])))&&(t.name+=`_${n.output.segments.filter(f(n=>e.isDynamicPathSegment(n)&&e.getDynamicPathSegmentName(n).replace(/_\d+$/,``)===t.name,[`segment`,``,`P"2!"/"`])).length+n.output.args.filter(f(e=>e.name.replace(/_\d+$/,``)===t.name,[`a`,``,`P"2!"/"`])).length}`,t.env=t.name?t.env||t.env===!1?t.env:n.input.context.config.autoAssignEnv?(0,s.constantCase)(t.name):!1:!1)},[`arg`,`index`,``,`P"2!"2""/#`])),r.applyDefaults(n),n.input.context.env&&((0,l.isSetObject)(n.output.options)&&Object.values(n.output.options).filter(f(e=>!!e.env,[`option`,``,`P"2!"/"`])).forEach(f(e=>{n.input.context.env.types.env.addProperty({name:e.env,optional:e.optional?!0:void 0,description:e.description,visibility:o.ReflectionVisibility.public,type:t.extractType(e),default:e.default,tags:{title:e.title,alias:e.alias.filter(f(e=>e.length>1,[`alias`,``,`P"2!"/"`])).map(f(e=>(0,s.constantCase)(e),[`alias`,``,`P"2!"/"`])),domain:`cli`}})},[`option`,``,`P"2!"/"`])),n.output.args.filter(f(e=>!!e.env,[`arg`,``,`P"2!"/"`])).forEach(f(e=>n.input.context.env.types.env.addProperty({name:e.env,optional:e.optional?!0:void 0,description:e.description,visibility:o.ReflectionVisibility.public,type:t.extractType(e),default:e.default,tags:{alias:e.alias.filter(f(e=>e.length>1,[`alias`,``,`P"2!"/"`])).map(f(e=>(0,s.constantCase)(e),[`alias`,``,`P"2!"/"`])),domain:`cli`}}),[`arg`,``,`P"2!"/"`]))),await Promise.all(n.input.context.inputs.filter(f(t=>t.segments.filter(f(t=>!e.isDynamicPathSegment(t),[`segment`,``,`P"2!"/"`])).length===n.input.command.segments.filter(f(t=>!e.isDynamicPathSegment(t),[`segment`,``,`P"2!"/"`])).length+1&&t.segments.slice(0,n.input.command.segments.length).every(f((e,t)=>e===n.input.command.segments[t],[`value`,`index`,``,`P"2!"2""/#`])),[`input`,``,`P"2!"/"`])).map(f(async e=>{n.output.children[e.name]=await(h.Ω=[[()=>n,`ResolverContext`,`Pi!"w"q"!j`]],h({context:n.input.context,command:e,parent:n.output}))},[`input`,``,`P"2!"/"`]))),n.output}m.__type=[`ResolverContext`,`ctx`,`CommandTree`,`postprocess`,'P"w!2""w#`/$'];async function h(e){let t=await(p.Ω=[[()=>e,`ResolverInput`,`Pi!"w"q"!j`]],p(e));return t.output.isVirtual?r.resolveVirtualCommand(t):(await a.resolveFromExports(t),i.resolveFromBytecode(t)),m(t)}h.__type=[`ResolverInput`,`input`,`CommandTree`,`resolve`,`Resolves a command tree from the given resolver input.`,'P"w!2""w#`/$?%'],exports.resolve=h;
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ const require_context_helpers = require('../plugin-utils/context-helpers.cjs');
3
+ const require_deepkit = require('../plugin-utils/deepkit.cjs');
4
+ const require_utilities = require('../helpers/utilities.cjs');
5
+ const require_helpers = require('./helpers.cjs');
6
+ const require_deepkit$1 = require('./deepkit.cjs');
7
+ const require_module = require('./module.cjs');
8
+ let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
9
+ let _stryke_string_format_constant_case = require("@stryke/string-format/constant-case");
10
+ let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
11
+ let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
12
+ let _powerlines_deepkit_esbuild_plugin = require("@powerlines/deepkit/esbuild-plugin");
13
+ let _powerlines_plugin_esbuild_helpers_resolve = require("@powerlines/plugin-esbuild/helpers/resolve");
14
+
15
+ //#region src/resolver/resolve.ts
16
+ function __assignType(fn, args) {
17
+ fn.__type = args;
18
+ return fn;
19
+ }
20
+ async function initialize(input) {
21
+ const { context, command, parent } = input;
22
+ const title = command.title || `${parent?.title ? `${parent.isVirtual ? parent.title.replace(/(?:c|C)ommands?$/, "").trim() : parent.title} - ` : ""}${(0, _stryke_string_format_title_case.titleCase)(command.name)}${command.isVirtual ? " Commands" : ""}`;
23
+ const result = {
24
+ input,
25
+ output: {
26
+ alias: [],
27
+ icon: parent?.icon,
28
+ tags: parent?.tags ?? [],
29
+ source: "file",
30
+ ...command,
31
+ title,
32
+ options: parent === null ? require_utilities.getGlobalOptions(context, command) : {},
33
+ args: [],
34
+ parent: parent ?? null,
35
+ children: {}
36
+ }
37
+ };
38
+ if (!command.isVirtual) {
39
+ 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}"`);
40
+ context.debug(`Adding reflection for CLI command: ${command.id} (file: ${command.entry.input.file})`);
41
+ result.module = await (_powerlines_plugin_esbuild_helpers_resolve.resolveModule.Ω = [["CommandModule", "\"w!"]], (0, _powerlines_plugin_esbuild_helpers_resolve.resolveModule)(context, command.entry.input, {
42
+ name: command.title || (0, _stryke_string_format_title_case.titleCase)(command.name),
43
+ treeShaking: true,
44
+ resolve: { skipNodeModulesBundle: true },
45
+ plugins: [(0, _powerlines_deepkit_esbuild_plugin.esbuildPlugin)(context, {
46
+ reflection: "default",
47
+ level: "all"
48
+ })]
49
+ }));
50
+ }
51
+ return result;
52
+ }
53
+ initialize.__type = [
54
+ "ResolverInput",
55
+ "input",
56
+ "ResolverContext",
57
+ "initialize",
58
+ "P\"w!2\"\"w#`/$"
59
+ ];
60
+ async function postprocess(ctx) {
61
+ ctx.output.options = require_helpers.applyOptionsDefaults(ctx);
62
+ ctx.output.args = require_helpers.applyArgsDefaults(ctx);
63
+ ctx.output.args.forEach(__assignType((arg, index) => {
64
+ const found = ctx.output.args.findIndex(__assignType((a) => a.name === arg.name, [
65
+ "a",
66
+ "",
67
+ "P\"2!\"/\""
68
+ ]));
69
+ if (found !== -1 && found !== index || ctx.output.segments.some(__assignType((segment) => require_context_helpers.isDynamicPathSegment(segment) && require_context_helpers.getDynamicPathSegmentName(segment) === arg.name, [
70
+ "segment",
71
+ "",
72
+ "P\"2!\"/\""
73
+ ]))) {
74
+ arg.name += `_${ctx.output.segments.filter(__assignType((segment) => require_context_helpers.isDynamicPathSegment(segment) && require_context_helpers.getDynamicPathSegmentName(segment).replace(/_\d+$/, "") === arg.name, [
75
+ "segment",
76
+ "",
77
+ "P\"2!\"/\""
78
+ ])).length + ctx.output.args.filter(__assignType((a) => a.name.replace(/_\d+$/, "") === arg.name, [
79
+ "a",
80
+ "",
81
+ "P\"2!\"/\""
82
+ ])).length}`;
83
+ arg.env = arg.name ? arg.env || arg.env === false ? arg.env : ctx.input.context.config.autoAssignEnv ? (0, _stryke_string_format_constant_case.constantCase)(arg.name) : false : false;
84
+ }
85
+ }, [
86
+ "arg",
87
+ "index",
88
+ "",
89
+ "P\"2!\"2\"\"/#"
90
+ ]));
91
+ require_helpers.applyDefaults(ctx);
92
+ if (ctx.input.context.env) {
93
+ if ((0, _stryke_type_checks_is_set_object.isSetObject)(ctx.output.options)) Object.values(ctx.output.options).filter(__assignType((option) => Boolean(option.env), [
94
+ "option",
95
+ "",
96
+ "P\"2!\"/\""
97
+ ])).forEach(__assignType((option) => {
98
+ ctx.input.context.env.types.env.addProperty({
99
+ name: option.env,
100
+ optional: option.optional ? true : void 0,
101
+ description: option.description,
102
+ visibility: _powerlines_deepkit_vendor_type.ReflectionVisibility.public,
103
+ type: require_deepkit.extractType(option),
104
+ default: option.default,
105
+ tags: {
106
+ title: option.title,
107
+ alias: option.alias.filter(__assignType((alias) => alias.length > 1, [
108
+ "alias",
109
+ "",
110
+ "P\"2!\"/\""
111
+ ])).map(__assignType((alias) => (0, _stryke_string_format_constant_case.constantCase)(alias), [
112
+ "alias",
113
+ "",
114
+ "P\"2!\"/\""
115
+ ])),
116
+ domain: "cli"
117
+ }
118
+ });
119
+ }, [
120
+ "option",
121
+ "",
122
+ "P\"2!\"/\""
123
+ ]));
124
+ ctx.output.args.filter(__assignType((arg) => Boolean(arg.env), [
125
+ "arg",
126
+ "",
127
+ "P\"2!\"/\""
128
+ ])).forEach(__assignType((arg) => ctx.input.context.env.types.env.addProperty({
129
+ name: arg.env,
130
+ optional: arg.optional ? true : void 0,
131
+ description: arg.description,
132
+ visibility: _powerlines_deepkit_vendor_type.ReflectionVisibility.public,
133
+ type: require_deepkit.extractType(arg),
134
+ default: arg.default,
135
+ tags: {
136
+ alias: arg.alias.filter(__assignType((alias) => alias.length > 1, [
137
+ "alias",
138
+ "",
139
+ "P\"2!\"/\""
140
+ ])).map(__assignType((alias) => (0, _stryke_string_format_constant_case.constantCase)(alias), [
141
+ "alias",
142
+ "",
143
+ "P\"2!\"/\""
144
+ ])),
145
+ domain: "cli"
146
+ }
147
+ }), [
148
+ "arg",
149
+ "",
150
+ "P\"2!\"/\""
151
+ ]));
152
+ }
153
+ await Promise.all(ctx.input.context.inputs.filter(__assignType((input) => input.segments.filter(__assignType((segment) => !require_context_helpers.isDynamicPathSegment(segment), [
154
+ "segment",
155
+ "",
156
+ "P\"2!\"/\""
157
+ ])).length === ctx.input.command.segments.filter(__assignType((segment) => !require_context_helpers.isDynamicPathSegment(segment), [
158
+ "segment",
159
+ "",
160
+ "P\"2!\"/\""
161
+ ])).length + 1 && input.segments.slice(0, ctx.input.command.segments.length).every(__assignType((value, index) => value === ctx.input.command.segments[index], [
162
+ "value",
163
+ "index",
164
+ "",
165
+ "P\"2!\"2\"\"/#"
166
+ ])), [
167
+ "input",
168
+ "",
169
+ "P\"2!\"/\""
170
+ ])).map(__assignType(async (input) => {
171
+ ctx.output.children[input.name] = await (resolve.Ω = [[
172
+ () => ctx,
173
+ "ResolverContext",
174
+ "Pi!\"w\"q\"!j"
175
+ ]], resolve({
176
+ context: ctx.input.context,
177
+ command: input,
178
+ parent: ctx.output
179
+ }));
180
+ }, [
181
+ "input",
182
+ "",
183
+ "P\"2!\"/\""
184
+ ])));
185
+ return ctx.output;
186
+ }
187
+ postprocess.__type = [
188
+ "ResolverContext",
189
+ "ctx",
190
+ "CommandTree",
191
+ "postprocess",
192
+ "P\"w!2\"\"w#`/$"
193
+ ];
194
+ /**
195
+ * Resolves a command tree from the given resolver input.
196
+ *
197
+ * @param input - The resolver input containing the context, command, and optional parent command tree.
198
+ * @returns A promise that resolves to the resolved command tree.
199
+ */
200
+ async function resolve(input) {
201
+ const ctx = await (initialize.Ω = [[
202
+ () => input,
203
+ "ResolverInput",
204
+ "Pi!\"w\"q\"!j"
205
+ ]], initialize(input));
206
+ if (!ctx.output.isVirtual) {
207
+ await require_module.resolveFromExports(ctx);
208
+ require_deepkit$1.resolveFromBytecode(ctx);
209
+ } else require_helpers.resolveVirtualCommand(ctx);
210
+ return postprocess(ctx);
211
+ }
212
+ resolve.__type = [
213
+ "ResolverInput",
214
+ "input",
215
+ "CommandTree",
216
+ "resolve",
217
+ "Resolves a command tree from the given resolver input.",
218
+ "P\"w!2\"\"w#`/$?%"
219
+ ];
220
+
221
+ //#endregion
222
+ exports.resolve = resolve;
@@ -1,2 +1,222 @@
1
- import{getDynamicPathSegmentName as e,isDynamicPathSegment as t}from"../plugin-utils/context-helpers.mjs";import{extractType as n}from"../plugin-utils/deepkit.mjs";import{getGlobalOptions as r}from"../helpers/utilities.mjs";import{applyArgsDefaults as i,applyDefaults as a,applyOptionsDefaults as o,resolveVirtualCommand as s}from"./helpers.mjs";import{resolveFromBytecode as c}from"./deepkit.mjs";import{resolveFromExports as l}from"./module.mjs";import{ReflectionVisibility as u}from"@powerlines/deepkit/vendor/type";import{constantCase as d}from"@stryke/string-format/constant-case";import{titleCase as f}from"@stryke/string-format/title-case";import{isSetObject as p}from"@stryke/type-checks/is-set-object";import{esbuildPlugin as m}from"@powerlines/deepkit/esbuild-plugin";import{resolveModule as h}from"@powerlines/plugin-esbuild/helpers/resolve";function g(e,t){return e.__type=t,e}async function _(e){let{context:t,command:n,parent:i}=e,a=n.title||`${i?.title?`${i.isVirtual?i.title.replace(/(?:c|C)ommands?$/,``).trim():i.title} - `:``}${f(n.name)}${n.isVirtual?` Commands`:``}`,o={input:e,output:{alias:[],icon:i?.icon,tags:i?.tags??[],source:`file`,...n,title:a,options:i===null?r(t,n):{},args:[],parent:i??null,children:{}}};if(!n.isVirtual){if(!n.entry.input?.file||!t.fs.existsSync(n.entry.input.file))throw Error(`${n.entry.input?.file?`Non-existent`:`Missing`} command entry file for "${n.name}"`);t.debug(`Adding reflection for CLI command: ${n.id} (file: ${n.entry.input.file})`),o.module=await(h.Ω=[[`CommandModule`,`"w!`]],h(t,n.entry.input,{name:n.title||f(n.name),treeShaking:!0,resolve:{skipNodeModulesBundle:!0},plugins:[m(t,{reflection:`default`,level:`all`})]}))}return o}_.__type=[`ResolverInput`,`input`,`ResolverContext`,`initialize`,'P"w!2""w#`/$'];async function v(r){return r.output.options=o(r),r.output.args=i(r),r.output.args.forEach(g((n,i)=>{let a=r.output.args.findIndex(g(e=>e.name===n.name,[`a`,``,`P"2!"/"`]));(a!==-1&&a!==i||r.output.segments.some(g(r=>t(r)&&e(r)===n.name,[`segment`,``,`P"2!"/"`])))&&(n.name+=`_${r.output.segments.filter(g(r=>t(r)&&e(r).replace(/_\d+$/,``)===n.name,[`segment`,``,`P"2!"/"`])).length+r.output.args.filter(g(e=>e.name.replace(/_\d+$/,``)===n.name,[`a`,``,`P"2!"/"`])).length}`,n.env=n.name?n.env||n.env===!1?n.env:r.input.context.config.autoAssignEnv?d(n.name):!1:!1)},[`arg`,`index`,``,`P"2!"2""/#`])),a(r),r.input.context.env&&(p(r.output.options)&&Object.values(r.output.options).filter(g(e=>!!e.env,[`option`,``,`P"2!"/"`])).forEach(g(e=>{r.input.context.env.types.env.addProperty({name:e.env,optional:e.optional?!0:void 0,description:e.description,visibility:u.public,type:n(e),default:e.default,tags:{title:e.title,alias:e.alias.filter(g(e=>e.length>1,[`alias`,``,`P"2!"/"`])).map(g(e=>d(e),[`alias`,``,`P"2!"/"`])),domain:`cli`}})},[`option`,``,`P"2!"/"`])),r.output.args.filter(g(e=>!!e.env,[`arg`,``,`P"2!"/"`])).forEach(g(e=>r.input.context.env.types.env.addProperty({name:e.env,optional:e.optional?!0:void 0,description:e.description,visibility:u.public,type:n(e),default:e.default,tags:{alias:e.alias.filter(g(e=>e.length>1,[`alias`,``,`P"2!"/"`])).map(g(e=>d(e),[`alias`,``,`P"2!"/"`])),domain:`cli`}}),[`arg`,``,`P"2!"/"`]))),await Promise.all(r.input.context.inputs.filter(g(e=>e.segments.filter(g(e=>!t(e),[`segment`,``,`P"2!"/"`])).length===r.input.command.segments.filter(g(e=>!t(e),[`segment`,``,`P"2!"/"`])).length+1&&e.segments.slice(0,r.input.command.segments.length).every(g((e,t)=>e===r.input.command.segments[t],[`value`,`index`,``,`P"2!"2""/#`])),[`input`,``,`P"2!"/"`])).map(g(async e=>{r.output.children[e.name]=await(y.Ω=[[()=>r,`ResolverContext`,`Pi!"w"q"!j`]],y({context:r.input.context,command:e,parent:r.output}))},[`input`,``,`P"2!"/"`]))),r.output}v.__type=[`ResolverContext`,`ctx`,`CommandTree`,`postprocess`,'P"w!2""w#`/$'];async function y(e){let t=await(_.Ω=[[()=>e,`ResolverInput`,`Pi!"w"q"!j`]],_(e));return t.output.isVirtual?s(t):(await l(t),c(t)),v(t)}y.__type=[`ResolverInput`,`input`,`CommandTree`,`resolve`,`Resolves a command tree from the given resolver input.`,'P"w!2""w#`/$?%'];export{y as resolve};
1
+ import { getDynamicPathSegmentName, isDynamicPathSegment } from "../plugin-utils/context-helpers.mjs";
2
+ import { extractType } from "../plugin-utils/deepkit.mjs";
3
+ import { getGlobalOptions } from "../helpers/utilities.mjs";
4
+ import { applyArgsDefaults, applyDefaults, applyOptionsDefaults, resolveVirtualCommand } from "./helpers.mjs";
5
+ import { resolveFromBytecode } from "./deepkit.mjs";
6
+ import { resolveFromExports } from "./module.mjs";
7
+ import { ReflectionVisibility } from "@powerlines/deepkit/vendor/type";
8
+ import { constantCase } from "@stryke/string-format/constant-case";
9
+ import { titleCase } from "@stryke/string-format/title-case";
10
+ import { isSetObject } from "@stryke/type-checks/is-set-object";
11
+ import { esbuildPlugin } from "@powerlines/deepkit/esbuild-plugin";
12
+ import { resolveModule } from "@powerlines/plugin-esbuild/helpers/resolve";
13
+
14
+ //#region src/resolver/resolve.ts
15
+ function __assignType(fn, args) {
16
+ fn.__type = args;
17
+ return fn;
18
+ }
19
+ async function initialize(input) {
20
+ const { context, command, parent } = input;
21
+ const title = command.title || `${parent?.title ? `${parent.isVirtual ? parent.title.replace(/(?:c|C)ommands?$/, "").trim() : parent.title} - ` : ""}${titleCase(command.name)}${command.isVirtual ? " Commands" : ""}`;
22
+ const result = {
23
+ input,
24
+ output: {
25
+ alias: [],
26
+ icon: parent?.icon,
27
+ tags: parent?.tags ?? [],
28
+ source: "file",
29
+ ...command,
30
+ title,
31
+ options: parent === null ? getGlobalOptions(context, command) : {},
32
+ args: [],
33
+ parent: parent ?? null,
34
+ children: {}
35
+ }
36
+ };
37
+ if (!command.isVirtual) {
38
+ 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}"`);
39
+ context.debug(`Adding reflection for CLI command: ${command.id} (file: ${command.entry.input.file})`);
40
+ result.module = await (resolveModule.Ω = [["CommandModule", "\"w!"]], resolveModule(context, command.entry.input, {
41
+ name: command.title || titleCase(command.name),
42
+ treeShaking: true,
43
+ resolve: { skipNodeModulesBundle: true },
44
+ plugins: [esbuildPlugin(context, {
45
+ reflection: "default",
46
+ level: "all"
47
+ })]
48
+ }));
49
+ }
50
+ return result;
51
+ }
52
+ initialize.__type = [
53
+ "ResolverInput",
54
+ "input",
55
+ "ResolverContext",
56
+ "initialize",
57
+ "P\"w!2\"\"w#`/$"
58
+ ];
59
+ async function postprocess(ctx) {
60
+ ctx.output.options = applyOptionsDefaults(ctx);
61
+ ctx.output.args = applyArgsDefaults(ctx);
62
+ ctx.output.args.forEach(__assignType((arg, index) => {
63
+ const found = ctx.output.args.findIndex(__assignType((a) => a.name === arg.name, [
64
+ "a",
65
+ "",
66
+ "P\"2!\"/\""
67
+ ]));
68
+ if (found !== -1 && found !== index || ctx.output.segments.some(__assignType((segment) => isDynamicPathSegment(segment) && getDynamicPathSegmentName(segment) === arg.name, [
69
+ "segment",
70
+ "",
71
+ "P\"2!\"/\""
72
+ ]))) {
73
+ arg.name += `_${ctx.output.segments.filter(__assignType((segment) => isDynamicPathSegment(segment) && getDynamicPathSegmentName(segment).replace(/_\d+$/, "") === arg.name, [
74
+ "segment",
75
+ "",
76
+ "P\"2!\"/\""
77
+ ])).length + ctx.output.args.filter(__assignType((a) => a.name.replace(/_\d+$/, "") === arg.name, [
78
+ "a",
79
+ "",
80
+ "P\"2!\"/\""
81
+ ])).length}`;
82
+ arg.env = arg.name ? arg.env || arg.env === false ? arg.env : ctx.input.context.config.autoAssignEnv ? constantCase(arg.name) : false : false;
83
+ }
84
+ }, [
85
+ "arg",
86
+ "index",
87
+ "",
88
+ "P\"2!\"2\"\"/#"
89
+ ]));
90
+ applyDefaults(ctx);
91
+ if (ctx.input.context.env) {
92
+ if (isSetObject(ctx.output.options)) Object.values(ctx.output.options).filter(__assignType((option) => Boolean(option.env), [
93
+ "option",
94
+ "",
95
+ "P\"2!\"/\""
96
+ ])).forEach(__assignType((option) => {
97
+ ctx.input.context.env.types.env.addProperty({
98
+ name: option.env,
99
+ optional: option.optional ? true : void 0,
100
+ description: option.description,
101
+ visibility: ReflectionVisibility.public,
102
+ type: extractType(option),
103
+ default: option.default,
104
+ tags: {
105
+ title: option.title,
106
+ alias: option.alias.filter(__assignType((alias) => alias.length > 1, [
107
+ "alias",
108
+ "",
109
+ "P\"2!\"/\""
110
+ ])).map(__assignType((alias) => constantCase(alias), [
111
+ "alias",
112
+ "",
113
+ "P\"2!\"/\""
114
+ ])),
115
+ domain: "cli"
116
+ }
117
+ });
118
+ }, [
119
+ "option",
120
+ "",
121
+ "P\"2!\"/\""
122
+ ]));
123
+ ctx.output.args.filter(__assignType((arg) => Boolean(arg.env), [
124
+ "arg",
125
+ "",
126
+ "P\"2!\"/\""
127
+ ])).forEach(__assignType((arg) => ctx.input.context.env.types.env.addProperty({
128
+ name: arg.env,
129
+ optional: arg.optional ? true : void 0,
130
+ description: arg.description,
131
+ visibility: ReflectionVisibility.public,
132
+ type: extractType(arg),
133
+ default: arg.default,
134
+ tags: {
135
+ alias: arg.alias.filter(__assignType((alias) => alias.length > 1, [
136
+ "alias",
137
+ "",
138
+ "P\"2!\"/\""
139
+ ])).map(__assignType((alias) => constantCase(alias), [
140
+ "alias",
141
+ "",
142
+ "P\"2!\"/\""
143
+ ])),
144
+ domain: "cli"
145
+ }
146
+ }), [
147
+ "arg",
148
+ "",
149
+ "P\"2!\"/\""
150
+ ]));
151
+ }
152
+ await Promise.all(ctx.input.context.inputs.filter(__assignType((input) => input.segments.filter(__assignType((segment) => !isDynamicPathSegment(segment), [
153
+ "segment",
154
+ "",
155
+ "P\"2!\"/\""
156
+ ])).length === ctx.input.command.segments.filter(__assignType((segment) => !isDynamicPathSegment(segment), [
157
+ "segment",
158
+ "",
159
+ "P\"2!\"/\""
160
+ ])).length + 1 && input.segments.slice(0, ctx.input.command.segments.length).every(__assignType((value, index) => value === ctx.input.command.segments[index], [
161
+ "value",
162
+ "index",
163
+ "",
164
+ "P\"2!\"2\"\"/#"
165
+ ])), [
166
+ "input",
167
+ "",
168
+ "P\"2!\"/\""
169
+ ])).map(__assignType(async (input) => {
170
+ ctx.output.children[input.name] = await (resolve.Ω = [[
171
+ () => ctx,
172
+ "ResolverContext",
173
+ "Pi!\"w\"q\"!j"
174
+ ]], resolve({
175
+ context: ctx.input.context,
176
+ command: input,
177
+ parent: ctx.output
178
+ }));
179
+ }, [
180
+ "input",
181
+ "",
182
+ "P\"2!\"/\""
183
+ ])));
184
+ return ctx.output;
185
+ }
186
+ postprocess.__type = [
187
+ "ResolverContext",
188
+ "ctx",
189
+ "CommandTree",
190
+ "postprocess",
191
+ "P\"w!2\"\"w#`/$"
192
+ ];
193
+ /**
194
+ * Resolves a command tree from the given resolver input.
195
+ *
196
+ * @param input - The resolver input containing the context, command, and optional parent command tree.
197
+ * @returns A promise that resolves to the resolved command tree.
198
+ */
199
+ async function resolve(input) {
200
+ const ctx = await (initialize.Ω = [[
201
+ () => input,
202
+ "ResolverInput",
203
+ "Pi!\"w\"q\"!j"
204
+ ]], initialize(input));
205
+ if (!ctx.output.isVirtual) {
206
+ await resolveFromExports(ctx);
207
+ resolveFromBytecode(ctx);
208
+ } else resolveVirtualCommand(ctx);
209
+ return postprocess(ctx);
210
+ }
211
+ resolve.__type = [
212
+ "ResolverInput",
213
+ "input",
214
+ "CommandTree",
215
+ "resolve",
216
+ "Resolves a command tree from the given resolver input.",
217
+ "P\"w!2\"\"w#`/$?%"
218
+ ];
219
+
220
+ //#endregion
221
+ export { resolve };
2
222
  //# sourceMappingURL=resolve.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.mjs","names":[],"sources":["../../src/resolver/resolve.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 { ReflectionVisibility } from \"@powerlines/deepkit/vendor/type\";\nimport { resolveModule } from \"@powerlines/plugin-esbuild/helpers/resolve\";\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 { getGlobalOptions } from \"../helpers/utilities\";\nimport {\n getDynamicPathSegmentName,\n isDynamicPathSegment\n} from \"../plugin-utils/context-helpers\";\nimport { extractType } from \"../plugin-utils/deepkit\";\nimport type { CommandModule, CommandTree, Context } from \"../types\";\nimport { resolveFromBytecode } from \"./deepkit\";\nimport {\n applyArgsDefaults,\n applyDefaults,\n applyOptionsDefaults,\n resolveVirtualCommand\n} from \"./helpers\";\nimport { resolveFromExports } from \"./module\";\nimport type { ResolverContext, ResolverInput } from \"./types\";\n\nasync function initialize<TContext extends Context = Context>(\n input: ResolverInput<TContext>\n): Promise<ResolverContext> {\n const { context, command, parent } = input;\n\n const title =\n command.title ||\n `${\n parent?.title\n ? `${\n parent.isVirtual\n ? parent.title.replace(/(?:c|C)ommands?$/, \"\").trim()\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const output = {\n alias: [],\n icon: parent?.icon,\n tags: parent?.tags ?? [],\n source: \"file\",\n ...command,\n title,\n options: parent === null ? getGlobalOptions(context, command) : {},\n args: [],\n parent: parent ?? null,\n children: {}\n } as CommandTree;\n\n const result: ResolverContext = {\n input,\n output\n };\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 CLI command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n result.module = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n name: command.title || titleCase(command.name),\n treeShaking: true,\n resolve: {\n skipNodeModulesBundle: true\n },\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n }\n );\n }\n\n return result;\n}\n\nasync function postprocess<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n): Promise<CommandTree> {\n ctx.output.options = applyOptionsDefaults(ctx);\n ctx.output.args = applyArgsDefaults(ctx);\n\n // Ensure unique argument names by appending an index suffix to duplicates\n ctx.output.args.forEach((arg, index) => {\n const found = ctx.output.args.findIndex(a => a.name === arg.name);\n if (\n (found !== -1 && found !== index) ||\n ctx.output.segments.some(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment) === arg.name\n )\n ) {\n arg.name += `_${\n ctx.output.segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(/_\\d+$/, \"\") === arg.name\n ).length +\n ctx.output.args.filter(a => a.name.replace(/_\\d+$/, \"\") === arg.name)\n .length\n }`;\n arg.env = arg.name\n ? arg.env || arg.env === false\n ? arg.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(arg.name)\n : false\n : false;\n }\n });\n\n applyDefaults(ctx);\n\n if (ctx.input.context.env) {\n if (isSetObject(ctx.output.options)) {\n Object.values(ctx.output.options)\n .filter(option => Boolean(option.env))\n .forEach(option => {\n ctx.input.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: extractType(option),\n default: option.default,\n tags: {\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n ctx.output.args\n .filter(arg => Boolean(arg.env))\n .forEach(arg =>\n ctx.input.context.env.types.env.addProperty({\n name: arg.env as string,\n optional: arg.optional ? true : undefined,\n description: arg.description,\n visibility: ReflectionVisibility.public,\n type: extractType(arg),\n default: arg.default,\n tags: {\n alias: arg.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n })\n );\n }\n\n await Promise.all(\n ctx.input.context.inputs\n .filter(\n input =>\n input.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n ctx.input.command.segments.filter(\n segment => !isDynamicPathSegment(segment)\n ).length +\n 1 &&\n input.segments\n .slice(0, ctx.input.command.segments.length)\n .every(\n (value, index) => value === ctx.input.command.segments[index]\n )\n )\n .map(async input => {\n ctx.output.children[input.name] = await resolve<TContext>({\n context: ctx.input.context,\n command: input,\n parent: ctx.output\n });\n })\n );\n\n return ctx.output;\n}\n\n/**\n * Resolves a command tree from the given resolver input.\n *\n * @param input - The resolver input containing the context, command, and optional parent command tree.\n * @returns A promise that resolves to the resolved command tree.\n */\nexport async function resolve<TContext extends Context = Context>(\n input: ResolverInput<TContext>\n): Promise<CommandTree> {\n const ctx = await initialize<TContext>(input);\n\n if (!ctx.output.isVirtual) {\n await resolveFromExports(ctx);\n resolveFromBytecode(ctx);\n } else {\n resolveVirtualCommand(ctx);\n }\n\n return postprocess(ctx);\n}\n"],"mappings":"q1BAAA,SAAS,EAAa,EAAI,EAAM,CAE9B,kBAAO,EA+BT,eAAE,EAAiB,EAAA,CACjB,GAAA,CACA,UACA,UACA,UACI,EACC,EAAO,EAAA,OAAiB,GAAA,GAAa,MAAQ,GAAG,EAAM,UAAA,EAAA,MAAA,QAAA,mBAAA,GAAA,CAAA,MAAA,CAAA,EAAA,MAAA,KAAA,KAAA,EAAA,EAAA,KAAA,GAA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EAAI,EAAA,EAHJ,MAAM,EAAO,EAAA,CACb,EAAoB,EAAA,EAIf,EAAY,EAAI,CAEzB,EAAQ,OAAQ,CAAA,gBAAc,QAAO,cAAA,UAAA,yDAAA,iBAAA"}
1
+ {"version":3,"file":"resolve.mjs","names":[],"sources":["../../src/resolver/resolve.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 { ReflectionVisibility } from \"@powerlines/deepkit/vendor/type\";\nimport { resolveModule } from \"@powerlines/plugin-esbuild/helpers/resolve\";\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 { getGlobalOptions } from \"../helpers/utilities\";\nimport {\n getDynamicPathSegmentName,\n isDynamicPathSegment\n} from \"../plugin-utils/context-helpers\";\nimport { extractType } from \"../plugin-utils/deepkit\";\nimport type { CommandModule, CommandTree, Context } from \"../types\";\nimport { resolveFromBytecode } from \"./deepkit\";\nimport {\n applyArgsDefaults,\n applyDefaults,\n applyOptionsDefaults,\n resolveVirtualCommand\n} from \"./helpers\";\nimport { resolveFromExports } from \"./module\";\nimport type { ResolverContext, ResolverInput } from \"./types\";\n\nasync function initialize<TContext extends Context = Context>(\n input: ResolverInput<TContext>\n): Promise<ResolverContext> {\n const { context, command, parent } = input;\n\n const title =\n command.title ||\n `${\n parent?.title\n ? `${\n parent.isVirtual\n ? parent.title.replace(/(?:c|C)ommands?$/, \"\").trim()\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const output = {\n alias: [],\n icon: parent?.icon,\n tags: parent?.tags ?? [],\n source: \"file\",\n ...command,\n title,\n options: parent === null ? getGlobalOptions(context, command) : {},\n args: [],\n parent: parent ?? null,\n children: {}\n } as CommandTree;\n\n const result: ResolverContext = {\n input,\n output\n };\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 CLI command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n result.module = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n name: command.title || titleCase(command.name),\n treeShaking: true,\n resolve: {\n skipNodeModulesBundle: true\n },\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n }\n );\n }\n\n return result;\n}\n\nasync function postprocess<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n): Promise<CommandTree> {\n ctx.output.options = applyOptionsDefaults(ctx);\n ctx.output.args = applyArgsDefaults(ctx);\n\n // Ensure unique argument names by appending an index suffix to duplicates\n ctx.output.args.forEach((arg, index) => {\n const found = ctx.output.args.findIndex(a => a.name === arg.name);\n if (\n (found !== -1 && found !== index) ||\n ctx.output.segments.some(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment) === arg.name\n )\n ) {\n arg.name += `_${\n ctx.output.segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(/_\\d+$/, \"\") === arg.name\n ).length +\n ctx.output.args.filter(a => a.name.replace(/_\\d+$/, \"\") === arg.name)\n .length\n }`;\n arg.env = arg.name\n ? arg.env || arg.env === false\n ? arg.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(arg.name)\n : false\n : false;\n }\n });\n\n applyDefaults(ctx);\n\n if (ctx.input.context.env) {\n if (isSetObject(ctx.output.options)) {\n Object.values(ctx.output.options)\n .filter(option => Boolean(option.env))\n .forEach(option => {\n ctx.input.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: extractType(option),\n default: option.default,\n tags: {\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n ctx.output.args\n .filter(arg => Boolean(arg.env))\n .forEach(arg =>\n ctx.input.context.env.types.env.addProperty({\n name: arg.env as string,\n optional: arg.optional ? true : undefined,\n description: arg.description,\n visibility: ReflectionVisibility.public,\n type: extractType(arg),\n default: arg.default,\n tags: {\n alias: arg.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n })\n );\n }\n\n await Promise.all(\n ctx.input.context.inputs\n .filter(\n input =>\n input.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n ctx.input.command.segments.filter(\n segment => !isDynamicPathSegment(segment)\n ).length +\n 1 &&\n input.segments\n .slice(0, ctx.input.command.segments.length)\n .every(\n (value, index) => value === ctx.input.command.segments[index]\n )\n )\n .map(async input => {\n ctx.output.children[input.name] = await resolve<TContext>({\n context: ctx.input.context,\n command: input,\n parent: ctx.output\n });\n })\n );\n\n return ctx.output;\n}\n\n/**\n * Resolves a command tree from the given resolver input.\n *\n * @param input - The resolver input containing the context, command, and optional parent command tree.\n * @returns A promise that resolves to the resolved command tree.\n */\nexport async function resolve<TContext extends Context = Context>(\n input: ResolverInput<TContext>\n): Promise<CommandTree> {\n const ctx = await initialize<TContext>(input);\n\n if (!ctx.output.isVirtual) {\n await resolveFromExports(ctx);\n resolveFromBytecode(ctx);\n } else {\n resolveVirtualCommand(ctx);\n }\n\n return postprocess(ctx);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