@shell-shock/preset-script 0.1.1 → 0.2.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 (134) hide show
  1. package/README.md +1 -1
  2. package/dist/components/args-parser-logic.cjs +678 -0
  3. package/dist/components/args-parser-logic.cjs.map +1 -0
  4. package/dist/components/args-parser-logic.d.cts +45 -0
  5. package/dist/components/args-parser-logic.d.cts.map +1 -0
  6. package/dist/components/args-parser-logic.d.mts +45 -0
  7. package/dist/components/args-parser-logic.d.mts.map +1 -0
  8. package/dist/components/args-parser-logic.mjs +672 -0
  9. package/dist/components/args-parser-logic.mjs.map +1 -0
  10. package/dist/components/bin-entry.cjs +188 -0
  11. package/dist/components/bin-entry.cjs.map +1 -0
  12. package/dist/components/{entry/bin.d.cts → bin-entry.d.cts} +9 -3
  13. package/dist/components/bin-entry.d.cts.map +1 -0
  14. package/dist/components/{entry/bin.d.mts → bin-entry.d.mts} +9 -3
  15. package/dist/components/bin-entry.d.mts.map +1 -0
  16. package/dist/components/bin-entry.mjs +185 -0
  17. package/dist/components/bin-entry.mjs.map +1 -0
  18. package/dist/components/command-entry.cjs +162 -0
  19. package/dist/components/command-entry.cjs.map +1 -0
  20. package/dist/components/command-entry.d.cts +24 -0
  21. package/dist/components/command-entry.d.cts.map +1 -0
  22. package/dist/components/command-entry.d.mts +24 -0
  23. package/dist/components/command-entry.d.mts.map +1 -0
  24. package/dist/components/command-entry.mjs +158 -0
  25. package/dist/components/command-entry.mjs.map +1 -0
  26. package/dist/components/command-router.cjs +129 -74
  27. package/dist/components/command-router.cjs.map +1 -1
  28. package/dist/components/command-router.d.cts +13 -4
  29. package/dist/components/command-router.d.cts.map +1 -0
  30. package/dist/components/command-router.d.mts +13 -4
  31. package/dist/components/command-router.d.mts.map +1 -0
  32. package/dist/components/command-router.mjs +128 -73
  33. package/dist/components/command-router.mjs.map +1 -1
  34. package/dist/components/console-builtin.cjs +2086 -0
  35. package/dist/components/console-builtin.cjs.map +1 -0
  36. package/dist/components/console-builtin.d.cts +56 -0
  37. package/dist/components/console-builtin.d.cts.map +1 -0
  38. package/dist/components/console-builtin.d.mts +56 -0
  39. package/dist/components/console-builtin.d.mts.map +1 -0
  40. package/dist/components/console-builtin.mjs +2077 -0
  41. package/dist/components/console-builtin.mjs.map +1 -0
  42. package/dist/components/help.cjs +130 -0
  43. package/dist/components/help.cjs.map +1 -0
  44. package/dist/components/help.d.cts +57 -0
  45. package/dist/components/help.d.cts.map +1 -0
  46. package/dist/components/help.d.mts +57 -0
  47. package/dist/components/help.d.mts.map +1 -0
  48. package/dist/components/help.mjs +126 -0
  49. package/dist/components/help.mjs.map +1 -0
  50. package/dist/components/index.cjs +39 -15
  51. package/dist/components/index.d.cts +9 -7
  52. package/dist/components/index.d.mts +9 -7
  53. package/dist/components/index.mjs +8 -6
  54. package/dist/components/utils-builtin.cjs +612 -0
  55. package/dist/components/utils-builtin.cjs.map +1 -0
  56. package/dist/components/utils-builtin.d.cts +32 -0
  57. package/dist/components/utils-builtin.d.cts.map +1 -0
  58. package/dist/components/utils-builtin.d.mts +32 -0
  59. package/dist/components/utils-builtin.d.mts.map +1 -0
  60. package/dist/components/utils-builtin.mjs +605 -0
  61. package/dist/components/utils-builtin.mjs.map +1 -0
  62. package/dist/components/virtual-command-entry.cjs +140 -0
  63. package/dist/components/virtual-command-entry.cjs.map +1 -0
  64. package/dist/components/virtual-command-entry.d.cts +21 -0
  65. package/dist/components/virtual-command-entry.d.cts.map +1 -0
  66. package/dist/components/virtual-command-entry.d.mts +21 -0
  67. package/dist/components/virtual-command-entry.d.mts.map +1 -0
  68. package/dist/components/virtual-command-entry.mjs +137 -0
  69. package/dist/components/virtual-command-entry.mjs.map +1 -0
  70. package/dist/contexts/index.cjs +4 -0
  71. package/dist/contexts/index.d.cts +2 -0
  72. package/dist/contexts/index.d.mts +2 -0
  73. package/dist/contexts/index.mjs +3 -0
  74. package/dist/contexts/theme.d.cts +20 -0
  75. package/dist/contexts/theme.d.cts.map +1 -0
  76. package/dist/contexts/theme.d.mts +20 -0
  77. package/dist/contexts/theme.d.mts.map +1 -0
  78. package/dist/helpers/ansi-utils.cjs +28 -4
  79. package/dist/helpers/ansi-utils.cjs.map +1 -1
  80. package/dist/helpers/ansi-utils.d.cts +68 -0
  81. package/dist/helpers/ansi-utils.d.cts.map +1 -0
  82. package/dist/helpers/ansi-utils.d.mts +68 -0
  83. package/dist/helpers/ansi-utils.d.mts.map +1 -0
  84. package/dist/helpers/ansi-utils.mjs +28 -4
  85. package/dist/helpers/ansi-utils.mjs.map +1 -1
  86. package/dist/helpers/get-default-options.cjs +6 -13
  87. package/dist/helpers/get-default-options.cjs.map +1 -1
  88. package/dist/helpers/get-default-options.mjs +6 -13
  89. package/dist/helpers/get-default-options.mjs.map +1 -1
  90. package/dist/index.cjs +117 -29
  91. package/dist/index.cjs.map +1 -1
  92. package/dist/index.d.cts.map +1 -0
  93. package/dist/index.d.mts.map +1 -0
  94. package/dist/index.mjs +118 -28
  95. package/dist/index.mjs.map +1 -1
  96. package/dist/types/plugin.d.cts +1 -6
  97. package/dist/types/plugin.d.cts.map +1 -0
  98. package/dist/types/plugin.d.mts +1 -6
  99. package/dist/types/plugin.d.mts.map +1 -0
  100. package/package.json +163 -71
  101. package/dist/components/builtin/console.cjs +0 -1232
  102. package/dist/components/builtin/console.cjs.map +0 -1
  103. package/dist/components/builtin/console.d.cts +0 -37
  104. package/dist/components/builtin/console.d.mts +0 -37
  105. package/dist/components/builtin/console.mjs +0 -1225
  106. package/dist/components/builtin/console.mjs.map +0 -1
  107. package/dist/components/builtin/index.cjs +0 -9
  108. package/dist/components/builtin/index.d.cts +0 -2
  109. package/dist/components/builtin/index.d.mts +0 -2
  110. package/dist/components/builtin/index.mjs +0 -3
  111. package/dist/components/entry/bin.cjs +0 -92
  112. package/dist/components/entry/bin.cjs.map +0 -1
  113. package/dist/components/entry/bin.mjs +0 -91
  114. package/dist/components/entry/bin.mjs.map +0 -1
  115. package/dist/components/entry/command.cjs +0 -54
  116. package/dist/components/entry/command.cjs.map +0 -1
  117. package/dist/components/entry/command.d.cts +0 -15
  118. package/dist/components/entry/command.d.mts +0 -15
  119. package/dist/components/entry/command.mjs +0 -53
  120. package/dist/components/entry/command.mjs.map +0 -1
  121. package/dist/components/entry/index.cjs +0 -3
  122. package/dist/components/entry/index.d.cts +0 -2
  123. package/dist/components/entry/index.d.mts +0 -2
  124. package/dist/components/entry/index.mjs +0 -3
  125. package/dist/components/shutdown.cjs +0 -93
  126. package/dist/components/shutdown.cjs.map +0 -1
  127. package/dist/components/shutdown.d.cts +0 -14
  128. package/dist/components/shutdown.d.mts +0 -14
  129. package/dist/components/shutdown.mjs +0 -91
  130. package/dist/components/shutdown.mjs.map +0 -1
  131. package/dist/contexts/command.cjs +0 -21
  132. package/dist/contexts/command.cjs.map +0 -1
  133. package/dist/contexts/command.mjs +0 -19
  134. package/dist/contexts/command.mjs.map +0 -1
@@ -0,0 +1,32 @@
1
+ import * as _alloy_js_core0 from "@alloy-js/core";
2
+ import { BuiltinFileProps } from "@powerlines/plugin-alloy/typescript/components/builtin-file";
3
+
4
+ //#region src/components/utils-builtin.d.ts
5
+ interface UtilsBuiltinProps extends Omit<BuiltinFileProps, "id" | "description"> {}
6
+ /**
7
+ * Generates utilities for detecting terminal color support.
8
+ */
9
+ declare function EnvSupportUtilities(): _alloy_js_core0.Children;
10
+ /**
11
+ * Generates utilities for detecting terminal color support.
12
+ */
13
+ declare function ColorSupportUtilities(): _alloy_js_core0.Children;
14
+ /**
15
+ * Generates utilities for detecting terminal color support.
16
+ */
17
+ declare function HyperlinkSupportUtilities(): _alloy_js_core0.Children;
18
+ /**
19
+ * Generates utilities for detecting terminal color support.
20
+ */
21
+ declare function ArgsUtilities(): _alloy_js_core0.Children;
22
+ /**
23
+ * The `exit` handler function declaration code for the Shell Shock project.
24
+ */
25
+ declare function ExitFunctionDeclaration(): _alloy_js_core0.Children;
26
+ /**
27
+ * A built-in utilities module for Shell Shock.
28
+ */
29
+ declare function UtilsBuiltin(props: UtilsBuiltinProps): _alloy_js_core0.Children;
30
+ //#endregion
31
+ export { ArgsUtilities, ColorSupportUtilities, EnvSupportUtilities, ExitFunctionDeclaration, HyperlinkSupportUtilities, UtilsBuiltin, UtilsBuiltinProps };
32
+ //# sourceMappingURL=utils-builtin.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils-builtin.d.cts","names":[],"sources":["../../src/components/utils-builtin.tsx"],"sourcesContent":[],"mappings":";;;;UAsCiB,iBAAA,SAA0B,KACzC;;AADF;AASA;AAmCgB,iBAnCA,mBAAA,CAAA,CAmCqB,EAnCF,eAAA,CAAA,QAmCE;AAwMrC;AA2GA;AA+DA;AA0IgB,iBA5fA,qBAAA,CAAA,CA4foB,EA5fC,eAAA,CAAA,QA4fgB;;;;iBApTrC,yBAAA,CAAA,GAAyB,eAAA,CAAA;;;;iBA2GzB,aAAA,CAAA,GAAa,eAAA,CAAA;;;;iBA+Db,uBAAA,CAAA,GAAuB,eAAA,CAAA;;;;iBA0IvB,YAAA,QAAoB,oBAAiB,eAAA,CAAA"}
@@ -0,0 +1,32 @@
1
+ import * as _alloy_js_core1 from "@alloy-js/core";
2
+ import { BuiltinFileProps } from "@powerlines/plugin-alloy/typescript/components/builtin-file";
3
+
4
+ //#region src/components/utils-builtin.d.ts
5
+ interface UtilsBuiltinProps extends Omit<BuiltinFileProps, "id" | "description"> {}
6
+ /**
7
+ * Generates utilities for detecting terminal color support.
8
+ */
9
+ declare function EnvSupportUtilities(): _alloy_js_core1.Children;
10
+ /**
11
+ * Generates utilities for detecting terminal color support.
12
+ */
13
+ declare function ColorSupportUtilities(): _alloy_js_core1.Children;
14
+ /**
15
+ * Generates utilities for detecting terminal color support.
16
+ */
17
+ declare function HyperlinkSupportUtilities(): _alloy_js_core1.Children;
18
+ /**
19
+ * Generates utilities for detecting terminal color support.
20
+ */
21
+ declare function ArgsUtilities(): _alloy_js_core1.Children;
22
+ /**
23
+ * The `exit` handler function declaration code for the Shell Shock project.
24
+ */
25
+ declare function ExitFunctionDeclaration(): _alloy_js_core1.Children;
26
+ /**
27
+ * A built-in utilities module for Shell Shock.
28
+ */
29
+ declare function UtilsBuiltin(props: UtilsBuiltinProps): _alloy_js_core1.Children;
30
+ //#endregion
31
+ export { ArgsUtilities, ColorSupportUtilities, EnvSupportUtilities, ExitFunctionDeclaration, HyperlinkSupportUtilities, UtilsBuiltin, UtilsBuiltinProps };
32
+ //# sourceMappingURL=utils-builtin.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils-builtin.d.mts","names":[],"sources":["../../src/components/utils-builtin.tsx"],"sourcesContent":[],"mappings":";;;;UAsCiB,iBAAA,SAA0B,KACzC;;AADF;AASA;AAmCgB,iBAnCA,mBAAA,CAAA,CAmCqB,EAnCF,eAAA,CAAA,QAmCE;AAwMrC;AA2GA;AA+DA;AA0IgB,iBA5fA,qBAAA,CAAA,CA4foB,EA5fC,eAAA,CAAA,QA4fgB;;;;iBApTrC,yBAAA,CAAA,GAAyB,eAAA,CAAA;;;;iBA2GzB,aAAA,CAAA,GAAa,eAAA,CAAA;;;;iBA+Db,uBAAA,CAAA,GAAuB,eAAA,CAAA;;;;iBA0IvB,YAAA,QAAoB,oBAAiB,eAAA,CAAA"}
@@ -0,0 +1,605 @@
1
+ import { createComponent, createIntrinsic, memo, mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { Show, code, splitProps } from "@alloy-js/core";
3
+ import { FunctionDeclaration, InterfaceDeclaration, InterfaceMember, VarDeclaration } from "@alloy-js/typescript";
4
+ import { getAppTitle } from "@shell-shock/core/plugin-utils/context-helpers";
5
+ import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
6
+ import { TSDoc, TSDocLink, TSDocParam, TSDocReturns } from "@powerlines/plugin-alloy/typescript/components/tsdoc";
7
+ import defu from "defu";
8
+ import { BuiltinFile } from "@powerlines/plugin-alloy/typescript/components/builtin-file";
9
+
10
+ //#region src/components/utils-builtin.tsx
11
+ /**
12
+ * Generates utilities for detecting terminal color support.
13
+ */
14
+ function EnvSupportUtilities() {
15
+ return [
16
+ createComponent(VarDeclaration, {
17
+ "export": true,
18
+ "const": true,
19
+ name: "isTTY",
20
+ doc: "Detect if stdout.TTY is available",
21
+ initializer: code`Boolean(process.stdout && process.stdout.isTTY);`
22
+ }),
23
+ createIntrinsic("hbr", {}),
24
+ createIntrinsic("hbr", {}),
25
+ createComponent(VarDeclaration, {
26
+ "export": true,
27
+ "const": true,
28
+ name: "isMinimal",
29
+ doc: "Detect if the current environment is minimal (CI, non-TTY, etc.)",
30
+ initializer: code` env.MINIMAL || isCI || isTest || !isTTY; `
31
+ }),
32
+ createIntrinsic("hbr", {}),
33
+ createIntrinsic("hbr", {}),
34
+ createComponent(VarDeclaration, {
35
+ "export": true,
36
+ "const": true,
37
+ name: "isInteractive",
38
+ doc: "Detect if the current environment is interactive",
39
+ initializer: code` !isMinimal && process.stdin?.isTTY && env.TERM !== "dumb"; `
40
+ })
41
+ ];
42
+ }
43
+ /**
44
+ * Generates utilities for detecting terminal color support.
45
+ */
46
+ function ColorSupportUtilities() {
47
+ return [
48
+ createComponent(InterfaceDeclaration, {
49
+ "export": true,
50
+ name: "GetColorSupportLevelOptions",
51
+ doc: "Options for the getColorSupportLevel function",
52
+ get children() {
53
+ return createComponent(InterfaceMember, {
54
+ name: "ignoreFlags",
55
+ type: "boolean",
56
+ doc: "Indicates if the function should skip checking command-line flags for color support"
57
+ });
58
+ }
59
+ }),
60
+ createIntrinsic("hbr", {}),
61
+ createIntrinsic("hbr", {}),
62
+ createComponent(TSDoc, {
63
+ heading: "Checks if a specific flag is present in the command line arguments.",
64
+ get children() {
65
+ return [
66
+ createComponent(TSDocLink, { children: "https://github.com/sindresorhus/has-flag/blob/main/index.js" }),
67
+ createComponent(TSDocParam, {
68
+ name: "flag",
69
+ children: "The flag to check for, e.g., \"color\", \"no-color\"."
70
+ }),
71
+ createComponent(TSDocParam, {
72
+ name: "argv",
73
+ children: "The command line arguments to check against. Defaults to global Deno args or process args."
74
+ }),
75
+ createComponent(TSDocReturns, { children: "True if the flag is present, false otherwise." })
76
+ ];
77
+ }
78
+ }),
79
+ createComponent(FunctionDeclaration, {
80
+ "export": true,
81
+ name: "getColorSupportLevel",
82
+ parameters: [{
83
+ name: "stream",
84
+ type: "NodeJS.WriteStream & { fd: 1 | 2; }"
85
+ }, {
86
+ name: "options",
87
+ type: "GetColorSupportLevelOptions",
88
+ default: "{ ignoreFlags: false }"
89
+ }],
90
+ children: code`const { ignoreFlags } = options;
91
+
92
+ let forceColor: number | undefined;
93
+ if (env.FORCE_COLOR !== undefined) {
94
+ forceColor = !env.FORCE_COLOR
95
+ ? 0
96
+ : typeof env.FORCE_COLOR === "boolean"
97
+ ? 1
98
+ : typeof env.FORCE_COLOR === "number" &&
99
+ [0, 1, 2, 3].includes(Math.min(env.FORCE_COLOR as number, 3))
100
+ ? Math.min(env.FORCE_COLOR as number, 3)
101
+ : undefined;
102
+ }
103
+
104
+ if (ignoreFlags !== true && forceColor === undefined) {
105
+ forceColor = hasFlag("no-color") ||
106
+ hasFlag("no-colors") ||
107
+ hasFlag("color=false") ||
108
+ hasFlag("color=never")
109
+ ? 0
110
+ : hasFlag("color") ||
111
+ hasFlag("colors") ||
112
+ hasFlag("color=true") ||
113
+ hasFlag("color=always")
114
+ ? 1
115
+ : 0;
116
+ }
117
+
118
+ if (forceColor === 0) {
119
+ return 0;
120
+ }
121
+
122
+ if (ignoreFlags !== true) {
123
+ if (hasFlag("color=16m") ||
124
+ hasFlag("color=full") ||
125
+ hasFlag("color=truecolor")) {
126
+ return 3;
127
+ }
128
+
129
+ if (hasFlag("color=256")) {
130
+ return 2;
131
+ }
132
+ }
133
+
134
+ const level = Boolean(env.TF_BUILD) || Boolean(env.AGENT_NAME)
135
+ ? 1
136
+ : stream &&
137
+ !(isTTY || (stream && stream.isTTY)) &&
138
+ forceColor === undefined
139
+ ? 0
140
+ : env.TERM === "dumb"
141
+ ? forceColor || 0
142
+ : isWindows
143
+ ? Number(os.release().split(".")[0]) >= 10 &&
144
+ Number(os.release().split(".")[2]) >= 10_586
145
+ ? Number(os.release().split(".")[2]) >= 14_931
146
+ ? 3
147
+ : 2
148
+ : 1
149
+ : isCI
150
+ ? Boolean(env.GITHUB_ACTIONS) ||
151
+ Boolean(env.GITEA_ACTIONS) ||
152
+ Boolean(env.CIRCLECI)
153
+ ? 3
154
+ : Boolean(env.TRAVIS) ||
155
+ Boolean(env.APPVEYOR) ||
156
+ Boolean(env.GITLAB_CI) ||
157
+ Boolean(env.BUILDKITE) ||
158
+ Boolean(env.DRONE) ||
159
+ env.CI_NAME === "codeship"
160
+ ? 1
161
+ : forceColor || 0
162
+ : Boolean(env.TEAMCITY_VERSION)
163
+ ? /^(?:9\.0*[1-9]\d*\.|\d{2,}\.)/.test(String(env.TEAMCITY_VERSION) || "")
164
+ ? 1
165
+ : 0
166
+ : String(env.COLORTERM) === "truecolor" ||
167
+ env.TERM === "xterm-kitty"
168
+ ? 3
169
+ : Boolean(env.TERM_PROGRAM)
170
+ ? env.TERM_PROGRAM === "iTerm.app"
171
+ ? Number.parseInt(
172
+ (env.TERM_PROGRAM_VERSION || "").split(".")[0] as string,
173
+ 10
174
+ ) >= 3
175
+ ? 3
176
+ : 2
177
+ : env.TERM_PROGRAM === "Apple_Terminal"
178
+ ? 2
179
+ : 0
180
+ : /-256(?:color)?$/i.test(env.TERM || "")
181
+ ? 2
182
+ : /^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(
183
+ env.TERM || ""
184
+ )
185
+ ? 1
186
+ : Boolean(env.COLORTERM);
187
+
188
+ return typeof level === "boolean" || level === 0
189
+ ? false
190
+ : {
191
+ level,
192
+ hasBasic: true,
193
+ has256: level >= 2,
194
+ has16m: level >= 3,
195
+ };
196
+
197
+ `
198
+ }),
199
+ createIntrinsic("hbr", {}),
200
+ createIntrinsic("hbr", {}),
201
+ createComponent(VarDeclaration, {
202
+ "export": true,
203
+ "const": true,
204
+ name: "colorSupportLevels",
205
+ doc: "Detect the terminal color support level in the current environment",
206
+ initializer: code` {
207
+ stdout: getColorSupportLevel(process.stdout),
208
+ stderr: getColorSupportLevel(process.stderr),
209
+ }; `
210
+ }),
211
+ createIntrinsic("hbr", {}),
212
+ createIntrinsic("hbr", {}),
213
+ createComponent(VarDeclaration, {
214
+ "export": true,
215
+ "const": true,
216
+ name: "isColorSupported",
217
+ doc: "Detect if terminal color is supported in the current environment",
218
+ initializer: code` Boolean(colorSupportLevels.stdout); `
219
+ }),
220
+ createIntrinsic("hbr", {}),
221
+ createIntrinsic("hbr", {}),
222
+ createComponent(VarDeclaration, {
223
+ "export": true,
224
+ "const": true,
225
+ name: "isUnicodeSupported",
226
+ doc: "Detect if Unicode characters are supported in the current environment",
227
+ initializer: 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
+ createComponent(FunctionDeclaration, {
248
+ name: "parseVersion",
249
+ parameters: [{
250
+ name: "version",
251
+ type: "string",
252
+ default: "\"\""
253
+ }],
254
+ children: 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
+ createIntrinsic("hbr", {}),
275
+ createIntrinsic("hbr", {}),
276
+ createComponent(TSDoc, {
277
+ heading: "Check if the current environment/terminal supports hyperlinks in the terminal.",
278
+ get children() {
279
+ return createComponent(TSDocReturns, { children: "True if the current environment/terminal supports hyperlinks." });
280
+ }
281
+ }),
282
+ createComponent(FunctionDeclaration, {
283
+ "export": true,
284
+ name: "isHyperlinkSupported",
285
+ returnType: "boolean",
286
+ children: code`if (Boolean(env.FORCE_HYPERLINK)) {
287
+ return true;
288
+ }
289
+
290
+ if (Boolean(env.NETLIFY)) {
291
+ return true;
292
+ } else if (isColorSupported || isTTY) {
293
+ return false;
294
+ } else if (Boolean(env.WT_SESSION)) {
295
+ return true;
296
+ } else if (isWindows || isMinimal || Boolean(env.TEAMCITY_VERSION)) {
297
+ return false;
298
+ } else if (Boolean(env.TERM_PROGRAM)) {
299
+ const version = parseVersion(env.TERM_PROGRAM_VERSION);
300
+
301
+ switch (String(env.TERM_PROGRAM)) {
302
+ case "iTerm.app": {
303
+ if (version.major === 3) {
304
+ return version.minor !== undefined && version.minor >= 1;
305
+ }
306
+
307
+ return version.major !== undefined && version.major > 3;
308
+ }
309
+ case "WezTerm": {
310
+ return version.major !== undefined && version.major >= 20_200_620;
311
+ }
312
+
313
+ case "vscode": {
314
+ if (Boolean(env.CURSOR_TRACE_ID)) {
315
+ return true;
316
+ }
317
+
318
+ return (
319
+ version.minor !== undefined &&
320
+ version.major !== undefined &&
321
+ (version.major > 1 || (version.major === 1 && version.minor >= 72))
322
+ );
323
+ }
324
+
325
+ case "ghostty": {
326
+ return true;
327
+ }
328
+ }
329
+ }
330
+
331
+ if (Boolean(env.VTE_VERSION)) {
332
+ if (env.VTE_VERSION === "0.50.0") {
333
+ return false;
334
+ }
335
+
336
+ const version = parseVersion(env.VTE_VERSION);
337
+ return (
338
+ (version.major !== undefined && version.major > 0) ||
339
+ (version.minor !== undefined && version.minor >= 50)
340
+ );
341
+ }
342
+
343
+ if (String(env.TERM) === "alacritty") {
344
+ return true;
345
+ }
346
+
347
+ return false; `
348
+ })
349
+ ];
350
+ }
351
+ /**
352
+ * Generates utilities for detecting terminal color support.
353
+ */
354
+ function ArgsUtilities() {
355
+ return [
356
+ createComponent(TSDoc, {
357
+ heading: "Retrieves the command line arguments from Deno or Node.js environments.",
358
+ get children() {
359
+ return createComponent(TSDocReturns, { children: "An array of command line arguments from Deno or Node.js environments." });
360
+ }
361
+ }),
362
+ createComponent(FunctionDeclaration, {
363
+ "export": true,
364
+ name: "getArgs",
365
+ children: code`return ((globalThis as { Deno?: { args: string[] } })?.Deno?.args ?? process.argv ?? []) as string[];`
366
+ }),
367
+ createIntrinsic("hbr", {}),
368
+ createIntrinsic("hbr", {}),
369
+ createComponent(TSDoc, {
370
+ heading: "Checks if a specific flag is present in the command line arguments.",
371
+ get children() {
372
+ return [
373
+ createComponent(TSDocLink, { children: "https://github.com/sindresorhus/has-flag/blob/main/index.js" }),
374
+ createComponent(TSDocParam, {
375
+ name: "flag",
376
+ children: "The flag (or an array of flags/aliases) to check for, e.g., \"color\", \"no-color\"."
377
+ }),
378
+ createComponent(TSDocParam, {
379
+ name: "argv",
380
+ children: "The command line arguments to check against. Defaults to global Deno args or process args."
381
+ }),
382
+ createComponent(TSDocReturns, { children: "True if the flag is present, false otherwise." })
383
+ ];
384
+ }
385
+ }),
386
+ createComponent(FunctionDeclaration, {
387
+ "export": true,
388
+ name: "hasFlag",
389
+ parameters: [{
390
+ name: "flag",
391
+ type: "string | string[]"
392
+ }, {
393
+ name: "argv",
394
+ type: "string[]",
395
+ default: "getArgs()"
396
+ }],
397
+ get children() {
398
+ return [
399
+ createComponent(VarDeclaration, {
400
+ "const": true,
401
+ name: "position",
402
+ type: "number",
403
+ initializer: code`(Array.isArray(flag) ? flag : [flag]).reduce((ret, f) => {
404
+ const pos = argv.findIndex(arg => (f.startsWith("-") ? "" : (f.length === 1 ? "-" : "--") + f)?.toLowerCase() === arg?.toLowerCase() || arg?.toLowerCase().startsWith((f.length === 1 ? "-" : "--") + f + "="));
405
+ return pos !== -1 ? pos : ret;
406
+ }, -1);`
407
+ }),
408
+ createIntrinsic("hbr", {}),
409
+ code`return position !== -1 && argv.indexOf("--") === -1 || position < argv.indexOf("--");`
410
+ ];
411
+ }
412
+ })
413
+ ];
414
+ }
415
+ /**
416
+ * The `exit` handler function declaration code for the Shell Shock project.
417
+ */
418
+ function ExitFunctionDeclaration() {
419
+ const context = usePowerlines();
420
+ return [
421
+ createComponent(InterfaceDeclaration, {
422
+ "export": true,
423
+ name: "ExitOptions",
424
+ doc: "Options for the exit handler function.",
425
+ get children() {
426
+ return [
427
+ createComponent(InterfaceMember, {
428
+ name: "exception",
429
+ optional: true,
430
+ type: "string | Error",
431
+ doc: "An optional exception that caused the exit. This can be a string message or an Error object."
432
+ }),
433
+ createIntrinsic("hbr", {}),
434
+ createComponent(InterfaceMember, {
435
+ name: "skipProcessExit",
436
+ optional: true,
437
+ type: "boolean",
438
+ 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."
439
+ }),
440
+ createIntrinsic("hbr", {}),
441
+ createComponent(InterfaceMember, {
442
+ name: "isSynchronous",
443
+ optional: true,
444
+ type: "boolean",
445
+ 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."
446
+ }),
447
+ createIntrinsic("hbr", {}),
448
+ createComponent(InterfaceMember, {
449
+ name: "signal",
450
+ optional: true,
451
+ type: "number",
452
+ 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)."
453
+ })
454
+ ];
455
+ }
456
+ }),
457
+ createIntrinsic("hbr", {}),
458
+ createIntrinsic("hbr", {}),
459
+ createComponent(VarDeclaration, {
460
+ "let": true,
461
+ name: "isExiting",
462
+ type: "boolean",
463
+ initializer: code`false;`
464
+ }),
465
+ createComponent(VarDeclaration, {
466
+ "const": true,
467
+ name: "callbackAsyncQueue",
468
+ type: "Array<[(code: number | string) => Promise<void> | void, number]>",
469
+ initializer: code`[];`
470
+ }),
471
+ createComponent(VarDeclaration, {
472
+ "const": true,
473
+ name: "callbackSyncQueue",
474
+ type: "Array<(code: number | string) => void>",
475
+ initializer: code`[];`
476
+ }),
477
+ createIntrinsic("hbr", {}),
478
+ createIntrinsic("hbr", {}),
479
+ createComponent(FunctionDeclaration, {
480
+ "export": true,
481
+ async: true,
482
+ name: "exit",
483
+ parameters: [{
484
+ name: "options",
485
+ type: "ExitOptions",
486
+ default: "{}"
487
+ }],
488
+ get children() {
489
+ return code`
490
+ try {
491
+ if (isExiting) {
492
+ return;
493
+ }
494
+
495
+ isExiting = true;
496
+
497
+ let exitCode: number | string = 0;
498
+ if ((options.signal !== undefined && options.signal > 0) || options.exception) {
499
+ exitCode = 128 + (options.signal ?? 1);
500
+ } else if (typeof process.exitCode === "number" || typeof process.exitCode === "string") {
501
+ exitCode = process.exitCode;
502
+ }
503
+
504
+ if (options.exception) {
505
+ error(\`A fatal error occured while running the application - please contact the ${getAppTitle(context)} support team: \\n\${typeof options.exception === "string" ? options.exception : options.exception.message}\`);
506
+ }
507
+
508
+ const terminate = (force = false) => {
509
+ verbose(\`The ${getAppTitle(context)} application exited \${options.exception ? \`early due to an exception\` : "successfully"}...\`);
510
+ if (!options.skipProcessExit) {
511
+ process.exit(exitCode);
512
+ }
513
+ };
514
+
515
+ for (const callbackSync of callbackSyncQueue) {
516
+ callbackSync(exitCode);
517
+ }
518
+
519
+ if (!options.isSynchronous) {
520
+ const promises = [];
521
+ let forceAfter = 0;
522
+ for (const [callbackAsync, wait] of callbackAsyncQueue) {
523
+ forceAfter = Math.max(forceAfter, wait);
524
+ promises.push(Promise.resolve(callbackAsync(exitCode)));
525
+ }
526
+
527
+ const asyncTimer = setTimeout(() => {
528
+ terminate(true);
529
+ }, forceAfter);
530
+ await Promise.all(promises);
531
+ clearTimeout(asyncTimer);
532
+ }
533
+
534
+ terminate();
535
+ } catch (err) {
536
+ error(\`The exit process failed to complete\${(err as Error).message ? \` - (err as Error).message\` : ""}. Please contact the ${getAppTitle(context)} support team.\`);
537
+
538
+ if (!options.skipProcessExit) {
539
+ process.exit(1);
540
+ }
541
+ }
542
+ `;
543
+ }
544
+ })
545
+ ];
546
+ }
547
+ /**
548
+ * A built-in utilities module for Shell Shock.
549
+ */
550
+ function UtilsBuiltin(props) {
551
+ const [{ children }, rest] = splitProps(props, ["children"]);
552
+ return createComponent(BuiltinFile, mergeProps({
553
+ id: "utils",
554
+ description: "A collection of helper utilities that ease command-line application development."
555
+ }, rest, {
556
+ get imports() {
557
+ return defu(rest.imports ?? {}, {
558
+ "node:os": "os",
559
+ "node:process": "process"
560
+ });
561
+ },
562
+ get builtinImports() {
563
+ return defu(rest.builtinImports ?? {}, {
564
+ console: ["error", "verbose"],
565
+ env: [
566
+ "env",
567
+ "isCI",
568
+ "isTest",
569
+ "isWindows"
570
+ ]
571
+ });
572
+ },
573
+ get children() {
574
+ return [
575
+ createIntrinsic("hbr", {}),
576
+ createIntrinsic("hbr", {}),
577
+ createComponent(ArgsUtilities, {}),
578
+ createIntrinsic("hbr", {}),
579
+ createIntrinsic("hbr", {}),
580
+ createComponent(EnvSupportUtilities, {}),
581
+ createIntrinsic("hbr", {}),
582
+ createIntrinsic("hbr", {}),
583
+ createComponent(HyperlinkSupportUtilities, {}),
584
+ createIntrinsic("hbr", {}),
585
+ createIntrinsic("hbr", {}),
586
+ createComponent(ColorSupportUtilities, {}),
587
+ createIntrinsic("hbr", {}),
588
+ createIntrinsic("hbr", {}),
589
+ createComponent(ExitFunctionDeclaration, {}),
590
+ createIntrinsic("hbr", {}),
591
+ createIntrinsic("hbr", {}),
592
+ createComponent(Show, {
593
+ get when() {
594
+ return Boolean(children);
595
+ },
596
+ children
597
+ })
598
+ ];
599
+ }
600
+ }));
601
+ }
602
+
603
+ //#endregion
604
+ export { ArgsUtilities, ColorSupportUtilities, EnvSupportUtilities, ExitFunctionDeclaration, HyperlinkSupportUtilities, UtilsBuiltin };
605
+ //# sourceMappingURL=utils-builtin.mjs.map