@shell-shock/core 0.17.7 → 0.17.8

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 (145) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +1 -29
  2. package/dist/api.cjs +1 -95
  3. package/dist/api.d.cts +52 -4
  4. package/dist/api.d.cts.map +1 -1
  5. package/dist/api.d.mts +52 -4
  6. package/dist/api.d.mts.map +1 -1
  7. package/dist/api.mjs +1 -92
  8. package/dist/api.mjs.map +1 -1
  9. package/dist/components/command-validation-logic.cjs +1 -292
  10. package/dist/components/command-validation-logic.mjs +1 -289
  11. package/dist/components/command-validation-logic.mjs.map +1 -1
  12. package/dist/components/docs.cjs +1 -265
  13. package/dist/components/docs.d.cts.map +1 -1
  14. package/dist/components/docs.d.mts.map +1 -1
  15. package/dist/components/docs.mjs +1 -256
  16. package/dist/components/docs.mjs.map +1 -1
  17. package/dist/components/exec-builtin.cjs +13 -429
  18. package/dist/components/exec-builtin.mjs +13 -425
  19. package/dist/components/exec-builtin.mjs.map +1 -1
  20. package/dist/components/helpers.cjs +1 -120
  21. package/dist/components/helpers.mjs +1 -112
  22. package/dist/components/helpers.mjs.map +1 -1
  23. package/dist/components/index.cjs +1 -58
  24. package/dist/components/index.mjs +1 -10
  25. package/dist/components/options-parser-logic.cjs +5 -960
  26. package/dist/components/options-parser-logic.d.cts +1 -1
  27. package/dist/components/options-parser-logic.mjs +5 -945
  28. package/dist/components/options-parser-logic.mjs.map +1 -1
  29. package/dist/components/state-builtin.cjs +8 -629
  30. package/dist/components/state-builtin.d.cts.map +1 -1
  31. package/dist/components/state-builtin.d.mts.map +1 -1
  32. package/dist/components/state-builtin.mjs +8 -622
  33. package/dist/components/state-builtin.mjs.map +1 -1
  34. package/dist/components/usage.cjs +1 -117
  35. package/dist/components/usage.mjs +1 -114
  36. package/dist/components/usage.mjs.map +1 -1
  37. package/dist/components/utils-builtin.cjs +33 -838
  38. package/dist/components/utils-builtin.d.cts.map +1 -1
  39. package/dist/components/utils-builtin.d.mts.map +1 -1
  40. package/dist/components/utils-builtin.mjs +33 -828
  41. package/dist/components/utils-builtin.mjs.map +1 -1
  42. package/dist/config.cjs +1 -31
  43. package/dist/config.mjs +1 -29
  44. package/dist/config.mjs.map +1 -1
  45. package/dist/contexts/command.cjs +1 -26
  46. package/dist/contexts/command.mjs +1 -23
  47. package/dist/contexts/command.mjs.map +1 -1
  48. package/dist/contexts/index.cjs +1 -9
  49. package/dist/contexts/index.mjs +1 -4
  50. package/dist/contexts/options.cjs +1 -63
  51. package/dist/contexts/options.mjs +1 -58
  52. package/dist/contexts/options.mjs.map +1 -1
  53. package/dist/helpers/automd.cjs +1 -71
  54. package/dist/helpers/automd.mjs +1 -70
  55. package/dist/helpers/automd.mjs.map +1 -1
  56. package/dist/helpers/docs-helpers.cjs +1 -23
  57. package/dist/helpers/docs-helpers.mjs +1 -22
  58. package/dist/helpers/docs-helpers.mjs.map +1 -1
  59. package/dist/helpers/paths.cjs +1 -137
  60. package/dist/helpers/paths.mjs +1 -133
  61. package/dist/helpers/paths.mjs.map +1 -1
  62. package/dist/helpers/persistence.cjs +1 -113
  63. package/dist/helpers/persistence.mjs +1 -110
  64. package/dist/helpers/persistence.mjs.map +1 -1
  65. package/dist/helpers/update-package-json.cjs +1 -59
  66. package/dist/helpers/update-package-json.mjs +1 -57
  67. package/dist/helpers/update-package-json.mjs.map +1 -1
  68. package/dist/helpers/utilities.cjs +1 -95
  69. package/dist/helpers/utilities.mjs +1 -93
  70. package/dist/helpers/utilities.mjs.map +1 -1
  71. package/dist/helpers/validations.cjs +1 -71
  72. package/dist/helpers/validations.mjs +1 -71
  73. package/dist/helpers/validations.mjs.map +1 -1
  74. package/dist/index.cjs +1 -52
  75. package/dist/index.d.cts +1 -1
  76. package/dist/index.d.mts +1 -1
  77. package/dist/index.mjs +1 -7
  78. package/dist/plugin-utils/compute-bin.cjs +1 -50
  79. package/dist/plugin-utils/compute-bin.mjs +1 -49
  80. package/dist/plugin-utils/compute-bin.mjs.map +1 -1
  81. package/dist/plugin-utils/context-helpers.cjs +1 -231
  82. package/dist/plugin-utils/context-helpers.mjs +1 -221
  83. package/dist/plugin-utils/context-helpers.mjs.map +1 -1
  84. package/dist/plugin-utils/deepkit.cjs +1 -71
  85. package/dist/plugin-utils/deepkit.mjs +1 -69
  86. package/dist/plugin-utils/deepkit.mjs.map +1 -1
  87. package/dist/plugin-utils/description-helpers.cjs +2 -111
  88. package/dist/plugin-utils/description-helpers.mjs +2 -107
  89. package/dist/plugin-utils/description-helpers.mjs.map +1 -1
  90. package/dist/plugin-utils/get-command-tree.cjs +1 -117
  91. package/dist/plugin-utils/get-command-tree.mjs +1 -114
  92. package/dist/plugin-utils/get-command-tree.mjs.map +1 -1
  93. package/dist/plugin-utils/index.cjs +1 -39
  94. package/dist/plugin-utils/index.mjs +1 -10
  95. package/dist/plugin-utils/reflect.cjs +1 -52
  96. package/dist/plugin-utils/reflect.mjs +1 -52
  97. package/dist/plugin-utils/reflect.mjs.map +1 -1
  98. package/dist/plugin-utils/traverse-command-tree.cjs +1 -64
  99. package/dist/plugin-utils/traverse-command-tree.mjs +1 -62
  100. package/dist/plugin-utils/traverse-command-tree.mjs.map +1 -1
  101. package/dist/plugin-utils/type-checks.cjs +1 -93
  102. package/dist/plugin-utils/type-checks.mjs +1 -88
  103. package/dist/plugin-utils/type-checks.mjs.map +1 -1
  104. package/dist/plugin.cjs +4 -429
  105. package/dist/plugin.d.cts.map +1 -1
  106. package/dist/plugin.d.mts.map +1 -1
  107. package/dist/plugin.mjs +4 -423
  108. package/dist/plugin.mjs.map +1 -1
  109. package/dist/resolver/deepkit.cjs +1 -135
  110. package/dist/resolver/deepkit.mjs +1 -134
  111. package/dist/resolver/deepkit.mjs.map +1 -1
  112. package/dist/resolver/helpers.cjs +1 -173
  113. package/dist/resolver/helpers.mjs +1 -168
  114. package/dist/resolver/helpers.mjs.map +1 -1
  115. package/dist/resolver/module.cjs +1 -145
  116. package/dist/resolver/module.mjs +1 -144
  117. package/dist/resolver/module.mjs.map +1 -1
  118. package/dist/resolver/resolve.cjs +1 -222
  119. package/dist/resolver/resolve.mjs +1 -221
  120. package/dist/resolver/resolve.mjs.map +1 -1
  121. package/dist/types/command.cjs +1 -441
  122. package/dist/types/command.mjs +1 -405
  123. package/dist/types/command.mjs.map +1 -1
  124. package/dist/types/config.cjs +1 -144
  125. package/dist/types/config.d.cts +3 -2
  126. package/dist/types/config.d.cts.map +1 -1
  127. package/dist/types/config.d.mts +3 -2
  128. package/dist/types/config.d.mts.map +1 -1
  129. package/dist/types/config.mjs +1 -138
  130. package/dist/types/config.mjs.map +1 -1
  131. package/dist/types/context.cjs +1 -37
  132. package/dist/types/context.d.cts +3 -2
  133. package/dist/types/context.d.cts.map +1 -1
  134. package/dist/types/context.d.mts +3 -2
  135. package/dist/types/context.d.mts.map +1 -1
  136. package/dist/types/context.mjs +1 -34
  137. package/dist/types/context.mjs.map +1 -1
  138. package/dist/types/env.cjs +1 -52
  139. package/dist/types/env.mjs +1 -50
  140. package/dist/types/env.mjs.map +1 -1
  141. package/dist/types/index.cjs +1 -49
  142. package/dist/types/index.mjs +1 -6
  143. package/dist/types/options.cjs +1 -12
  144. package/dist/types/options.mjs +1 -10
  145. package/package.json +23 -23
@@ -1,222 +1 @@
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 _stryke_string_format_constant_case = require("@stryke/string-format/constant-case");
9
- let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
10
- let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
11
- let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
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
+ 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,222 +1,2 @@
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 { constantCase } from "@stryke/string-format/constant-case";
8
- import { titleCase } from "@stryke/string-format/title-case";
9
- import { isSetObject } from "@stryke/type-checks/is-set-object";
10
- import { ReflectionVisibility } from "@powerlines/deepkit/vendor/type";
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 };
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};
222
2
  //# 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":";;;;;;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;AA+BX,eAAE,WAAiB,OAAA;CACjB,MAAA,EAAA,SAAa,SAAA,WAAA;CACb,MAAA,QAAA,QAAoB,SACpB,GAAA,QAAA,QACQ,GAAO,OAAC,YACT,OAAA,MAAqB,QAAQ,oBAAO,GAAA,CAAA,MAAA,GAC/B,OAAA,MAAiB;CAc3B,MAAM,SAAM;EACR;EACA,QAdO;GACP,OAAC,EAAA;GACN,MAAQ,QAAA;GACH,MAAE,QAAS,QAAS,EAAA;;GAEpB,GAAA;GACJ;GACE,SAAA,WAAA,OAAA,iBAAA,SAAA,QAAA,GAAA,EAAA;GACA,MAAQ,EAAA;GACN,QAAI,UAAA;GACJ,UAAU,EAAC;GACd;EAIA;;AAEG,MAAA,CAAA,QAAS,MAAA,OAAA,QACL,CAAC,QAAA,GAAA,WAAA,QAAA,MAAA,MAAA,KAAA,CACH,OAAQ,IAAI,MAAA,GAAA,CAAA,QAAA,MAAA,OAAA,O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EP,OAAM,QAAM,IAAI,IAAA,MAAA,QAAA,OACX,OAAK,cAAe,UAAI,MAAA,SAAA,OAAA,cAAA,YAAA,CAAA,qBAAA,QAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CACxB,WACD,IAAI,MAAI,QAAM,SAAQ,OAAO,cAAA,YAAA,CAAA,qBAAA,QAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA,SACzB,KACJ,MAAM,SACJ,MAAK,GAAA,IAAA,MAAA,QAAA,SAAA,OAAA,CACX,MAAA,cAAA,OAAA,UAAA,UAAA,IAAA,MAAA,QAAA,SAAA,QAAA;EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CACA,IAAA,aAAA,OAAA,UAAA;;;;;;GAEF,SAAkB,IAAA,MAAA;;GAEV,QAAM,IAAQ;GAChB,CAAA;IACF;EAAA;EAAO;EAAO;EAAW,CAAA,CAAA,CAAA;AAC3B,QAAK,IAAM;;AAEf,YAAU,SAAU;CAAA;CAAqB;CAAC;CAAY;CAAA;CAAA;;;;;;;AAOtD,eAAkB,QAAA,OAAA;CACd,MAAM,MAAI,OAAO,WAAY,IAAA,CAAA;QAAA;EAAA;EAAA;EAAA,CAAA,EAAA,WAAA,MAAA;AAC7B,KAAI,CAAC,IAAI,OAAO,WAAQ;AACpB,QAAM,mBAAmB,IAAA;AACzB,sBAAoB,IAAE;OAGtB,uBAAI,IAAA;AAER,QAAA,YAAA,IAAA;;AAEJ,QAAQ,SAAO;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
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,GAAA,EAAA,UAAA,YAAA,KAarD,EAAQ,CACZ,QACA,OAAA,CAbJ,MAAM,EAAA,CACJ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