@shell-shock/core 0.2.1 → 0.3.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 (148) hide show
  1. package/README.md +1 -1
  2. package/dist/api.cjs +15 -3
  3. package/dist/api.cjs.map +1 -0
  4. package/dist/api.d.cts +9 -1
  5. package/dist/api.d.cts.map +1 -0
  6. package/dist/api.d.mts +9 -1
  7. package/dist/api.d.mts.map +1 -0
  8. package/dist/api.mjs +14 -3
  9. package/dist/api.mjs.map +1 -0
  10. package/dist/components/docs.cjs +105 -0
  11. package/dist/components/docs.cjs.map +1 -0
  12. package/dist/components/docs.d.cts +56 -0
  13. package/dist/components/docs.d.cts.map +1 -0
  14. package/dist/components/docs.d.mts +56 -0
  15. package/dist/components/docs.d.mts.map +1 -0
  16. package/dist/components/docs.mjs +102 -0
  17. package/dist/components/docs.mjs.map +1 -0
  18. package/dist/components/index.cjs +4 -6
  19. package/dist/components/index.d.cts +2 -2
  20. package/dist/components/index.d.mts +2 -2
  21. package/dist/components/index.mjs +2 -2
  22. package/dist/config.cjs +2 -1
  23. package/dist/config.cjs.map +1 -0
  24. package/dist/config.d.cts +2 -1
  25. package/dist/config.d.cts.map +1 -0
  26. package/dist/config.d.mts +2 -1
  27. package/dist/config.d.mts.map +1 -0
  28. package/dist/config.mjs +2 -1
  29. package/dist/config.mjs.map +1 -0
  30. package/dist/contexts/command.cjs +21 -0
  31. package/dist/contexts/command.cjs.map +1 -0
  32. package/dist/contexts/command.d.cts +18 -0
  33. package/dist/contexts/command.d.cts.map +1 -0
  34. package/dist/contexts/command.d.mts +18 -0
  35. package/dist/contexts/command.d.mts.map +1 -0
  36. package/dist/contexts/command.mjs +19 -0
  37. package/dist/contexts/command.mjs.map +1 -0
  38. package/dist/contexts/index.cjs +4 -0
  39. package/dist/contexts/index.d.cts +2 -0
  40. package/dist/contexts/index.d.mts +2 -0
  41. package/dist/contexts/index.mjs +3 -0
  42. package/dist/helpers/docs-helpers.cjs +17 -0
  43. package/dist/helpers/docs-helpers.cjs.map +1 -0
  44. package/dist/helpers/docs-helpers.mjs +16 -0
  45. package/dist/helpers/docs-helpers.mjs.map +1 -0
  46. package/dist/helpers/persistence.cjs +2 -1
  47. package/dist/helpers/persistence.cjs.map +1 -0
  48. package/dist/helpers/persistence.mjs +2 -1
  49. package/dist/helpers/persistence.mjs.map +1 -0
  50. package/dist/helpers/resolve-command.cjs +118 -33
  51. package/dist/helpers/resolve-command.cjs.map +1 -0
  52. package/dist/helpers/resolve-command.mjs +116 -32
  53. package/dist/helpers/resolve-command.mjs.map +1 -0
  54. package/dist/helpers/update-package-json.cjs +18 -10
  55. package/dist/helpers/update-package-json.cjs.map +1 -0
  56. package/dist/helpers/update-package-json.mjs +17 -10
  57. package/dist/helpers/update-package-json.mjs.map +1 -0
  58. package/dist/helpers/utilities.cjs +30 -30
  59. package/dist/helpers/utilities.cjs.map +1 -0
  60. package/dist/helpers/utilities.mjs +29 -28
  61. package/dist/helpers/utilities.mjs.map +1 -0
  62. package/dist/helpers/validations.cjs +97 -0
  63. package/dist/helpers/validations.cjs.map +1 -0
  64. package/dist/helpers/validations.mjs +97 -0
  65. package/dist/helpers/validations.mjs.map +1 -0
  66. package/dist/index.cjs +5 -13
  67. package/dist/index.cjs.map +1 -0
  68. package/dist/index.d.cts +6 -17
  69. package/dist/index.d.mts +6 -17
  70. package/dist/index.mjs +4 -13
  71. package/dist/index.mjs.map +1 -0
  72. package/dist/plugin-utils/context-helpers.cjs +86 -0
  73. package/dist/plugin-utils/context-helpers.cjs.map +1 -0
  74. package/dist/plugin-utils/context-helpers.d.cts +58 -0
  75. package/dist/plugin-utils/context-helpers.d.cts.map +1 -0
  76. package/dist/plugin-utils/context-helpers.d.mts +58 -0
  77. package/dist/plugin-utils/context-helpers.d.mts.map +1 -0
  78. package/dist/plugin-utils/context-helpers.mjs +79 -0
  79. package/dist/plugin-utils/context-helpers.mjs.map +1 -0
  80. package/dist/plugin-utils/get-command-tree.cjs +4 -2
  81. package/dist/plugin-utils/get-command-tree.cjs.map +1 -0
  82. package/dist/plugin-utils/get-command-tree.d.cts +2 -1
  83. package/dist/plugin-utils/get-command-tree.d.cts.map +1 -0
  84. package/dist/plugin-utils/get-command-tree.d.mts +2 -1
  85. package/dist/plugin-utils/get-command-tree.d.mts.map +1 -0
  86. package/dist/plugin-utils/get-command-tree.mjs +5 -2
  87. package/dist/plugin-utils/get-command-tree.mjs.map +1 -0
  88. package/dist/plugin-utils/index.cjs +14 -1
  89. package/dist/plugin-utils/index.d.cts +4 -1
  90. package/dist/plugin-utils/index.d.mts +4 -1
  91. package/dist/plugin-utils/index.mjs +4 -1
  92. package/dist/plugin-utils/reflect.cjs +25 -0
  93. package/dist/plugin-utils/reflect.cjs.map +1 -0
  94. package/dist/plugin-utils/reflect.d.cts +14 -0
  95. package/dist/plugin-utils/reflect.d.cts.map +1 -0
  96. package/dist/plugin-utils/reflect.d.mts +14 -0
  97. package/dist/plugin-utils/reflect.d.mts.map +1 -0
  98. package/dist/plugin-utils/reflect.mjs +24 -0
  99. package/dist/plugin-utils/reflect.mjs.map +1 -0
  100. package/dist/plugin-utils/traverse-command-tree.cjs +33 -0
  101. package/dist/plugin-utils/traverse-command-tree.cjs.map +1 -0
  102. package/dist/plugin-utils/traverse-command-tree.d.cts +23 -0
  103. package/dist/plugin-utils/traverse-command-tree.d.cts.map +1 -0
  104. package/dist/plugin-utils/traverse-command-tree.d.mts +23 -0
  105. package/dist/plugin-utils/traverse-command-tree.d.mts.map +1 -0
  106. package/dist/plugin-utils/traverse-command-tree.mjs +31 -0
  107. package/dist/plugin-utils/traverse-command-tree.mjs.map +1 -0
  108. package/dist/plugin.cjs +267 -0
  109. package/dist/plugin.cjs.map +1 -0
  110. package/dist/plugin.d.cts +13 -0
  111. package/dist/plugin.d.cts.map +1 -0
  112. package/dist/plugin.d.mts +13 -0
  113. package/dist/plugin.d.mts.map +1 -0
  114. package/dist/plugin.mjs +261 -0
  115. package/dist/plugin.mjs.map +1 -0
  116. package/dist/types/command.d.cts +13 -4
  117. package/dist/types/command.d.cts.map +1 -0
  118. package/dist/types/command.d.mts +13 -4
  119. package/dist/types/command.d.mts.map +1 -0
  120. package/dist/types/config.d.cts +73 -10
  121. package/dist/types/config.d.cts.map +1 -0
  122. package/dist/types/config.d.mts +73 -10
  123. package/dist/types/config.d.mts.map +1 -0
  124. package/dist/types/context.d.cts +7 -4
  125. package/dist/types/context.d.cts.map +1 -0
  126. package/dist/types/context.d.mts +7 -4
  127. package/dist/types/context.d.mts.map +1 -0
  128. package/dist/types/index.d.cts +4 -4
  129. package/dist/types/index.d.mts +4 -4
  130. package/dist/types/internal.cjs +0 -0
  131. package/dist/types/internal.d.cts +24 -0
  132. package/dist/types/internal.d.cts.map +1 -0
  133. package/dist/types/internal.d.mts +24 -0
  134. package/dist/types/internal.d.mts.map +1 -0
  135. package/dist/types/internal.mjs +1 -0
  136. package/dist/types/options.d.cts +2 -1
  137. package/dist/types/options.d.cts.map +1 -0
  138. package/dist/types/options.d.mts +2 -1
  139. package/dist/types/options.d.mts.map +1 -0
  140. package/package.json +207 -92
  141. package/dist/components/utils-builtin.cjs +0 -453
  142. package/dist/components/utils-builtin.d.cts +0 -27
  143. package/dist/components/utils-builtin.d.mts +0 -27
  144. package/dist/components/utils-builtin.mjs +0 -447
  145. package/dist/powerlines.cjs +0 -172
  146. package/dist/powerlines.d.cts +0 -12
  147. package/dist/powerlines.d.mts +0 -12
  148. package/dist/powerlines.mjs +0 -168
@@ -1,18 +1,46 @@
1
- import { getUniqueBy } from "@stryke/helpers/get-unique";
1
+ import { getAppTitle, getVariableCommandPathName, isVariableCommandPath } from "../plugin-utils/context-helpers.mjs";
2
+ import { getDefaultOptions } from "./utilities.mjs";
2
3
  import { appendPath } from "@stryke/path/append";
3
4
  import { findFilePath, findFolderName } from "@stryke/path/file-path-fns";
4
5
  import { replacePath } from "@stryke/path/replace";
5
6
  import { resolveParentPath } from "@stryke/path/resolve-parent-path";
6
- import { titleCase } from "@stryke/string-format/title-case";
7
- import { isFunction } from "@stryke/type-checks/is-function";
7
+ import { constantCase } from "@stryke/string-format/constant-case";
8
8
  import { isSetObject } from "@stryke/type-checks/is-set-object";
9
+ import { isSetString } from "@stryke/type-checks/is-set-string";
10
+ import { titleCase } from "@stryke/string-format/title-case";
11
+ import { ReflectionClass, ReflectionKind, ReflectionVisibility, stringifyType } from "@powerlines/deepkit/vendor/type";
9
12
  import { reflectType } from "@powerlines/deepkit/reflect-type";
10
- import { ReflectionClass, ReflectionKind, stringifyType } from "@powerlines/deepkit/vendor/type";
11
13
  import { commonPath } from "@stryke/path/common";
12
14
  import { stripStars } from "@stryke/path/normalize";
13
- import { isSetString } from "@stryke/type-checks/is-set-string";
14
15
 
15
16
  //#region src/helpers/resolve-command.ts
17
+ /**
18
+ * Resolves the description for a command option based on its reflection.
19
+ *
20
+ * @param propertyReflection - The reflection property of the command option.
21
+ * @returns The resolved description for the command option.
22
+ */
23
+ function resolveCommandDescription(propertyReflection) {
24
+ return propertyReflection.getDescription()?.trim() || `A${propertyReflection.isOptional() && !propertyReflection.getDefaultValue() ? "n optional" : ""} ${propertyReflection.getType().kind === ReflectionKind.boolean ? "flag provided via the command-line" : "command-line option"} that allows the user to ${propertyReflection.getType().kind === ReflectionKind.boolean ? "set the" : propertyReflection.getType().kind === ReflectionKind.array ? "specify custom" : "specify a custom"} ${propertyReflection.getTags().title?.trim() || titleCase(propertyReflection.getNameAsString())} ${propertyReflection.getType().kind === ReflectionKind.boolean ? "indicator" : `${propertyReflection.getType().kind === ReflectionKind.number ? "numeric" : "string"} value${propertyReflection.getType().kind === ReflectionKind.array ? "s" : ""}`} that will be used in the application.`;
25
+ }
26
+ function resolveCommandId(context, file) {
27
+ return replacePath(findFilePath(file), context.commandsPath).split("/").filter((p) => Boolean(p) && !isVariableCommandPath(p)).join("/").replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "").replaceAll("/", "-");
28
+ }
29
+ /**
30
+ * Finds the command name from the given file path.
31
+ *
32
+ * @param file - The file path to extract the command name from.
33
+ * @returns The command name.
34
+ */
35
+ function resolveCommandName(file) {
36
+ let path = findFilePath(file);
37
+ let name = findFolderName(file, { requireExtension: true });
38
+ while (isVariableCommandPath(name)) {
39
+ path = resolveParentPath(path);
40
+ name = findFolderName(path, { requireExtension: true });
41
+ }
42
+ return name;
43
+ }
16
44
  function resolveCommandPath(context, file) {
17
45
  return replacePath(findFilePath(file), context.commandsPath).replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "");
18
46
  }
@@ -23,35 +51,46 @@ function findCommandsRoot(context) {
23
51
  return appendPath(context.config.sourceRoot || context.config.projectRoot, context.workspaceConfig.workspaceRoot);
24
52
  }
25
53
  /**
26
- * Finds the command name from the given file path.
54
+ * Extracts command parameter information from a type parameter reflection.
27
55
  *
28
- * @param file - The file path to extract the command name from.
29
- * @returns The command name.
56
+ * @param param - The type parameter reflection to extract information from.
57
+ * @returns The extracted command parameter information.
30
58
  */
31
- function findCommandName(file) {
32
- let name = findFolderName(file);
33
- let count = 1;
34
- while (name.startsWith("[") && name.endsWith("]")) name = findFolderName(resolveParentPath(file, count++));
35
- return name;
59
+ function extractCommandParameters(param) {
60
+ return {
61
+ name: param.name,
62
+ description: param.description,
63
+ optional: !!param.optional,
64
+ variadic: param.type.kind === ReflectionKind.array,
65
+ default: param.default
66
+ };
36
67
  }
68
+ /**
69
+ * Reflects the command tree for a given command input.
70
+ *
71
+ * @param context - The context in which the command is being reflected.
72
+ * @param command - The command input to reflect.
73
+ * @param parent - The parent command tree, if any.
74
+ * @returns The reflected command tree.
75
+ */
37
76
  async function reflectCommandTree(context, command, parent) {
38
- const title = command.title || `${parent?.title ? `${parent.title} - ` : ""}${titleCase(command.name)}`;
39
- const commandTree = {
77
+ const title = command.title || `${parent?.title ? `${parent.title} - ` : ""}${titleCase(command.name)}${command.isVirtual ? " Commands" : ""}`;
78
+ const tree = {
40
79
  ...command,
41
80
  title,
42
- description: command.description || `The ${title} ${parent ? "sub-" : ""}command.`,
43
- options: {},
81
+ description: command.description || (command.isVirtual ? `A collection of available ${command.title || titleCase(command.name)} commands that are included in the ${getAppTitle(context)} command-line application.` : `The ${title} executable command-line interface.`),
82
+ path: {
83
+ ...command.path,
84
+ variables: {}
85
+ },
86
+ options: getDefaultOptions(context, command),
44
87
  params: [],
45
88
  parent: parent ?? null,
46
89
  children: {}
47
90
  };
48
- if (context.config.defaultOptions === false) commandTree.options = {};
49
- else if (Array.isArray(context.config.defaultOptions)) commandTree.options = Object.fromEntries(getUniqueBy(context.config.defaultOptions, (item) => item.name).map((option) => [option.name, option]));
50
- else if (isFunction(context.config.defaultOptions)) commandTree.options = Object.fromEntries(getUniqueBy(context.config.defaultOptions(context, command), (item) => item.name).map((option) => [option.name, option]));
51
- if (command.isVirtual) context.trace(`Adding reflection for virtual command: ${command.id}`);
52
- else {
91
+ if (!command.isVirtual) {
53
92
  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}"`);
54
- context.trace(`Adding reflection for user-defined command: ${command.id} (file: ${command.entry.input.file})`);
93
+ context.debug(`Adding reflection for user-defined command: ${command.id} (file: ${command.entry.input.file})`);
55
94
  const type = await reflectType(context, command.entry.input);
56
95
  if (type.kind !== ReflectionKind.function) throw new Error(`The command entry file "${command.entry.input.file}" does not export a valid function.`);
57
96
  if (type.parameters.length > 0 && type.parameters[0]) {
@@ -60,29 +99,74 @@ async function reflectCommandTree(context, command, parent) {
60
99
  const optionsReflection = ReflectionClass.from(firstParam.type);
61
100
  for (const propertyReflection of optionsReflection.getProperties()) {
62
101
  const propertyType = propertyReflection.getType();
63
- commandTree.options[propertyReflection.getNameAsString()] = {
102
+ tree.options[propertyReflection.getNameAsString()] = {
64
103
  name: propertyReflection.getNameAsString(),
65
104
  alias: propertyReflection.getTags().alias ?? [],
66
- title: propertyReflection.getTags().title || titleCase(propertyReflection.getNameAsString()),
67
- description: propertyReflection.getDescription(),
105
+ title: propertyReflection.getTags().title?.trim() || titleCase(propertyReflection.getNameAsString()),
106
+ description: resolveCommandDescription(propertyReflection),
107
+ env: constantCase(propertyReflection.getNameAsString()),
68
108
  kind: propertyType.kind,
69
109
  optional: propertyReflection.isOptional(),
70
110
  default: propertyReflection.getDefaultValue(),
71
111
  variadic: false
72
112
  };
73
- commandTree.options[propertyReflection.getNameAsString()].description ??= `The ${commandTree.options[propertyReflection.getNameAsString()].title} option.`;
74
113
  if (propertyType.kind === ReflectionKind.array) if (propertyType.type.kind === ReflectionKind.string || propertyType.type.kind === ReflectionKind.number) {
75
- commandTree.options[propertyReflection.getNameAsString()].variadic = true;
76
- commandTree.options[propertyReflection.getNameAsString()].kind = propertyType.type.kind;
114
+ tree.options[propertyReflection.getNameAsString()].variadic = true;
115
+ tree.options[propertyReflection.getNameAsString()].kind = propertyType.type.kind;
77
116
  } else throw new Error(`Unsupported array type for option "${propertyReflection.getNameAsString()}" in command "${command.name}". Only string[] and number[] are supported.`);
78
117
  else if (propertyType.kind !== ReflectionKind.boolean && propertyType.kind !== ReflectionKind.string && propertyType.kind !== ReflectionKind.number) throw new Error(`Unsupported type for option "${propertyReflection.getNameAsString()}" in command "${command.name}". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(propertyType).trim().replaceAll(" | ", ", or ")}.`);
79
118
  }
80
119
  }
120
+ tree.path.variables = tree.path.segments.filter((segment) => isVariableCommandPath(segment)).reduce((obj, segment, index) => {
121
+ if (type.parameters.length < index + 2 || !type.parameters[index + 1]) return obj;
122
+ const paramName = getVariableCommandPathName(segment);
123
+ obj[paramName] = extractCommandParameters(type.parameters[index + 1]);
124
+ obj[paramName].description = obj[paramName].description || `The ${paramName} variable for the ${command.name} command.`;
125
+ return obj;
126
+ }, {});
127
+ if (type.parameters.length > 1) type.parameters.slice(tree.path.segments.filter((segment) => isVariableCommandPath(segment)).length + 1).forEach((param) => {
128
+ tree.params.push(extractCommandParameters(param));
129
+ });
81
130
  }
82
131
  }
83
- for (const input of context.inputs.filter((input$1) => input$1.path.length === command.path.length + 1 && input$1.path.slice(0, command.path.length).every((value, index) => value === command.path[index]))) commandTree.children[input.name] = await reflectCommandTree(context, input, commandTree);
84
- return commandTree;
132
+ if (context.env) {
133
+ if (isSetObject(tree.options)) Object.values(tree.options).filter((option) => option.env !== false).forEach((option) => {
134
+ context.env.types.env.addProperty({
135
+ name: option.env,
136
+ optional: option.optional ? true : void 0,
137
+ description: option.description,
138
+ visibility: ReflectionVisibility.public,
139
+ type: option.kind === ReflectionKind.string || option.kind === ReflectionKind.number ? option.variadic ? {
140
+ kind: ReflectionKind.array,
141
+ type: { kind: option.kind }
142
+ } : { kind: option.kind } : { kind: ReflectionKind.boolean },
143
+ default: option.default,
144
+ tags: {
145
+ title: option.title,
146
+ alias: option.alias.filter((alias) => alias.length > 0).map((alias) => constantCase(alias)),
147
+ domain: "cli"
148
+ }
149
+ });
150
+ });
151
+ if (tree.params) tree.params.forEach((param) => {
152
+ context.env.types.env.addProperty({
153
+ name: constantCase(param.name),
154
+ optional: param.optional ? true : void 0,
155
+ description: param.description,
156
+ visibility: ReflectionVisibility.public,
157
+ type: param.variadic ? {
158
+ kind: ReflectionKind.array,
159
+ type: { kind: ReflectionKind.string }
160
+ } : { kind: ReflectionKind.string },
161
+ default: param.default,
162
+ tags: { domain: "cli" }
163
+ });
164
+ });
165
+ }
166
+ for (const input of context.inputs.filter((input$1) => input$1.path.segments.filter((segment) => !isVariableCommandPath(segment)).length === command.path.segments.filter((segment) => !isVariableCommandPath(segment)).length + 1 && input$1.path.segments.slice(0, command.path.segments.length).every((value, index) => value === command.path.segments[index]))) tree.children[input.name] = await reflectCommandTree(context, input, tree);
167
+ return tree;
85
168
  }
86
169
 
87
170
  //#endregion
88
- export { findCommandName, findCommandsRoot, reflectCommandTree, resolveCommandPath };
171
+ export { findCommandsRoot, reflectCommandTree, resolveCommandId, resolveCommandName, resolveCommandPath };
172
+ //# sourceMappingURL=resolve-command.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-command.mjs","names":["reflectType","ReflectionClass","ReflectionKind","ReflectionVisibility","stringifyType","appendPath","commonPath","findFilePath","findFolderName","stripStars","replacePath","resolveParentPath","constantCase","titleCase","isSetObject","isSetString","getAppTitle","getVariableCommandPathName","isVariableCommandPath","getDefaultOptions","resolveCommandDescription","propertyReflection","getDescription","trim","isOptional","getDefaultValue","getType","kind","boolean","array","getTags","title","getNameAsString","number","resolveCommandId","context","file","commandsPath","split","filter","p","Boolean","join","replaceAll","resolveCommandName","path","name","requireExtension","resolveCommandPath","resolveCommandParams","map","findCommandsRoot","config","entry","projectRoot","workspaceConfig","workspaceRoot","Array","isArray","length","sourceRoot","extractCommandParameters","param","description","optional","variadic","type","default","reflectCommandTree","command","parent","isVirtual","tree","variables","options","params","children","input","fs","existsSync","Error","debug","id","function","parameters","firstParam","objectLiteral","class","optionsReflection","from","getProperties","propertyType","alias","env","string","segments","segment","reduce","obj","index","paramName","slice","forEach","push","Object","values","option","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 { reflectType } from \"@powerlines/deepkit/reflect-type\";\nimport type {\n ReflectionProperty,\n TypeParameter\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n ReflectionClass,\n ReflectionKind,\n ReflectionVisibility,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\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 {\n getAppTitle,\n getVariableCommandPathName,\n isVariableCommandPath\n} from \"../plugin-utils/context-helpers\";\nimport type {\n CommandInput,\n CommandParam,\n CommandTree,\n NumberCommandOption,\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 propertyReflection - The reflection property of the command option.\n * @returns The resolved description for the command option.\n */\nexport function resolveCommandDescription(\n propertyReflection: ReflectionProperty\n): string {\n return (\n propertyReflection.getDescription()?.trim() ||\n `A${\n propertyReflection.isOptional() && !propertyReflection.getDefaultValue()\n ? \"n optional\"\n : \"\"\n } ${\n propertyReflection.getType().kind === ReflectionKind.boolean\n ? \"flag provided via the command-line\"\n : \"command-line option\"\n } that allows the user to ${\n propertyReflection.getType().kind === ReflectionKind.boolean\n ? \"set the\"\n : propertyReflection.getType().kind === ReflectionKind.array\n ? \"specify custom\"\n : \"specify a custom\"\n } ${\n propertyReflection.getTags().title?.trim() ||\n titleCase(propertyReflection.getNameAsString())\n } ${\n propertyReflection.getType().kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${propertyReflection.getType().kind === ReflectionKind.number ? \"numeric\" : \"string\"} value${\n propertyReflection.getType().kind === ReflectionKind.array\n ? \"s\"\n : \"\"\n }`\n } that will be used in the application.`\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) && !isVariableCommandPath(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 (isVariableCommandPath(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}\n\nexport function resolveCommandParams(context: Context, file: string): string[] {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && isVariableCommandPath(p))\n .map(p => p.replaceAll(/^\\[+/g, \"\").replaceAll(/\\]+$/g, \"\"));\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 param - The type parameter reflection to extract information from.\n * @returns The extracted command parameter information.\n */\nexport function extractCommandParameters(param: TypeParameter): CommandParam {\n return {\n name: param.name,\n description: param.description,\n optional: !!param.optional,\n variadic: param.type.kind === ReflectionKind.array,\n default: param.default\n } as CommandParam;\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 `${parent?.title ? `${parent.title} - ` : \"\"}${titleCase(command.name)}${\n command.isVirtual ? \" Commands\" : \"\"\n }`;\n\n const tree = {\n ...command,\n title,\n description:\n command.description ||\n (command.isVirtual\n ? `A collection of available ${command.title || titleCase(command.name)} commands that are included in the ${getAppTitle(\n context\n )} command-line application.`\n : `The ${title} executable command-line interface.`),\n path: {\n ...command.path,\n variables: {}\n },\n options: getDefaultOptions(context, command),\n params: [],\n parent: parent ?? null,\n children: {}\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 type = await reflectType<TContext>(context, command.entry.input);\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 if (type.parameters.length > 0 && type.parameters[0]) {\n const firstParam = type.parameters[0];\n if (\n firstParam.type.kind === ReflectionKind.objectLiteral ||\n firstParam.type.kind === ReflectionKind.class\n ) {\n const optionsReflection = ReflectionClass.from(firstParam.type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n const propertyType = propertyReflection.getType();\n\n tree.options[propertyReflection.getNameAsString()] = {\n name: propertyReflection.getNameAsString(),\n alias: propertyReflection.getTags().alias ?? [],\n title:\n propertyReflection.getTags().title?.trim() ||\n titleCase(propertyReflection.getNameAsString()),\n description: resolveCommandDescription(propertyReflection),\n env: constantCase(propertyReflection.getNameAsString()),\n kind: propertyType.kind as\n | ReflectionKind.string\n | ReflectionKind.number\n | ReflectionKind.boolean,\n optional: propertyReflection.isOptional(),\n default: propertyReflection.getDefaultValue(),\n variadic: false\n };\n if (propertyType.kind === ReflectionKind.array) {\n if (\n propertyType.type.kind === ReflectionKind.string ||\n propertyType.type.kind === ReflectionKind.number\n ) {\n (\n tree.options[propertyReflection.getNameAsString()] as\n | StringCommandOption\n | NumberCommandOption\n ).variadic = true;\n (\n tree.options[propertyReflection.getNameAsString()] as\n | StringCommandOption\n | NumberCommandOption\n ).kind = propertyType.type.kind;\n } else {\n throw new Error(\n `Unsupported array type for option \"${propertyReflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported.`\n );\n }\n } else if (\n propertyType.kind !== ReflectionKind.boolean &&\n propertyType.kind !== ReflectionKind.string &&\n propertyType.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${propertyReflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n propertyType\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n }\n }\n\n tree.path.variables = tree.path.segments\n .filter(segment => isVariableCommandPath(segment))\n .reduce(\n (obj, segment, index) => {\n if (\n type.parameters.length < index + 2 ||\n !type.parameters[index + 1]\n ) {\n return obj;\n }\n\n const paramName = getVariableCommandPathName(segment);\n obj[paramName] = extractCommandParameters(\n type.parameters[index + 1]!\n );\n obj[paramName].description =\n obj[paramName].description ||\n `The ${paramName} variable for the ${command.name} command.`;\n\n return obj;\n },\n {} as Record<string, CommandParam>\n );\n\n if (type.parameters.length > 1) {\n type.parameters\n .slice(\n tree.path.segments.filter(segment => isVariableCommandPath(segment))\n .length + 1\n )\n .forEach(param => {\n tree.params.push(extractCommandParameters(param));\n });\n }\n }\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.kind === ReflectionKind.string ||\n option.kind === ReflectionKind.number\n ? option.variadic\n ? { kind: ReflectionKind.array, type: { kind: option.kind } }\n : { kind: option.kind }\n : { kind: ReflectionKind.boolean },\n default: option.default,\n tags: {\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 0)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n if (tree.params) {\n tree.params.forEach(param => {\n context.env.types.env.addProperty({\n name: constantCase(param.name),\n optional: param.optional ? true : undefined,\n description: param.description,\n visibility: ReflectionVisibility.public,\n type: param.variadic\n ? {\n kind: ReflectionKind.array,\n type: { kind: ReflectionKind.string }\n }\n : { kind: ReflectionKind.string },\n default: param.default,\n tags: {\n domain: \"cli\"\n }\n });\n });\n }\n }\n\n for (const input of context.inputs.filter(\n input =>\n input.path.segments.filter(segment => !isVariableCommandPath(segment))\n .length ===\n command.path.segments.filter(segment => !isVariableCommandPath(segment))\n .length +\n 1 &&\n input.path.segments\n .slice(0, command.path.segments.length)\n .every((value, index) => value === command.path.segments[index])\n )) {\n tree.children[input.name] = await reflectCommandTree(context, input, tree);\n }\n\n return tree;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA4DA,SAAgBoB,0BACdC,oBACQ;AACR,QACEA,mBAAmBC,gBAAgB,EAAEC,MAAM,IAC3C,IACEF,mBAAmBG,YAAY,IAAI,CAACH,mBAAmBI,iBAAiB,GACpE,eACA,GAAE,GAENJ,mBAAmBK,SAAS,CAACC,SAASzB,eAAe0B,UACjD,uCACA,sBAAqB,2BAEzBP,mBAAmBK,SAAS,CAACC,SAASzB,eAAe0B,UACjD,YACAP,mB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MAAMG,WACR;KACEtC,MAAMzB,eAAe2B;KACrBqC,MAAM,EAAEvC,MAAMzB,eAAe4F,QAAO;KACrC,GACD,EAAEnE,MAAMzB,eAAe4F,QAAQ;IACnC3B,SAASL,MAAMK;IACf6C,MAAM,EACJC,QAAQ,OACV;IACD,CAAC;IACF;;AAIN,MAAK,MAAMpC,SAAS1C,QAAQ+E,OAAO3E,QACjCsC,YACEA,QAAMhC,KAAKkD,SAASxD,QAAOyD,YAAW,CAAC9E,sBAAsB8E,QAAQ,CAAC,CACnErC,WACDU,QAAQxB,KAAKkD,SAASxD,QAAOyD,YAAW,CAAC9E,sBAAsB8E,QAAQ,CAAC,CACrErC,SACD,KACJkB,QAAMhC,KAAKkD,SACRM,MAAM,GAAGhC,QAAQxB,KAAKkD,SAASpC,OAAO,CACtCwD,OAAOC,OAAOjB,UAAUiB,UAAU/C,QAAQxB,KAAKkD,SAASI,OAC/D,CAAC,CACC3B,MAAKI,SAASC,MAAM/B,QAAQ,MAAMsB,mBAAmBjC,SAAS0C,OAAOL,KAAK;AAG5E,QAAOA"}
@@ -1,23 +1,29 @@
1
1
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
- let __stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
2
+ const require_plugin_utils_context_helpers = require('../plugin-utils/context-helpers.cjs');
3
+ let __stryke_convert_to_array = require("@stryke/convert/to-array");
3
4
  let __stryke_path_join_paths = require("@stryke/path/join-paths");
4
- let __stryke_path_replace = require("@stryke/path/replace");
5
+ let __stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
5
6
  let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
6
- let __stryke_convert_to_array = require("@stryke/convert/to-array");
7
+ let __stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
7
8
  let __stryke_json_storm_json = require("@stryke/json/storm-json");
8
- let __stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
9
9
 
10
10
  //#region src/helpers/update-package-json.ts
11
- function formatBinaryPath(name, format) {
12
- return `./bin/${(0, __stryke_string_format_kebab_case.kebabCase)((0, __stryke_path_replace.replaceExtension)(name))}.${format === "cjs" || Array.isArray(format) && format.includes("cjs") ? "cjs" : "mjs"}`;
11
+ function formatBinaryPath(format) {
12
+ return `./dist/bin.${format === "cjs" || Array.isArray(format) && format.includes("cjs") ? "cjs" : "mjs"}`;
13
13
  }
14
14
  async function updatePackageJsonBinary(context) {
15
15
  const packageJsonPath = (0, __stryke_path_join_paths.joinPaths)(context.workspaceConfig.workspaceRoot, context.config.projectRoot, "package.json");
16
16
  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(bin, context.config.output.format)]));
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)]));
18
18
  await context.fs.write(packageJsonPath, __stryke_json_storm_json.StormJSON.stringify(context.packageJson));
19
- } else if (!(0, __stryke_type_checks_is_set_object.isSetObject)(context.packageJson.bin) && (context.config.name || context.packageJson.name)) {
20
- context.packageJson.bin = { [context.config.name || context.packageJson.name]: formatBinaryPath(context.config.name || context.packageJson.name, context.config.output.format) };
19
+ } else {
20
+ if (Array.isArray(context.config.output.format) && context.config.output.format.length > 1) {
21
+ 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) => {
23
+ ret[`${(0, __stryke_string_format_kebab_case.kebabCase)(require_plugin_utils_context_helpers.getAppName(context))}-${format}`] = formatBinaryPath(format);
24
+ return ret;
25
+ }, context.packageJson.bin);
26
+ } else context.packageJson.bin = { [(0, __stryke_string_format_kebab_case.kebabCase)(require_plugin_utils_context_helpers.getAppName(context))]: formatBinaryPath(context.config.output.format) };
21
27
  await context.fs.write(packageJsonPath, __stryke_json_storm_json.StormJSON.stringify(context.packageJson));
22
28
  }
23
29
  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.");
@@ -25,4 +31,6 @@ async function updatePackageJsonBinary(context) {
25
31
  }
26
32
 
27
33
  //#endregion
28
- exports.updatePackageJsonBinary = updatePackageJsonBinary;
34
+ exports.formatBinaryPath = formatBinaryPath;
35
+ exports.updatePackageJsonBinary = updatePackageJsonBinary;
36
+ //# sourceMappingURL=update-package-json.cjs.map
@@ -0,0 +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,SA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,OAAOE,MAAMG,OAAOU,KAAKnB,QAAQQ,YAAYF,IAAI"}
@@ -1,22 +1,28 @@
1
- import { getUnique } from "@stryke/helpers/get-unique";
1
+ import { getAppName } from "../plugin-utils/context-helpers.mjs";
2
+ import { toArray } from "@stryke/convert/to-array";
2
3
  import { joinPaths } from "@stryke/path/join-paths";
3
- import { replaceExtension } from "@stryke/path/replace";
4
+ import { kebabCase } from "@stryke/string-format/kebab-case";
4
5
  import { isSetObject } from "@stryke/type-checks/is-set-object";
5
- import { toArray } from "@stryke/convert/to-array";
6
+ import { getUnique } from "@stryke/helpers/get-unique";
6
7
  import { StormJSON } from "@stryke/json/storm-json";
7
- import { kebabCase } from "@stryke/string-format/kebab-case";
8
8
 
9
9
  //#region src/helpers/update-package-json.ts
10
- function formatBinaryPath(name, format) {
11
- return `./bin/${kebabCase(replaceExtension(name))}.${format === "cjs" || Array.isArray(format) && format.includes("cjs") ? "cjs" : "mjs"}`;
10
+ function formatBinaryPath(format) {
11
+ return `./dist/bin.${format === "cjs" || Array.isArray(format) && format.includes("cjs") ? "cjs" : "mjs"}`;
12
12
  }
13
13
  async function updatePackageJsonBinary(context) {
14
14
  const packageJsonPath = joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot, "package.json");
15
15
  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(bin, context.config.output.format)]));
16
+ context.packageJson.bin = Object.fromEntries(getUnique(toArray(context.config.bin)).map((bin) => [bin, formatBinaryPath(context.config.output.format)]));
17
17
  await context.fs.write(packageJsonPath, StormJSON.stringify(context.packageJson));
18
- } else if (!isSetObject(context.packageJson.bin) && (context.config.name || context.packageJson.name)) {
19
- context.packageJson.bin = { [context.config.name || context.packageJson.name]: formatBinaryPath(context.config.name || context.packageJson.name, context.config.output.format) };
18
+ } else {
19
+ if (Array.isArray(context.config.output.format) && context.config.output.format.length > 1) {
20
+ 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) => {
22
+ ret[`${kebabCase(getAppName(context))}-${format}`] = formatBinaryPath(format);
23
+ return ret;
24
+ }, context.packageJson.bin);
25
+ } else context.packageJson.bin = { [kebabCase(getAppName(context))]: formatBinaryPath(context.config.output.format) };
20
26
  await context.fs.write(packageJsonPath, StormJSON.stringify(context.packageJson));
21
27
  }
22
28
  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.");
@@ -24,4 +30,5 @@ async function updatePackageJsonBinary(context) {
24
30
  }
25
31
 
26
32
  //#endregion
27
- export { updatePackageJsonBinary };
33
+ export { formatBinaryPath, updatePackageJsonBinary };
34
+ //# sourceMappingURL=update-package-json.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-package-json.mjs","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":";;;;;;;;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,QAAQQ,YAC9B,CAAC;;AAGH,KAAI,CAAChB,YAAYQ,QAAQQ,YAAYF,IAAI,CACvC,OAAM,IAAIY,MACR,0KACD;AAGHlB,SAAQI,OAAOE,MAAMG,OAAOU,KAAKnB,QAAQQ,YAAYF,IAAI"}
@@ -1,41 +1,41 @@
1
1
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
- let __stryke_string_format_title_case = require("@stryke/string-format/title-case");
3
- let __stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
4
- let __stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
2
+ let __stryke_string_format_constant_case = require("@stryke/string-format/constant-case");
3
+ let __stryke_cli_utils_tree = require("@stryke/cli/utils/tree");
4
+ let __stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
5
+ let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
5
6
 
6
7
  //#region src/helpers/utilities.ts
7
- /**
8
- * Retrieves the application name from the context and configuration.
9
- *
10
- * @param context - The build context containing workspace and package information.
11
- * @returns The application name in kebab-case format.
12
- * @throws An error if no valid application name is found.
13
- */
14
- function getAppName(context) {
15
- const result = context.config.bin && ((0, __stryke_type_checks_is_set_string.isSetString)(context.config.bin) || Array.isArray(context.config.bin) && context.config.bin.length > 0 && context.config.bin[0]) ? (0, __stryke_type_checks_is_set_string.isSetString)(context.config.bin) ? context.config.bin : context.config.bin[0] : context.config.name || context.packageJson?.name;
16
- if (!(0, __stryke_type_checks_is_set_string.isSetString)(result)) throw new Error("No application name found. Please provide a 'bin' option in the configuration or ensure the package.json has a valid 'name' field.");
17
- return (0, __stryke_string_format_kebab_case.kebabCase)(result);
8
+ function innerFormatCommandTree(command) {
9
+ return {
10
+ name: `${command.name}${command.isVirtual ? " (virtual)" : ""}`,
11
+ children: Object.values(command.children ?? {}).map(innerFormatCommandTree)
12
+ };
18
13
  }
19
- /**
20
- * Retrieves the application title from the context and configuration.
21
- *
22
- * @param context - The build context containing workspace and package information.
23
- * @returns The application title in title-case format.
24
- */
25
- function getAppTitle(context) {
26
- return (0, __stryke_string_format_title_case.titleCase)(context.config.name || getAppName(context));
14
+ function formatCommandTree(context) {
15
+ return (0, __stryke_cli_utils_tree.formatTree)({
16
+ name: context.config.name,
17
+ children: Object.values(context.commands ?? {}).map(innerFormatCommandTree)
18
+ });
27
19
  }
28
20
  /**
29
- * Retrieves the application description from the context and configuration.
21
+ * Retrieves the default command options based on the context configuration.
30
22
  *
31
- * @param context - The build context containing workspace and package information.
32
- * @returns The application description.
23
+ * @param context - The build context.
24
+ * @param command - The command for which to retrieve default options.
25
+ * @returns A record of default command options.
33
26
  */
34
- function getAppDescription(context) {
35
- return context.config.description || context.packageJson?.description || `The ${getAppTitle(context)} command-line interface application.`;
27
+ function getDefaultOptions(context, command) {
28
+ let options;
29
+ if (Array.isArray(context.config.defaultOptions)) options = Object.fromEntries((0, __stryke_helpers_get_unique.getUniqueBy)(context.config.defaultOptions, (item) => item.name).map((option) => [option.name, option]));
30
+ else if ((0, __stryke_type_checks_is_function.isFunction)(context.config.defaultOptions)) options = Object.fromEntries((0, __stryke_helpers_get_unique.getUniqueBy)(context.config.defaultOptions(context, command), (item) => item.name).map((option) => [option.name, option]));
31
+ else options = {};
32
+ return Object.fromEntries(Object.entries(options).map(([key, value]) => [key, {
33
+ ...value,
34
+ env: value.env ?? (0, __stryke_string_format_constant_case.constantCase)(key)
35
+ }]));
36
36
  }
37
37
 
38
38
  //#endregion
39
- exports.getAppDescription = getAppDescription;
40
- exports.getAppName = getAppName;
41
- exports.getAppTitle = getAppTitle;
39
+ exports.formatCommandTree = formatCommandTree;
40
+ exports.getDefaultOptions = getDefaultOptions;
41
+ //# sourceMappingURL=utilities.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.cjs","names":["formatTree","getUniqueBy","constantCase","isFunction","innerFormatCommandTree","command","name","isVirtual","children","Object","values","map","formatCommandTree","context","config","commands","getDefaultOptions","options","Array","isArray","defaultOptions","fromEntries","item","option","entries","key","value","env"],"sources":["../../src/helpers/utilities.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { TreeItem } from \"@stryke/cli/utils/tree\";\nimport { formatTree } from \"@stryke/cli/utils/tree\";\nimport { getUniqueBy } from \"@stryke/helpers/get-unique\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport type { CommandBase, CommandOption, CommandTree } from \"../types/command\";\nimport type { Context } from \"../types/context\";\n\nfunction innerFormatCommandTree(command: CommandTree): TreeItem {\n return {\n name: `${command.name}${command.isVirtual ? \" (virtual)\" : \"\"}`,\n children: Object.values(command.children ?? {}).map(innerFormatCommandTree)\n };\n}\n\nexport function formatCommandTree(context: Context): string {\n return formatTree({\n name: context.config.name,\n children: Object.values(context.commands ?? {}).map(innerFormatCommandTree)\n });\n}\n\n/**\n * Retrieves the default command options based on the context configuration.\n *\n * @param context - The build context.\n * @param command - The command for which to retrieve default options.\n * @returns A record of default command options.\n */\nexport function getDefaultOptions(\n context: Context,\n command: CommandBase\n): Record<string, CommandOption> {\n let options!: Record<string, CommandOption>;\n if (Array.isArray(context.config.defaultOptions)) {\n options = Object.fromEntries(\n getUniqueBy(\n context.config.defaultOptions,\n (item: CommandOption) => item.name\n ).map(option => [option.name, option])\n );\n } else if (isFunction(context.config.defaultOptions)) {\n options = Object.fromEntries(\n getUniqueBy(\n context.config.defaultOptions(context, command),\n (item: CommandOption) => item.name\n ).map(option => [option.name, option])\n );\n } else {\n options = {};\n }\n\n return Object.fromEntries(\n Object.entries(options).map(([key, value]) => [\n key,\n { ...value, env: value.env ?? constantCase(key) }\n ])\n );\n}\n"],"mappings":";;;;;;;AA0BA,SAASI,uBAAuBC,SAAgC;AAC9D,QAAO;EACLC,MAAM,GAAGD,QAAQC,OAAOD,QAAQE,YAAY,eAAe;EAC3DC,UAAUC,OAAOC,OAAOL,QAAQG,YAAY,EAAE,CAAC,CAACG,IAAIP,uBAAsB;EAC3E;;AAGH,SAAgBQ,kBAAkBC,SAA0B;AAC1D,gDAAkB;EAChBP,MAAMO,QAAQC,OAAOR;EACrBE,UAAUC,OAAOC,OAAOG,QAAQE,YAAY,EAAE,CAAC,CAACJ,IAAIP,uBAAsB;EAC3E,CAAC;;;;;;;;;AAUJ,SAAgBY,kBACdH,SACAR,SAC+B;CAC/B,IAAIY;AACJ,KAAIC,MAAMC,QAAQN,QAAQC,OAAOM,eAAe,CAC9CH,WAAUR,OAAOY,yDAEbR,QAAQC,OAAOM,iBACdE,SAAwBA,KAAKhB,KAC/B,CAACK,KAAIY,WAAU,CAACA,OAAOjB,MAAMiB,OAAO,CACvC,CAAC;2DACmBV,QAAQC,OAAOM,eAAe,CAClDH,WAAUR,OAAOY,yDAEbR,QAAQC,OAAOM,eAAeP,SAASR,QAAQ,GAC9CiB,SAAwBA,KAAKhB,KAC/B,CAACK,KAAIY,WAAU,CAACA,OAAOjB,MAAMiB,OAAO,CACvC,CAAC;KAEDN,WAAU,EAAE;AAGd,QAAOR,OAAOY,YACZZ,OAAOe,QAAQP,QAAQ,CAACN,KAAK,CAACc,KAAKC,WAAW,CAC5CD,KACA;EAAE,GAAGC;EAAOC,KAAKD,MAAMC,8DAAoBF,IAAG;EAAG,CAClD,CACH,CAAC"}
@@ -1,38 +1,39 @@
1
- import { titleCase } from "@stryke/string-format/title-case";
2
- import { isSetString } from "@stryke/type-checks/is-set-string";
3
- import { kebabCase } from "@stryke/string-format/kebab-case";
1
+ import { constantCase } from "@stryke/string-format/constant-case";
2
+ import { formatTree } from "@stryke/cli/utils/tree";
3
+ import { getUniqueBy } from "@stryke/helpers/get-unique";
4
+ import { isFunction } from "@stryke/type-checks/is-function";
4
5
 
5
6
  //#region src/helpers/utilities.ts
6
- /**
7
- * Retrieves the application name from the context and configuration.
8
- *
9
- * @param context - The build context containing workspace and package information.
10
- * @returns The application name in kebab-case format.
11
- * @throws An error if no valid application name is found.
12
- */
13
- function getAppName(context) {
14
- const result = context.config.bin && (isSetString(context.config.bin) || Array.isArray(context.config.bin) && context.config.bin.length > 0 && context.config.bin[0]) ? isSetString(context.config.bin) ? context.config.bin : context.config.bin[0] : context.config.name || context.packageJson?.name;
15
- if (!isSetString(result)) throw new Error("No application name found. Please provide a 'bin' option in the configuration or ensure the package.json has a valid 'name' field.");
16
- return kebabCase(result);
7
+ function innerFormatCommandTree(command) {
8
+ return {
9
+ name: `${command.name}${command.isVirtual ? " (virtual)" : ""}`,
10
+ children: Object.values(command.children ?? {}).map(innerFormatCommandTree)
11
+ };
17
12
  }
18
- /**
19
- * Retrieves the application title from the context and configuration.
20
- *
21
- * @param context - The build context containing workspace and package information.
22
- * @returns The application title in title-case format.
23
- */
24
- function getAppTitle(context) {
25
- return titleCase(context.config.name || getAppName(context));
13
+ function formatCommandTree(context) {
14
+ return formatTree({
15
+ name: context.config.name,
16
+ children: Object.values(context.commands ?? {}).map(innerFormatCommandTree)
17
+ });
26
18
  }
27
19
  /**
28
- * Retrieves the application description from the context and configuration.
20
+ * Retrieves the default command options based on the context configuration.
29
21
  *
30
- * @param context - The build context containing workspace and package information.
31
- * @returns The application description.
22
+ * @param context - The build context.
23
+ * @param command - The command for which to retrieve default options.
24
+ * @returns A record of default command options.
32
25
  */
33
- function getAppDescription(context) {
34
- return context.config.description || context.packageJson?.description || `The ${getAppTitle(context)} command-line interface application.`;
26
+ function getDefaultOptions(context, command) {
27
+ let options;
28
+ if (Array.isArray(context.config.defaultOptions)) options = Object.fromEntries(getUniqueBy(context.config.defaultOptions, (item) => item.name).map((option) => [option.name, option]));
29
+ else if (isFunction(context.config.defaultOptions)) options = Object.fromEntries(getUniqueBy(context.config.defaultOptions(context, command), (item) => item.name).map((option) => [option.name, option]));
30
+ else options = {};
31
+ return Object.fromEntries(Object.entries(options).map(([key, value]) => [key, {
32
+ ...value,
33
+ env: value.env ?? constantCase(key)
34
+ }]));
35
35
  }
36
36
 
37
37
  //#endregion
38
- export { getAppDescription, getAppName, getAppTitle };
38
+ export { formatCommandTree, getDefaultOptions };
39
+ //# sourceMappingURL=utilities.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.mjs","names":["formatTree","getUniqueBy","constantCase","isFunction","innerFormatCommandTree","command","name","isVirtual","children","Object","values","map","formatCommandTree","context","config","commands","getDefaultOptions","options","Array","isArray","defaultOptions","fromEntries","item","option","entries","key","value","env"],"sources":["../../src/helpers/utilities.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { TreeItem } from \"@stryke/cli/utils/tree\";\nimport { formatTree } from \"@stryke/cli/utils/tree\";\nimport { getUniqueBy } from \"@stryke/helpers/get-unique\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport type { CommandBase, CommandOption, CommandTree } from \"../types/command\";\nimport type { Context } from \"../types/context\";\n\nfunction innerFormatCommandTree(command: CommandTree): TreeItem {\n return {\n name: `${command.name}${command.isVirtual ? \" (virtual)\" : \"\"}`,\n children: Object.values(command.children ?? {}).map(innerFormatCommandTree)\n };\n}\n\nexport function formatCommandTree(context: Context): string {\n return formatTree({\n name: context.config.name,\n children: Object.values(context.commands ?? {}).map(innerFormatCommandTree)\n });\n}\n\n/**\n * Retrieves the default command options based on the context configuration.\n *\n * @param context - The build context.\n * @param command - The command for which to retrieve default options.\n * @returns A record of default command options.\n */\nexport function getDefaultOptions(\n context: Context,\n command: CommandBase\n): Record<string, CommandOption> {\n let options!: Record<string, CommandOption>;\n if (Array.isArray(context.config.defaultOptions)) {\n options = Object.fromEntries(\n getUniqueBy(\n context.config.defaultOptions,\n (item: CommandOption) => item.name\n ).map(option => [option.name, option])\n );\n } else if (isFunction(context.config.defaultOptions)) {\n options = Object.fromEntries(\n getUniqueBy(\n context.config.defaultOptions(context, command),\n (item: CommandOption) => item.name\n ).map(option => [option.name, option])\n );\n } else {\n options = {};\n }\n\n return Object.fromEntries(\n Object.entries(options).map(([key, value]) => [\n key,\n { ...value, env: value.env ?? constantCase(key) }\n ])\n );\n}\n"],"mappings":";;;;;;AA0BA,SAASI,uBAAuBC,SAAgC;AAC9D,QAAO;EACLC,MAAM,GAAGD,QAAQC,OAAOD,QAAQE,YAAY,eAAe;EAC3DC,UAAUC,OAAOC,OAAOL,QAAQG,YAAY,EAAE,CAAC,CAACG,IAAIP,uBAAsB;EAC3E;;AAGH,SAAgBQ,kBAAkBC,SAA0B;AAC1D,QAAOb,WAAW;EAChBM,MAAMO,QAAQC,OAAOR;EACrBE,UAAUC,OAAOC,OAAOG,QAAQE,YAAY,EAAE,CAAC,CAACJ,IAAIP,uBAAsB;EAC3E,CAAC;;;;;;;;;AAUJ,SAAgBY,kBACdH,SACAR,SAC+B;CAC/B,IAAIY;AACJ,KAAIC,MAAMC,QAAQN,QAAQC,OAAOM,eAAe,CAC9CH,WAAUR,OAAOY,YACfpB,YACEY,QAAQC,OAAOM,iBACdE,SAAwBA,KAAKhB,KAC/B,CAACK,KAAIY,WAAU,CAACA,OAAOjB,MAAMiB,OAAO,CACvC,CAAC;UACQpB,WAAWU,QAAQC,OAAOM,eAAe,CAClDH,WAAUR,OAAOY,YACfpB,YACEY,QAAQC,OAAOM,eAAeP,SAASR,QAAQ,GAC9CiB,SAAwBA,KAAKhB,KAC/B,CAACK,KAAIY,WAAU,CAACA,OAAOjB,MAAMiB,OAAO,CACvC,CAAC;KAEDN,WAAU,EAAE;AAGd,QAAOR,OAAOY,YACZZ,OAAOe,QAAQP,QAAQ,CAACN,KAAK,CAACc,KAAKC,WAAW,CAC5CD,KACA;EAAE,GAAGC;EAAOC,KAAKD,MAAMC,OAAOzB,aAAauB,IAAG;EAAG,CAClD,CACH,CAAC"}