@shell-shock/preset-script 0.6.10 → 0.6.12

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 (79) hide show
  1. package/dist/components/banner-function-declaration.cjs +3 -4
  2. package/dist/components/banner-function-declaration.cjs.map +1 -1
  3. package/dist/components/banner-function-declaration.mjs +1 -2
  4. package/dist/components/banner-function-declaration.mjs.map +1 -1
  5. package/dist/components/bin-entry.cjs +8 -1
  6. package/dist/components/bin-entry.cjs.map +1 -1
  7. package/dist/components/bin-entry.d.cts.map +1 -1
  8. package/dist/components/bin-entry.d.mts.map +1 -1
  9. package/dist/components/bin-entry.mjs +8 -1
  10. package/dist/components/bin-entry.mjs.map +1 -1
  11. package/dist/components/command-entry.cjs +1 -1
  12. package/dist/components/command-entry.mjs +1 -1
  13. package/dist/components/exit-function-declaration.cjs +161 -0
  14. package/dist/components/exit-function-declaration.cjs.map +1 -0
  15. package/dist/components/exit-function-declaration.d.cts +10 -0
  16. package/dist/components/exit-function-declaration.d.cts.map +1 -0
  17. package/dist/components/exit-function-declaration.d.mts +10 -0
  18. package/dist/components/exit-function-declaration.d.mts.map +1 -0
  19. package/dist/components/exit-function-declaration.mjs +160 -0
  20. package/dist/components/exit-function-declaration.mjs.map +1 -0
  21. package/dist/components/help.cjs +3 -4
  22. package/dist/components/help.cjs.map +1 -1
  23. package/dist/components/help.d.cts +7 -7
  24. package/dist/components/help.d.mts +7 -7
  25. package/dist/components/help.d.mts.map +1 -1
  26. package/dist/components/help.mjs +1 -2
  27. package/dist/components/help.mjs.map +1 -1
  28. package/dist/components/index.cjs +3 -20
  29. package/dist/components/index.d.cts +2 -3
  30. package/dist/components/index.d.mts +2 -3
  31. package/dist/components/index.mjs +2 -3
  32. package/dist/components/virtual-command-entry.cjs +1 -0
  33. package/dist/components/virtual-command-entry.cjs.map +1 -1
  34. package/dist/components/virtual-command-entry.mjs +1 -0
  35. package/dist/components/virtual-command-entry.mjs.map +1 -1
  36. package/dist/index.cjs +3 -9
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.d.cts.map +1 -1
  39. package/dist/index.d.mts.map +1 -1
  40. package/dist/index.mjs +2 -8
  41. package/dist/index.mjs.map +1 -1
  42. package/dist/types/plugin.d.mts.map +1 -1
  43. package/package.json +16 -71
  44. package/dist/components/console-builtin.cjs +0 -2963
  45. package/dist/components/console-builtin.cjs.map +0 -1
  46. package/dist/components/console-builtin.d.cts +0 -60
  47. package/dist/components/console-builtin.d.cts.map +0 -1
  48. package/dist/components/console-builtin.d.mts +0 -60
  49. package/dist/components/console-builtin.d.mts.map +0 -1
  50. package/dist/components/console-builtin.mjs +0 -2953
  51. package/dist/components/console-builtin.mjs.map +0 -1
  52. package/dist/components/utils-builtin.cjs +0 -725
  53. package/dist/components/utils-builtin.cjs.map +0 -1
  54. package/dist/components/utils-builtin.d.cts +0 -33
  55. package/dist/components/utils-builtin.d.cts.map +0 -1
  56. package/dist/components/utils-builtin.d.mts +0 -33
  57. package/dist/components/utils-builtin.d.mts.map +0 -1
  58. package/dist/components/utils-builtin.mjs +0 -717
  59. package/dist/components/utils-builtin.mjs.map +0 -1
  60. package/dist/contexts/index.cjs +0 -4
  61. package/dist/contexts/index.d.cts +0 -2
  62. package/dist/contexts/index.d.mts +0 -2
  63. package/dist/contexts/index.mjs +0 -3
  64. package/dist/contexts/theme.cjs +0 -29
  65. package/dist/contexts/theme.cjs.map +0 -1
  66. package/dist/contexts/theme.d.cts +0 -20
  67. package/dist/contexts/theme.d.cts.map +0 -1
  68. package/dist/contexts/theme.d.mts +0 -20
  69. package/dist/contexts/theme.d.mts.map +0 -1
  70. package/dist/contexts/theme.mjs +0 -27
  71. package/dist/contexts/theme.mjs.map +0 -1
  72. package/dist/helpers/ansi-utils.cjs +0 -693
  73. package/dist/helpers/ansi-utils.cjs.map +0 -1
  74. package/dist/helpers/ansi-utils.d.cts +0 -75
  75. package/dist/helpers/ansi-utils.d.cts.map +0 -1
  76. package/dist/helpers/ansi-utils.d.mts +0 -75
  77. package/dist/helpers/ansi-utils.d.mts.map +0 -1
  78. package/dist/helpers/ansi-utils.mjs +0 -689
  79. package/dist/helpers/ansi-utils.mjs.map +0 -1
@@ -1,725 +0,0 @@
1
- const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
- const require_components_helpers = require('./helpers.cjs');
3
- let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
4
- let __alloy_js_core = require("@alloy-js/core");
5
- let __alloy_js_typescript = require("@alloy-js/typescript");
6
- let __powerlines_plugin_alloy_core_components_spacing = require("@powerlines/plugin-alloy/core/components/spacing");
7
- let __powerlines_plugin_alloy_core_contexts_context = require("@powerlines/plugin-alloy/core/contexts/context");
8
- let __shell_shock_core_plugin_utils_context_helpers = require("@shell-shock/core/plugin-utils/context-helpers");
9
- let __powerlines_plugin_alloy_typescript_components_tsdoc = require("@powerlines/plugin-alloy/typescript/components/tsdoc");
10
- let defu = require("defu");
11
- defu = require_rolldown_runtime.__toESM(defu);
12
- let __powerlines_plugin_alloy_typescript_components_builtin_file = require("@powerlines/plugin-alloy/typescript/components/builtin-file");
13
-
14
- //#region src/components/utils-builtin.tsx
15
- /**
16
- * Generates utilities for detecting terminal color support.
17
- */
18
- function EnvSupportUtilities() {
19
- return [
20
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
21
- "export": true,
22
- "const": true,
23
- name: "isTTY",
24
- doc: "Detect if stdout.TTY is available",
25
- initializer: __alloy_js_core.code`Boolean(process.stdout && process.stdout.isTTY);`
26
- }),
27
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
28
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
29
- "export": true,
30
- "const": true,
31
- name: "isMinimal",
32
- doc: "Detect if the current environment is minimal (CI, non-TTY, etc.)",
33
- initializer: __alloy_js_core.code` env.MINIMAL || isCI || isTest || !isTTY; `
34
- }),
35
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
36
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
37
- "export": true,
38
- "const": true,
39
- name: "isInteractive",
40
- doc: "Detect if the current environment is interactive",
41
- initializer: __alloy_js_core.code` !isMinimal && process.stdin?.isTTY && env.TERM !== "dumb" && !hasFlag(["no-interactive", "non-interactive", "no-interact"]); `
42
- })
43
- ];
44
- }
45
- /**
46
- * Generates utilities for detecting terminal color support.
47
- */
48
- function ColorSupportUtilities() {
49
- return [
50
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceDeclaration, {
51
- "export": true,
52
- name: "GetColorSupportLevelOptions",
53
- doc: "Options for the getColorSupportLevel function",
54
- get children() {
55
- return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceMember, {
56
- name: "ignoreFlags",
57
- type: "boolean",
58
- doc: "Indicates if the function should skip checking command-line flags for color support"
59
- });
60
- }
61
- }),
62
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
63
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
64
- heading: "Checks if a specific flag is present in the command-line arguments.",
65
- get children() {
66
- return [
67
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocLink, { children: "https://github.com/sindresorhus/has-flag/blob/main/index.js" }),
68
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
69
- name: "flag",
70
- children: "The flag to check for, e.g., \"color\", \"no-color\"."
71
- }),
72
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
73
- name: "argv",
74
- children: "The command-line arguments to check against. Defaults to global Deno args or process args."
75
- }),
76
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "True if the flag is present, false otherwise." })
77
- ];
78
- }
79
- }),
80
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
81
- "export": true,
82
- name: "getColorSupportLevel",
83
- parameters: [{
84
- name: "stream",
85
- type: "NodeJS.WriteStream & { fd: 1 | 2; }"
86
- }, {
87
- name: "options",
88
- type: "GetColorSupportLevelOptions",
89
- default: "{ ignoreFlags: false }"
90
- }],
91
- children: __alloy_js_core.code`const { ignoreFlags } = options;
92
-
93
- let forceColor: number | undefined;
94
- if (env.FORCE_COLOR !== undefined) {
95
- forceColor = !env.FORCE_COLOR
96
- ? 0
97
- : typeof env.FORCE_COLOR === "boolean"
98
- ? 1
99
- : typeof env.FORCE_COLOR === "number" &&
100
- [0, 1, 2, 3].includes(Math.min(env.FORCE_COLOR as number, 3))
101
- ? Math.min(env.FORCE_COLOR as number, 3)
102
- : undefined;
103
- }
104
-
105
- if (ignoreFlags !== true && forceColor === undefined) {
106
- if (
107
- hasFlag("no-color") ||
108
- hasFlag("no-colors") ||
109
- hasFlag("color=false") ||
110
- hasFlag("color=never")
111
- ) {
112
- return 0;
113
- }
114
-
115
- if (
116
- hasFlag("color=16m") ||
117
- hasFlag("color=full") ||
118
- hasFlag("color=truecolor")
119
- ) {
120
- return 3;
121
- }
122
-
123
- if (hasFlag("color=256")) {
124
- return 2;
125
- }
126
-
127
- if (
128
- hasFlag("color") ||
129
- hasFlag("colors") ||
130
- hasFlag("color=true") ||
131
- hasFlag("color=always")
132
- ) {
133
- forceColor = 1;
134
- }
135
- }
136
-
137
- const level = Boolean(env.TF_BUILD) || Boolean(env.AGENT_NAME)
138
- ? 1
139
- : stream &&
140
- !(isTTY || (stream && stream.isTTY)) &&
141
- forceColor === undefined
142
- ? 0
143
- : env.TERM === "dumb"
144
- ? forceColor || 0
145
- : isWindows
146
- ? Number(os.release().split(".")[0]) >= 10 &&
147
- Number(os.release().split(".")[2]) >= 10_586
148
- ? Number(os.release().split(".")[2]) >= 14_931
149
- ? 3
150
- : 2
151
- : 1
152
- : isCI
153
- ? Boolean(env.GITHUB_ACTIONS) ||
154
- Boolean(env.GITEA_ACTIONS) ||
155
- Boolean(env.CIRCLECI)
156
- ? 3
157
- : Boolean(env.TRAVIS) ||
158
- Boolean(env.APPVEYOR) ||
159
- Boolean(env.GITLAB_CI) ||
160
- Boolean(env.BUILDKITE) ||
161
- Boolean(env.DRONE) ||
162
- env.CI_NAME === "codeship"
163
- ? 1
164
- : forceColor || 0
165
- : Boolean(env.TEAMCITY_VERSION)
166
- ? /^(?:9\.0*[1-9]\d*\.|\d{2,}\.)/.test(String(env.TEAMCITY_VERSION) || "")
167
- ? 1
168
- : 0
169
- : String(env.COLORTERM) === "truecolor" ||
170
- env.TERM === "xterm-kitty"
171
- ? 3
172
- : Boolean(env.TERM_PROGRAM)
173
- ? env.TERM_PROGRAM === "iTerm.app"
174
- ? Number.parseInt(
175
- (env.TERM_PROGRAM_VERSION || "").split(".")[0] as string,
176
- 10
177
- ) >= 3
178
- ? 3
179
- : 2
180
- : env.TERM_PROGRAM === "Apple_Terminal"
181
- ? 2
182
- : 0
183
- : /-256(?:color)?$/i.test(env.TERM || "")
184
- ? 2
185
- : /^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(
186
- env.TERM || ""
187
- )
188
- ? 1
189
- : Boolean(env.COLORTERM);
190
-
191
- return typeof level === "boolean" || level === 0
192
- ? false
193
- : {
194
- level,
195
- hasBasic: true,
196
- has256: level >= 2,
197
- has16m: level >= 3,
198
- };
199
-
200
- `
201
- }),
202
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
203
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
204
- "export": true,
205
- "const": true,
206
- name: "colorSupportLevels",
207
- doc: "Detect the terminal color support level in the current environment",
208
- initializer: __alloy_js_core.code` {
209
- stdout: getColorSupportLevel(process.stdout),
210
- stderr: getColorSupportLevel(process.stderr),
211
- }; `
212
- }),
213
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
214
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
215
- "export": true,
216
- "const": true,
217
- name: "isColorSupported",
218
- doc: "Detect if terminal color is supported in the current environment",
219
- initializer: __alloy_js_core.code` Boolean(colorSupportLevels.stdout); `
220
- }),
221
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
222
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
223
- "export": true,
224
- "const": true,
225
- name: "isUnicodeSupported",
226
- doc: "Detect if Unicode characters are supported in the current environment",
227
- initializer: __alloy_js_core.code` !isWindows
228
- ? env.TERM !== "linux"
229
- : Boolean(env.WT_SESSION) ||
230
- Boolean(env.TERMINUS_SUBLIME) ||
231
- env.ConEmuTask === "{cmd::Cmder}" ||
232
- env.TERM_PROGRAM === "Terminus-Sublime" ||
233
- env.TERM_PROGRAM === "vscode" ||
234
- env.TERM === "xterm-256color" ||
235
- env.TERM === "alacritty" ||
236
- env.TERM === "rxvt-unicode" ||
237
- env.TERM === "rxvt-unicode-256color" ||
238
- env.TERMINAL_EMULATOR === "JetBrains-JediTerm"; `
239
- })
240
- ];
241
- }
242
- /**
243
- * Generates utilities for detecting terminal color support.
244
- */
245
- function HyperlinkSupportUtilities() {
246
- return [
247
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
248
- name: "parseVersion",
249
- parameters: [{
250
- name: "version",
251
- type: "string",
252
- default: "\"\""
253
- }],
254
- children: __alloy_js_core.code`if (/^\d{3,4}$/.test(version)) {
255
- const match = /(\d{1,2})(\d{2})/.exec(version) ?? [];
256
-
257
- return {
258
- major: 0,
259
- minor: Number.parseInt(match[1]!, 10),
260
- patch: Number.parseInt(match[2]!, 10)
261
- };
262
- }
263
-
264
- const versionParts = (version ?? "")
265
- .split(".")
266
- .map(n => Number.parseInt(n, 10));
267
-
268
- return {
269
- major: versionParts[0],
270
- minor: versionParts[1],
271
- patch: versionParts[2]
272
- }; `
273
- }),
274
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
275
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
276
- heading: "Check if the current environment/terminal supports hyperlinks in the terminal.",
277
- get children() {
278
- return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "True if the current environment/terminal supports hyperlinks." });
279
- }
280
- }),
281
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
282
- "export": true,
283
- name: "isHyperlinkSupported",
284
- returnType: "boolean",
285
- children: __alloy_js_core.code`if (Boolean(env.FORCE_HYPERLINK)) {
286
- return true;
287
- }
288
-
289
- if (Boolean(env.NETLIFY)) {
290
- return true;
291
- } else if (isColorSupported || isTTY) {
292
- return false;
293
- } else if (Boolean(env.WT_SESSION)) {
294
- return true;
295
- } else if (isWindows || isMinimal || Boolean(env.TEAMCITY_VERSION)) {
296
- return false;
297
- } else if (Boolean(env.TERM_PROGRAM)) {
298
- const version = parseVersion(env.TERM_PROGRAM_VERSION);
299
-
300
- switch (String(env.TERM_PROGRAM)) {
301
- case "iTerm.app": {
302
- if (version.major === 3) {
303
- return version.minor !== undefined && version.minor >= 1;
304
- }
305
-
306
- return version.major !== undefined && version.major > 3;
307
- }
308
- case "WezTerm": {
309
- return version.major !== undefined && version.major >= 20_200_620;
310
- }
311
-
312
- case "vscode": {
313
- if (Boolean(env.CURSOR_TRACE_ID)) {
314
- return true;
315
- }
316
-
317
- return (
318
- version.minor !== undefined &&
319
- version.major !== undefined &&
320
- (version.major > 1 || (version.major === 1 && version.minor >= 72))
321
- );
322
- }
323
-
324
- case "ghostty": {
325
- return true;
326
- }
327
- }
328
- }
329
-
330
- if (Boolean(env.VTE_VERSION)) {
331
- if (env.VTE_VERSION === "0.50.0") {
332
- return false;
333
- }
334
-
335
- const version = parseVersion(env.VTE_VERSION);
336
- return (
337
- (version.major !== undefined && version.major > 0) ||
338
- (version.minor !== undefined && version.minor >= 50)
339
- );
340
- }
341
-
342
- if (String(env.TERM) === "alacritty") {
343
- return true;
344
- }
345
-
346
- return false; `
347
- })
348
- ];
349
- }
350
- /**
351
- * Generates utilities for detecting terminal color support.
352
- */
353
- function ArgsUtilities() {
354
- return [
355
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
356
- heading: "Retrieves the command-line arguments from Deno or Node.js environments.",
357
- get children() {
358
- return [
359
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocRemarks, { children: "This function is only intended for internal use. Please use `useArgs()` instead." }),
360
- (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
361
- (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
362
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocInternal, {}),
363
- (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
364
- (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
365
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "An array of command-line arguments from Deno or Node.js environments." })
366
- ];
367
- }
368
- }),
369
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
370
- "export": true,
371
- name: "getArgs",
372
- returnType: "string[]",
373
- children: __alloy_js_core.code`return ((globalThis as { Deno?: { args: string[] } })?.Deno?.args ?? process.argv ?? []) as string[];`
374
- }),
375
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
376
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
377
- heading: "Checks if a specific flag is present in the command-line arguments.",
378
- get children() {
379
- return [
380
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocLink, { children: "https://github.com/sindresorhus/has-flag/blob/main/index.js" }),
381
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
382
- name: "flag",
383
- children: "The flag (or an array of flags/aliases) to check for, e.g., \"color\", \"no-color\"."
384
- }),
385
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
386
- name: "argv",
387
- children: "The command-line arguments to check against. Defaults to global Deno args or process args."
388
- }),
389
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "True if the flag is present, false otherwise." })
390
- ];
391
- }
392
- }),
393
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
394
- "export": true,
395
- name: "hasFlag",
396
- parameters: [{
397
- name: "flag",
398
- type: "string | string[]"
399
- }, {
400
- name: "argv",
401
- type: "string[]",
402
- default: "useArgs()"
403
- }],
404
- get children() {
405
- return [
406
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
407
- "const": true,
408
- name: "position",
409
- type: "number",
410
- initializer: __alloy_js_core.code`(Array.isArray(flag) ? flag : [flag]).reduce((ret, f) => {
411
- const pos = argv.findIndex(arg => (f.startsWith("-") ? "" : (f.length === 1 ? "-" : "--") + f)?.toLowerCase() === arg?.toLowerCase() || arg?.toLowerCase().startsWith((f.length === 1 ? "-" : "--") + f + "="));
412
- return pos !== -1 ? pos : ret;
413
- }, -1);`
414
- }),
415
- (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
416
- __alloy_js_core.code`return position !== -1 && argv.indexOf("--") === -1 || position < argv.indexOf("--");`
417
- ];
418
- }
419
- }),
420
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
421
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
422
- "export": true,
423
- name: "isHelp",
424
- type: "boolean",
425
- initializer: __alloy_js_core.code` !isCI && hasFlag(["help", "h", "?"]); `
426
- })
427
- ];
428
- }
429
- /**
430
- * The `exit` handler function declaration code for the Shell Shock project.
431
- */
432
- function ExitFunctionDeclaration() {
433
- const context = (0, __powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
434
- return [
435
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceDeclaration, {
436
- "export": true,
437
- name: "ExitOptions",
438
- doc: "Options for the exit handler function.",
439
- get children() {
440
- return [
441
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceMember, {
442
- name: "exception",
443
- optional: true,
444
- type: "string | Error",
445
- doc: "An optional exception that caused the exit. This can be a string message or an Error object."
446
- }),
447
- (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
448
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceMember, {
449
- name: "skipProcessExit",
450
- optional: true,
451
- type: "boolean",
452
- doc: "Indicates whether the exit function should manually exit the process or not. If set to true, the exit function will not call process.exit() and will allow the application to continue running. If set to false or not specified, the exit function will call process.exit() to terminate the application."
453
- }),
454
- (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
455
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceMember, {
456
- name: "isSynchronous",
457
- optional: true,
458
- type: "boolean",
459
- doc: "Indicates whether the exit function should perform synchronous operations only. If set to true, the exit function will avoid any asynchronous operations during exit. If set to false or not specified, the exit function may perform asynchronous operations as needed."
460
- }),
461
- (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
462
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceMember, {
463
- name: "signal",
464
- optional: true,
465
- type: "number",
466
- doc: "The signal number that triggered the exit. This is typically used when the shutdown is initiated by a system signal (e.g., SIGINT, SIGTERM)."
467
- }),
468
- (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
469
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceMember, {
470
- name: "startDate",
471
- optional: true,
472
- type: "Date",
473
- doc: "A Date object representing the timestamp when the process started. This can be used to measure the duration of the shutdown process."
474
- })
475
- ];
476
- }
477
- }),
478
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
479
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
480
- "let": true,
481
- name: "isExiting",
482
- type: "boolean",
483
- initializer: __alloy_js_core.code`false;`
484
- }),
485
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
486
- "const": true,
487
- name: "callbackAsyncQueue",
488
- type: "Array<[(code: number | string) => Promise<void> | void, number]>",
489
- initializer: __alloy_js_core.code`[];`
490
- }),
491
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
492
- "const": true,
493
- name: "callbackSyncQueue",
494
- type: "Array<(code: number | string) => void>",
495
- initializer: __alloy_js_core.code`[];`
496
- }),
497
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
498
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
499
- "export": true,
500
- async: true,
501
- name: "exit",
502
- parameters: [{
503
- name: "options",
504
- type: "ExitOptions",
505
- default: "{}"
506
- }],
507
- get children() {
508
- return [
509
- (0, __alloy_js_core_jsx_runtime.memo)(() => __alloy_js_core.code`
510
- try {
511
- if (isExiting) {
512
- return;
513
- }
514
-
515
- isExiting = true;
516
-
517
- let exitCode: number | string = 0;
518
- if ((options.signal !== undefined && options.signal > 0) || options.exception) {
519
- exitCode = 128 + (options.signal ?? 1);
520
- } else if (typeof process.exitCode === "number" || typeof process.exitCode === "string") {
521
- exitCode = process.exitCode;
522
- }
523
-
524
- if (options.exception) {
525
- error(\`A fatal error occured while running the application - please contact the ${(0, __shell_shock_core_plugin_utils_context_helpers.getAppTitle)(context)} support team\${options.exception && typeof options.exception !== "symbol" ? \`: \\n\\n\${typeof options.exception === "string" ? options.exception : options.exception.message}\` : "."}\`);
526
- }
527
-
528
- const terminate = (force = false) => { `),
529
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
530
- get condition() {
531
- return (0, __alloy_js_core_jsx_runtime.createComponent)(require_components_helpers.IsVerbose, {});
532
- },
533
- children: __alloy_js_core.code`writeLine("");`
534
- }),
535
- (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
536
- (0, __alloy_js_core_jsx_runtime.memo)(() => __alloy_js_core.code`
537
- verbose(\`The ${(0, __shell_shock_core_plugin_utils_context_helpers.getAppTitle)(context)} application exited \${options.exception ? \`early due to an exception\` : "successfully"}\${options.startDate ? \`. Total processing time is \${Date.now() - options.startDate.getTime() > 5000 ? Math.floor((Date.now() - options.startDate.getTime()) / 1000) : Date.now() - options.startDate.getTime()} \${Date.now() - options.startDate.getTime() > 5000 ? "seconds" : "milliseconds"}\` : ""}...\`);
538
- if (!options.skipProcessExit) {
539
- process.nextTick(() => process.exit(exitCode));
540
- }
541
- };
542
-
543
- for (const callbackSync of callbackSyncQueue) {
544
- callbackSync(exitCode);
545
- }
546
-
547
- if (!options.isSynchronous) {
548
- const promises = [];
549
- let forceAfter = 0;
550
- for (const [callbackAsync, wait] of callbackAsyncQueue) {
551
- forceAfter = Math.max(forceAfter, wait);
552
- promises.push(Promise.resolve(callbackAsync(exitCode)));
553
- }
554
-
555
- const asyncTimer = setTimeout(() => {
556
- terminate(true);
557
- }, forceAfter);
558
- await Promise.all(promises);
559
- clearTimeout(asyncTimer);
560
- }
561
-
562
- terminate();
563
- } catch (err) {
564
- error(\`The exit process failed to complete\${(err as Error).message ? \` - (err as Error).message\` : ""}. Please contact the ${(0, __shell_shock_core_plugin_utils_context_helpers.getAppTitle)(context)} support team.\`);
565
-
566
- if (!options.skipProcessExit) {
567
- process.nextTick(() => process.exit(1));
568
- }
569
- }
570
- `)
571
- ];
572
- }
573
- })
574
- ];
575
- }
576
- function ContextUtilities() {
577
- return __alloy_js_core.code`
578
- /**
579
- * The global Shell Shock - Application context instance.
580
- *
581
- * @internal
582
- */
583
- export let internal_appContext = new AsyncLocalStorage<Map<string, any>>();
584
-
585
- /**
586
- * Get the Shell Shock - Application context for the current application.
587
- *
588
- * @param options - The options to use when getting the context.
589
- * @returns The Shell Shock - Application context for the current application or undefined if the context is not available.
590
- */
591
- export function useApp(): Map<string, any> | undefined {
592
- return internal_appContext.getStore();
593
- }
594
-
595
- /**
596
- * A utility hook function to get the command line arguments from the application context.
597
- *
598
- * @returns An array of command-line arguments from the application context.
599
- * @throws If the application context is not available.
600
- */
601
- export function useArgs(): string[] {
602
- return useApp()?.get("args") ?? getArgs();
603
- }
604
-
605
- /**
606
- * The context object for the current command execution, containing the command path and segments.
607
- */
608
- export interface CommandContext {
609
- path: string;
610
- segments: string[];
611
- }
612
-
613
- /**
614
- * The global Shell Shock - Command context instance.
615
- *
616
- * @internal
617
- */
618
- export let internal_commandContext = new AsyncLocalStorage<CommandContext>();
619
-
620
- /**
621
- * Get the Shell Shock - Command context for the current application.
622
- *
623
- * @param options - The options to use when getting the context.
624
- * @returns The Shell Shock - Command context for the current application.
625
- * @throws If the Shell Shock - Command context is not available.
626
- */
627
- export function useCommand(): CommandContext {
628
- const result = internal_commandContext.getStore();
629
- if (!result) {
630
- throw new Error(
631
- \`The Shell Shock - Command context is not available. Make sure to call useCommand() within a valid context scope.\`
632
- );
633
- }
634
- return result;
635
- }
636
-
637
- /**
638
- * A utility hook function to get the individual segments of the current command path.
639
- *
640
- * @returns An array of command path segments.
641
- * @throws If the command context is not available.
642
- */
643
- export function useSegments(): string[] {
644
- return useCommand().segments;
645
- }
646
-
647
- /**
648
- * A utility hook function to get the full command path as a string.
649
- *
650
- * @returns The full command path as a string.
651
- * @throws If the command context is not available.
652
- */
653
- export function usePath(): string {
654
- return useCommand().path;
655
- }
656
- `;
657
- }
658
- /**
659
- * A built-in utilities module for Shell Shock.
660
- */
661
- function UtilsBuiltin(props) {
662
- const [{ children }, rest] = (0, __alloy_js_core.splitProps)(props, ["children"]);
663
- return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_builtin_file.BuiltinFile, (0, __alloy_js_core_jsx_runtime.mergeProps)({
664
- id: "utils",
665
- description: "A collection of helper utilities that ease command-line application development."
666
- }, rest, {
667
- get imports() {
668
- return (0, defu.default)(rest.imports ?? {}, {
669
- "node:os": "os",
670
- "node:process": "process",
671
- "node:async_hooks": ["AsyncLocalStorage"]
672
- });
673
- },
674
- get builtinImports() {
675
- return (0, defu.default)(rest.builtinImports ?? {}, {
676
- console: [
677
- "error",
678
- "verbose",
679
- "writeLine"
680
- ],
681
- env: [
682
- "env",
683
- "isCI",
684
- "isTest",
685
- "isWindows",
686
- "isDevelopment",
687
- "isDebug"
688
- ]
689
- });
690
- },
691
- get children() {
692
- return [
693
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
694
- (0, __alloy_js_core_jsx_runtime.createComponent)(ContextUtilities, {}),
695
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
696
- (0, __alloy_js_core_jsx_runtime.createComponent)(ArgsUtilities, {}),
697
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
698
- (0, __alloy_js_core_jsx_runtime.createComponent)(EnvSupportUtilities, {}),
699
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
700
- (0, __alloy_js_core_jsx_runtime.createComponent)(HyperlinkSupportUtilities, {}),
701
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
702
- (0, __alloy_js_core_jsx_runtime.createComponent)(ColorSupportUtilities, {}),
703
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
704
- (0, __alloy_js_core_jsx_runtime.createComponent)(ExitFunctionDeclaration, {}),
705
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
706
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
707
- get when() {
708
- return Boolean(children);
709
- },
710
- children
711
- })
712
- ];
713
- }
714
- }));
715
- }
716
-
717
- //#endregion
718
- exports.ArgsUtilities = ArgsUtilities;
719
- exports.ColorSupportUtilities = ColorSupportUtilities;
720
- exports.ContextUtilities = ContextUtilities;
721
- exports.EnvSupportUtilities = EnvSupportUtilities;
722
- exports.ExitFunctionDeclaration = ExitFunctionDeclaration;
723
- exports.HyperlinkSupportUtilities = HyperlinkSupportUtilities;
724
- exports.UtilsBuiltin = UtilsBuiltin;
725
- //# sourceMappingURL=utils-builtin.cjs.map