@shell-shock/core 0.2.1 → 0.4.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 (158) 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 +175 -0
  11. package/dist/components/docs.cjs.map +1 -0
  12. package/dist/components/docs.d.cts +81 -0
  13. package/dist/components/docs.d.cts.map +1 -0
  14. package/dist/components/docs.d.mts +81 -0
  15. package/dist/components/docs.d.mts.map +1 -0
  16. package/dist/components/docs.mjs +171 -0
  17. package/dist/components/docs.mjs.map +1 -0
  18. package/dist/components/index.cjs +5 -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/automd.cjs +59 -0
  43. package/dist/helpers/automd.cjs.map +1 -0
  44. package/dist/helpers/automd.mjs +58 -0
  45. package/dist/helpers/automd.mjs.map +1 -0
  46. package/dist/helpers/docs-helpers.cjs +17 -0
  47. package/dist/helpers/docs-helpers.cjs.map +1 -0
  48. package/dist/helpers/docs-helpers.mjs +16 -0
  49. package/dist/helpers/docs-helpers.mjs.map +1 -0
  50. package/dist/helpers/persistence.cjs +2 -1
  51. package/dist/helpers/persistence.cjs.map +1 -0
  52. package/dist/helpers/persistence.mjs +2 -1
  53. package/dist/helpers/persistence.mjs.map +1 -0
  54. package/dist/helpers/resolve-command.cjs +118 -33
  55. package/dist/helpers/resolve-command.cjs.map +1 -0
  56. package/dist/helpers/resolve-command.mjs +116 -32
  57. package/dist/helpers/resolve-command.mjs.map +1 -0
  58. package/dist/helpers/update-package-json.cjs +18 -10
  59. package/dist/helpers/update-package-json.cjs.map +1 -0
  60. package/dist/helpers/update-package-json.mjs +17 -10
  61. package/dist/helpers/update-package-json.mjs.map +1 -0
  62. package/dist/helpers/utilities.cjs +30 -30
  63. package/dist/helpers/utilities.cjs.map +1 -0
  64. package/dist/helpers/utilities.mjs +29 -28
  65. package/dist/helpers/utilities.mjs.map +1 -0
  66. package/dist/helpers/validations.cjs +97 -0
  67. package/dist/helpers/validations.cjs.map +1 -0
  68. package/dist/helpers/validations.mjs +97 -0
  69. package/dist/helpers/validations.mjs.map +1 -0
  70. package/dist/index.cjs +5 -13
  71. package/dist/index.cjs.map +1 -0
  72. package/dist/index.d.cts +6 -17
  73. package/dist/index.d.mts +6 -17
  74. package/dist/index.mjs +4 -13
  75. package/dist/index.mjs.map +1 -0
  76. package/dist/plugin-utils/context-helpers.cjs +86 -0
  77. package/dist/plugin-utils/context-helpers.cjs.map +1 -0
  78. package/dist/plugin-utils/context-helpers.d.cts +58 -0
  79. package/dist/plugin-utils/context-helpers.d.cts.map +1 -0
  80. package/dist/plugin-utils/context-helpers.d.mts +58 -0
  81. package/dist/plugin-utils/context-helpers.d.mts.map +1 -0
  82. package/dist/plugin-utils/context-helpers.mjs +79 -0
  83. package/dist/plugin-utils/context-helpers.mjs.map +1 -0
  84. package/dist/plugin-utils/get-command-tree.cjs +4 -2
  85. package/dist/plugin-utils/get-command-tree.cjs.map +1 -0
  86. package/dist/plugin-utils/get-command-tree.d.cts +2 -1
  87. package/dist/plugin-utils/get-command-tree.d.cts.map +1 -0
  88. package/dist/plugin-utils/get-command-tree.d.mts +2 -1
  89. package/dist/plugin-utils/get-command-tree.d.mts.map +1 -0
  90. package/dist/plugin-utils/get-command-tree.mjs +5 -2
  91. package/dist/plugin-utils/get-command-tree.mjs.map +1 -0
  92. package/dist/plugin-utils/index.cjs +14 -1
  93. package/dist/plugin-utils/index.d.cts +4 -1
  94. package/dist/plugin-utils/index.d.mts +4 -1
  95. package/dist/plugin-utils/index.mjs +4 -1
  96. package/dist/plugin-utils/reflect.cjs +25 -0
  97. package/dist/plugin-utils/reflect.cjs.map +1 -0
  98. package/dist/plugin-utils/reflect.d.cts +14 -0
  99. package/dist/plugin-utils/reflect.d.cts.map +1 -0
  100. package/dist/plugin-utils/reflect.d.mts +14 -0
  101. package/dist/plugin-utils/reflect.d.mts.map +1 -0
  102. package/dist/plugin-utils/reflect.mjs +24 -0
  103. package/dist/plugin-utils/reflect.mjs.map +1 -0
  104. package/dist/plugin-utils/traverse-command-tree.cjs +33 -0
  105. package/dist/plugin-utils/traverse-command-tree.cjs.map +1 -0
  106. package/dist/plugin-utils/traverse-command-tree.d.cts +23 -0
  107. package/dist/plugin-utils/traverse-command-tree.d.cts.map +1 -0
  108. package/dist/plugin-utils/traverse-command-tree.d.mts +23 -0
  109. package/dist/plugin-utils/traverse-command-tree.d.mts.map +1 -0
  110. package/dist/plugin-utils/traverse-command-tree.mjs +31 -0
  111. package/dist/plugin-utils/traverse-command-tree.mjs.map +1 -0
  112. package/dist/plugin.cjs +284 -0
  113. package/dist/plugin.cjs.map +1 -0
  114. package/dist/plugin.d.cts +13 -0
  115. package/dist/plugin.d.cts.map +1 -0
  116. package/dist/plugin.d.mts +13 -0
  117. package/dist/plugin.d.mts.map +1 -0
  118. package/dist/plugin.mjs +276 -0
  119. package/dist/plugin.mjs.map +1 -0
  120. package/dist/types/command.d.cts +14 -4
  121. package/dist/types/command.d.cts.map +1 -0
  122. package/dist/types/command.d.mts +14 -4
  123. package/dist/types/command.d.mts.map +1 -0
  124. package/dist/types/config.d.cts +74 -10
  125. package/dist/types/config.d.cts.map +1 -0
  126. package/dist/types/config.d.mts +74 -10
  127. package/dist/types/config.d.mts.map +1 -0
  128. package/dist/types/context.d.cts +7 -4
  129. package/dist/types/context.d.cts.map +1 -0
  130. package/dist/types/context.d.mts +7 -4
  131. package/dist/types/context.d.mts.map +1 -0
  132. package/dist/types/index.d.cts +4 -4
  133. package/dist/types/index.d.mts +4 -4
  134. package/dist/types/internal.cjs +0 -0
  135. package/dist/types/internal.d.cts +24 -0
  136. package/dist/types/internal.d.cts.map +1 -0
  137. package/dist/types/internal.d.mts +24 -0
  138. package/dist/types/internal.d.mts.map +1 -0
  139. package/dist/types/internal.mjs +1 -0
  140. package/dist/types/options.d.cts +2 -1
  141. package/dist/types/options.d.cts.map +1 -0
  142. package/dist/types/options.d.mts +2 -1
  143. package/dist/types/options.d.mts.map +1 -0
  144. package/dist/types/runtime.cjs +0 -0
  145. package/dist/types/runtime.d.cts +24 -0
  146. package/dist/types/runtime.d.cts.map +1 -0
  147. package/dist/types/runtime.d.mts +24 -0
  148. package/dist/types/runtime.d.mts.map +1 -0
  149. package/dist/types/runtime.mjs +1 -0
  150. package/package.json +223 -91
  151. package/dist/components/utils-builtin.cjs +0 -453
  152. package/dist/components/utils-builtin.d.cts +0 -27
  153. package/dist/components/utils-builtin.d.mts +0 -27
  154. package/dist/components/utils-builtin.mjs +0 -447
  155. package/dist/powerlines.cjs +0 -172
  156. package/dist/powerlines.d.cts +0 -12
  157. package/dist/powerlines.d.mts +0 -12
  158. package/dist/powerlines.mjs +0 -168
@@ -0,0 +1,276 @@
1
+ import { getAppDescription, getAppName, getAppTitle, isVariableCommandPath } from "./plugin-utils/context-helpers.mjs";
2
+ import { CommandDocsFile } from "./components/docs.mjs";
3
+ import { getCommandTree } from "./plugin-utils/get-command-tree.mjs";
4
+ import { traverseCommands } from "./plugin-utils/traverse-command-tree.mjs";
5
+ import { commands } from "./helpers/automd.mjs";
6
+ import { getCommandsPersistencePath, readCommandsPersistence, writeCommandsPersistence } from "./helpers/persistence.mjs";
7
+ import { formatCommandTree, getDefaultOptions } from "./helpers/utilities.mjs";
8
+ import { findCommandsRoot, reflectCommandTree, resolveCommandId, resolveCommandName, resolveCommandPath } from "./helpers/resolve-command.mjs";
9
+ import { formatBinaryPath, updatePackageJsonBinary } from "./helpers/update-package-json.mjs";
10
+ import { validateCommand } from "./helpers/validations.mjs";
11
+ import { createComponent } from "@alloy-js/core/jsx-runtime";
12
+ import { For, Show } from "@alloy-js/core/components";
13
+ import { render } from "@powerlines/plugin-alloy/render";
14
+ import automd from "@powerlines/plugin-automd";
15
+ import deepkit from "@powerlines/plugin-deepkit";
16
+ import nodejs from "@powerlines/plugin-nodejs";
17
+ import tsdown from "@powerlines/plugin-tsdown";
18
+ import { toArray } from "@stryke/convert/to-array";
19
+ import { chmodX } from "@stryke/fs/chmod-x";
20
+ import { appendPath } from "@stryke/path/append";
21
+ import { findFilePath } from "@stryke/path/file-path-fns";
22
+ import { isParentPath } from "@stryke/path/is-parent-path";
23
+ import { joinPaths } from "@stryke/path/join-paths";
24
+ import { replacePath } from "@stryke/path/replace";
25
+ import { resolveParentPath } from "@stryke/path/resolve-parent-path";
26
+ import { camelCase } from "@stryke/string-format/camel-case";
27
+ import { constantCase } from "@stryke/string-format/constant-case";
28
+ import { kebabCase } from "@stryke/string-format/kebab-case";
29
+ import { isSetObject } from "@stryke/type-checks/is-set-object";
30
+ import { isSetString } from "@stryke/type-checks/is-set-string";
31
+ import { defu } from "defu";
32
+ import { resolveEntries } from "powerlines/lib/entry";
33
+
34
+ //#region src/plugin.tsx
35
+ const MAX_DEPTH = 50;
36
+ /**
37
+ * The core Powerlines plugin to build Shell Shock projects.
38
+ */
39
+ const plugin = (options = {}) => {
40
+ return [
41
+ tsdown(),
42
+ deepkit(),
43
+ automd(),
44
+ {
45
+ name: "shell-shock:config",
46
+ async config() {
47
+ this.debug("Resolving the Shell Shock configuration.");
48
+ await updatePackageJsonBinary(this);
49
+ const result = defu({ output: { buildPath: joinPaths(this.config.projectRoot, "dist") } }, options, {
50
+ name: getAppName(this),
51
+ title: getAppTitle(this),
52
+ description: getAppDescription(this),
53
+ envPrefix: constantCase(getAppName(this)),
54
+ env: { prefix: [] },
55
+ isCaseSensitive: false,
56
+ output: {
57
+ format: "esm",
58
+ dts: true
59
+ },
60
+ entry: !this.config.entry || Array.isArray(this.config.entry) && this.config.entry.length === 0 ? [joinPaths(this.config.sourceRoot, "**/*.ts"), joinPaths(this.config.sourceRoot, "**/*.tsx")] : void 0,
61
+ build: {
62
+ dts: false,
63
+ platform: "node",
64
+ nodeProtocol: true,
65
+ unbundle: false,
66
+ noExternal: ["@powerlines/deepkit"]
67
+ },
68
+ type: "application",
69
+ framework: "shell-shock"
70
+ });
71
+ if (!result.env.prefix.includes(result.envPrefix)) result.env.prefix.push(result.envPrefix);
72
+ return result;
73
+ },
74
+ configResolved: {
75
+ order: "pre",
76
+ async handler() {
77
+ this.debug("Shell Shock configuration has been resolved.");
78
+ this.config.bin = (isSetString(this.packageJson.bin) ? { [kebabCase(this.config.name)]: this.packageJson.bin } : this.packageJson.bin) ?? { [kebabCase(this.config.name)]: formatBinaryPath(this.config.output.format) };
79
+ this.inputs ??= [];
80
+ this.options = Object.values(getDefaultOptions(this, {
81
+ id: null,
82
+ name: this.config.name,
83
+ title: this.config.title,
84
+ description: this.config.description,
85
+ alias: [],
86
+ path: {
87
+ value: null,
88
+ segments: []
89
+ },
90
+ isVirtual: false
91
+ }));
92
+ }
93
+ }
94
+ },
95
+ ...nodejs(),
96
+ {
97
+ name: "shell-shock:inputs",
98
+ async configResolved() {
99
+ this.debug("Finding command entry point files.");
100
+ this.commandsPath = findCommandsRoot(this);
101
+ const entries = await resolveEntries(this, toArray(this.config.entry || []));
102
+ this.debug(`Found ${entries.length} entry points specified in the configuration options.`);
103
+ this.inputs = entries.reduce((ret, entry) => {
104
+ if (!isParentPath(entry.file, this.commandsPath)) throw new Error(`Command entry point "${entry.file}" is not located within the commands root "${this.commandsPath}". Please ensure that all command entry points are located within the current project.`);
105
+ const id = resolveCommandId(this, entry.file);
106
+ if (!ret.some((existing) => existing.id === id)) {
107
+ const path = resolveCommandPath(this, entry.file);
108
+ const name = resolveCommandName(entry.file);
109
+ ret.push({
110
+ id,
111
+ path: {
112
+ value: path,
113
+ segments: path.split("/").filter(Boolean)
114
+ },
115
+ name,
116
+ alias: [],
117
+ isVirtual: false,
118
+ entry: {
119
+ ...entry,
120
+ file: entry.file,
121
+ input: {
122
+ file: entry.file,
123
+ name: entry.name
124
+ },
125
+ output: name
126
+ }
127
+ });
128
+ }
129
+ return ret;
130
+ }, this.inputs);
131
+ this.debug(`Shell Shock will process ${this.inputs.length} command entry files: \n${this.inputs.map((command) => ` - ${command.id}: ${replacePath(command.entry.file, this.commandsPath)}`).join("\n")}`);
132
+ }
133
+ },
134
+ {
135
+ name: "shell-shock:virtual-inputs",
136
+ configResolved: {
137
+ order: "post",
138
+ async handler() {
139
+ if (this.inputs.length === 0) this.warn("No commands were found in the project. Please ensure at least one command exists.");
140
+ else {
141
+ this.debug(`Shell Shock will create an application with the following commands: \n${this.inputs.filter((cmd) => !cmd.isVirtual).map((command) => ` - ${command.id}: ${replacePath(command.entry.file, this.commandsPath)}${command.isVirtual ? " (virtual)" : ""}`).join("\n")}`);
142
+ this.debug("Finding and adding virtual command inputs for each command previously found.");
143
+ this.inputs = this.inputs.reduce((ret, command) => {
144
+ let depth = 0;
145
+ let parentPath = resolveParentPath(findFilePath(command.entry.file));
146
+ while (parentPath !== this.commandsPath) {
147
+ if (depth++ > MAX_DEPTH) throw new Error(`Maximum command virtual parent depth of ${MAX_DEPTH} exceeded while processing command: ${command.name}`);
148
+ if (!ret.some((existing) => findFilePath(existing.entry.file) === parentPath)) {
149
+ const file = joinPaths(parentPath, "command.ts");
150
+ const id = resolveCommandId(this, file);
151
+ if (!ret.some((existing) => existing.id === id)) {
152
+ const name = resolveCommandName(file);
153
+ const path = resolveCommandPath(this, file);
154
+ ret.push({
155
+ id,
156
+ path: {
157
+ value: path,
158
+ segments: path.split("/").filter(Boolean)
159
+ },
160
+ name,
161
+ alias: [],
162
+ isVirtual: true,
163
+ entry: { file }
164
+ });
165
+ }
166
+ }
167
+ parentPath = resolveParentPath(parentPath);
168
+ }
169
+ return ret;
170
+ }, this.inputs).sort((a, b) => a.path.segments.length - b.path.segments.length);
171
+ this.debug(`Final command input list: \n${this.inputs.map((command) => ` - ${command.id}: ${replacePath(command.entry.file, this.commandsPath)}${command.isVirtual ? " (virtual)" : ""}`).join("\n")}`);
172
+ }
173
+ }
174
+ }
175
+ },
176
+ {
177
+ name: "shell-shock:reflect-commands",
178
+ prepare: {
179
+ order: "post",
180
+ async handler() {
181
+ this.debug("Initializing the CLI application's command tree.");
182
+ this.commands = {};
183
+ if (this.config.command !== "prepare" && this.config.skipCache !== true && this.persistedMeta?.checksum === this.meta.checksum && this.fs.existsSync(getCommandsPersistencePath(this))) {
184
+ this.debug(`Skipping reflection initialization as the meta checksum has not changed.`);
185
+ await readCommandsPersistence(this);
186
+ } else {
187
+ for (const input of this.inputs.filter((input$1) => input$1.path.segments.filter((segment) => !isVariableCommandPath(segment)).length === 1)) this.commands[input.name] = await reflectCommandTree(this, input);
188
+ this.debug("Post-processing commands to ensure proper reflection.");
189
+ this.options = this.options.map((option) => ({
190
+ ...option,
191
+ name: camelCase(option.name),
192
+ alias: option.alias ?? [],
193
+ optional: option.optional ?? false
194
+ }));
195
+ await traverseCommands(this, (command) => {
196
+ command.options = Object.fromEntries(Object.entries(command.options).map(([name, option]) => [camelCase(name), {
197
+ ...option,
198
+ name: camelCase(name),
199
+ alias: option.alias ?? [],
200
+ optional: option.optional ?? false
201
+ }]));
202
+ });
203
+ await writeCommandsPersistence(this);
204
+ }
205
+ this.debug("Validating the CLI applications command tree.");
206
+ let isValid = true;
207
+ await traverseCommands(this, (command) => {
208
+ const failures = validateCommand(command);
209
+ if (failures.length > 0) {
210
+ this.error(`Found ${failures.length} issue${failures.length > 1 ? "s" : ""} with the ${command.title} command: \n${failures.map((failure) => ` - ${failure.code}: ${failure.details}`).join("\n")}\n`);
211
+ isValid = false;
212
+ }
213
+ });
214
+ if (!isValid) throw new Error(`One or more commands in the command tree are invalid. Please review the errors above and correct them before proceeding.`);
215
+ this.info(`\nCreating an application with the following command tree: \n${formatCommandTree(this)}\n`);
216
+ }
217
+ }
218
+ },
219
+ {
220
+ name: "shell-shock:chmod+x",
221
+ configResolved() {
222
+ this.config.build.outputOptions ??= {};
223
+ this.config.build.outputOptions.banner = (chunk) => {
224
+ if (chunk.isEntry && joinPaths(this.entryPath, "bin.ts") === chunk.facadeModuleId) {
225
+ this.debug(`Adding hashbang to binary executable output file: ${chunk.fileName}`);
226
+ return `#!/usr/bin/env ${this.config.mode === "development" ? "-S NODE_OPTIONS=--enable-source-maps" : ""} node\n`;
227
+ }
228
+ return "";
229
+ };
230
+ },
231
+ async buildEnd() {
232
+ if (!isSetObject(this.config.bin)) this.warn(`No binaries were found for the ${this.config.name} application. Please ensure the binaries are correctly configured in your Shell Shock configuration or package.json.`);
233
+ else await Promise.all(Object.values(this.config.bin).map(async (bin) => {
234
+ const path = appendPath(bin, joinPaths(this.workspaceConfig.workspaceRoot, this.config.projectRoot));
235
+ if (this.fs.existsSync(path)) {
236
+ this.debug(`Adding executable permissions (chmod+x) to binary executable output file: ${path}`);
237
+ await chmodX(path);
238
+ } else this.warn(`Unable to locate the binary executable output file: ${path}. This may indicate either a misconfiguration in the package.json file or an issue with the build process.`);
239
+ }));
240
+ }
241
+ },
242
+ {
243
+ name: "shell-shock:docs",
244
+ configResolved() {
245
+ this.config.automd ??= {};
246
+ this.config.automd.generators = {
247
+ ...this.config.automd.generators ?? {},
248
+ commands: commands(this)
249
+ };
250
+ },
251
+ async docs() {
252
+ this.debug("Rendering entrypoint modules for the Shell Shock `script` preset.");
253
+ const commands$1 = this.inputs.map((input) => getCommandTree(this, input.path.segments)).filter(Boolean);
254
+ return render(this, createComponent(For, {
255
+ get each() {
256
+ return Object.values(commands$1);
257
+ },
258
+ doubleHardline: true,
259
+ children: (child) => createComponent(Show, {
260
+ get when() {
261
+ return !child.isVirtual;
262
+ },
263
+ get children() {
264
+ return createComponent(CommandDocsFile, { command: child });
265
+ }
266
+ })
267
+ }));
268
+ }
269
+ }
270
+ ];
271
+ };
272
+ var plugin_default = plugin;
273
+
274
+ //#endregion
275
+ export { plugin_default as default, plugin, plugin as shellShock };
276
+ //# sourceMappingURL=plugin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.mjs","names":["For","Show","render","automd","deepkit","nodejs","tsdown","toArray","chmodX","appendPath","findFilePath","isParentPath","joinPaths","replacePath","resolveParentPath","camelCase","constantCase","kebabCase","isSetObject","isSetString","defu","resolveEntries","CommandDocsFile","commands","getCommandsPersistencePath","readCommandsPersistence","writeCommandsPersistence","findCommandsRoot","reflectCommandTree","resolveCommandId","resolveCommandName","resolveCommandPath","formatBinaryPath","updatePackageJsonBinary","formatCommandTree","getDefaultOptions","validateCommand","getAppDescription","getAppName","getAppTitle","isVariableCommandPath","getCommandTree","traverseCommands","MAX_DEPTH","plugin","options","name","config","debug","result","output","buildPath","projectRoot","title","description","envPrefix","env","prefix","isCaseSensitive","format","dts","entry","Array","isArray","length","sourceRoot","undefined","build","platform","nodeProtocol","unbundle","noExternal","type","framework","includes","push","configResolved","order","handler","bin","packageJson","inputs","Object","values","id","alias","path","value","segments","isVirtual","commandsPath","entries","reduce","ret","file","Error","some","existing","split","filter","Boolean","input","map","command","join","warn","cmd","depth","parentPath","sort","a","b","prepare","skipCache","persistedMeta","checksum","meta","fs","existsSync","segment","option","optional","fromEntries","isValid","failures","error","failure","code","details","info","outputOptions","banner","chunk","isEntry","entryPath","facadeModuleId","fileName","mode","buildEnd","Promise","all","workspaceConfig","workspaceRoot","generators","docs","_$createComponent","each","doubleHardline","children","child","when","shellShock"],"sources":["../src/plugin.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { For, Show } from \"@alloy-js/core/components\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport automd from \"@powerlines/plugin-automd\";\nimport deepkit from \"@powerlines/plugin-deepkit\";\nimport nodejs from \"@powerlines/plugin-nodejs\";\nimport tsdown from \"@powerlines/plugin-tsdown\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { chmodX } from \"@stryke/fs/chmod-x\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { findFilePath } from \"@stryke/path/file-path-fns\";\nimport { isParentPath } from \"@stryke/path/is-parent-path\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { defu } from \"defu\";\nimport type { Plugin } from \"powerlines\";\nimport { resolveEntries } from \"powerlines/lib/entry\";\nimport type { OutputOptions, RenderedChunk } from \"rolldown\";\nimport { CommandDocsFile } from \"./components/docs\";\nimport { commands } from \"./helpers/automd\";\nimport {\n getCommandsPersistencePath,\n readCommandsPersistence,\n writeCommandsPersistence\n} from \"./helpers/persistence\";\nimport {\n findCommandsRoot,\n reflectCommandTree,\n resolveCommandId,\n resolveCommandName,\n resolveCommandPath\n} from \"./helpers/resolve-command\";\nimport {\n formatBinaryPath,\n updatePackageJsonBinary\n} from \"./helpers/update-package-json\";\nimport { formatCommandTree, getDefaultOptions } from \"./helpers/utilities\";\nimport { validateCommand } from \"./helpers/validations\";\nimport {\n getAppDescription,\n getAppName,\n getAppTitle,\n isVariableCommandPath\n} from \"./plugin-utils/context-helpers\";\nimport { getCommandTree } from \"./plugin-utils/get-command-tree\";\nimport { traverseCommands } from \"./plugin-utils/traverse-command-tree\";\nimport type { CommandOption, CommandTree } from \"./types/command\";\nimport type { Options } from \"./types/config\";\nimport type { Context } from \"./types/context\";\n\nconst MAX_DEPTH = 50;\n\n/**\n * The core Powerlines plugin to build Shell Shock projects.\n */\nexport const plugin = <TContext extends Context = Context>(\n options: Options = {}\n) => {\n return [\n tsdown(),\n deepkit(),\n automd(),\n {\n name: \"shell-shock:config\",\n async config() {\n this.debug(\"Resolving the Shell Shock configuration.\");\n\n await updatePackageJsonBinary(this);\n\n const result = defu(\n {\n output: {\n buildPath: joinPaths(this.config.projectRoot, \"dist\")\n }\n },\n options,\n {\n name: getAppName(this),\n title: getAppTitle(this),\n description: getAppDescription(this),\n envPrefix: constantCase(getAppName(this)),\n env: {\n prefix: [] as string[]\n },\n isCaseSensitive: false,\n output: {\n format: \"esm\",\n dts: true\n },\n entry:\n !this.config.entry ||\n (Array.isArray(this.config.entry) &&\n this.config.entry.length === 0)\n ? [\n joinPaths(this.config.sourceRoot, \"**/*.ts\"),\n joinPaths(this.config.sourceRoot, \"**/*.tsx\")\n ]\n : undefined,\n build: {\n dts: false,\n platform: \"node\",\n nodeProtocol: true,\n unbundle: false,\n noExternal: [\"@powerlines/deepkit\"]\n },\n type: \"application\",\n framework: \"shell-shock\"\n }\n );\n if (!result.env.prefix.includes(result.envPrefix)) {\n result.env.prefix.push(result.envPrefix);\n }\n\n return result;\n },\n configResolved: {\n order: \"pre\",\n async handler() {\n this.debug(\"Shell Shock configuration has been resolved.\");\n\n this.config.bin = (isSetString(this.packageJson.bin)\n ? { [kebabCase(this.config.name)]: this.packageJson.bin }\n : this.packageJson.bin) ?? {\n [kebabCase(this.config.name)]: formatBinaryPath(\n this.config.output.format\n )\n };\n\n this.inputs ??= [];\n this.options = Object.values(\n getDefaultOptions(this, {\n id: null,\n name: this.config.name,\n title: this.config.title,\n description: this.config.description,\n alias: [],\n path: {\n value: null,\n segments: []\n },\n isVirtual: false\n })\n );\n }\n }\n },\n ...nodejs<TContext>(),\n {\n name: \"shell-shock:inputs\",\n async configResolved() {\n this.debug(\"Finding command entry point files.\");\n\n this.commandsPath = findCommandsRoot(this);\n\n const entries = await resolveEntries(\n this,\n toArray(this.config.entry || [])\n );\n this.debug(\n `Found ${\n entries.length\n } entry points specified in the configuration options.`\n );\n\n this.inputs = entries.reduce((ret, entry) => {\n if (!isParentPath(entry.file, this.commandsPath)) {\n throw new Error(\n `Command entry point \"${\n entry.file\n }\" is not located within the commands root \"${\n this.commandsPath\n }\". Please ensure that all command entry points are located within the current project.`\n );\n }\n\n const id = resolveCommandId(this, entry.file);\n if (!ret.some(existing => existing.id === id)) {\n const path = resolveCommandPath(this, entry.file);\n const name = resolveCommandName(entry.file);\n\n ret.push({\n id,\n path: {\n value: path,\n segments: path.split(\"/\").filter(Boolean)\n },\n name,\n alias: [],\n isVirtual: false,\n entry: {\n ...entry,\n file: entry.file,\n input: {\n file: entry.file,\n name: entry.name\n },\n output: name\n }\n });\n }\n\n return ret;\n }, this.inputs);\n\n this.debug(\n `Shell Shock will process ${\n this.inputs.length\n } command entry files: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}`\n )\n .join(\"\\n\")}`\n );\n }\n },\n {\n name: \"shell-shock:virtual-inputs\",\n configResolved: {\n order: \"post\",\n async handler() {\n if (this.inputs.length === 0) {\n this.warn(\n \"No commands were found in the project. Please ensure at least one command exists.\"\n );\n } else {\n this.debug(\n `Shell Shock will create an application with the following commands: \\n${this.inputs\n .filter(cmd => !cmd.isVirtual)\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n\n this.debug(\n \"Finding and adding virtual command inputs for each command previously found.\"\n );\n\n this.inputs = this.inputs\n .reduce((ret, command) => {\n let depth = 0;\n\n let parentPath = resolveParentPath(\n findFilePath(command.entry.file)\n );\n while (parentPath !== this.commandsPath) {\n if (depth++ > MAX_DEPTH) {\n throw new Error(\n `Maximum command virtual parent depth of ${\n MAX_DEPTH\n } exceeded while processing command: ${command.name}`\n );\n }\n\n if (\n !ret.some(\n existing =>\n findFilePath(existing.entry.file) === parentPath\n )\n ) {\n const file = joinPaths(parentPath, \"command.ts\");\n const id = resolveCommandId(this, file);\n if (!ret.some(existing => existing.id === id)) {\n const name = resolveCommandName(file);\n const path = resolveCommandPath(this, file);\n\n ret.push({\n id,\n path: {\n value: path,\n segments: path.split(\"/\").filter(Boolean)\n },\n name,\n alias: [],\n isVirtual: true,\n entry: {\n file\n }\n });\n }\n }\n\n parentPath = resolveParentPath(parentPath);\n }\n\n return ret;\n }, this.inputs)\n .sort((a, b) => a.path.segments.length - b.path.segments.length);\n\n this.debug(\n `Final command input list: \\n${this.inputs\n .map(\n command =>\n ` - ${command.id}: ${replacePath(\n command.entry.file,\n this.commandsPath\n )}${command.isVirtual ? \" (virtual)\" : \"\"}`\n )\n .join(\"\\n\")}`\n );\n }\n }\n }\n },\n {\n name: \"shell-shock:reflect-commands\",\n prepare: {\n order: \"post\",\n async handler() {\n this.debug(\"Initializing the CLI application's command tree.\");\n this.commands = {};\n\n if (\n this.config.command !== \"prepare\" &&\n this.config.skipCache !== true &&\n this.persistedMeta?.checksum === this.meta.checksum &&\n this.fs.existsSync(getCommandsPersistencePath(this))\n ) {\n this.debug(\n `Skipping reflection initialization as the meta checksum has not changed.`\n );\n\n await readCommandsPersistence(this);\n } else {\n for (const input of this.inputs.filter(\n input =>\n input.path.segments.filter(\n segment => !isVariableCommandPath(segment)\n ).length === 1\n )) {\n this.commands[input.name] = await reflectCommandTree(this, input);\n }\n\n this.debug(\"Post-processing commands to ensure proper reflection.\");\n\n this.options = this.options.map(\n option =>\n ({\n ...option,\n name: camelCase(option.name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n }) as CommandOption\n );\n\n await traverseCommands(this, command => {\n command.options = Object.fromEntries(\n Object.entries(command.options).map(([name, option]) => [\n camelCase(name),\n {\n ...option,\n name: camelCase(name),\n alias: option.alias ?? [],\n optional: option.optional ?? false\n } as CommandOption\n ])\n );\n });\n\n await writeCommandsPersistence(this);\n }\n\n this.debug(\"Validating the CLI applications command tree.\");\n\n let isValid = true;\n await traverseCommands(this, command => {\n const failures = validateCommand(command);\n if (failures.length > 0) {\n this.error(\n `Found ${failures.length} issue${failures.length > 1 ? \"s\" : \"\"} with the ${\n command.title\n } command: \\n${failures\n .map(failure => ` - ${failure.code}: ${failure.details}`)\n .join(\"\\n\")}\\n`\n );\n isValid = false;\n }\n });\n if (!isValid) {\n throw new Error(\n `One or more commands in the command tree are invalid. Please review the errors above and correct them before proceeding.`\n );\n }\n\n this.info(\n `\\nCreating an application with the following command tree: \\n${formatCommandTree(\n this\n )}\\n`\n );\n }\n }\n },\n {\n name: \"shell-shock:chmod+x\",\n configResolved() {\n this.config.build.outputOptions ??= {} as OutputOptions;\n (this.config.build.outputOptions as OutputOptions).banner = (\n chunk: RenderedChunk\n ) => {\n if (\n chunk.isEntry &&\n joinPaths(this.entryPath, \"bin.ts\") === chunk.facadeModuleId\n ) {\n this.debug(\n `Adding hashbang to binary executable output file: ${chunk.fileName}`\n );\n\n return `#!/usr/bin/env ${\n this.config.mode === \"development\"\n ? \"-S NODE_OPTIONS=--enable-source-maps\"\n : \"\"\n } node\\n`;\n }\n return \"\";\n };\n },\n async buildEnd() {\n if (!isSetObject(this.config.bin)) {\n this.warn(\n `No binaries were found for the ${\n this.config.name\n } application. Please ensure the binaries are correctly configured in your Shell Shock configuration or package.json.`\n );\n } else {\n await Promise.all(\n Object.values(this.config.bin).map(async bin => {\n const path = appendPath(\n bin,\n joinPaths(\n this.workspaceConfig.workspaceRoot,\n this.config.projectRoot\n )\n );\n\n if (this.fs.existsSync(path)) {\n this.debug(\n `Adding executable permissions (chmod+x) to binary executable output file: ${path}`\n );\n\n await chmodX(path);\n } else {\n this.warn(\n `Unable to locate the binary executable output file: ${path}. This may indicate either a misconfiguration in the package.json file or an issue with the build process.`\n );\n }\n })\n );\n }\n }\n },\n {\n name: \"shell-shock:docs\",\n configResolved() {\n this.config.automd ??= {};\n this.config.automd.generators = {\n ...(this.config.automd.generators ?? {}),\n commands: commands(this)\n };\n },\n async docs() {\n this.debug(\n \"Rendering entrypoint modules for the Shell Shock `script` preset.\"\n );\n\n const commands = this.inputs\n .map(input => getCommandTree(this, input.path.segments))\n .filter(Boolean) as CommandTree[];\n\n return render(\n this,\n <For each={Object.values(commands)} doubleHardline>\n {child => (\n <Show when={!child.isVirtual}>\n <CommandDocsFile command={child} />\n </Show>\n )}\n </For>\n );\n }\n }\n ] as Plugin<TContext>[];\n};\n\nexport { plugin as shellShock };\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyEA,MAAM2C,YAAY;;;;AAKlB,MAAaC,UACXC,UAAmB,EAAE,KAClB;AACH,QAAO;EACLvC,QAAQ;EACRF,SAAS;EACTD,QAAQ;EACR;GACE2C,MAAM;GACN,MAAMC,SAAS;AACb,SAAKC,MAAM,2CAA2C;AAEtD,UAAMf,wBAAwB,KAAK;IAEnC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AM6F,QAAQC,IACZ1D,OAAOC,OAAO,KAAKpC,OAAOgC,IAAI,CAACuB,IAAI,OAAMvB,QAAO;KAC9C,MAAMO,OAAO7E,WACXsE,KACAnE,UACE,KAAKiI,gBAAgBC,eACrB,KAAK/F,OAAOK,YAEhB,CAAC;AAED,SAAI,KAAKiE,GAAGC,WAAWhC,KAAK,EAAE;AAC5B,WAAKtC,MACH,6EAA6EsC,OAC9E;AAED,YAAM9E,OAAO8E,KAAK;WAElB,MAAKmB,KACH,uDAAuDnB,KAAI,4GAC5D;MAGP,CAAC;;GAGN;EACD;GACExC,MAAM;GACN8B,iBAAiB;AACf,SAAK7B,OAAO5C,WAAW,EAAE;AACzB,SAAK4C,OAAO5C,OAAO4I,aAAa;KAC9B,GAAI,KAAKhG,OAAO5C,OAAO4I,cAAc,EAAE;KACvCxH,UAAUA,SAAS,KAAI;KACxB;;GAEH,MAAMyH,OAAO;AACX,SAAKhG,MACH,oEACD;IAED,MAAMzB,aAAW,KAAK0D,OACnBqB,KAAID,UAAS5D,eAAe,MAAM4D,MAAMf,KAAKE,SAAS,CAAC,CACvDW,OAAOC,QAAyB;AAEnC,WAAOlG,OACL,MAAI+I,gBACHjJ,KAAG;KAAA,IAACkJ,OAAI;AAAA,aAAEhE,OAAOC,OAAO5D,WAAS;;KAAE4H,gBAAc;KAAAC,WAC/CC,UAAKJ,gBACHhJ,MAAI;MAAA,IAACqJ,OAAI;AAAA,cAAE,CAACD,MAAM5D;;MAAS,IAAA2D,WAAA;AAAA,cAAAH,gBACzB3H,iBAAe,EAACiF,SAAS8C,OAAK,CAAA;;MAAA,CAAA;KAElC,CAEL,CAAC;;GAEJ;EACF;;AAIH,qBAAezG"}
@@ -6,13 +6,13 @@ interface BaseCommandOption {
6
6
  name: string;
7
7
  kind: ReflectionKind;
8
8
  title: string;
9
- description?: string;
9
+ description: string;
10
10
  alias: string[];
11
+ env: string | false;
11
12
  optional: boolean;
12
13
  }
13
14
  interface StringCommandOption extends BaseCommandOption {
14
15
  kind: ReflectionKind.string;
15
- format?: "path" | "url" | "date" | "time" | "datetime" | "json" | "regex" | string;
16
16
  default?: string;
17
17
  variadic: boolean;
18
18
  }
@@ -35,21 +35,30 @@ interface CommandParam {
35
35
  optional: boolean;
36
36
  variadic: boolean;
37
37
  }
38
+ interface CommandPath {
39
+ value: string | null;
40
+ segments: string[];
41
+ }
38
42
  interface CommandBase {
39
43
  id: string | null;
40
44
  name: string;
41
45
  title?: string;
42
46
  description?: string;
43
- path: string[];
47
+ alias: string[];
48
+ path: CommandPath;
44
49
  isVirtual: boolean;
45
50
  }
46
51
  interface CommandInput extends CommandBase {
47
52
  id: string;
48
53
  entry: ResolvedEntryTypeDefinition;
49
54
  }
55
+ interface CommandTreePath extends CommandPath {
56
+ variables: Record<string, CommandParam>;
57
+ }
50
58
  type CommandTree = CommandInput & {
51
59
  title: string;
52
60
  description: string;
61
+ path: CommandTreePath;
53
62
  options: Record<string, CommandOption>;
54
63
  params: CommandParam[];
55
64
  parent: null | CommandTree;
@@ -60,4 +69,5 @@ type SerializedCommandTree = Omit<CommandTree, "parent" | "children"> & {
60
69
  children: Record<string, SerializedCommandTree>;
61
70
  };
62
71
  //#endregion
63
- export { BaseCommandOption, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandTree, NumberCommandOption, SerializedCommandTree, StringCommandOption };
72
+ export { BaseCommandOption, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandPath, CommandTree, CommandTreePath, NumberCommandOption, SerializedCommandTree, StringCommandOption };
73
+ //# sourceMappingURL=command.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.d.cts","names":[],"sources":["../../src/types/command.ts"],"sourcesContent":[],"mappings":";;;;UAqBiB,iBAAA;;EAAA,IAAA,EAET,cAF0B;EAUjB,KAAA,EAAA,MAAA;EAMA,WAAA,EAAA,MAAA;EAMA,KAAA,EAAA,MAAA,EAAA;EAOL,GAAA,EAAA,MAAA,GAAA,KAAa;EACrB,QAAA,EAAA,OAAA;;AAEA,UAtBa,mBAAA,SAA4B,iBAsBzC,CAAA;EAAoB,IAAA,EArBhB,cAAA,CAAe,MAqBC;EAEP,OAAA,CAAA,EAAA,MAAY;EAQZ,QAAA,EAAA,OAAW;AAK5B;AAUiB,UAzCA,mBAAA,SAA4B,iBAyCP,CAAA;EAKrB,IAAA,EA7CT,cAAA,CAAe,MA6CU;EACL,OAAA,CAAA,EAAA,MAAA;EAAf,QAAA,EAAA,OAAA;;AADuC,UAxCnC,oBAAA,SAA6B,iBAwCM,CAAA;EAIxC,IAAA,EA3CJ,cAAA,CAAe,OA2CA;EAAG,OAAA,CAAA,EAAA,OAAA;EAGlB,YAAA,CAAA,EAAA,MAAA;EACkB,kBAAA,CAAA,EAAA,OAAA;;AAChB,KA1CE,aAAA,GACR,mBAyCM,GAxCN,mBAwCM,GAvCN,oBAuCM;AACO,UAtCA,YAAA,CAsCA;EACU,IAAA,EAAA,MAAA;EAAf,WAAA,CAAA,EAAA,MAAA;EAAM,OAAA,CAAA,EAAA,MAAA;EAGN,QAAA,EAAA,OAAA;EAA6B,QAAA,EAAA,OAAA;;AAEd,UApCV,WAAA,CAoCU;EAAf,KAAA,EAAA,MAAA,GAAA,IAAA;EAAM,QAAA,EAAA,MAAA,EAAA;;UA/BD,WAAA;;;;;;QAMT;;;UAIS,YAAA,SAAqB;;SAE7B;;UAGQ,eAAA,SAAwB;aAC5B,eAAe;;KAGhB,WAAA,GAAc;;;QAGlB;WACG,eAAe;UAChB;iBACO;YACL,eAAe;;KAGf,qBAAA,GAAwB,KAAK;;YAE7B,eAAe"}
@@ -6,13 +6,13 @@ interface BaseCommandOption {
6
6
  name: string;
7
7
  kind: ReflectionKind;
8
8
  title: string;
9
- description?: string;
9
+ description: string;
10
10
  alias: string[];
11
+ env: string | false;
11
12
  optional: boolean;
12
13
  }
13
14
  interface StringCommandOption extends BaseCommandOption {
14
15
  kind: ReflectionKind.string;
15
- format?: "path" | "url" | "date" | "time" | "datetime" | "json" | "regex" | string;
16
16
  default?: string;
17
17
  variadic: boolean;
18
18
  }
@@ -35,21 +35,30 @@ interface CommandParam {
35
35
  optional: boolean;
36
36
  variadic: boolean;
37
37
  }
38
+ interface CommandPath {
39
+ value: string | null;
40
+ segments: string[];
41
+ }
38
42
  interface CommandBase {
39
43
  id: string | null;
40
44
  name: string;
41
45
  title?: string;
42
46
  description?: string;
43
- path: string[];
47
+ alias: string[];
48
+ path: CommandPath;
44
49
  isVirtual: boolean;
45
50
  }
46
51
  interface CommandInput extends CommandBase {
47
52
  id: string;
48
53
  entry: ResolvedEntryTypeDefinition;
49
54
  }
55
+ interface CommandTreePath extends CommandPath {
56
+ variables: Record<string, CommandParam>;
57
+ }
50
58
  type CommandTree = CommandInput & {
51
59
  title: string;
52
60
  description: string;
61
+ path: CommandTreePath;
53
62
  options: Record<string, CommandOption>;
54
63
  params: CommandParam[];
55
64
  parent: null | CommandTree;
@@ -60,4 +69,5 @@ type SerializedCommandTree = Omit<CommandTree, "parent" | "children"> & {
60
69
  children: Record<string, SerializedCommandTree>;
61
70
  };
62
71
  //#endregion
63
- export { BaseCommandOption, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandTree, NumberCommandOption, SerializedCommandTree, StringCommandOption };
72
+ export { BaseCommandOption, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandPath, CommandTree, CommandTreePath, NumberCommandOption, SerializedCommandTree, StringCommandOption };
73
+ //# sourceMappingURL=command.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.d.mts","names":[],"sources":["../../src/types/command.ts"],"sourcesContent":[],"mappings":";;;;UAqBiB,iBAAA;;EAAA,IAAA,EAET,cAF0B;EAUjB,KAAA,EAAA,MAAA;EAMA,WAAA,EAAA,MAAA;EAMA,KAAA,EAAA,MAAA,EAAA;EAOL,GAAA,EAAA,MAAA,GAAA,KAAa;EACrB,QAAA,EAAA,OAAA;;AAEA,UAtBa,mBAAA,SAA4B,iBAsBzC,CAAA;EAAoB,IAAA,EArBhB,cAAA,CAAe,MAqBC;EAEP,OAAA,CAAA,EAAA,MAAY;EAQZ,QAAA,EAAA,OAAW;AAK5B;AAUiB,UAzCA,mBAAA,SAA4B,iBAyCP,CAAA;EAKrB,IAAA,EA7CT,cAAA,CAAe,MA6CU;EACL,OAAA,CAAA,EAAA,MAAA;EAAf,QAAA,EAAA,OAAA;;AADuC,UAxCnC,oBAAA,SAA6B,iBAwCM,CAAA;EAIxC,IAAA,EA3CJ,cAAA,CAAe,OA2CA;EAAG,OAAA,CAAA,EAAA,OAAA;EAGlB,YAAA,CAAA,EAAA,MAAA;EACkB,kBAAA,CAAA,EAAA,OAAA;;AAChB,KA1CE,aAAA,GACR,mBAyCM,GAxCN,mBAwCM,GAvCN,oBAuCM;AACO,UAtCA,YAAA,CAsCA;EACU,IAAA,EAAA,MAAA;EAAf,WAAA,CAAA,EAAA,MAAA;EAAM,OAAA,CAAA,EAAA,MAAA;EAGN,QAAA,EAAA,OAAA;EAA6B,QAAA,EAAA,OAAA;;AAEd,UApCV,WAAA,CAoCU;EAAf,KAAA,EAAA,MAAA,GAAA,IAAA;EAAM,QAAA,EAAA,MAAA,EAAA;;UA/BD,WAAA;;;;;;QAMT;;;UAIS,YAAA,SAAqB;;SAE7B;;UAGQ,eAAA,SAAwB;aAC5B,eAAe;;KAGhB,WAAA,GAAc;;;QAGlB;WACG,eAAe;UAChB;iBACO;YACL,eAAe;;KAGf,qBAAA,GAAwB,KAAK;;YAE7B,eAAe"}
@@ -1,10 +1,16 @@
1
1
  import { CommandBase, CommandOption } from "./command.cjs";
2
2
  import { Context } from "./context.cjs";
3
- import { NodeJsPluginOptions, NodeJsPluginResolvedConfig, NodeJsPluginUserConfig } from "@powerlines/plugin-nodejs/types/plugin";
4
- import { TsdownPluginResolvedConfig, TsdownPluginUserConfig } from "@powerlines/plugin-tsdown";
3
+ import { OutputConfig as OutputConfig$1 } from "powerlines/types/config";
4
+ import { AutoMDPluginResolvedConfig } from "@powerlines/plugin-automd/types/plugin";
5
+ import { NodeJsPluginResolvedConfig } from "@powerlines/plugin-nodejs/types/plugin";
6
+ import { TsdownPluginResolvedConfig, TsdownPluginUserConfig } from "@powerlines/plugin-tsdown/types/plugin";
5
7
 
6
8
  //#region src/types/config.d.ts
7
- interface Options extends NodeJsPluginOptions {
9
+ type BaseConfig = Pick<TsdownPluginUserConfig, "root" | "name" | "title" | "description" | "logLevel" | "mode" | "skipCache" | "autoInstall" | "entry" | "plugins" | "tsconfig" | "tsconfigRaw">;
10
+ /**
11
+ * The plugin options for Shell Shock.
12
+ */
13
+ type Options = Partial<BaseConfig> & {
8
14
  /**
9
15
  * A set of default command options to apply to each command.
10
16
  *
@@ -13,13 +19,71 @@ interface Options extends NodeJsPluginOptions {
13
19
  */
14
20
  defaultOptions?: CommandOption[] | ((context: Context, input: CommandBase) => CommandOption[]) | false;
15
21
  /**
16
- * The name(s) of the binary that will be generated to run the CLI
22
+ * Determines whether commands and option names are treated as case-sensitive.
23
+ *
24
+ * @defaultValue `false`
25
+ */
26
+ isCaseSensitive?: boolean;
27
+ /**
28
+ * The name of the binary (the {@link https://docs.npmjs.com/cli/v11/configuring-npm/package-json#bin | "bin" field} in package.json) that will be used to run the application through NodeJs package managers (e.g., npm, yarn, pnpm).
29
+ *
30
+ * @remarks
31
+ * If an array is provided, each binary will be linked to the same compiled output file. If not provided, the {@link Options.name | name} option will be used.
32
+ *
33
+ * @see https://docs.npmjs.com/cli/v11/configuring-npm/package-json#bin
34
+ * @see https://yarnpkg.com/cli/bin
35
+ * @see https://pnpm.io/package_json#bin
17
36
  */
18
37
  bin?: string | string[];
19
- }
20
- type UserConfig = Partial<Omit<TsdownPluginUserConfig, "type" | "framework" | "singleBuild" | "environments">> & Partial<NodeJsPluginUserConfig> & Omit<Options, "env">;
21
- type ResolvedConfig = TsdownPluginResolvedConfig & NodeJsPluginResolvedConfig & Required<Omit<Options, "bin" | "env"> & {
22
- bin: string[];
23
- }>;
38
+ /**
39
+ * An application specific prefix to check for environment variables.
40
+ *
41
+ * @remarks
42
+ * If not provided, Shell Shock will convert {@link Options.name | name} to {@link https://stringcase.org/cases/constant/ | constant case} format and append an underscore (`_`). If the provided {@link Options.name | name} is `"my-app"`, environment variables starting with `"MY_APP_"` will be used - for example: `"MY_APP_CONFIG_NAME"`. If a trailing underscore already exists in the user provided value, it will result in two consecutive underscores - for example: `"MY_APP__CONFIG_NAME"` (this was done intentionally so that users who specifically want multiple underscores have a way to do so).
43
+ *
44
+ * @see https://medium.com/chingu/an-introduction-to-environment-variables-and-how-to-use-them-f602f66d15fa
45
+ * @see https://stringcase.org/cases/constant/
46
+ */
47
+ envPrefix?: string;
48
+ };
49
+ /**
50
+ * The output configuration options for Shell Shock.
51
+ */
52
+ type OutputConfig = Pick<OutputConfig$1, "outputPath" | "assets" | "storage"> & {
53
+ /**
54
+ * An indicator specifying whether to generate TypeScript declaration files (.d.ts) during the build process.
55
+ */
56
+ dts?: false;
57
+ };
58
+ /**
59
+ * The user configuration options for Shell Shock.
60
+ */
61
+ type UserConfig = Options & {
62
+ /**
63
+ * Configuration for the output of the build process
64
+ */
65
+ output?: OutputConfig;
66
+ };
67
+ /**
68
+ * The resolved configuration options for Shell Shock.
69
+ */
70
+ type ResolvedConfig = TsdownPluginResolvedConfig & NodeJsPluginResolvedConfig & AutoMDPluginResolvedConfig & Required<Omit<Options, "bin">> & {
71
+ /**
72
+ * The name of the binary (the {@link https://docs.npmjs.com/cli/v11/configuring-npm/package-json#bin | "bin" field} in package.json) that will be used to run the application through NodeJs package managers (e.g., npm, yarn, pnpm).
73
+ *
74
+ * @remarks
75
+ * If an array is provided, each binary will be linked to the same compiled output file. If not provided, the {@link Options.name | name} option will be used.
76
+ *
77
+ * @see https://docs.npmjs.com/cli/v11/configuring-npm/package-json#bin
78
+ * @see https://yarnpkg.com/cli/bin
79
+ * @see https://pnpm.io/package_json#bin
80
+ */
81
+ bin: Record<string, string>;
82
+ /**
83
+ * The user configuration for the Shell Shock process.
84
+ */
85
+ userConfig: UserConfig & NodeJsPluginResolvedConfig;
86
+ };
24
87
  //#endregion
25
- export { Options, ResolvedConfig, UserConfig };
88
+ export { BaseConfig, Options, OutputConfig, ResolvedConfig, UserConfig };
89
+ //# sourceMappingURL=config.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.cts","names":[],"sources":["../../src/types/config.ts"],"sourcesContent":[],"mappings":";;;;;;;;KA4BY,UAAA,GAAa,KACvB;;AADF;AAmBA;AAA8B,KAAlB,OAAA,GAAU,OAAQ,CAAA,UAAA,CAAA,GAAA;EAAR;;;;;;EA8CV,cAAA,CAAY,EAtClB,aAuCJ,EAAA,GAAA,CAAA,CAAA,OADyB,EArCV,OAqCc,EAAA,KAAA,EArCE,WAqCF,EAAA,GArCkB,aAqClB,EAAA,CAAA,GAAA,KAAA;EAanB;AAUZ;;;;EAGgB,eAAA,CAAA,EAAA,OAAA;EAAL;;;;;;;;;;;;;;;;;;;;;;;;;KA1BC,YAAA,GAAe,KACzB;;;;;;;;;KAYU,UAAA,GAAa;;;;WAId;;;;;KAMC,cAAA,GAAiB,6BAC3B,6BACA,6BACA,SAAS,KAAK;;;;;;;;;;;OAWP;;;;cAKO,aAAa"}