@shell-shock/core 0.8.13 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/dist/api.cjs +34 -0
  2. package/dist/api.cjs.map +1 -1
  3. package/dist/api.mjs +34 -0
  4. package/dist/api.mjs.map +1 -1
  5. package/dist/components/docs.d.cts +5 -5
  6. package/dist/components/docs.d.cts.map +1 -1
  7. package/dist/components/docs.d.mts +5 -5
  8. package/dist/components/helpers.d.cts +6 -6
  9. package/dist/components/helpers.d.mts +6 -6
  10. package/dist/components/index.cjs +1 -0
  11. package/dist/components/index.d.cts +2 -2
  12. package/dist/components/index.d.mts +2 -2
  13. package/dist/components/index.mjs +2 -2
  14. package/dist/components/options-parser-logic.d.cts +9 -9
  15. package/dist/components/options-parser-logic.d.mts +9 -9
  16. package/dist/components/usage.d.cts +2 -2
  17. package/dist/components/usage.d.cts.map +1 -1
  18. package/dist/components/usage.d.mts +2 -2
  19. package/dist/components/utils-builtin.cjs +341 -0
  20. package/dist/components/utils-builtin.cjs.map +1 -1
  21. package/dist/components/utils-builtin.d.cts +12 -8
  22. package/dist/components/utils-builtin.d.cts.map +1 -1
  23. package/dist/components/utils-builtin.d.mts +12 -8
  24. package/dist/components/utils-builtin.d.mts.map +1 -1
  25. package/dist/components/utils-builtin.mjs +342 -2
  26. package/dist/components/utils-builtin.mjs.map +1 -1
  27. package/dist/config.cjs +12 -0
  28. package/dist/config.cjs.map +1 -1
  29. package/dist/config.mjs +12 -0
  30. package/dist/config.mjs.map +1 -1
  31. package/dist/contexts/command.cjs +3 -2
  32. package/dist/contexts/command.cjs.map +1 -1
  33. package/dist/contexts/command.mjs +3 -2
  34. package/dist/contexts/command.mjs.map +1 -1
  35. package/dist/contexts/options.cjs +20 -4
  36. package/dist/contexts/options.cjs.map +1 -1
  37. package/dist/contexts/options.mjs +20 -4
  38. package/dist/contexts/options.mjs.map +1 -1
  39. package/dist/helpers/docs-helpers.cjs +6 -0
  40. package/dist/helpers/docs-helpers.cjs.map +1 -1
  41. package/dist/helpers/docs-helpers.mjs +6 -0
  42. package/dist/helpers/docs-helpers.mjs.map +1 -1
  43. package/dist/helpers/persistence.cjs +92 -11
  44. package/dist/helpers/persistence.cjs.map +1 -1
  45. package/dist/helpers/persistence.mjs +92 -11
  46. package/dist/helpers/persistence.mjs.map +1 -1
  47. package/dist/helpers/resolve-command.cjs +200 -18
  48. package/dist/helpers/resolve-command.cjs.map +1 -1
  49. package/dist/helpers/resolve-command.mjs +201 -19
  50. package/dist/helpers/resolve-command.mjs.map +1 -1
  51. package/dist/helpers/update-package-json.cjs +27 -3
  52. package/dist/helpers/update-package-json.cjs.map +1 -1
  53. package/dist/helpers/update-package-json.mjs +27 -3
  54. package/dist/helpers/update-package-json.mjs.map +1 -1
  55. package/dist/helpers/utilities.cjs +58 -4
  56. package/dist/helpers/utilities.cjs.map +1 -1
  57. package/dist/helpers/utilities.mjs +58 -4
  58. package/dist/helpers/utilities.mjs.map +1 -1
  59. package/dist/helpers/validations.cjs +28 -1
  60. package/dist/helpers/validations.cjs.map +1 -1
  61. package/dist/helpers/validations.mjs +28 -1
  62. package/dist/helpers/validations.mjs.map +1 -1
  63. package/dist/index.cjs +33 -0
  64. package/dist/index.cjs.map +1 -1
  65. package/dist/index.d.cts +2 -2
  66. package/dist/index.d.mts +2 -2
  67. package/dist/index.mjs +6 -1
  68. package/dist/index.mjs.map +1 -1
  69. package/dist/plugin-utils/context-helpers.cjs +78 -3
  70. package/dist/plugin-utils/context-helpers.cjs.map +1 -1
  71. package/dist/plugin-utils/context-helpers.mjs +78 -3
  72. package/dist/plugin-utils/context-helpers.mjs.map +1 -1
  73. package/dist/plugin-utils/get-command-tree.cjs +17 -1
  74. package/dist/plugin-utils/get-command-tree.cjs.map +1 -1
  75. package/dist/plugin-utils/get-command-tree.mjs +17 -1
  76. package/dist/plugin-utils/get-command-tree.mjs.map +1 -1
  77. package/dist/plugin-utils/reflect.cjs +31 -3
  78. package/dist/plugin-utils/reflect.cjs.map +1 -1
  79. package/dist/plugin-utils/reflect.mjs +31 -3
  80. package/dist/plugin-utils/reflect.mjs.map +1 -1
  81. package/dist/plugin-utils/traverse-command-tree.cjs +34 -4
  82. package/dist/plugin-utils/traverse-command-tree.cjs.map +1 -1
  83. package/dist/plugin-utils/traverse-command-tree.mjs +34 -4
  84. package/dist/plugin-utils/traverse-command-tree.mjs.map +1 -1
  85. package/dist/plugin.cjs +5 -1
  86. package/dist/plugin.cjs.map +1 -1
  87. package/dist/plugin.d.cts.map +1 -1
  88. package/dist/plugin.d.mts.map +1 -1
  89. package/dist/plugin.mjs +5 -1
  90. package/dist/plugin.mjs.map +1 -1
  91. package/dist/types/command.cjs +241 -0
  92. package/dist/types/command.cjs.map +1 -0
  93. package/dist/types/command.mjs +221 -1
  94. package/dist/types/command.mjs.map +1 -0
  95. package/dist/types/config.cjs +114 -0
  96. package/dist/types/config.cjs.map +1 -0
  97. package/dist/types/config.d.cts +11 -10
  98. package/dist/types/config.d.cts.map +1 -1
  99. package/dist/types/config.d.mts +11 -10
  100. package/dist/types/config.d.mts.map +1 -1
  101. package/dist/types/config.mjs +110 -1
  102. package/dist/types/config.mjs.map +1 -0
  103. package/dist/types/context.cjs +33 -0
  104. package/dist/types/context.cjs.map +1 -0
  105. package/dist/types/context.mjs +31 -1
  106. package/dist/types/context.mjs.map +1 -0
  107. package/dist/types/env.cjs +12 -0
  108. package/dist/types/env.cjs.map +1 -0
  109. package/dist/types/env.d.cts +17 -0
  110. package/dist/types/env.d.cts.map +1 -0
  111. package/dist/types/env.d.mts +17 -0
  112. package/dist/types/env.d.mts.map +1 -0
  113. package/dist/types/env.mjs +11 -0
  114. package/dist/types/env.mjs.map +1 -0
  115. package/dist/types/index.cjs +34 -0
  116. package/dist/types/index.d.cts +2 -2
  117. package/dist/types/index.d.mts +2 -2
  118. package/dist/types/index.mjs +7 -1
  119. package/dist/types/options.cjs +12 -0
  120. package/dist/types/options.cjs.map +1 -0
  121. package/dist/types/options.mjs +11 -1
  122. package/dist/types/options.mjs.map +1 -0
  123. package/dist/types/runtime.cjs +12 -0
  124. package/dist/types/runtime.cjs.map +1 -0
  125. package/dist/types/runtime.mjs +11 -1
  126. package/dist/types/runtime.mjs.map +1 -0
  127. package/package.json +25 -11
@@ -9,13 +9,17 @@ import { constantCase } from "@stryke/string-format/constant-case";
9
9
  import { isSetObject } from "@stryke/type-checks/is-set-object";
10
10
  import { isSetString } from "@stryke/type-checks/is-set-string";
11
11
  import { titleCase } from "@stryke/string-format/title-case";
12
- import { ReflectionClass, ReflectionFunction, ReflectionKind, ReflectionVisibility, reflect, stringifyType } from "@powerlines/deepkit/vendor/type";
12
+ import { ReflectionClass, ReflectionFunction, ReflectionKind, ReflectionVisibility, __ΩReflectionKind, reflect, stringifyType } from "@powerlines/deepkit/vendor/type";
13
13
  import { esbuildPlugin } from "@powerlines/deepkit/esbuild-plugin";
14
14
  import { commonPath } from "@stryke/path/common";
15
15
  import { stripStars } from "@stryke/path/normalize";
16
16
  import { resolveModule } from "powerlines/lib/utilities/resolve";
17
17
 
18
18
  //#region src/helpers/resolve-command.ts
19
+ function __assignType(fn, args) {
20
+ fn.__type = args;
21
+ return fn;
22
+ }
19
23
  /**
20
24
  * Resolves the description for a command option based on its reflection.
21
25
  *
@@ -30,6 +34,17 @@ import { resolveModule } from "powerlines/lib/utilities/resolve";
30
34
  function resolveCommandOptionDescription(name, kind, optional = false, variadic = false, title, defaultValue) {
31
35
  return `A${optional && !defaultValue ? "n optional" : ""} command-line ${kind === ReflectionKind.boolean ? "flag" : "option"} that allows the user to ${kind === ReflectionKind.boolean ? "set the" : variadic ? "specify custom" : "specify a custom"} ${title?.trim() || titleCase(name)} ${kind === ReflectionKind.boolean ? "indicator" : `${kind === ReflectionKind.number ? "numeric" : "string"} value${variadic ? "s" : ""}`}.`;
32
36
  }
37
+ resolveCommandOptionDescription.__type = [
38
+ "name",
39
+ () => __ΩReflectionKind,
40
+ "kind",
41
+ "optional",
42
+ "variadic",
43
+ "title",
44
+ "defaultValue",
45
+ "resolveCommandOptionDescription",
46
+ "P&2!n\"2#\"2$\"2%&2&8\"2'8&/("
47
+ ];
33
48
  /**
34
49
  * Resolves the description for a command argument based on its reflection.
35
50
  *
@@ -44,9 +59,31 @@ function resolveCommandOptionDescription(name, kind, optional = false, variadic
44
59
  function resolveCommandArgumentDescription(name, kind, optional = false, variadic = false, title, defaultValue) {
45
60
  return `An${optional && !defaultValue ? " optional" : ""} argument that allows the user to ${kind === ReflectionKind.boolean ? "set the" : variadic ? "specify custom" : "specify a custom"} ${title?.trim() || titleCase(name)} ${kind === ReflectionKind.boolean ? "indicator" : `${kind === ReflectionKind.number ? "numeric" : "string"} value${variadic ? "s" : ""}`}.`;
46
61
  }
62
+ resolveCommandArgumentDescription.__type = [
63
+ "name",
64
+ () => __ΩReflectionKind,
65
+ "kind",
66
+ "optional",
67
+ "variadic",
68
+ "title",
69
+ "defaultValue",
70
+ "resolveCommandArgumentDescription",
71
+ "P&2!n\"2#\"2$\"2%&2&8\"2'8&/("
72
+ ];
47
73
  function resolveCommandId(context, file) {
48
- return replacePath(findFilePath(file), context.commandsPath).split("/").filter((p) => Boolean(p) && !isDynamicPathSegment(p)).join("/").replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "").replaceAll("/", "-");
74
+ return replacePath(findFilePath(file), context.commandsPath).split("/").filter(__assignType((p) => Boolean(p) && !isDynamicPathSegment(p), [
75
+ "p",
76
+ "",
77
+ "P\"2!\"/\""
78
+ ])).join("/").replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "").replaceAll("/", "-");
49
79
  }
80
+ resolveCommandId.__type = [
81
+ "Context",
82
+ "context",
83
+ "file",
84
+ "resolveCommandId",
85
+ "P\"w!2\"&2#&/$"
86
+ ];
50
87
  /**
51
88
  * Finds the command name from the given file path.
52
89
  *
@@ -62,15 +99,59 @@ function resolveCommandName(file) {
62
99
  }
63
100
  return name;
64
101
  }
102
+ resolveCommandName.__type = [
103
+ "file",
104
+ "resolveCommandName",
105
+ "P&2!\"/\""
106
+ ];
65
107
  function resolveCommandPath(context, file) {
66
- return replacePath(findFilePath(file), context.commandsPath).replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "").split("/").filter((path) => path && !isPathSegmentGroup(path)).join("/");
108
+ return replacePath(findFilePath(file), context.commandsPath).replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "").split("/").filter(__assignType((path) => path && !isPathSegmentGroup(path), [
109
+ "path",
110
+ "",
111
+ "P\"2!\"/\""
112
+ ])).join("/");
113
+ }
114
+ resolveCommandPath.__type = [
115
+ "Context",
116
+ "context",
117
+ "file",
118
+ "resolveCommandPath",
119
+ "P\"w!2\"&2#&/$"
120
+ ];
121
+ function resolveCommandDynamicPathSegments(context, file) {
122
+ return replacePath(findFilePath(file), context.commandsPath).split("/").filter(__assignType((path) => Boolean(path) && isDynamicPathSegment(path), [
123
+ "path",
124
+ "",
125
+ "P\"2!\"/\""
126
+ ])).map(__assignType((path) => getDynamicPathSegmentName(path), [
127
+ "path",
128
+ "",
129
+ "P\"2!\"/\""
130
+ ]));
67
131
  }
132
+ resolveCommandDynamicPathSegments.__type = [
133
+ "Context",
134
+ "context",
135
+ "file",
136
+ "resolveCommandDynamicPathSegments",
137
+ "P\"w!2\"&2#&F/$"
138
+ ];
68
139
  function findCommandsRoot(context) {
69
140
  if (isSetString(context.config.entry)) return appendPath(appendPath(stripStars(context.config.entry), context.config.projectRoot), context.workspaceConfig.workspaceRoot);
70
141
  else if (isSetObject(context.config.entry) && "file" in context.config.entry) return appendPath(appendPath(stripStars(context.config.entry.file), context.config.projectRoot), context.workspaceConfig.workspaceRoot);
71
- else if (Array.isArray(context.config.entry) && context.config.entry.length > 0) return commonPath(context.config.entry.map((entry) => appendPath(appendPath(stripStars(isSetString(entry) ? entry : entry.file), context.config.projectRoot), context.workspaceConfig.workspaceRoot)));
142
+ else if (Array.isArray(context.config.entry) && context.config.entry.length > 0) return commonPath(context.config.entry.map(__assignType((entry) => appendPath(appendPath(stripStars(isSetString(entry) ? entry : entry.file), context.config.projectRoot), context.workspaceConfig.workspaceRoot), [
143
+ "entry",
144
+ "",
145
+ "P\"2!\"/\""
146
+ ])));
72
147
  return appendPath(context.config.sourceRoot || context.config.projectRoot, context.workspaceConfig.workspaceRoot);
73
148
  }
149
+ findCommandsRoot.__type = [
150
+ "Context",
151
+ "context",
152
+ "findCommandsRoot",
153
+ "P\"w!2\"&/#"
154
+ ];
74
155
  /**
75
156
  * Extracts command parameter information from a type parameter reflection.
76
157
  *
@@ -99,6 +180,15 @@ function extractCommandOption(command, reflection) {
99
180
  else if (type.kind !== ReflectionKind.boolean && type.kind !== ReflectionKind.string && type.kind !== ReflectionKind.number) throw new Error(`Unsupported type for option "${reflection.getNameAsString()}" in command "${command.name}". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(type).trim().replaceAll(" | ", ", or ")}.`);
100
181
  return option;
101
182
  }
183
+ extractCommandOption.__type = [
184
+ "CommandInput",
185
+ "command",
186
+ "ReflectionProperty",
187
+ "reflection",
188
+ "CommandOption",
189
+ "extractCommandOption",
190
+ "P\"w!2\"\"w#2$\"w%/&"
191
+ ];
102
192
  /**
103
193
  * Extracts command positional argument information from a type parameter reflection.
104
194
  *
@@ -127,6 +217,15 @@ function extractCommandArgument(command, reflection) {
127
217
  else if (type.kind !== ReflectionKind.boolean && type.kind !== ReflectionKind.string && type.kind !== ReflectionKind.number) throw new Error(`Unsupported type for argument "${reflection.getName()}" in command "${command.name}". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(type).trim().replaceAll(" | ", ", or ")}.`);
128
218
  return argument;
129
219
  }
220
+ extractCommandArgument.__type = [
221
+ "CommandInput",
222
+ "command",
223
+ "ReflectionParameter",
224
+ "reflection",
225
+ "CommandArgument",
226
+ "extractCommandArgument",
227
+ "P\"w!2\"\"w#2$\"w%/&"
228
+ ];
130
229
  /**
131
230
  * Reflects the command tree for a given command input.
132
231
  *
@@ -151,10 +250,10 @@ async function reflectCommandTree(context, command, parent) {
151
250
  if (!command.isVirtual) {
152
251
  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}"`);
153
252
  context.debug(`Adding reflection for user-defined command: ${command.id} (file: ${command.entry.input.file})`);
154
- const resolved = await resolveModule(context, command.entry.input, { plugins: [esbuildPlugin(context, {
253
+ const resolved = await (resolveModule.Ω = [["CommandModule", "\"w!"]], resolveModule(context, command.entry.input, { plugins: [esbuildPlugin(context, {
155
254
  reflection: "default",
156
255
  reflectionLevel: "verbose"
157
- })] });
256
+ })] }));
158
257
  const metadata = resolved.metadata ?? {};
159
258
  if (isSetString(metadata.title)) tree.title = metadata.title;
160
259
  if (isSetString(metadata.description)) tree.description = metadata.description;
@@ -170,18 +269,47 @@ async function reflectCommandTree(context, command, parent) {
170
269
  const optionsReflection = ReflectionClass.from(parameters[0].type);
171
270
  for (const propertyReflection of optionsReflection.getProperties()) tree.options[propertyReflection.getNameAsString()] = extractCommandOption(command, propertyReflection);
172
271
  } else throw new Error(`The first parameter of the command handler function in "${command.entry.input.file}" must be an object literal or class type representing the command options.`);
173
- tree.arguments = parameters.slice(1).map((arg) => extractCommandArgument(command, arg));
174
- tree.arguments.forEach((argument, index) => {
175
- const found = tree.arguments.findIndex((arg) => arg.name === argument.name);
176
- if (found !== -1 && found !== index || tree.segments.some((segment) => isDynamicPathSegment(segment) && getDynamicPathSegmentName(segment) === argument.name)) {
177
- argument.name += `_${tree.segments.filter((segment) => isDynamicPathSegment(segment) && getDynamicPathSegmentName(segment).replace(/_\d+$/, "") === argument.name).length + tree.arguments.filter((arg) => arg.name.replace(/_\d+$/, "") === argument.name).length}`;
272
+ tree.arguments = parameters.slice(1).map(__assignType((arg) => extractCommandArgument(command, arg), [
273
+ "arg",
274
+ "",
275
+ "P\"2!\"/\""
276
+ ]));
277
+ tree.arguments.forEach(__assignType((argument, index) => {
278
+ const found = tree.arguments.findIndex(__assignType((arg) => arg.name === argument.name, [
279
+ "arg",
280
+ "",
281
+ "P\"2!\"/\""
282
+ ]));
283
+ if (found !== -1 && found !== index || tree.segments.some(__assignType((segment) => isDynamicPathSegment(segment) && getDynamicPathSegmentName(segment) === argument.name, [
284
+ "segment",
285
+ "",
286
+ "P\"2!\"/\""
287
+ ]))) {
288
+ argument.name += `_${tree.segments.filter(__assignType((segment) => isDynamicPathSegment(segment) && getDynamicPathSegmentName(segment).replace(/_\d+$/, "") === argument.name, [
289
+ "segment",
290
+ "",
291
+ "P\"2!\"/\""
292
+ ])).length + tree.arguments.filter(__assignType((arg) => arg.name.replace(/_\d+$/, "") === argument.name, [
293
+ "arg",
294
+ "",
295
+ "P\"2!\"/\""
296
+ ])).length}`;
178
297
  argument.env = constantCase(argument.name);
179
298
  }
180
- });
299
+ }, [
300
+ "argument",
301
+ "index",
302
+ "",
303
+ "P\"2!\"2\"\"/#"
304
+ ]));
181
305
  }
182
306
  } else tree.description ??= `A collection of available ${tree.title.replace(/(?:c|C)ommands?$/, "").trim() || titleCase(tree.name)} commands that are included in the ${getAppTitle(context)} command-line application.`;
183
307
  if (context.env) {
184
- if (isSetObject(tree.options)) Object.values(tree.options).filter((option) => option.env !== false).forEach((option) => {
308
+ if (isSetObject(tree.options)) Object.values(tree.options).filter(__assignType((option) => option.env !== false, [
309
+ "option",
310
+ "",
311
+ "P\"2!\"/\""
312
+ ])).forEach(__assignType((option) => {
185
313
  context.env.types.env.addProperty({
186
314
  name: option.env,
187
315
  optional: option.optional ? true : void 0,
@@ -195,12 +323,28 @@ async function reflectCommandTree(context, command, parent) {
195
323
  tags: {
196
324
  ...option.reflection?.getTags(),
197
325
  title: option.title,
198
- alias: option.alias.filter((alias) => alias.length > 1).map((alias) => constantCase(alias)),
326
+ alias: option.alias.filter(__assignType((alias) => alias.length > 1, [
327
+ "alias",
328
+ "",
329
+ "P\"2!\"/\""
330
+ ])).map(__assignType((alias) => constantCase(alias), [
331
+ "alias",
332
+ "",
333
+ "P\"2!\"/\""
334
+ ])),
199
335
  domain: "cli"
200
336
  }
201
337
  });
202
- });
203
- tree.arguments.filter((arg) => arg.env !== false).forEach((arg) => context.env.types.env.addProperty({
338
+ }, [
339
+ "option",
340
+ "",
341
+ "P\"2!\"/\""
342
+ ]));
343
+ tree.arguments.filter(__assignType((arg) => arg.env !== false, [
344
+ "arg",
345
+ "",
346
+ "P\"2!\"/\""
347
+ ])).forEach(__assignType((arg) => context.env.types.env.addProperty({
204
348
  name: arg.env,
205
349
  optional: arg.optional ? true : void 0,
206
350
  description: arg.description,
@@ -209,14 +353,52 @@ async function reflectCommandTree(context, command, parent) {
209
353
  default: arg.default,
210
354
  tags: {
211
355
  ...arg.reflection.getTags(),
212
- alias: arg.alias.filter((alias) => alias.length > 1).map((alias) => constantCase(alias)),
356
+ alias: arg.alias.filter(__assignType((alias) => alias.length > 1, [
357
+ "alias",
358
+ "",
359
+ "P\"2!\"/\""
360
+ ])).map(__assignType((alias) => constantCase(alias), [
361
+ "alias",
362
+ "",
363
+ "P\"2!\"/\""
364
+ ])),
213
365
  domain: "cli"
214
366
  }
215
- }));
367
+ }), [
368
+ "arg",
369
+ "",
370
+ "P\"2!\"/\""
371
+ ]));
216
372
  }
217
- for (const input of context.inputs.filter((input$1) => input$1.segments.filter((segment) => !isDynamicPathSegment(segment)).length === command.segments.filter((segment) => !isDynamicPathSegment(segment)).length + 1 && input$1.segments.slice(0, command.segments.length).every((value, index) => value === command.segments[index]))) tree.children[input.name] = await reflectCommandTree(context, input, tree);
373
+ for (const input of context.inputs.filter(__assignType((input$1) => input$1.segments.filter(__assignType((segment) => !isDynamicPathSegment(segment), [
374
+ "segment",
375
+ "",
376
+ "P\"2!\"/\""
377
+ ])).length === command.segments.filter(__assignType((segment) => !isDynamicPathSegment(segment), [
378
+ "segment",
379
+ "",
380
+ "P\"2!\"/\""
381
+ ])).length + 1 && input$1.segments.slice(0, command.segments.length).every(__assignType((value, index) => value === command.segments[index], [
382
+ "value",
383
+ "index",
384
+ "",
385
+ "P\"2!\"2\"\"/#"
386
+ ])), [
387
+ "input",
388
+ "",
389
+ "P\"2!\"/\""
390
+ ]))) tree.children[input.name] = await reflectCommandTree(context, input, tree);
218
391
  return tree;
219
392
  }
393
+ reflectCommandTree.__type = [
394
+ "context",
395
+ "CommandInput",
396
+ "command",
397
+ "CommandTree",
398
+ "parent",
399
+ "reflectCommandTree",
400
+ "P\"2!\"w\"2#\"w$2%8\"w$`/&"
401
+ ];
220
402
 
221
403
  //#endregion
222
404
  export { findCommandsRoot, reflectCommandTree, resolveCommandId, resolveCommandName, resolveCommandPath };
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-command.mjs","names":["esbuildPlugin","reflect","ReflectionClass","ReflectionFunction","ReflectionKind","ReflectionVisibility","stringifyType","toArray","appendPath","commonPath","findFilePath","findFolderName","stripStars","replacePath","resolveParentPath","constantCase","titleCase","isSetObject","isSetString","resolveModule","getAppTitle","getDynamicPathSegmentName","isDynamicPathSegment","isPathSegmentGroup","getDefaultOptions","resolveCommandOptionDescription","name","kind","optional","variadic","title","defaultValue","boolean","trim","number","resolveCommandArgumentDescription","resolveCommandId","context","file","commandsPath","split","filter","p","Boolean","join","replaceAll","resolveCommandName","path","requireExtension","resolveCommandPath","resolveCommandDynamicPathSegments","map","findCommandsRoot","config","entry","projectRoot","workspaceConfig","workspaceRoot","Array","isArray","length","sourceRoot","extractCommandOption","command","reflection","type","getType","option","getNameAsString","alias","getTags","description","getDescription","getKind","isOptional","getDefaultValue","env","default","string","Error","extractCommandArgument","array","getName","argument","getAlias","parameter","reflectCommandTree","parent","isVirtual","replace","tree","icon","options","arguments","children","input","fs","existsSync","debug","id","resolved","plugins","reflectionLevel","metadata","function","parameters","getParameters","objectLiteral","class","optionsReflection","from","propertyReflection","getProperties","slice","arg","forEach","index","found","findIndex","segments","some","segment","Object","values","types","addProperty","undefined","visibility","public","tags","domain","inputs","every","value"],"sources":["../../src/helpers/resolve-command.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport type {\n ReflectionParameter,\n ReflectionProperty,\n TypeArray\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n reflect,\n ReflectionClass,\n ReflectionFunction,\n ReflectionKind,\n ReflectionVisibility,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { commonPath } from \"@stryke/path/common\";\nimport { findFilePath, findFolderName } from \"@stryke/path/file-path-fns\";\nimport { stripStars } from \"@stryke/path/normalize\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { resolveModule } from \"powerlines/lib/utilities/resolve\";\nimport {\n getAppTitle,\n getDynamicPathSegmentName,\n isDynamicPathSegment,\n isPathSegmentGroup\n} from \"../plugin-utils/context-helpers\";\nimport type {\n CommandArgument,\n CommandInput,\n CommandModule,\n CommandOption,\n CommandTree,\n NumberCommandArgument,\n NumberCommandOption,\n StringCommandArgument,\n StringCommandOption\n} from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport { getDefaultOptions } from \"./utilities\";\n\n/**\n * Resolves the description for a command option based on its reflection.\n *\n * @param name - The name of the command option.\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param variadic - Whether the command option is variadic (i.e., an array).\n * @param title - The title of the command option, if any.\n * @param defaultValue - The default value of the command option, if any.\n * @returns The resolved description for the command option.\n */\nexport function resolveCommandOptionDescription(\n name: string,\n kind: ReflectionKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} command-line ${\n kind === ReflectionKind.boolean ? \"flag\" : \"option\"\n } that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\n/**\n * Resolves the description for a command argument based on its reflection.\n *\n * @param name - The name of the command argument.\n * @param kind - The reflection kind of the command argument.\n * @param optional - Whether the command argument is optional.\n * @param variadic - Whether the command argument is variadic (i.e., an array).\n * @param title - The title of the command argument, if any.\n * @param defaultValue - The default value of the command argument, if any.\n * @returns The resolved description for the command argument.\n */\nexport function resolveCommandArgumentDescription(\n name: string,\n kind: ReflectionKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `An${\n optional && !defaultValue ? \" optional\" : \"\"\n } argument that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\nexport function resolveCommandId(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && !isDynamicPathSegment(p))\n .join(\"/\")\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .replaceAll(\"/\", \"-\");\n}\n\n/**\n * Finds the command name from the given file path.\n *\n * @param file - The file path to extract the command name from.\n * @returns The command name.\n */\nexport function resolveCommandName(file: string) {\n let path = findFilePath(file);\n let name = findFolderName(file, {\n requireExtension: true\n });\n\n while (isDynamicPathSegment(name)) {\n path = resolveParentPath(path);\n name = findFolderName(path, {\n requireExtension: true\n });\n }\n\n return name;\n}\n\nexport function resolveCommandPath(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .split(\"/\")\n .filter(path => path && !isPathSegmentGroup(path))\n .join(\"/\");\n}\n\nexport function resolveCommandDynamicPathSegments(\n context: Context,\n file: string\n): string[] {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(path => Boolean(path) && isDynamicPathSegment(path))\n .map(path => getDynamicPathSegmentName(path));\n}\n\nexport function findCommandsRoot(context: Context): string {\n if (isSetString(context.config.entry)) {\n return appendPath(\n appendPath(stripStars(context.config.entry), context.config.projectRoot),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n isSetObject(context.config.entry) &&\n \"file\" in context.config.entry\n ) {\n return appendPath(\n appendPath(\n stripStars(context.config.entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n Array.isArray(context.config.entry) &&\n context.config.entry.length > 0\n ) {\n return commonPath(\n context.config.entry.map(entry =>\n appendPath(\n appendPath(\n stripStars(isSetString(entry) ? entry : entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\n }\n\n return appendPath(\n context.config.sourceRoot || context.config.projectRoot,\n context.workspaceConfig.workspaceRoot\n );\n}\n\n/**\n * Extracts command parameter information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command option information.\n */\nexport function extractCommandOption(\n command: CommandInput,\n reflection: ReflectionProperty\n): CommandOption {\n const type = reflection.getType();\n\n const option = {\n name: reflection.getNameAsString(),\n alias: reflection.getTags().alias ?? [],\n title:\n reflection.getTags().title?.trim() ||\n titleCase(reflection.getNameAsString()),\n description:\n reflection.getDescription() ||\n resolveCommandOptionDescription(\n reflection.getNameAsString(),\n reflection.getKind(),\n reflection.isOptional(),\n reflection.isArray(),\n reflection.getTags().title,\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getNameAsString()),\n kind: type.kind as\n | ReflectionKind.string\n | ReflectionKind.number\n | ReflectionKind.boolean,\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n variadic: reflection.isArray(),\n reflection\n } as CommandOption;\n\n if (reflection.isArray()) {\n if (\n (type as TypeArray).type.kind === ReflectionKind.string ||\n (type as TypeArray).type.kind === ReflectionKind.number\n ) {\n (option as StringCommandOption | NumberCommandOption).variadic = true;\n (option as StringCommandOption | NumberCommandOption).kind = (\n type as TypeArray\n ).type.kind as ReflectionKind.string | ReflectionKind.number;\n } else {\n throw new Error(\n `Unsupported array type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return option;\n}\n\n/**\n * Extracts command positional argument information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command positional argument information.\n */\nexport function extractCommandArgument(\n command: CommandInput,\n reflection: ReflectionParameter\n): CommandArgument {\n const type = reflection.getType();\n\n if (\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number &&\n type.kind !== ReflectionKind.boolean &&\n !(\n type.kind === ReflectionKind.array &&\n (type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number)\n )\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string types (or an array of strings) are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const argument = {\n name: reflection.getName(),\n alias: reflection.getAlias(),\n kind: type.kind,\n title: titleCase(reflection.getName()),\n description:\n reflection.parameter.description ||\n resolveCommandArgumentDescription(\n reflection.getName(),\n type.kind === ReflectionKind.array ? type.type.kind : type.kind,\n reflection.isOptional(),\n type.kind === ReflectionKind.array,\n titleCase(reflection.getName()),\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getName()),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n reflection\n } as CommandArgument;\n\n if (type.kind === ReflectionKind.array) {\n if (\n type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number\n ) {\n (argument as StringCommandArgument | NumberCommandArgument).variadic =\n true;\n (argument as StringCommandArgument | NumberCommandArgument).kind =\n type.type.kind;\n } else {\n throw new Error(\n `Unsupported array type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return argument;\n}\n\n/**\n * Reflects the command tree for a given command input.\n *\n * @param context - The context in which the command is being reflected.\n * @param command - The command input to reflect.\n * @param parent - The parent command tree, if any.\n * @returns The reflected command tree.\n */\nexport async function reflectCommandTree<TContext extends Context = Context>(\n context: TContext,\n command: CommandInput,\n parent?: CommandTree\n): Promise<CommandTree> {\n const title =\n command.title ||\n `${\n parent?.title\n ? `${\n parent.isVirtual\n ? parent.title.replace(/(?:c|C)ommands?$/, \"\").trim()\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const tree = {\n alias: [],\n icon: parent?.icon,\n ...command,\n title,\n options: getDefaultOptions(context, command),\n arguments: [],\n parent: parent ?? null,\n children: {},\n reflection: null\n } as CommandTree;\n\n if (!command.isVirtual) {\n if (\n !command.entry.input?.file ||\n !context.fs.existsSync(command.entry.input.file)\n ) {\n throw new Error(\n `${\n !command.entry.input?.file ? \"Missing\" : \"Non-existent\"\n } command entry file for \"${command.name}\"`\n );\n }\n\n context.debug(\n `Adding reflection for user-defined command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n const resolved = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n reflectionLevel: \"verbose\"\n })\n ]\n }\n );\n\n const metadata = resolved.metadata ?? {};\n if (isSetString(metadata.title)) {\n tree.title = metadata.title;\n }\n if (isSetString(metadata.description)) {\n tree.description = metadata.description;\n }\n if (\n isSetString(metadata.alias) ||\n (Array.isArray(metadata.alias) && metadata.alias.length > 0)\n ) {\n tree.alias = toArray(metadata.alias);\n }\n if (isSetString(metadata.icon)) {\n tree.icon = metadata.icon;\n }\n\n const type = reflect(resolved);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `The command entry file \"${command.entry.input.file}\" does not export a valid function.`\n );\n }\n\n tree.reflection = new ReflectionFunction(type);\n tree.description ??=\n command.description ||\n type.description ||\n `The ${tree.title.replace(/(?:c|C)ommands?$/, \"\").trim()} executable command-line interface.`;\n\n const parameters = tree.reflection.getParameters();\n if (parameters.length > 0 && parameters[0]) {\n if (\n parameters[0].type.kind === ReflectionKind.objectLiteral ||\n parameters[0].type.kind === ReflectionKind.class\n ) {\n const optionsReflection = ReflectionClass.from(parameters[0].type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n tree.options[propertyReflection.getNameAsString()] =\n extractCommandOption(command, propertyReflection);\n }\n } else {\n throw new Error(\n `The first parameter of the command handler function in \"${\n command.entry.input.file\n }\" must be an object literal or class type representing the command options.`\n );\n }\n\n tree.arguments = parameters\n .slice(1)\n .map(arg => extractCommandArgument(command, arg));\n\n // Ensure unique argument names by appending an index suffix to duplicates\n tree.arguments.forEach((argument, index) => {\n const found = tree.arguments.findIndex(\n arg => arg.name === argument.name\n );\n if (\n (found !== -1 && found !== index) ||\n tree.segments.some(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment) === argument.name\n )\n ) {\n argument.name += `_${\n tree.segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(/_\\d+$/, \"\") ===\n argument.name\n ).length +\n tree.arguments.filter(\n arg => arg.name.replace(/_\\d+$/, \"\") === argument.name\n ).length\n }`;\n argument.env = constantCase(argument.name);\n }\n });\n }\n } else {\n tree.description ??= `A collection of available ${\n tree.title.replace(/(?:c|C)ommands?$/, \"\").trim() || titleCase(tree.name)\n } commands that are included in the ${getAppTitle(\n context\n )} command-line application.`;\n }\n\n if (context.env) {\n if (isSetObject(tree.options)) {\n Object.values(tree.options)\n .filter(option => option.env !== false)\n .forEach(option => {\n context.env.types.env.addProperty({\n name: option.env as string,\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type:\n option.reflection?.getType() ??\n ((option as StringCommandOption | NumberCommandOption).variadic\n ? { kind: ReflectionKind.array, type: { kind: option.kind } }\n : { kind: option.kind }),\n default: option.default,\n tags: {\n ...option.reflection?.getTags(),\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n tree.arguments\n .filter(arg => arg.env !== false)\n .forEach(arg =>\n 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: arg.reflection.getType(),\n default: arg.default,\n tags: {\n ...arg.reflection.getTags(),\n alias: arg.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n })\n );\n }\n\n for (const input of context.inputs.filter(\n input =>\n input.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n command.segments.filter(segment => !isDynamicPathSegment(segment))\n .length +\n 1 &&\n input.segments\n .slice(0, command.segments.length)\n .every((value, index) => value === command.segments[index])\n )) {\n tree.children[input.name] = await reflectCommandTree(context, input, tree);\n }\n\n return tree;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,SAAgByB,gCACdC,MACAC,MACAC,WAAW,OACXC,WAAW,OACXC,OACAC,cACQ;AACR,QAAO,IAAIH,YAAY,CAACG,eAAe,eAAe,GAAE,gBACtDJ,SAASvB,eAAe4B,UAAU,SAAS,SAAQ,2BAEnDL,SAASvB,eAAe4B,UACpB,YACAH,WACE,mBACA,mBAAkB,GACtBC,OAAOG,MAAM,IAAIjB,UAAUU,KAAK,CAAA,GAClCC,SAASvB,eAAe4B,UACpB,cACA,GAAGL,SAASvB,eAAe8B,SAAS,YAAY,SAAQ,QACtDL,WAAW,MAAM,KACjB;;;;;;;;;;;;;AAeV,SAAgBM,kCACdT,MACAC,MACAC,WAAW,OACXC,WAAW,OACXC,OACAC,cACQ;AACR,QAAO,KACLH,YAAY,CAACG,eAAe,cAAc,GAAE,oCAE5CJ,SAASvB,eAAe4B,UACpB,YACAH,WACE,mBACA,mBAAkB,GACtBC,OAAOG,MAAM,IAAIjB,UAAUU,KAAK,CAAA,GAClCC,SAASvB,eAAe4B,UACpB,cAC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StD,aAAasD,MAAM,CAAC;IACpC6D,QAAQ;IACV;GACD,CACH,CAAC;;AAGL,MAAK,MAAMnC,SAAS1D,QAAQ8F,OAAO1F,QACjCsD,YACEA,QAAMwB,SAAS9E,QAAOgF,YAAW,CAACnG,qBAAqBmG,QAAQ,CAAC,CAC7D7D,WACDG,QAAQwD,SAAS9E,QAAOgF,YAAW,CAACnG,qBAAqBmG,QAAQ,CAAC,CAC/D7D,SACD,KACJmC,QAAMwB,SACHN,MAAM,GAAGlD,QAAQwD,SAAS3D,OAAO,CACjCwE,OAAOC,OAAOjB,UAAUiB,UAAUtE,QAAQwD,SAASH,OAC1D,CAAC,CACC1B,MAAKI,SAASC,MAAMrE,QAAQ,MAAM4D,mBAAmBjD,SAAS0D,OAAOL,KAAK;AAG5E,QAAOA"}
1
+ {"version":3,"file":"resolve-command.mjs","names":[],"sources":["../../src/helpers/resolve-command.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport type {\n ReflectionParameter,\n ReflectionProperty,\n TypeArray\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n reflect,\n ReflectionClass,\n ReflectionFunction,\n ReflectionKind,\n ReflectionVisibility,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { commonPath } from \"@stryke/path/common\";\nimport { findFilePath, findFolderName } from \"@stryke/path/file-path-fns\";\nimport { stripStars } from \"@stryke/path/normalize\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { resolveModule } from \"powerlines/lib/utilities/resolve\";\nimport {\n getAppTitle,\n getDynamicPathSegmentName,\n isDynamicPathSegment,\n isPathSegmentGroup\n} from \"../plugin-utils/context-helpers\";\nimport type {\n CommandArgument,\n CommandInput,\n CommandModule,\n CommandOption,\n CommandTree,\n NumberCommandArgument,\n NumberCommandOption,\n StringCommandArgument,\n StringCommandOption\n} from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport { getDefaultOptions } from \"./utilities\";\n\n/**\n * Resolves the description for a command option based on its reflection.\n *\n * @param name - The name of the command option.\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param variadic - Whether the command option is variadic (i.e., an array).\n * @param title - The title of the command option, if any.\n * @param defaultValue - The default value of the command option, if any.\n * @returns The resolved description for the command option.\n */\nexport function resolveCommandOptionDescription(\n name: string,\n kind: ReflectionKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} command-line ${\n kind === ReflectionKind.boolean ? \"flag\" : \"option\"\n } that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\n/**\n * Resolves the description for a command argument based on its reflection.\n *\n * @param name - The name of the command argument.\n * @param kind - The reflection kind of the command argument.\n * @param optional - Whether the command argument is optional.\n * @param variadic - Whether the command argument is variadic (i.e., an array).\n * @param title - The title of the command argument, if any.\n * @param defaultValue - The default value of the command argument, if any.\n * @returns The resolved description for the command argument.\n */\nexport function resolveCommandArgumentDescription(\n name: string,\n kind: ReflectionKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `An${\n optional && !defaultValue ? \" optional\" : \"\"\n } argument that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\nexport function resolveCommandId(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && !isDynamicPathSegment(p))\n .join(\"/\")\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .replaceAll(\"/\", \"-\");\n}\n\n/**\n * Finds the command name from the given file path.\n *\n * @param file - The file path to extract the command name from.\n * @returns The command name.\n */\nexport function resolveCommandName(file: string) {\n let path = findFilePath(file);\n let name = findFolderName(file, {\n requireExtension: true\n });\n\n while (isDynamicPathSegment(name)) {\n path = resolveParentPath(path);\n name = findFolderName(path, {\n requireExtension: true\n });\n }\n\n return name;\n}\n\nexport function resolveCommandPath(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .split(\"/\")\n .filter(path => path && !isPathSegmentGroup(path))\n .join(\"/\");\n}\n\nexport function resolveCommandDynamicPathSegments(\n context: Context,\n file: string\n): string[] {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(path => Boolean(path) && isDynamicPathSegment(path))\n .map(path => getDynamicPathSegmentName(path));\n}\n\nexport function findCommandsRoot(context: Context): string {\n if (isSetString(context.config.entry)) {\n return appendPath(\n appendPath(stripStars(context.config.entry), context.config.projectRoot),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n isSetObject(context.config.entry) &&\n \"file\" in context.config.entry\n ) {\n return appendPath(\n appendPath(\n stripStars(context.config.entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n Array.isArray(context.config.entry) &&\n context.config.entry.length > 0\n ) {\n return commonPath(\n context.config.entry.map(entry =>\n appendPath(\n appendPath(\n stripStars(isSetString(entry) ? entry : entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\n }\n\n return appendPath(\n context.config.sourceRoot || context.config.projectRoot,\n context.workspaceConfig.workspaceRoot\n );\n}\n\n/**\n * Extracts command parameter information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command option information.\n */\nexport function extractCommandOption(\n command: CommandInput,\n reflection: ReflectionProperty\n): CommandOption {\n const type = reflection.getType();\n\n const option = {\n name: reflection.getNameAsString(),\n alias: reflection.getTags().alias ?? [],\n title:\n reflection.getTags().title?.trim() ||\n titleCase(reflection.getNameAsString()),\n description:\n reflection.getDescription() ||\n resolveCommandOptionDescription(\n reflection.getNameAsString(),\n reflection.getKind(),\n reflection.isOptional(),\n reflection.isArray(),\n reflection.getTags().title,\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getNameAsString()),\n kind: type.kind as\n | ReflectionKind.string\n | ReflectionKind.number\n | ReflectionKind.boolean,\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n variadic: reflection.isArray(),\n reflection\n } as CommandOption;\n\n if (reflection.isArray()) {\n if (\n (type as TypeArray).type.kind === ReflectionKind.string ||\n (type as TypeArray).type.kind === ReflectionKind.number\n ) {\n (option as StringCommandOption | NumberCommandOption).variadic = true;\n (option as StringCommandOption | NumberCommandOption).kind = (\n type as TypeArray\n ).type.kind as ReflectionKind.string | ReflectionKind.number;\n } else {\n throw new Error(\n `Unsupported array type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return option;\n}\n\n/**\n * Extracts command positional argument information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command positional argument information.\n */\nexport function extractCommandArgument(\n command: CommandInput,\n reflection: ReflectionParameter\n): CommandArgument {\n const type = reflection.getType();\n\n if (\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number &&\n type.kind !== ReflectionKind.boolean &&\n !(\n type.kind === ReflectionKind.array &&\n (type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number)\n )\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string types (or an array of strings) are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const argument = {\n name: reflection.getName(),\n alias: reflection.getAlias(),\n kind: type.kind,\n title: titleCase(reflection.getName()),\n description:\n reflection.parameter.description ||\n resolveCommandArgumentDescription(\n reflection.getName(),\n type.kind === ReflectionKind.array ? type.type.kind : type.kind,\n reflection.isOptional(),\n type.kind === ReflectionKind.array,\n titleCase(reflection.getName()),\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getName()),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n reflection\n } as CommandArgument;\n\n if (type.kind === ReflectionKind.array) {\n if (\n type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number\n ) {\n (argument as StringCommandArgument | NumberCommandArgument).variadic =\n true;\n (argument as StringCommandArgument | NumberCommandArgument).kind =\n type.type.kind;\n } else {\n throw new Error(\n `Unsupported array type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return argument;\n}\n\n/**\n * Reflects the command tree for a given command input.\n *\n * @param context - The context in which the command is being reflected.\n * @param command - The command input to reflect.\n * @param parent - The parent command tree, if any.\n * @returns The reflected command tree.\n */\nexport async function reflectCommandTree<TContext extends Context = Context>(\n context: TContext,\n command: CommandInput,\n parent?: CommandTree\n): Promise<CommandTree> {\n const title =\n command.title ||\n `${\n parent?.title\n ? `${\n parent.isVirtual\n ? parent.title.replace(/(?:c|C)ommands?$/, \"\").trim()\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const tree = {\n alias: [],\n icon: parent?.icon,\n ...command,\n title,\n options: getDefaultOptions(context, command),\n arguments: [],\n parent: parent ?? null,\n children: {},\n reflection: null\n } as CommandTree;\n\n if (!command.isVirtual) {\n if (\n !command.entry.input?.file ||\n !context.fs.existsSync(command.entry.input.file)\n ) {\n throw new Error(\n `${\n !command.entry.input?.file ? \"Missing\" : \"Non-existent\"\n } command entry file for \"${command.name}\"`\n );\n }\n\n context.debug(\n `Adding reflection for user-defined command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n const resolved = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n reflectionLevel: \"verbose\"\n })\n ]\n }\n );\n\n const metadata = resolved.metadata ?? {};\n if (isSetString(metadata.title)) {\n tree.title = metadata.title;\n }\n if (isSetString(metadata.description)) {\n tree.description = metadata.description;\n }\n if (\n isSetString(metadata.alias) ||\n (Array.isArray(metadata.alias) && metadata.alias.length > 0)\n ) {\n tree.alias = toArray(metadata.alias);\n }\n if (isSetString(metadata.icon)) {\n tree.icon = metadata.icon;\n }\n\n const type = reflect(resolved);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `The command entry file \"${command.entry.input.file}\" does not export a valid function.`\n );\n }\n\n tree.reflection = new ReflectionFunction(type);\n tree.description ??=\n command.description ||\n type.description ||\n `The ${tree.title.replace(/(?:c|C)ommands?$/, \"\").trim()} executable command-line interface.`;\n\n const parameters = tree.reflection.getParameters();\n if (parameters.length > 0 && parameters[0]) {\n if (\n parameters[0].type.kind === ReflectionKind.objectLiteral ||\n parameters[0].type.kind === ReflectionKind.class\n ) {\n const optionsReflection = ReflectionClass.from(parameters[0].type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n tree.options[propertyReflection.getNameAsString()] =\n extractCommandOption(command, propertyReflection);\n }\n } else {\n throw new Error(\n `The first parameter of the command handler function in \"${\n command.entry.input.file\n }\" must be an object literal or class type representing the command options.`\n );\n }\n\n tree.arguments = parameters\n .slice(1)\n .map(arg => extractCommandArgument(command, arg));\n\n // Ensure unique argument names by appending an index suffix to duplicates\n tree.arguments.forEach((argument, index) => {\n const found = tree.arguments.findIndex(\n arg => arg.name === argument.name\n );\n if (\n (found !== -1 && found !== index) ||\n tree.segments.some(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment) === argument.name\n )\n ) {\n argument.name += `_${\n tree.segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(/_\\d+$/, \"\") ===\n argument.name\n ).length +\n tree.arguments.filter(\n arg => arg.name.replace(/_\\d+$/, \"\") === argument.name\n ).length\n }`;\n argument.env = constantCase(argument.name);\n }\n });\n }\n } else {\n tree.description ??= `A collection of available ${\n tree.title.replace(/(?:c|C)ommands?$/, \"\").trim() || titleCase(tree.name)\n } commands that are included in the ${getAppTitle(\n context\n )} command-line application.`;\n }\n\n if (context.env) {\n if (isSetObject(tree.options)) {\n Object.values(tree.options)\n .filter(option => option.env !== false)\n .forEach(option => {\n context.env.types.env.addProperty({\n name: option.env as string,\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type:\n option.reflection?.getType() ??\n ((option as StringCommandOption | NumberCommandOption).variadic\n ? { kind: ReflectionKind.array, type: { kind: option.kind } }\n : { kind: option.kind }),\n default: option.default,\n tags: {\n ...option.reflection?.getTags(),\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n tree.arguments\n .filter(arg => arg.env !== false)\n .forEach(arg =>\n 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: arg.reflection.getType(),\n default: arg.default,\n tags: {\n ...arg.reflection.getTags(),\n alias: arg.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n })\n );\n }\n\n for (const input of context.inputs.filter(\n input =>\n input.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n command.segments.filter(segment => !isDynamicPathSegment(segment))\n .length +\n 1 &&\n input.segments\n .slice(0, command.segments.length)\n .every((value, index) => value === command.segments[index])\n )) {\n tree.children[input.name] = await reflectCommandTree(context, input, tree);\n }\n\n return tree;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAEA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;;;;;;;;;;;;AA8CX,SAAY,gCAAA,MAAA,MAAA,WAAA,OAA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AA,SAAA;IACL,OAAA,IAAA,MACQ,OAAA,cAAA,UAAA,MAAA,SAAA,GAAA;KAAA;KAAA;KAAA;KAAA,CAAA,CAAA,CACK,IAAI,cAAa,UAAC,aAAA,MAAA,EAAA;KAAA;KAAA;KAAA;KAAA,CAAA,CAAA;IAChC,QAAA;IACH;GACK,CAAC,EAAE;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;;AAER,MAAK,MAAM,SAAS,QAAQ,OAAO,OAAE,cAAA,YAAA,QAAA,SAAA,OAAA,cAAA,YAAA,CAAA,qBAAA,QAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAChC,WACL,QAAA,SAAA,OAAA,cAAA,YAAA,CAAA,qBAAA,QAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CACS,SACD,KACJ,QAAM,SACD,MAAM,GAAG,QAAQ,SAAS,OAAO,CACnC,MAAA,cAAA,OAAA,UAAA,UAAA,QAAA,SAAA,QAAA;EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CACL,MAAA,SAAA,MAAA,QAAA,MAAA,mBAAA,SAAA,OAAA,KAAA;AAEF,QAAO;;AAEX,mBAAE,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
@@ -8,27 +8,51 @@ let __stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
8
8
  let __stryke_json_storm_json = require("@stryke/json/storm-json");
9
9
 
10
10
  //#region src/helpers/update-package-json.ts
11
+ function __assignType(fn, args) {
12
+ fn.__type = args;
13
+ return fn;
14
+ }
11
15
  function formatBinaryPath(format) {
12
16
  return `./dist/bin.${format === "cjs" || Array.isArray(format) && format.includes("cjs") ? "cjs" : "mjs"}`;
13
17
  }
18
+ formatBinaryPath.__type = [
19
+ "format",
20
+ "formatBinaryPath",
21
+ "PP&&F-J2!&/\""
22
+ ];
14
23
  async function updatePackageJsonBinary(context) {
15
24
  const packageJsonPath = (0, __stryke_path_join_paths.joinPaths)(context.workspaceConfig.workspaceRoot, context.config.projectRoot, "package.json");
16
25
  if (context.config.bin && Array.isArray(context.config.bin) && context.config.bin.length > 0) {
17
- context.packageJson.bin = Object.fromEntries((0, __stryke_helpers_get_unique.getUnique)((0, __stryke_convert_to_array.toArray)(context.config.bin)).map((bin) => [bin, formatBinaryPath(context.config.output.format)]));
26
+ context.packageJson.bin = Object.fromEntries((0, __stryke_helpers_get_unique.getUnique)((0, __stryke_convert_to_array.toArray)(context.config.bin)).map(__assignType((bin) => [bin, formatBinaryPath(context.config.output.format)], [
27
+ "bin",
28
+ "",
29
+ "P\"2!\"/\""
30
+ ])));
18
31
  await context.fs.write(packageJsonPath, __stryke_json_storm_json.StormJSON.stringify(context.packageJson));
19
32
  } else {
20
33
  if (Array.isArray(context.config.output.format) && context.config.output.format.length > 1) {
21
34
  context.packageJson.bin = { [(0, __stryke_string_format_kebab_case.kebabCase)(require_plugin_utils_context_helpers.getAppName(context))]: formatBinaryPath((0, __stryke_convert_to_array.toArray)(context.config.output.format)[0]) };
22
- context.packageJson.bin = (0, __stryke_convert_to_array.toArray)(context.config.output.format).reduce((ret, format) => {
35
+ context.packageJson.bin = (0, __stryke_convert_to_array.toArray)(context.config.output.format).reduce(__assignType((ret, format) => {
23
36
  ret[`${(0, __stryke_string_format_kebab_case.kebabCase)(require_plugin_utils_context_helpers.getAppName(context))}-${format}`] = formatBinaryPath(format);
24
37
  return ret;
25
- }, context.packageJson.bin);
38
+ }, [
39
+ "ret",
40
+ "format",
41
+ "",
42
+ "P\"2!\"2\"\"/#"
43
+ ]), context.packageJson.bin);
26
44
  } else context.packageJson.bin = { [(0, __stryke_string_format_kebab_case.kebabCase)(require_plugin_utils_context_helpers.getAppName(context))]: formatBinaryPath(context.config.output.format) };
27
45
  await context.fs.write(packageJsonPath, __stryke_json_storm_json.StormJSON.stringify(context.packageJson));
28
46
  }
29
47
  if (!(0, __stryke_type_checks_is_set_object.isSetObject)(context.packageJson.bin)) throw new Error("Unable to determine the CLI binary name. Please specify the `bin` option in your Shell Shock configuration or ensure that the `name` field is set in your package.json.");
30
48
  context.config.bin = Object.keys(context.packageJson.bin);
31
49
  }
50
+ updatePackageJsonBinary.__type = [
51
+ "UnresolvedContext",
52
+ "context",
53
+ "updatePackageJsonBinary",
54
+ "P\"w!2\"$`/#"
55
+ ];
32
56
 
33
57
  //#endregion
34
58
  exports.formatBinaryPath = formatBinaryPath;
@@ -1 +1 @@
1
- {"version":3,"file":"update-package-json.cjs","names":["toArray","getUnique","StormJSON","joinPaths","kebabCase","isSetObject","getAppName","formatBinaryPath","format","Array","isArray","includes","updatePackageJsonBinary","context","packageJsonPath","workspaceConfig","workspaceRoot","config","projectRoot","bin","length","packageJson","Object","fromEntries","map","output","fs","write","stringify","reduce","ret","Error","keys"],"sources":["../../src/helpers/update-package-json.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 { toArray } from \"@stryke/convert/to-array\";\nimport { getUnique } from \"@stryke/helpers/get-unique\";\nimport { StormJSON } from \"@stryke/json/storm-json\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { getAppName } from \"../plugin-utils/context-helpers\";\nimport type { UnresolvedContext } from \"../types/context\";\n\nexport function formatBinaryPath(\n format: string | string[] | undefined\n): string {\n return `./dist/bin.${\n format === \"cjs\" || (Array.isArray(format) && format.includes(\"cjs\"))\n ? \"cjs\"\n : \"mjs\"\n }`;\n}\n\nexport async function updatePackageJsonBinary(\n context: UnresolvedContext\n): Promise<void> {\n const packageJsonPath = joinPaths(\n context.workspaceConfig.workspaceRoot,\n context.config.projectRoot,\n \"package.json\"\n );\n if (\n context.config.bin &&\n Array.isArray(context.config.bin) &&\n context.config.bin.length > 0\n ) {\n context.packageJson.bin = Object.fromEntries(\n getUnique(toArray(context.config.bin)).map(bin => [\n bin,\n formatBinaryPath(context.config.output.format)\n ])\n );\n\n await context.fs.write(\n packageJsonPath,\n StormJSON.stringify(context.packageJson)\n );\n } else {\n if (\n Array.isArray(context.config.output.format) &&\n context.config.output.format.length > 1\n ) {\n context.packageJson.bin = {\n [kebabCase(getAppName(context))]: formatBinaryPath(\n toArray(context.config.output.format)[0]\n )\n };\n context.packageJson.bin = toArray(context.config.output.format).reduce(\n (ret, format) => {\n ret[`${kebabCase(getAppName(context))}-${format}`] =\n formatBinaryPath(format);\n\n return ret;\n },\n context.packageJson.bin\n );\n } else {\n context.packageJson.bin = {\n [kebabCase(getAppName(context))]: formatBinaryPath(\n context.config.output.format\n )\n };\n }\n\n await context.fs.write(\n packageJsonPath,\n StormJSON.stringify(context.packageJson)\n );\n }\n\n if (!isSetObject(context.packageJson.bin)) {\n throw new Error(\n \"Unable to determine the CLI binary name. Please specify the `bin` option in your Shell Shock configuration or ensure that the `name` field is set in your package.json.\"\n );\n }\n\n context.config.bin = Object.keys(context.packageJson.bin);\n}\n"],"mappings":";;;;;;;;;;AA2BA,SAAgBO,iBACdC,QACQ;AACR,QAAO,cACLA,WAAW,SAAUC,MAAMC,QAAQF,OAAO,IAAIA,OAAOG,SAAS,MAAO,GACjE,QACA;;AAIR,eAAsBC,wBACpBC,SACe;CACf,MAAMC,0DACJD,QAAQE,gBAAgBC,eACxBH,QAAQI,OAAOC,aACf,eACD;AACD,KACEL,QAAQI,OAAOE,OACfV,MAAMC,QAAQG,QAAQI,OAAOE,IAAI,IACjCN,QAAQI,OAAOE,IAAIC,SAAS,GAC5B;AACAP,UAAQQ,YAAYF,MAAMG,OAAOC,8FACbV,QAAQI,OAAOE,IAAI,CAAC,CAACK,KAAIL,QAAO,CAChDA,KACAZ,iBAAiBM,QAAQI,OAAOQ,OAAOjB,OAAO,CAC/C,CACH,CAAC;AAED,QAAMK,QAAQa,GAAGC,MACfb,iBACAZ,mCAAU0B,UAAUf,QAAQQ,YAC9B,CAAC;QACI;AACL,MACEZ,MAAMC,QAAQG,QAAQI,OAAOQ,OAAOjB,OAAO,IAC3CK,QAAQI,OAAOQ,OAAOjB,OAAOY,SAAS,GACtC;AACAP,WAAQQ,YAAYF,MAAM,oDACbb,gDAAWO,QAAQ,CAAC,GAAGN,wDACxBM,QAAQI,OAAOQ,OAAOjB,OAAO,CAAC,GACxC,EACD;AACDK,WAAQQ,YAAYF,6CAAcN,QAAQI,OAAOQ,OAAOjB,OAAO,CAACqB,QAC7DC,KAAKtB,WAAW;AACfsB,QAAI,oDAAaxB,gDAAWO,QAAQ,CAAC,CAAA,GAAIL,YACvCD,iBAAiBC,OAAO;AAE1B,WAAOsB;MAETjB,QAAQQ,YAAYF,IACrB;QAEDN,SAAQQ,YAAYF,MAAM,oDACbb,gDAAWO,QAAQ,CAAC,GAAGN,iBAChCM,QAAQI,OAAOQ,OAAOjB,OACxB,EACD;AAGH,QAAMK,QAAQa,GAAGC,MACfb,iBACAZ,mCAAU0B,UAAUf,QAAQQ,YAC9B,CAAC;;AAGH,KAAI,qDAAaR,QAAQQ,YAAYF,IAAI,CACvC,OAAM,IAAIY,MACR,0KACD;AAGHlB,SAAQI,OAAOE,MAAMG,OAAOU,KAAKnB,QAAQQ,YAAYF,IAAI"}
1
+ {"version":3,"file":"update-package-json.cjs","names":[],"sources":["../../src/helpers/update-package-json.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 { toArray } from \"@stryke/convert/to-array\";\nimport { getUnique } from \"@stryke/helpers/get-unique\";\nimport { StormJSON } from \"@stryke/json/storm-json\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { getAppName } from \"../plugin-utils/context-helpers\";\nimport type { UnresolvedContext } from \"../types/context\";\n\nexport function formatBinaryPath(\n format: string | string[] | undefined\n): string {\n return `./dist/bin.${\n format === \"cjs\" || (Array.isArray(format) && format.includes(\"cjs\"))\n ? \"cjs\"\n : \"mjs\"\n }`;\n}\n\nexport async function updatePackageJsonBinary(\n context: UnresolvedContext\n): Promise<void> {\n const packageJsonPath = joinPaths(\n context.workspaceConfig.workspaceRoot,\n context.config.projectRoot,\n \"package.json\"\n );\n if (\n context.config.bin &&\n Array.isArray(context.config.bin) &&\n context.config.bin.length > 0\n ) {\n context.packageJson.bin = Object.fromEntries(\n getUnique(toArray(context.config.bin)).map(bin => [\n bin,\n formatBinaryPath(context.config.output.format)\n ])\n );\n\n await context.fs.write(\n packageJsonPath,\n StormJSON.stringify(context.packageJson)\n );\n } else {\n if (\n Array.isArray(context.config.output.format) &&\n context.config.output.format.length > 1\n ) {\n context.packageJson.bin = {\n [kebabCase(getAppName(context))]: formatBinaryPath(\n toArray(context.config.output.format)[0]\n )\n };\n context.packageJson.bin = toArray(context.config.output.format).reduce(\n (ret, format) => {\n ret[`${kebabCase(getAppName(context))}-${format}`] =\n formatBinaryPath(format);\n\n return ret;\n },\n context.packageJson.bin\n );\n } else {\n context.packageJson.bin = {\n [kebabCase(getAppName(context))]: formatBinaryPath(\n context.config.output.format\n )\n };\n }\n\n await context.fs.write(\n packageJsonPath,\n StormJSON.stringify(context.packageJson)\n );\n }\n\n if (!isSetObject(context.packageJson.bin)) {\n throw new Error(\n \"Unable to determine the CLI binary name. Please specify the `bin` option in your Shell Shock configuration or ensure that the `name` field is set in your package.json.\"\n );\n }\n\n context.config.bin = Object.keys(context.packageJson.bin);\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;AA0BX,SAAgB,iBAAiB,QAAK;AAClC,QAAM,cAAA,WAAA,SAAA,MAAA,QAAA,OAAA,IAAA,OAAA,SAAA,MAAA,GACA,QACA;;AAEV,iBAAY,SAAA;CAAA;CAAA;CAAA;CAAA;AACZ,eAAI,wBAAA,SAAA;CACJ,MAAA,0DAAA,QAAA,gBAAA,eAAA,QAAA,OAAA,aAAA,eAAA;2BAEQ,MAAM,QAAQ,QAAQ,OAAO,IAAI,IACjC,QAAQ,OAAO,IAAI,SAAA,GAAA;AACnB,UAAQ,YAAC,MAAA,OAAA,8FAAA,QAAA,OAAA,IAAA,CAAA,CAAA,IAAA,cAAA,QAAA,CACL,KACA,iBAAiB,QAAQ,OAAI,OAAA,OAAA,CAChC,EAAE;GAAC;GAAO;GAAI;GAAO,CAAA,CAAA,CAAA;AACtB,QAAM,QAAG,GAAA,MAAA,iBAAA,mCAAA,UAAA,QAAA,YAAA,CAAA;QAEZ;AACG,MAAI,MAAM,QAAM,QAAA,OAAA,OAAA,OAAA,IACZ,QAAQ,OAAO,OAAO,OAAK,SAAA,GAAA;AAC3B,WAAQ,YAAY,MAAA,oDAC5B,gDAAA,QAAA,CAAA,GAAA,wDAAA,QAAA,OAAA,OAAA,OAAA,CAAA,GAAA,EACS;AACD,WAAQ,YAAY,6CAAc,QAAQ,OAAE,OAAA,OAAA,CAAA,OAAA,cAAA,KAAA,WAAA;AAC7C,QAAA,oDAAA,gDAAA,QAAA,CAAA,CAAA,GAAA,YACS,iBAAiB,OAAO;AACrC,WAAA;MACF;IAAA;IAAA;IAAA;IAAA;IAAA,CAAA,EAAA,QAAA,YAAA,IAAA;QAGO,SAAQ,YAAC,MAAA,oDACM,gDAAW,QAAO,CAAA,GAAA,iBAAA,QAAA,OAAA,OAAA,OAAA,EACxC;AAEE,QAAA,QAAA,GAAA,MAAA,iBAAA,mCAAA,UAAA,QAAA,YAAA,CAAA;;AAEH,KAAI,qDAAa,QAAQ,YAAY,IAAG,CACtC,OAAA,IAAA,MAAA,0KAAA;AAEF,SAAQ,OAAO,MAAM,OAAO,KAAK,QAAQ,YAAY,IAAC;;AAE1D,wBAAQ,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
@@ -7,27 +7,51 @@ import { getUnique } from "@stryke/helpers/get-unique";
7
7
  import { StormJSON } from "@stryke/json/storm-json";
8
8
 
9
9
  //#region src/helpers/update-package-json.ts
10
+ function __assignType(fn, args) {
11
+ fn.__type = args;
12
+ return fn;
13
+ }
10
14
  function formatBinaryPath(format) {
11
15
  return `./dist/bin.${format === "cjs" || Array.isArray(format) && format.includes("cjs") ? "cjs" : "mjs"}`;
12
16
  }
17
+ formatBinaryPath.__type = [
18
+ "format",
19
+ "formatBinaryPath",
20
+ "PP&&F-J2!&/\""
21
+ ];
13
22
  async function updatePackageJsonBinary(context) {
14
23
  const packageJsonPath = joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot, "package.json");
15
24
  if (context.config.bin && Array.isArray(context.config.bin) && context.config.bin.length > 0) {
16
- context.packageJson.bin = Object.fromEntries(getUnique(toArray(context.config.bin)).map((bin) => [bin, formatBinaryPath(context.config.output.format)]));
25
+ context.packageJson.bin = Object.fromEntries(getUnique(toArray(context.config.bin)).map(__assignType((bin) => [bin, formatBinaryPath(context.config.output.format)], [
26
+ "bin",
27
+ "",
28
+ "P\"2!\"/\""
29
+ ])));
17
30
  await context.fs.write(packageJsonPath, StormJSON.stringify(context.packageJson));
18
31
  } else {
19
32
  if (Array.isArray(context.config.output.format) && context.config.output.format.length > 1) {
20
33
  context.packageJson.bin = { [kebabCase(getAppName(context))]: formatBinaryPath(toArray(context.config.output.format)[0]) };
21
- context.packageJson.bin = toArray(context.config.output.format).reduce((ret, format) => {
34
+ context.packageJson.bin = toArray(context.config.output.format).reduce(__assignType((ret, format) => {
22
35
  ret[`${kebabCase(getAppName(context))}-${format}`] = formatBinaryPath(format);
23
36
  return ret;
24
- }, context.packageJson.bin);
37
+ }, [
38
+ "ret",
39
+ "format",
40
+ "",
41
+ "P\"2!\"2\"\"/#"
42
+ ]), context.packageJson.bin);
25
43
  } else context.packageJson.bin = { [kebabCase(getAppName(context))]: formatBinaryPath(context.config.output.format) };
26
44
  await context.fs.write(packageJsonPath, StormJSON.stringify(context.packageJson));
27
45
  }
28
46
  if (!isSetObject(context.packageJson.bin)) throw new Error("Unable to determine the CLI binary name. Please specify the `bin` option in your Shell Shock configuration or ensure that the `name` field is set in your package.json.");
29
47
  context.config.bin = Object.keys(context.packageJson.bin);
30
48
  }
49
+ updatePackageJsonBinary.__type = [
50
+ "UnresolvedContext",
51
+ "context",
52
+ "updatePackageJsonBinary",
53
+ "P\"w!2\"$`/#"
54
+ ];
31
55
 
32
56
  //#endregion
33
57
  export { formatBinaryPath, updatePackageJsonBinary };