@shell-shock/core 0.8.11 → 0.8.13
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.
- package/dist/components/docs.d.cts +5 -5
- package/dist/components/docs.d.mts +5 -5
- package/dist/components/docs.d.mts.map +1 -1
- package/dist/components/helpers.cjs +47 -0
- package/dist/components/helpers.cjs.map +1 -1
- package/dist/components/helpers.d.cts +25 -3
- package/dist/components/helpers.d.cts.map +1 -1
- package/dist/components/helpers.d.mts +25 -3
- package/dist/components/helpers.d.mts.map +1 -1
- package/dist/components/helpers.mjs +44 -1
- package/dist/components/helpers.mjs.map +1 -1
- package/dist/components/index.cjs +12 -1
- package/dist/components/index.d.cts +3 -2
- package/dist/components/index.d.mts +3 -2
- package/dist/components/index.mjs +3 -2
- package/dist/components/options-parser-logic.d.cts +9 -9
- package/dist/components/options-parser-logic.d.mts +9 -9
- package/dist/components/usage.d.cts +2 -2
- package/dist/components/usage.d.cts.map +1 -1
- package/dist/components/utils-builtin.cjs +572 -0
- package/dist/components/utils-builtin.cjs.map +1 -0
- package/dist/components/utils-builtin.d.cts +29 -0
- package/dist/components/utils-builtin.d.cts.map +1 -0
- package/dist/components/utils-builtin.d.mts +29 -0
- package/dist/components/utils-builtin.d.mts.map +1 -0
- package/dist/components/utils-builtin.mjs +565 -0
- package/dist/components/utils-builtin.mjs.map +1 -0
- package/dist/plugin.cjs +5 -0
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +5 -0
- package/dist/plugin.mjs.map +1 -1
- package/package.json +18 -4
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
3
|
+
let defu = require("defu");
|
|
4
|
+
defu = require_rolldown_runtime.__toESM(defu);
|
|
5
|
+
let __alloy_js_core = require("@alloy-js/core");
|
|
6
|
+
let __powerlines_plugin_alloy_core_components_spacing = require("@powerlines/plugin-alloy/core/components/spacing");
|
|
7
|
+
let __alloy_js_typescript = require("@alloy-js/typescript");
|
|
8
|
+
let __powerlines_plugin_alloy_typescript_components_builtin_file = require("@powerlines/plugin-alloy/typescript/components/builtin-file");
|
|
9
|
+
let __powerlines_plugin_alloy_typescript_components_tsdoc = require("@powerlines/plugin-alloy/typescript/components/tsdoc");
|
|
10
|
+
|
|
11
|
+
//#region src/components/utils-builtin.tsx
|
|
12
|
+
/**
|
|
13
|
+
* Generates utilities for detecting terminal color support.
|
|
14
|
+
*/
|
|
15
|
+
function EnvSupportUtilities() {
|
|
16
|
+
return [
|
|
17
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
|
|
18
|
+
"export": true,
|
|
19
|
+
"const": true,
|
|
20
|
+
name: "isTTY",
|
|
21
|
+
doc: "Detect if stdout.TTY is available",
|
|
22
|
+
initializer: __alloy_js_core.code`Boolean(process.stdout && process.stdout.isTTY);`
|
|
23
|
+
}),
|
|
24
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
25
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.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: __alloy_js_core.code` env.MINIMAL || isCI || isTest || !isTTY; `
|
|
31
|
+
}),
|
|
32
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
33
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
|
|
34
|
+
"export": true,
|
|
35
|
+
"const": true,
|
|
36
|
+
name: "isInteractive",
|
|
37
|
+
doc: "Detect if the current environment is interactive",
|
|
38
|
+
initializer: __alloy_js_core.code` !isMinimal && process.stdin?.isTTY && env.TERM !== "dumb" && !hasFlag(["no-interactive", "non-interactive", "no-interact"]); `
|
|
39
|
+
})
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Generates utilities for detecting terminal color support.
|
|
44
|
+
*/
|
|
45
|
+
function ColorSupportUtilities() {
|
|
46
|
+
return [
|
|
47
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceDeclaration, {
|
|
48
|
+
"export": true,
|
|
49
|
+
name: "GetColorSupportLevelOptions",
|
|
50
|
+
doc: "Options for the getColorSupportLevel function",
|
|
51
|
+
get children() {
|
|
52
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.InterfaceMember, {
|
|
53
|
+
name: "ignoreFlags",
|
|
54
|
+
type: "boolean",
|
|
55
|
+
doc: "Indicates if the function should skip checking command-line flags for color support"
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}),
|
|
59
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
60
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
61
|
+
heading: "Checks if a specific flag is present in the command-line arguments.",
|
|
62
|
+
get children() {
|
|
63
|
+
return [
|
|
64
|
+
(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" }),
|
|
65
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
|
|
66
|
+
name: "flag",
|
|
67
|
+
children: "The flag to check for, e.g., \"color\", \"no-color\"."
|
|
68
|
+
}),
|
|
69
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
|
|
70
|
+
name: "argv",
|
|
71
|
+
children: "The command-line arguments to check against. Defaults to global Deno args or process args."
|
|
72
|
+
}),
|
|
73
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "True if the flag is present, false otherwise." })
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
}),
|
|
77
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
|
|
78
|
+
"export": true,
|
|
79
|
+
name: "getColorSupportLevel",
|
|
80
|
+
parameters: [{
|
|
81
|
+
name: "stream",
|
|
82
|
+
type: "NodeJS.WriteStream & { fd: 1 | 2; }"
|
|
83
|
+
}, {
|
|
84
|
+
name: "options",
|
|
85
|
+
type: "GetColorSupportLevelOptions",
|
|
86
|
+
default: "{ ignoreFlags: false }"
|
|
87
|
+
}],
|
|
88
|
+
children: __alloy_js_core.code`const { ignoreFlags } = options;
|
|
89
|
+
|
|
90
|
+
let forceColor: number | undefined;
|
|
91
|
+
if (env.FORCE_COLOR !== undefined) {
|
|
92
|
+
forceColor = !env.FORCE_COLOR
|
|
93
|
+
? 0
|
|
94
|
+
: typeof env.FORCE_COLOR === "boolean"
|
|
95
|
+
? 1
|
|
96
|
+
: typeof env.FORCE_COLOR === "number" &&
|
|
97
|
+
[0, 1, 2, 3].includes(Math.min(env.FORCE_COLOR as number, 3))
|
|
98
|
+
? Math.min(env.FORCE_COLOR as number, 3)
|
|
99
|
+
: undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (ignoreFlags !== true && forceColor === undefined) {
|
|
103
|
+
if (
|
|
104
|
+
hasFlag("no-color") ||
|
|
105
|
+
hasFlag("no-colors") ||
|
|
106
|
+
hasFlag("color=false") ||
|
|
107
|
+
hasFlag("color=never")
|
|
108
|
+
) {
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (
|
|
113
|
+
hasFlag("color=16m") ||
|
|
114
|
+
hasFlag("color=full") ||
|
|
115
|
+
hasFlag("color=truecolor")
|
|
116
|
+
) {
|
|
117
|
+
return 3;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (hasFlag("color=256")) {
|
|
121
|
+
return 2;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (
|
|
125
|
+
hasFlag("color") ||
|
|
126
|
+
hasFlag("colors") ||
|
|
127
|
+
hasFlag("color=true") ||
|
|
128
|
+
hasFlag("color=always")
|
|
129
|
+
) {
|
|
130
|
+
forceColor = 1;
|
|
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
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
200
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
|
|
201
|
+
"export": true,
|
|
202
|
+
"const": true,
|
|
203
|
+
name: "colorSupportLevels",
|
|
204
|
+
doc: "Detect the terminal color support level in the current environment",
|
|
205
|
+
initializer: __alloy_js_core.code` {
|
|
206
|
+
stdout: getColorSupportLevel(process.stdout),
|
|
207
|
+
stderr: getColorSupportLevel(process.stderr),
|
|
208
|
+
}; `
|
|
209
|
+
}),
|
|
210
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
211
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
|
|
212
|
+
"export": true,
|
|
213
|
+
"const": true,
|
|
214
|
+
name: "isColorSupported",
|
|
215
|
+
doc: "Detect if terminal color is supported in the current environment",
|
|
216
|
+
initializer: __alloy_js_core.code` Boolean(colorSupportLevels.stdout); `
|
|
217
|
+
}),
|
|
218
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
219
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
|
|
220
|
+
"export": true,
|
|
221
|
+
"const": true,
|
|
222
|
+
name: "isUnicodeSupported",
|
|
223
|
+
doc: "Detect if Unicode characters are supported in the current environment",
|
|
224
|
+
initializer: __alloy_js_core.code` !isWindows
|
|
225
|
+
? env.TERM !== "linux"
|
|
226
|
+
: Boolean(env.WT_SESSION) ||
|
|
227
|
+
Boolean(env.TERMINUS_SUBLIME) ||
|
|
228
|
+
env.ConEmuTask === "{cmd::Cmder}" ||
|
|
229
|
+
env.TERM_PROGRAM === "Terminus-Sublime" ||
|
|
230
|
+
env.TERM_PROGRAM === "vscode" ||
|
|
231
|
+
env.TERM === "xterm-256color" ||
|
|
232
|
+
env.TERM === "alacritty" ||
|
|
233
|
+
env.TERM === "rxvt-unicode" ||
|
|
234
|
+
env.TERM === "rxvt-unicode-256color" ||
|
|
235
|
+
env.TERMINAL_EMULATOR === "JetBrains-JediTerm"; `
|
|
236
|
+
})
|
|
237
|
+
];
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Generates utilities for detecting terminal color support.
|
|
241
|
+
*/
|
|
242
|
+
function HyperlinkSupportUtilities() {
|
|
243
|
+
return [
|
|
244
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
|
|
245
|
+
name: "parseVersion",
|
|
246
|
+
parameters: [{
|
|
247
|
+
name: "version",
|
|
248
|
+
type: "string",
|
|
249
|
+
default: "\"\""
|
|
250
|
+
}],
|
|
251
|
+
children: __alloy_js_core.code`if (/^\d{3,4}$/.test(version)) {
|
|
252
|
+
const match = /(\d{1,2})(\d{2})/.exec(version) ?? [];
|
|
253
|
+
|
|
254
|
+
return {
|
|
255
|
+
major: 0,
|
|
256
|
+
minor: Number.parseInt(match[1]!, 10),
|
|
257
|
+
patch: Number.parseInt(match[2]!, 10)
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const versionParts = (version ?? "")
|
|
262
|
+
.split(".")
|
|
263
|
+
.map(n => Number.parseInt(n, 10));
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
major: versionParts[0],
|
|
267
|
+
minor: versionParts[1],
|
|
268
|
+
patch: versionParts[2]
|
|
269
|
+
}; `
|
|
270
|
+
}),
|
|
271
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
272
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
273
|
+
heading: "Check if the current environment/terminal supports hyperlinks in the terminal.",
|
|
274
|
+
get children() {
|
|
275
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "True if the current environment/terminal supports hyperlinks." });
|
|
276
|
+
}
|
|
277
|
+
}),
|
|
278
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
|
|
279
|
+
"export": true,
|
|
280
|
+
name: "isHyperlinkSupported",
|
|
281
|
+
returnType: "boolean",
|
|
282
|
+
children: __alloy_js_core.code`if (Boolean(env.FORCE_HYPERLINK)) {
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (Boolean(env.NETLIFY)) {
|
|
287
|
+
return true;
|
|
288
|
+
} else if (isColorSupported || isTTY) {
|
|
289
|
+
return false;
|
|
290
|
+
} else if (Boolean(env.WT_SESSION)) {
|
|
291
|
+
return true;
|
|
292
|
+
} else if (isWindows || isMinimal || Boolean(env.TEAMCITY_VERSION)) {
|
|
293
|
+
return false;
|
|
294
|
+
} else if (Boolean(env.TERM_PROGRAM)) {
|
|
295
|
+
const version = parseVersion(env.TERM_PROGRAM_VERSION);
|
|
296
|
+
|
|
297
|
+
switch (String(env.TERM_PROGRAM)) {
|
|
298
|
+
case "iTerm.app": {
|
|
299
|
+
if (version.major === 3) {
|
|
300
|
+
return version.minor !== undefined && version.minor >= 1;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return version.major !== undefined && version.major > 3;
|
|
304
|
+
}
|
|
305
|
+
case "WezTerm": {
|
|
306
|
+
return version.major !== undefined && version.major >= 20_200_620;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
case "vscode": {
|
|
310
|
+
if (Boolean(env.CURSOR_TRACE_ID)) {
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return (
|
|
315
|
+
version.minor !== undefined &&
|
|
316
|
+
version.major !== undefined &&
|
|
317
|
+
(version.major > 1 || (version.major === 1 && version.minor >= 72))
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
case "ghostty": {
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (Boolean(env.VTE_VERSION)) {
|
|
328
|
+
if (env.VTE_VERSION === "0.50.0") {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const version = parseVersion(env.VTE_VERSION);
|
|
333
|
+
return (
|
|
334
|
+
(version.major !== undefined && version.major > 0) ||
|
|
335
|
+
(version.minor !== undefined && version.minor >= 50)
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (String(env.TERM) === "alacritty") {
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return false; `
|
|
344
|
+
})
|
|
345
|
+
];
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Generates utilities for detecting terminal color support.
|
|
349
|
+
*/
|
|
350
|
+
function ArgsUtilities() {
|
|
351
|
+
return [
|
|
352
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
353
|
+
heading: "Retrieves the command-line arguments from Deno or Node.js environments.",
|
|
354
|
+
get children() {
|
|
355
|
+
return [
|
|
356
|
+
(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." }),
|
|
357
|
+
(0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
358
|
+
(0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
359
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocInternal, {}),
|
|
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.TSDocReturns, { children: "An array of command-line arguments from Deno or Node.js environments." })
|
|
363
|
+
];
|
|
364
|
+
}
|
|
365
|
+
}),
|
|
366
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
|
|
367
|
+
"export": true,
|
|
368
|
+
name: "getArgs",
|
|
369
|
+
returnType: "string[]",
|
|
370
|
+
children: __alloy_js_core.code`return ((globalThis as { Deno?: { args: string[] } })?.Deno?.args ?? process.argv ?? []) as string[];`
|
|
371
|
+
}),
|
|
372
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
373
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
374
|
+
heading: "Checks if a specific flag is present in the command-line arguments.",
|
|
375
|
+
get children() {
|
|
376
|
+
return [
|
|
377
|
+
(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" }),
|
|
378
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
|
|
379
|
+
name: "flag",
|
|
380
|
+
children: "The flag (or an array of flags/aliases) to check for, e.g., \"color\", \"no-color\"."
|
|
381
|
+
}),
|
|
382
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
|
|
383
|
+
name: "argv",
|
|
384
|
+
children: "The command-line arguments to check against. Defaults to global Deno args or process args."
|
|
385
|
+
}),
|
|
386
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "True if the flag is present, false otherwise." })
|
|
387
|
+
];
|
|
388
|
+
}
|
|
389
|
+
}),
|
|
390
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
|
|
391
|
+
"export": true,
|
|
392
|
+
name: "hasFlag",
|
|
393
|
+
parameters: [{
|
|
394
|
+
name: "flag",
|
|
395
|
+
type: "string | string[]"
|
|
396
|
+
}, {
|
|
397
|
+
name: "argv",
|
|
398
|
+
type: "string[]",
|
|
399
|
+
default: "useArgs()"
|
|
400
|
+
}],
|
|
401
|
+
get children() {
|
|
402
|
+
return [
|
|
403
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
|
|
404
|
+
"const": true,
|
|
405
|
+
name: "position",
|
|
406
|
+
type: "number",
|
|
407
|
+
initializer: __alloy_js_core.code`(Array.isArray(flag) ? flag : [flag]).reduce((ret, f) => {
|
|
408
|
+
const pos = argv.findIndex(arg => (f.startsWith("-") ? "" : (f.length === 1 ? "-" : "--") + f)?.toLowerCase() === arg?.toLowerCase() || arg?.toLowerCase().startsWith((f.length === 1 ? "-" : "--") + f + "="));
|
|
409
|
+
return pos !== -1 ? pos : ret;
|
|
410
|
+
}, -1);`
|
|
411
|
+
}),
|
|
412
|
+
(0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
413
|
+
__alloy_js_core.code`return position !== -1 && argv.indexOf("--") === -1 || position < argv.indexOf("--");`
|
|
414
|
+
];
|
|
415
|
+
}
|
|
416
|
+
}),
|
|
417
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
418
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
|
|
419
|
+
"export": true,
|
|
420
|
+
name: "isHelp",
|
|
421
|
+
type: "boolean",
|
|
422
|
+
initializer: __alloy_js_core.code` !isCI && hasFlag(["help", "h", "?"]); `
|
|
423
|
+
})
|
|
424
|
+
];
|
|
425
|
+
}
|
|
426
|
+
function ContextUtilities() {
|
|
427
|
+
return __alloy_js_core.code`
|
|
428
|
+
/**
|
|
429
|
+
* The global Shell Shock - Application context instance.
|
|
430
|
+
*
|
|
431
|
+
* @internal
|
|
432
|
+
*/
|
|
433
|
+
export let internal_appContext = new AsyncLocalStorage<Map<string, any>>();
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Get the Shell Shock - Application context for the current application.
|
|
437
|
+
*
|
|
438
|
+
* @param options - The options to use when getting the context.
|
|
439
|
+
* @returns The Shell Shock - Application context for the current application or undefined if the context is not available.
|
|
440
|
+
*/
|
|
441
|
+
export function useApp(): Map<string, any> | undefined {
|
|
442
|
+
return internal_appContext.getStore();
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* A utility hook function to get the command line arguments from the application context.
|
|
447
|
+
*
|
|
448
|
+
* @returns An array of command-line arguments from the application context.
|
|
449
|
+
* @throws If the application context is not available.
|
|
450
|
+
*/
|
|
451
|
+
export function useArgs(): string[] {
|
|
452
|
+
return useApp()?.get("args") ?? getArgs();
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* The context object for the current command execution, containing the command path and segments.
|
|
457
|
+
*/
|
|
458
|
+
export interface CommandContext {
|
|
459
|
+
path: string;
|
|
460
|
+
segments: string[];
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* The global Shell Shock - Command context instance.
|
|
465
|
+
*
|
|
466
|
+
* @internal
|
|
467
|
+
*/
|
|
468
|
+
export let internal_commandContext = new AsyncLocalStorage<CommandContext>();
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Get the Shell Shock - Command context for the current application.
|
|
472
|
+
*
|
|
473
|
+
* @param options - The options to use when getting the context.
|
|
474
|
+
* @returns The Shell Shock - Command context for the current application.
|
|
475
|
+
* @throws If the Shell Shock - Command context is not available.
|
|
476
|
+
*/
|
|
477
|
+
export function useCommand(): CommandContext {
|
|
478
|
+
const result = internal_commandContext.getStore();
|
|
479
|
+
if (!result) {
|
|
480
|
+
throw new Error(
|
|
481
|
+
\`The Shell Shock - Command context is not available. Make sure to call useCommand() within a valid context scope.\`
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
return result;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* A utility hook function to get the individual segments of the current command path.
|
|
489
|
+
*
|
|
490
|
+
* @returns An array of command path segments.
|
|
491
|
+
* @throws If the command context is not available.
|
|
492
|
+
*/
|
|
493
|
+
export function useSegments(): string[] {
|
|
494
|
+
return useCommand().segments;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* A utility hook function to get the full command path as a string.
|
|
499
|
+
*
|
|
500
|
+
* @returns The full command path as a string.
|
|
501
|
+
* @throws If the command context is not available.
|
|
502
|
+
*/
|
|
503
|
+
export function usePath(): string {
|
|
504
|
+
return useCommand().path;
|
|
505
|
+
}
|
|
506
|
+
`;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* A built-in utilities module for Shell Shock.
|
|
510
|
+
*/
|
|
511
|
+
function UtilsBuiltin(props) {
|
|
512
|
+
const [{ children }, rest] = (0, __alloy_js_core.splitProps)(props, ["children"]);
|
|
513
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_builtin_file.BuiltinFile, (0, __alloy_js_core_jsx_runtime.mergeProps)({
|
|
514
|
+
id: "utils",
|
|
515
|
+
description: "A collection of helper utilities that ease command-line application development."
|
|
516
|
+
}, rest, {
|
|
517
|
+
get imports() {
|
|
518
|
+
return (0, defu.default)(rest.imports ?? {}, {
|
|
519
|
+
"node:os": "os",
|
|
520
|
+
"node:process": "process",
|
|
521
|
+
"node:async_hooks": ["AsyncLocalStorage"]
|
|
522
|
+
});
|
|
523
|
+
},
|
|
524
|
+
get builtinImports() {
|
|
525
|
+
return (0, defu.default)(rest.builtinImports ?? {}, {
|
|
526
|
+
console: [
|
|
527
|
+
"error",
|
|
528
|
+
"verbose",
|
|
529
|
+
"writeLine"
|
|
530
|
+
],
|
|
531
|
+
env: [
|
|
532
|
+
"env",
|
|
533
|
+
"isCI",
|
|
534
|
+
"isTest",
|
|
535
|
+
"isWindows",
|
|
536
|
+
"isDevelopment",
|
|
537
|
+
"isDebug"
|
|
538
|
+
]
|
|
539
|
+
});
|
|
540
|
+
},
|
|
541
|
+
get children() {
|
|
542
|
+
return [
|
|
543
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
544
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(ContextUtilities, {}),
|
|
545
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
546
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(ArgsUtilities, {}),
|
|
547
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
548
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(EnvSupportUtilities, {}),
|
|
549
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
550
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(HyperlinkSupportUtilities, {}),
|
|
551
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
552
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(ColorSupportUtilities, {}),
|
|
553
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
554
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
|
|
555
|
+
get when() {
|
|
556
|
+
return Boolean(children);
|
|
557
|
+
},
|
|
558
|
+
children
|
|
559
|
+
})
|
|
560
|
+
];
|
|
561
|
+
}
|
|
562
|
+
}));
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
//#endregion
|
|
566
|
+
exports.ArgsUtilities = ArgsUtilities;
|
|
567
|
+
exports.ColorSupportUtilities = ColorSupportUtilities;
|
|
568
|
+
exports.ContextUtilities = ContextUtilities;
|
|
569
|
+
exports.EnvSupportUtilities = EnvSupportUtilities;
|
|
570
|
+
exports.HyperlinkSupportUtilities = HyperlinkSupportUtilities;
|
|
571
|
+
exports.UtilsBuiltin = UtilsBuiltin;
|
|
572
|
+
//# sourceMappingURL=utils-builtin.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-builtin.cjs","names":["code","Show","splitProps","FunctionDeclaration","InterfaceDeclaration","InterfaceMember","VarDeclaration","Spacing","BuiltinFile","TSDoc","TSDocInternal","TSDocLink","TSDocParam","TSDocRemarks","TSDocReturns","defu","EnvSupportUtilities","_$createComponent","name","doc","initializer","ColorSupportUtilities","children","type","heading","parameters","default","HyperlinkSupportUtilities","returnType","ArgsUtilities","_$createIntrinsic","ContextUtilities","UtilsBuiltin","props","rest","_$mergeProps","id","description","imports","builtinImports","console","env","when","Boolean"],"sources":["../../src/components/utils-builtin.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 { code, Show, splitProps } from \"@alloy-js/core\";\nimport {\n FunctionDeclaration,\n InterfaceDeclaration,\n InterfaceMember,\n VarDeclaration\n} from \"@alloy-js/typescript\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core/components/spacing\";\nimport type { BuiltinFileProps } from \"@powerlines/plugin-alloy/typescript/components/builtin-file\";\nimport { BuiltinFile } from \"@powerlines/plugin-alloy/typescript/components/builtin-file\";\nimport {\n TSDoc,\n TSDocInternal,\n TSDocLink,\n TSDocParam,\n TSDocRemarks,\n TSDocReturns\n} from \"@powerlines/plugin-alloy/typescript/components/tsdoc\";\nimport defu from \"defu\";\n\nexport interface UtilsBuiltinProps extends Omit<\n BuiltinFileProps,\n \"id\" | \"description\"\n> {}\n\n/**\n * Generates utilities for detecting terminal color support.\n */\nexport function EnvSupportUtilities() {\n return (\n <>\n <VarDeclaration\n export\n const\n name=\"isTTY\"\n doc=\"Detect if stdout.TTY is available\"\n initializer={code`Boolean(process.stdout && process.stdout.isTTY);`}\n />\n <Spacing />\n <VarDeclaration\n export\n const\n name=\"isMinimal\"\n doc=\"Detect if the current environment is minimal (CI, non-TTY, etc.)\"\n initializer={code` env.MINIMAL || isCI || isTest || !isTTY; `}\n />\n <Spacing />\n <VarDeclaration\n export\n const\n name=\"isInteractive\"\n doc=\"Detect if the current environment is interactive\"\n initializer={code` !isMinimal && process.stdin?.isTTY && env.TERM !== \"dumb\" && !hasFlag([\"no-interactive\", \"non-interactive\", \"no-interact\"]); `}\n />\n </>\n );\n}\n\n/**\n * Generates utilities for detecting terminal color support.\n */\nexport function ColorSupportUtilities() {\n return (\n <>\n <InterfaceDeclaration\n export\n name=\"GetColorSupportLevelOptions\"\n doc=\"Options for the getColorSupportLevel function\">\n <InterfaceMember\n name=\"ignoreFlags\"\n type=\"boolean\"\n doc=\"Indicates if the function should skip checking command-line flags for color support\"\n />\n </InterfaceDeclaration>\n <Spacing />\n <TSDoc heading=\"Checks if a specific flag is present in the command-line arguments.\">\n <TSDocLink>\n {\"https://github.com/sindresorhus/has-flag/blob/main/index.js\"}\n </TSDocLink>\n <TSDocParam name=\"flag\">\n {'The flag to check for, e.g., \"color\", \"no-color\".'}\n </TSDocParam>\n <TSDocParam name=\"argv\">\n {\n \"The command-line arguments to check against. Defaults to global Deno args or process args.\"\n }\n </TSDocParam>\n <TSDocReturns>\n {\"True if the flag is present, false otherwise.\"}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"getColorSupportLevel\"\n parameters={[\n { name: \"stream\", type: \"NodeJS.WriteStream & { fd: 1 | 2; }\" },\n {\n name: \"options\",\n type: \"GetColorSupportLevelOptions\",\n default: \"{ ignoreFlags: false }\"\n }\n ]}>\n {code`const { ignoreFlags } = options;\n\n let forceColor: number | undefined;\n if (env.FORCE_COLOR !== undefined) {\n forceColor = !env.FORCE_COLOR\n ? 0\n : typeof env.FORCE_COLOR === \"boolean\"\n ? 1\n : typeof env.FORCE_COLOR === \"number\" &&\n [0, 1, 2, 3].includes(Math.min(env.FORCE_COLOR as number, 3))\n ? Math.min(env.FORCE_COLOR as number, 3)\n : undefined;\n }\n\n if (ignoreFlags !== true && forceColor === undefined) {\n if (\n hasFlag(\"no-color\") ||\n hasFlag(\"no-colors\") ||\n hasFlag(\"color=false\") ||\n hasFlag(\"color=never\")\n ) {\n return 0;\n }\n\n if (\n hasFlag(\"color=16m\") ||\n hasFlag(\"color=full\") ||\n hasFlag(\"color=truecolor\")\n ) {\n return 3;\n }\n\n if (hasFlag(\"color=256\")) {\n return 2;\n }\n\n if (\n hasFlag(\"color\") ||\n hasFlag(\"colors\") ||\n hasFlag(\"color=true\") ||\n hasFlag(\"color=always\")\n ) {\n forceColor = 1;\n }\n }\n\n const level = Boolean(env.TF_BUILD) || Boolean(env.AGENT_NAME)\n ? 1\n : stream &&\n !(isTTY || (stream && stream.isTTY)) &&\n forceColor === undefined\n ? 0\n : env.TERM === \"dumb\"\n ? forceColor || 0\n : isWindows\n ? Number(os.release().split(\".\")[0]) >= 10 &&\n Number(os.release().split(\".\")[2]) >= 10_586\n ? Number(os.release().split(\".\")[2]) >= 14_931\n ? 3\n : 2\n : 1\n : isCI\n ? Boolean(env.GITHUB_ACTIONS) ||\n Boolean(env.GITEA_ACTIONS) ||\n Boolean(env.CIRCLECI)\n ? 3\n : Boolean(env.TRAVIS) ||\n Boolean(env.APPVEYOR) ||\n Boolean(env.GITLAB_CI) ||\n Boolean(env.BUILDKITE) ||\n Boolean(env.DRONE) ||\n env.CI_NAME === \"codeship\"\n ? 1\n : forceColor || 0\n : Boolean(env.TEAMCITY_VERSION)\n ? /^(?:9\\.0*[1-9]\\d*\\.|\\d{2,}\\.)/.test(String(env.TEAMCITY_VERSION) || \"\")\n ? 1\n : 0\n : String(env.COLORTERM) === \"truecolor\" ||\n env.TERM === \"xterm-kitty\"\n ? 3\n : Boolean(env.TERM_PROGRAM)\n ? env.TERM_PROGRAM === \"iTerm.app\"\n ? Number.parseInt(\n (env.TERM_PROGRAM_VERSION || \"\").split(\".\")[0] as string,\n 10\n ) >= 3\n ? 3\n : 2\n : env.TERM_PROGRAM === \"Apple_Terminal\"\n ? 2\n : 0\n : /-256(?:color)?$/i.test(env.TERM || \"\")\n ? 2\n : /^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(\n env.TERM || \"\"\n )\n ? 1\n : Boolean(env.COLORTERM);\n\n return typeof level === \"boolean\" || level === 0\n ? false\n : {\n level,\n hasBasic: true,\n has256: level >= 2,\n has16m: level >= 3,\n };\n\n `}\n </FunctionDeclaration>\n <Spacing />\n <VarDeclaration\n export\n const\n name=\"colorSupportLevels\"\n doc=\"Detect the terminal color support level in the current environment\"\n initializer={code` {\n stdout: getColorSupportLevel(process.stdout),\n stderr: getColorSupportLevel(process.stderr),\n }; `}\n />\n <Spacing />\n <VarDeclaration\n export\n const\n name=\"isColorSupported\"\n doc=\"Detect if terminal color is supported in the current environment\"\n initializer={code` Boolean(colorSupportLevels.stdout); `}\n />\n <Spacing />\n <VarDeclaration\n export\n const\n name=\"isUnicodeSupported\"\n doc=\"Detect if Unicode characters are supported in the current environment\"\n initializer={code` !isWindows\n ? env.TERM !== \"linux\"\n : Boolean(env.WT_SESSION) ||\n Boolean(env.TERMINUS_SUBLIME) ||\n env.ConEmuTask === \"{cmd::Cmder}\" ||\n env.TERM_PROGRAM === \"Terminus-Sublime\" ||\n env.TERM_PROGRAM === \"vscode\" ||\n env.TERM === \"xterm-256color\" ||\n env.TERM === \"alacritty\" ||\n env.TERM === \"rxvt-unicode\" ||\n env.TERM === \"rxvt-unicode-256color\" ||\n env.TERMINAL_EMULATOR === \"JetBrains-JediTerm\"; `}\n />\n </>\n );\n}\n\n/**\n * Generates utilities for detecting terminal color support.\n */\n\nexport function HyperlinkSupportUtilities() {\n return (\n <>\n <FunctionDeclaration\n name=\"parseVersion\"\n parameters={[{ name: \"version\", type: \"string\", default: '\"\"' }]}>\n {code`if (/^\\d{3,4}$/.test(version)) {\n const match = /(\\d{1,2})(\\d{2})/.exec(version) ?? [];\n\n return {\n major: 0,\n minor: Number.parseInt(match[1]!, 10),\n patch: Number.parseInt(match[2]!, 10)\n };\n }\n\n const versionParts = (version ?? \"\")\n .split(\".\")\n .map(n => Number.parseInt(n, 10));\n\n return {\n major: versionParts[0],\n minor: versionParts[1],\n patch: versionParts[2]\n }; `}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc heading=\"Check if the current environment/terminal supports hyperlinks in the terminal.\">\n <TSDocReturns>\n {\"True if the current environment/terminal supports hyperlinks.\"}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"isHyperlinkSupported\"\n returnType=\"boolean\">\n {code`if (Boolean(env.FORCE_HYPERLINK)) {\n return true;\n }\n\n if (Boolean(env.NETLIFY)) {\n return true;\n } else if (isColorSupported || isTTY) {\n return false;\n } else if (Boolean(env.WT_SESSION)) {\n return true;\n } else if (isWindows || isMinimal || Boolean(env.TEAMCITY_VERSION)) {\n return false;\n } else if (Boolean(env.TERM_PROGRAM)) {\n const version = parseVersion(env.TERM_PROGRAM_VERSION);\n\n switch (String(env.TERM_PROGRAM)) {\n case \"iTerm.app\": {\n if (version.major === 3) {\n return version.minor !== undefined && version.minor >= 1;\n }\n\n return version.major !== undefined && version.major > 3;\n }\n case \"WezTerm\": {\n return version.major !== undefined && version.major >= 20_200_620;\n }\n\n case \"vscode\": {\n if (Boolean(env.CURSOR_TRACE_ID)) {\n return true;\n }\n\n return (\n version.minor !== undefined &&\n version.major !== undefined &&\n (version.major > 1 || (version.major === 1 && version.minor >= 72))\n );\n }\n\n case \"ghostty\": {\n return true;\n }\n }\n }\n\n if (Boolean(env.VTE_VERSION)) {\n if (env.VTE_VERSION === \"0.50.0\") {\n return false;\n }\n\n const version = parseVersion(env.VTE_VERSION);\n return (\n (version.major !== undefined && version.major > 0) ||\n (version.minor !== undefined && version.minor >= 50)\n );\n }\n\n if (String(env.TERM) === \"alacritty\") {\n return true;\n }\n\n return false; `}\n </FunctionDeclaration>\n </>\n );\n}\n\n/**\n * Generates utilities for detecting terminal color support.\n */\nexport function ArgsUtilities() {\n return (\n <>\n <TSDoc heading=\"Retrieves the command-line arguments from Deno or Node.js environments.\">\n <TSDocRemarks>\n {\n \"This function is only intended for internal use. Please use `useArgs()` instead.\"\n }\n </TSDocRemarks>\n <hbr />\n <hbr />\n <TSDocInternal />\n <hbr />\n <hbr />\n <TSDocReturns>\n {\n \"An array of command-line arguments from Deno or Node.js environments.\"\n }\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration export name=\"getArgs\" returnType=\"string[]\">\n {code`return ((globalThis as { Deno?: { args: string[] } })?.Deno?.args ?? process.argv ?? []) as string[];`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc heading=\"Checks if a specific flag is present in the command-line arguments.\">\n <TSDocLink>\n {\"https://github.com/sindresorhus/has-flag/blob/main/index.js\"}\n </TSDocLink>\n <TSDocParam name=\"flag\">\n {\n 'The flag (or an array of flags/aliases) to check for, e.g., \"color\", \"no-color\".'\n }\n </TSDocParam>\n <TSDocParam name=\"argv\">\n {\n \"The command-line arguments to check against. Defaults to global Deno args or process args.\"\n }\n </TSDocParam>\n <TSDocReturns>\n {\"True if the flag is present, false otherwise.\"}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"hasFlag\"\n parameters={[\n { name: \"flag\", type: \"string | string[]\" },\n {\n name: \"argv\",\n type: \"string[]\",\n default: \"useArgs()\"\n }\n ]}>\n <VarDeclaration\n const\n name=\"position\"\n type=\"number\"\n initializer={code`(Array.isArray(flag) ? flag : [flag]).reduce((ret, f) => {\n const pos = argv.findIndex(arg => (f.startsWith(\"-\") ? \"\" : (f.length === 1 ? \"-\" : \"--\") + f)?.toLowerCase() === arg?.toLowerCase() || arg?.toLowerCase().startsWith((f.length === 1 ? \"-\" : \"--\") + f + \"=\"));\n return pos !== -1 ? pos : ret;\n }, -1);`}\n />\n <hbr />\n {code`return position !== -1 && argv.indexOf(\"--\") === -1 || position < argv.indexOf(\"--\");`}\n </FunctionDeclaration>\n <Spacing />\n <VarDeclaration\n export\n name=\"isHelp\"\n type=\"boolean\"\n initializer={code` !isCI && hasFlag([\"help\", \"h\", \"?\"]); `}\n />\n </>\n );\n}\n\nexport function ContextUtilities() {\n return code`\n /**\n * The global Shell Shock - Application context instance.\n *\n * @internal\n */\n export let internal_appContext = new AsyncLocalStorage<Map<string, any>>();\n\n /**\n * Get the Shell Shock - Application context for the current application.\n *\n * @param options - The options to use when getting the context.\n * @returns The Shell Shock - Application context for the current application or undefined if the context is not available.\n */\n export function useApp(): Map<string, any> | undefined {\n return internal_appContext.getStore();\n }\n\n /**\n * A utility hook function to get the command line arguments from the application context.\n *\n * @returns An array of command-line arguments from the application context.\n * @throws If the application context is not available.\n */\n export function useArgs(): string[] {\n return useApp()?.get(\"args\") ?? getArgs();\n }\n\n /**\n * The context object for the current command execution, containing the command path and segments.\n */\n export interface CommandContext {\n path: string;\n segments: string[];\n }\n\n /**\n * The global Shell Shock - Command context instance.\n *\n * @internal\n */\n export let internal_commandContext = new AsyncLocalStorage<CommandContext>();\n\n /**\n * Get the Shell Shock - Command context for the current application.\n *\n * @param options - The options to use when getting the context.\n * @returns The Shell Shock - Command context for the current application.\n * @throws If the Shell Shock - Command context is not available.\n */\n export function useCommand(): CommandContext {\n const result = internal_commandContext.getStore();\n if (!result) {\n throw new Error(\n \\`The Shell Shock - Command context is not available. Make sure to call useCommand() within a valid context scope.\\`\n );\n }\n return result;\n }\n\n /**\n * A utility hook function to get the individual segments of the current command path.\n *\n * @returns An array of command path segments.\n * @throws If the command context is not available.\n */\n export function useSegments(): string[] {\n return useCommand().segments;\n }\n\n /**\n * A utility hook function to get the full command path as a string.\n *\n * @returns The full command path as a string.\n * @throws If the command context is not available.\n */\n export function usePath(): string {\n return useCommand().path;\n }\n `;\n}\n\n/**\n * A built-in utilities module for Shell Shock.\n */\nexport function UtilsBuiltin(props: UtilsBuiltinProps) {\n const [{ children }, rest] = splitProps(props, [\"children\"]);\n\n return (\n <BuiltinFile\n id=\"utils\"\n description=\"A collection of helper utilities that ease command-line application development.\"\n {...rest}\n imports={defu(rest.imports ?? {}, {\n \"node:os\": \"os\",\n \"node:process\": \"process\",\n \"node:async_hooks\": [\"AsyncLocalStorage\"]\n })}\n builtinImports={defu(rest.builtinImports ?? {}, {\n console: [\"error\", \"verbose\", \"writeLine\"],\n env: [\"env\", \"isCI\", \"isTest\", \"isWindows\", \"isDevelopment\", \"isDebug\"]\n })}>\n <Spacing />\n <ContextUtilities />\n <Spacing />\n <ArgsUtilities />\n <Spacing />\n <EnvSupportUtilities />\n <Spacing />\n <HyperlinkSupportUtilities />\n <Spacing />\n <ColorSupportUtilities />\n <Spacing />\n <Show when={Boolean(children)}>{children}</Show>\n </BuiltinFile>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AA8CA,SAAgBgB,sBAAsB;AACpC,QAAA;mDAEKV,sCAAc;GAAA,UAAA;GAAA,SAAA;GAGbY,MAAI;GACJC,KAAG;GACHC,aAAapB,oBAAI;GAAkD,CAAA;mDAEpEO,2DAAO,EAAA,CAAA;mDACPD,sCAAc;GAAA,UAAA;GAAA,SAAA;GAGbY,MAAI;GACJC,KAAG;GACHC,aAAapB,oBAAI;GAA4C,CAAA;mDAE9DO,2DAAO,EAAA,CAAA;mDACPD,sCAAc;GAAA,UAAA;GAAA,SAAA;GAGbY,MAAI;GACJC,KAAG;GACHC,a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qDACbtB,2DAAO,EAAA,CAAA;qDACPS,qBAAmB,EAAA,CAAA;qDACnBT,2DAAO,EAAA,CAAA;qDACPoB,2BAAyB,EAAA,CAAA;qDACzBpB,2DAAO,EAAA,CAAA;qDACPc,uBAAqB,EAAA,CAAA;qDACrBd,2DAAO,EAAA,CAAA;qDACPN,sBAAI;KAAA,IAACyC,OAAI;AAAA,aAAEC,QAAQrB,SAAS;;KAAGA;KAAQ,CAAA;IAAA;;EAAA,CAAA,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as _alloy_js_core3 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_core3.Children;
|
|
10
|
+
/**
|
|
11
|
+
* Generates utilities for detecting terminal color support.
|
|
12
|
+
*/
|
|
13
|
+
declare function ColorSupportUtilities(): _alloy_js_core3.Children;
|
|
14
|
+
/**
|
|
15
|
+
* Generates utilities for detecting terminal color support.
|
|
16
|
+
*/
|
|
17
|
+
declare function HyperlinkSupportUtilities(): _alloy_js_core3.Children;
|
|
18
|
+
/**
|
|
19
|
+
* Generates utilities for detecting terminal color support.
|
|
20
|
+
*/
|
|
21
|
+
declare function ArgsUtilities(): _alloy_js_core3.Children;
|
|
22
|
+
declare function ContextUtilities(): _alloy_js_core3.Children;
|
|
23
|
+
/**
|
|
24
|
+
* A built-in utilities module for Shell Shock.
|
|
25
|
+
*/
|
|
26
|
+
declare function UtilsBuiltin(props: UtilsBuiltinProps): _alloy_js_core3.Children;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { ArgsUtilities, ColorSupportUtilities, ContextUtilities, EnvSupportUtilities, HyperlinkSupportUtilities, UtilsBuiltin, UtilsBuiltinProps };
|
|
29
|
+
//# 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;AAQA;AAiCgB,iBAjCA,mBAAA,CAAA,CAiCqB,EAjCF,eAAA,CAAA,QAiCE;AAsMrC;AA0GA;AA4EA;AAsFgB,iBAldA,qBAAA,CAAA,CAkdoB,EAldC,eAAA,CAAA,QAkdgB;;;;iBA5QrC,yBAAA,CAAA,GAAyB,eAAA,CAAA;;;;iBA0GzB,aAAA,CAAA,GAAa,eAAA,CAAA;iBA4Eb,gBAAA,CAAA,GAAgB,eAAA,CAAA;;;;iBAsFhB,YAAA,QAAoB,oBAAiB,eAAA,CAAA"}
|