@stacksjs/stx 0.0.10 → 0.1.7
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/README.md +69 -21
- package/dist/a11y.d.ts +40 -0
- package/dist/analyzer.d.ts +64 -0
- package/dist/animation.d.ts +64 -0
- package/dist/assets.d.ts +19 -0
- package/dist/auth.d.ts +11 -0
- package/dist/bin/cli.js +2821 -154
- package/dist/caching.d.ts +18 -6
- package/dist/chunk-2ndtnc0t.js +9822 -0
- package/dist/{chunk-ywm063e4.js → chunk-e11q5a3p.js} +2 -2
- package/dist/chunk-vsbm352h.js +670 -0
- package/dist/client.d.ts +19 -35
- package/dist/components.d.ts +6 -0
- package/dist/conditionals.d.ts +17 -1
- package/dist/config.d.ts +6 -2
- package/dist/csrf.d.ts +28 -0
- package/dist/custom-directives.d.ts +5 -6
- package/dist/dev-server.d.ts +21 -0
- package/dist/docs.d.ts +39 -3
- package/dist/error-handling.d.ts +101 -0
- package/dist/expressions.d.ts +43 -4
- package/dist/formatter.d.ts +16 -0
- package/dist/forms.d.ts +15 -25
- package/dist/i18n.d.ts +17 -20
- package/dist/includes.d.ts +21 -18
- package/dist/index.d.ts +30 -24
- package/dist/init.d.ts +9 -0
- package/dist/js-ts.d.ts +10 -0
- package/dist/loops.d.ts +4 -3
- package/dist/markdown.d.ts +8 -0
- package/dist/method-spoofing.d.ts +13 -0
- package/dist/middleware.d.ts +9 -1
- package/dist/performance-utils.d.ts +58 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/process.d.ts +9 -7
- package/dist/release.d.ts +1 -0
- package/dist/routes.d.ts +36 -0
- package/dist/safe-evaluator.d.ts +16 -0
- package/dist/seo.d.ts +33 -0
- package/dist/serve.d.ts +35 -0
- package/dist/src/index.js +2893 -135
- package/dist/streaming.d.ts +30 -14
- package/dist/types.d.ts +214 -48
- package/dist/utils.d.ts +21 -3
- package/dist/view-composers.d.ts +26 -0
- package/dist/web-components.d.ts +7 -14
- package/package.json +18 -9
- package/dist/chunk-04bqmpzb.js +0 -7069
- package/dist/chunk-8ehp5m3y.js +0 -4279
- package/dist/chunk-9ynf73q9.js +0 -2502
package/dist/bin/cli.js
CHANGED
|
@@ -1,114 +1,235 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
analyzeProject,
|
|
4
|
+
docsCommand,
|
|
5
|
+
formatStxContent,
|
|
6
|
+
gitHash,
|
|
7
|
+
initFile,
|
|
8
|
+
plugin,
|
|
9
|
+
serveMultipleStxFiles,
|
|
10
|
+
serveStxFile
|
|
11
|
+
} from "../src/index.js";
|
|
12
|
+
import {
|
|
13
|
+
performanceMonitor,
|
|
14
|
+
scanA11yIssues
|
|
15
|
+
} from "../chunk-2ndtnc0t.js";
|
|
16
|
+
import {
|
|
17
|
+
__require,
|
|
18
|
+
__toESM
|
|
19
|
+
} from "../chunk-e11q5a3p.js";
|
|
20
|
+
|
|
21
|
+
// bin/cli.ts
|
|
22
|
+
import { spawn } from "child_process";
|
|
23
|
+
import fs from "fs";
|
|
24
|
+
import os from "os";
|
|
25
|
+
import path from "path";
|
|
26
|
+
import process7 from "process";
|
|
7
27
|
|
|
8
|
-
// ../../node_modules/
|
|
28
|
+
// ../../node_modules/.bun/@stacksjs+clapp@0.2.0/node_modules/@stacksjs/clapp/dist/index.js
|
|
9
29
|
import { EventEmitter } from "events";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
30
|
+
import process2 from "process";
|
|
31
|
+
import process3 from "process";
|
|
32
|
+
import process4 from "process";
|
|
33
|
+
import process5, { stdin, stdout } from "process";
|
|
34
|
+
import process6, { stdin as stdin2, stdout as stdout2 } from "process";
|
|
35
|
+
import readline2 from "readline";
|
|
36
|
+
var __create = Object.create;
|
|
37
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
38
|
+
var __defProp = Object.defineProperty;
|
|
39
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
40
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
41
|
+
var __toESM2 = (mod, isNodeMode, target) => {
|
|
42
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
43
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
44
|
+
for (let key of __getOwnPropNames(mod))
|
|
45
|
+
if (!__hasOwnProp.call(to, key))
|
|
46
|
+
__defProp(to, key, {
|
|
47
|
+
get: () => mod[key],
|
|
48
|
+
enumerable: true
|
|
49
|
+
});
|
|
50
|
+
return to;
|
|
51
|
+
};
|
|
52
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
53
|
+
var require_lib = __commonJS((exports, module) => {
|
|
54
|
+
function toArr(any) {
|
|
55
|
+
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
56
|
+
}
|
|
57
|
+
function toVal(out, key, val, opts) {
|
|
58
|
+
var x, old = out[key], nxt = ~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : ~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
|
|
59
|
+
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
|
60
|
+
}
|
|
61
|
+
module.exports = function(args, opts) {
|
|
62
|
+
args = args || [];
|
|
63
|
+
opts = opts || {};
|
|
64
|
+
var k, arr, arg, name, val, out = { _: [] };
|
|
65
|
+
var i = 0, j = 0, idx = 0, len = args.length;
|
|
66
|
+
const alibi = opts.alias !== undefined;
|
|
67
|
+
const strict = opts.unknown !== undefined;
|
|
68
|
+
const defaults = opts.default !== undefined;
|
|
69
|
+
opts.alias = opts.alias || {};
|
|
70
|
+
opts.string = toArr(opts.string);
|
|
71
|
+
opts.boolean = toArr(opts.boolean);
|
|
72
|
+
if (alibi) {
|
|
73
|
+
for (k in opts.alias) {
|
|
74
|
+
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
52
75
|
for (i = 0;i < arr.length; i++) {
|
|
53
|
-
opts[
|
|
76
|
+
(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
54
77
|
}
|
|
55
78
|
}
|
|
56
79
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (arg === "--") {
|
|
62
|
-
out._ = out._.concat(args.slice(++i));
|
|
63
|
-
break;
|
|
80
|
+
for (i = opts.boolean.length;i-- > 0; ) {
|
|
81
|
+
arr = opts.alias[opts.boolean[i]] || [];
|
|
82
|
+
for (j = arr.length;j-- > 0; )
|
|
83
|
+
opts.boolean.push(arr[j]);
|
|
64
84
|
}
|
|
65
|
-
for (
|
|
66
|
-
|
|
67
|
-
|
|
85
|
+
for (i = opts.string.length;i-- > 0; ) {
|
|
86
|
+
arr = opts.alias[opts.string[i]] || [];
|
|
87
|
+
for (j = arr.length;j-- > 0; )
|
|
88
|
+
opts.string.push(arr[j]);
|
|
68
89
|
}
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
90
|
+
if (defaults) {
|
|
91
|
+
for (k in opts.default) {
|
|
92
|
+
name = typeof opts.default[k];
|
|
93
|
+
arr = opts.alias[k] = opts.alias[k] || [];
|
|
94
|
+
if (opts[name] !== undefined) {
|
|
95
|
+
opts[name].push(k);
|
|
96
|
+
for (i = 0;i < arr.length; i++) {
|
|
97
|
+
opts[name].push(arr[i]);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
75
100
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
101
|
+
}
|
|
102
|
+
const keys = strict ? Object.keys(opts.alias) : [];
|
|
103
|
+
for (i = 0;i < len; i++) {
|
|
104
|
+
arg = args[i];
|
|
105
|
+
if (arg === "--") {
|
|
106
|
+
out._ = out._.concat(args.slice(++i));
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
for (j = 0;j < arg.length; j++) {
|
|
110
|
+
if (arg.charCodeAt(j) !== 45)
|
|
80
111
|
break;
|
|
81
112
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
name
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
113
|
+
if (j === 0) {
|
|
114
|
+
out._.push(arg);
|
|
115
|
+
} else if (arg.substring(j, j + 3) === "no-") {
|
|
116
|
+
name = arg.substring(j + 3);
|
|
117
|
+
if (strict && !~keys.indexOf(name)) {
|
|
118
|
+
return opts.unknown(arg);
|
|
119
|
+
}
|
|
120
|
+
out[name] = false;
|
|
121
|
+
} else {
|
|
122
|
+
for (idx = j + 1;idx < arg.length; idx++) {
|
|
123
|
+
if (arg.charCodeAt(idx) === 61)
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
name = arg.substring(j, idx);
|
|
127
|
+
val = arg.substring(++idx) || (i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i]);
|
|
128
|
+
arr = j === 2 ? [name] : name;
|
|
129
|
+
for (idx = 0;idx < arr.length; idx++) {
|
|
130
|
+
name = arr[idx];
|
|
131
|
+
if (strict && !~keys.indexOf(name))
|
|
132
|
+
return opts.unknown("-".repeat(j) + name);
|
|
133
|
+
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
134
|
+
}
|
|
90
135
|
}
|
|
91
136
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
137
|
+
if (defaults) {
|
|
138
|
+
for (k in opts.default) {
|
|
139
|
+
if (out[k] === undefined) {
|
|
140
|
+
out[k] = opts.default[k];
|
|
141
|
+
}
|
|
97
142
|
}
|
|
98
143
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
144
|
+
if (alibi) {
|
|
145
|
+
for (k in out) {
|
|
146
|
+
arr = opts.alias[k] || [];
|
|
147
|
+
while (arr.length > 0) {
|
|
148
|
+
out[arr.shift()] = out[k];
|
|
149
|
+
}
|
|
105
150
|
}
|
|
106
151
|
}
|
|
107
|
-
|
|
108
|
-
|
|
152
|
+
return out;
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
var require_picocolors = __commonJS((exports, module) => {
|
|
156
|
+
var p = process || {};
|
|
157
|
+
var argv = p.argv || [];
|
|
158
|
+
var env = p.env || {};
|
|
159
|
+
var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
160
|
+
var formatter = (open, close, replace = open) => (input) => {
|
|
161
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
162
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
163
|
+
};
|
|
164
|
+
var replaceClose = (string, close, replace, index) => {
|
|
165
|
+
let result = "", cursor2 = 0;
|
|
166
|
+
do {
|
|
167
|
+
result += string.substring(cursor2, index) + replace;
|
|
168
|
+
cursor2 = index + close.length;
|
|
169
|
+
index = string.indexOf(close, cursor2);
|
|
170
|
+
} while (~index);
|
|
171
|
+
return result + string.substring(cursor2);
|
|
172
|
+
};
|
|
173
|
+
var createColors = (enabled = isColorSupported) => {
|
|
174
|
+
let f = enabled ? formatter : () => String;
|
|
175
|
+
return {
|
|
176
|
+
isColorSupported: enabled,
|
|
177
|
+
reset: f("\x1B[0m", "\x1B[0m"),
|
|
178
|
+
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
179
|
+
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
180
|
+
italic: f("\x1B[3m", "\x1B[23m"),
|
|
181
|
+
underline: f("\x1B[4m", "\x1B[24m"),
|
|
182
|
+
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
183
|
+
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
184
|
+
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
185
|
+
black: f("\x1B[30m", "\x1B[39m"),
|
|
186
|
+
red: f("\x1B[31m", "\x1B[39m"),
|
|
187
|
+
green: f("\x1B[32m", "\x1B[39m"),
|
|
188
|
+
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
189
|
+
blue: f("\x1B[34m", "\x1B[39m"),
|
|
190
|
+
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
191
|
+
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
192
|
+
white: f("\x1B[37m", "\x1B[39m"),
|
|
193
|
+
gray: f("\x1B[90m", "\x1B[39m"),
|
|
194
|
+
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
195
|
+
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
196
|
+
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
197
|
+
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
198
|
+
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
199
|
+
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
200
|
+
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
201
|
+
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
202
|
+
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
203
|
+
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
204
|
+
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
205
|
+
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
206
|
+
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
207
|
+
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
208
|
+
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
209
|
+
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
210
|
+
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
211
|
+
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
212
|
+
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
213
|
+
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
214
|
+
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
215
|
+
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
216
|
+
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
217
|
+
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
module.exports = createColors();
|
|
221
|
+
module.exports.createColors = createColors;
|
|
222
|
+
});
|
|
223
|
+
var require_emoji_regex = __commonJS((exports, module) => {
|
|
224
|
+
module.exports = () => {
|
|
225
|
+
return /[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE89\uDE8F-\uDEC2\uDEC6\uDECE-\uDEDC\uDEDF-\uDEE9]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g;
|
|
226
|
+
};
|
|
227
|
+
});
|
|
228
|
+
var import_mri = __toESM2(require_lib(), 1);
|
|
229
|
+
function removeBrackets(v) {
|
|
230
|
+
return v.replace(/[<[].+/, "").trim();
|
|
109
231
|
}
|
|
110
|
-
|
|
111
|
-
var findAllBrackets = (v) => {
|
|
232
|
+
function findAllBrackets(v) {
|
|
112
233
|
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
113
234
|
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
114
235
|
const res = [];
|
|
@@ -134,8 +255,8 @@ var findAllBrackets = (v) => {
|
|
|
134
255
|
res.push(parse(squareMatch));
|
|
135
256
|
}
|
|
136
257
|
return res;
|
|
137
|
-
}
|
|
138
|
-
|
|
258
|
+
}
|
|
259
|
+
function getMriOptions(options) {
|
|
139
260
|
const result = { alias: {}, boolean: [] };
|
|
140
261
|
for (const [index, option] of options.entries()) {
|
|
141
262
|
if (option.names.length > 1) {
|
|
@@ -155,31 +276,31 @@ var getMriOptions = (options) => {
|
|
|
155
276
|
}
|
|
156
277
|
}
|
|
157
278
|
return result;
|
|
158
|
-
}
|
|
159
|
-
|
|
279
|
+
}
|
|
280
|
+
function findLongest(arr) {
|
|
160
281
|
return arr.sort((a, b) => {
|
|
161
282
|
return a.length > b.length ? -1 : 1;
|
|
162
283
|
})[0];
|
|
163
|
-
}
|
|
164
|
-
|
|
284
|
+
}
|
|
285
|
+
function padRight(str, length) {
|
|
165
286
|
return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
|
166
|
-
}
|
|
167
|
-
|
|
287
|
+
}
|
|
288
|
+
function camelcase(input) {
|
|
168
289
|
return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
|
|
169
290
|
return p1 + p2.toUpperCase();
|
|
170
291
|
});
|
|
171
|
-
}
|
|
172
|
-
|
|
292
|
+
}
|
|
293
|
+
function setDotProp(obj, keys, val) {
|
|
173
294
|
let i = 0;
|
|
174
|
-
|
|
295
|
+
const length = keys.length;
|
|
175
296
|
let t = obj;
|
|
176
297
|
let x;
|
|
177
298
|
for (;i < length; ++i) {
|
|
178
299
|
x = t[keys[i]];
|
|
179
300
|
t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
|
|
180
301
|
}
|
|
181
|
-
}
|
|
182
|
-
|
|
302
|
+
}
|
|
303
|
+
function setByType(obj, transforms) {
|
|
183
304
|
for (const key of Object.keys(transforms)) {
|
|
184
305
|
const transform = transforms[key];
|
|
185
306
|
if (transform.shouldTransform) {
|
|
@@ -189,18 +310,18 @@ var setByType = (obj, transforms) => {
|
|
|
189
310
|
}
|
|
190
311
|
}
|
|
191
312
|
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const m = /([
|
|
313
|
+
}
|
|
314
|
+
function getFileName(input) {
|
|
315
|
+
const m = /([^\\/]+)$/.exec(input);
|
|
195
316
|
return m ? m[1] : "";
|
|
196
|
-
}
|
|
197
|
-
|
|
317
|
+
}
|
|
318
|
+
function camelcaseOptionName(name) {
|
|
198
319
|
return name.split(".").map((v, i) => {
|
|
199
320
|
return i === 0 ? camelcase(v) : v;
|
|
200
321
|
}).join(".");
|
|
201
|
-
}
|
|
322
|
+
}
|
|
202
323
|
|
|
203
|
-
class
|
|
324
|
+
class ClappError extends Error {
|
|
204
325
|
constructor(message) {
|
|
205
326
|
super(message);
|
|
206
327
|
this.name = this.constructor.name;
|
|
@@ -211,8 +332,75 @@ class CACError extends Error {
|
|
|
211
332
|
}
|
|
212
333
|
}
|
|
213
334
|
}
|
|
335
|
+
function isUnicodeSupported() {
|
|
336
|
+
const { env } = process2;
|
|
337
|
+
const { TERM, TERM_PROGRAM } = env;
|
|
338
|
+
if (process2.platform !== "win32") {
|
|
339
|
+
return TERM !== "linux";
|
|
340
|
+
}
|
|
341
|
+
return Boolean(env.WT_SESSION) || Boolean(env.TERMINUS_SUBLIME) || env.ConEmuTask === "{cmd::Cmder}" || TERM_PROGRAM === "Terminus-Sublime" || TERM_PROGRAM === "vscode" || TERM === "xterm-256color" || TERM === "alacritty" || TERM === "rxvt-unicode" || TERM === "rxvt-unicode-256color" || env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
342
|
+
}
|
|
343
|
+
var ESC = "\x1B";
|
|
344
|
+
var CSI = `${ESC}[`;
|
|
345
|
+
var cursor = {
|
|
346
|
+
to(x, y) {
|
|
347
|
+
if (!y)
|
|
348
|
+
return `${CSI}${x + 1}G`;
|
|
349
|
+
return `${CSI}${y + 1};${x + 1}H`;
|
|
350
|
+
},
|
|
351
|
+
move(x, y) {
|
|
352
|
+
let ret = "";
|
|
353
|
+
if (x < 0)
|
|
354
|
+
ret += `${CSI}${-x}D`;
|
|
355
|
+
else if (x > 0)
|
|
356
|
+
ret += `${CSI}${x}C`;
|
|
357
|
+
if (y < 0)
|
|
358
|
+
ret += `${CSI}${-y}A`;
|
|
359
|
+
else if (y > 0)
|
|
360
|
+
ret += `${CSI}${y}B`;
|
|
361
|
+
return ret;
|
|
362
|
+
},
|
|
363
|
+
up: (count = 1) => `${CSI}${count}A`,
|
|
364
|
+
down: (count = 1) => `${CSI}${count}B`,
|
|
365
|
+
forward: (count = 1) => `${CSI}${count}C`,
|
|
366
|
+
backward: (count = 1) => `${CSI}${count}D`,
|
|
367
|
+
nextLine: (count = 1) => `${CSI}E`.repeat(count),
|
|
368
|
+
prevLine: (count = 1) => `${CSI}F`.repeat(count),
|
|
369
|
+
left: `${CSI}G`,
|
|
370
|
+
hide: `${CSI}?25l`,
|
|
371
|
+
show: `${CSI}?25h`,
|
|
372
|
+
save: `${ESC}7`,
|
|
373
|
+
restore: `${ESC}8`
|
|
374
|
+
};
|
|
375
|
+
var erase = {
|
|
376
|
+
screen: `${CSI}2J`,
|
|
377
|
+
up: (count = 1) => `${CSI}1J`.repeat(count),
|
|
378
|
+
down: (count = 1) => `${CSI}J`.repeat(count),
|
|
379
|
+
line: `${CSI}2K`,
|
|
380
|
+
lineEnd: `${CSI}K`,
|
|
381
|
+
lineStart: `${CSI}1K`,
|
|
382
|
+
lines(count) {
|
|
383
|
+
let clear = "";
|
|
384
|
+
for (let i = 0;i < count; i++)
|
|
385
|
+
clear += this.line + (i < count - 1 ? cursor.up() : "");
|
|
386
|
+
if (count)
|
|
387
|
+
clear += cursor.left;
|
|
388
|
+
return clear;
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
var clear = {
|
|
392
|
+
screen: `${ESC}c`
|
|
393
|
+
};
|
|
214
394
|
|
|
215
395
|
class Option {
|
|
396
|
+
rawName;
|
|
397
|
+
description;
|
|
398
|
+
name;
|
|
399
|
+
names;
|
|
400
|
+
isBoolean;
|
|
401
|
+
required;
|
|
402
|
+
config;
|
|
403
|
+
negated;
|
|
216
404
|
constructor(rawName, description, config) {
|
|
217
405
|
this.rawName = rawName;
|
|
218
406
|
this.description = description;
|
|
@@ -240,11 +428,27 @@ class Option {
|
|
|
240
428
|
}
|
|
241
429
|
}
|
|
242
430
|
}
|
|
243
|
-
var processArgs =
|
|
244
|
-
var platformInfo = `${
|
|
431
|
+
var processArgs = process3.argv;
|
|
432
|
+
var platformInfo = `${process3.platform}-${process3.arch} bun-v${typeof Bun !== "undefined" ? Bun.version : "unknown"}`;
|
|
433
|
+
var processArgs2 = process4.argv;
|
|
434
|
+
var platformInfo2 = `${process4.platform}-${process4.arch} node-${process4.version}`;
|
|
245
435
|
|
|
246
436
|
class Command {
|
|
247
|
-
|
|
437
|
+
rawName;
|
|
438
|
+
description;
|
|
439
|
+
config;
|
|
440
|
+
cli;
|
|
441
|
+
options;
|
|
442
|
+
aliasNames;
|
|
443
|
+
name;
|
|
444
|
+
args;
|
|
445
|
+
commandAction;
|
|
446
|
+
usageText;
|
|
447
|
+
versionNumber;
|
|
448
|
+
examples;
|
|
449
|
+
helpCallback;
|
|
450
|
+
globalCommand;
|
|
451
|
+
constructor(rawName, description, config, cli) {
|
|
248
452
|
this.rawName = rawName;
|
|
249
453
|
this.description = description;
|
|
250
454
|
this.config = config;
|
|
@@ -254,6 +458,9 @@ class Command {
|
|
|
254
458
|
this.name = removeBrackets(rawName);
|
|
255
459
|
this.args = findAllBrackets(rawName);
|
|
256
460
|
this.examples = [];
|
|
461
|
+
if (!config) {
|
|
462
|
+
this.config = {};
|
|
463
|
+
}
|
|
257
464
|
}
|
|
258
465
|
usage(text) {
|
|
259
466
|
this.usageText = text;
|
|
@@ -300,7 +507,7 @@ class Command {
|
|
|
300
507
|
}
|
|
301
508
|
hasOption(name) {
|
|
302
509
|
name = name.split(".")[0];
|
|
303
|
-
return this.options.find((option) => {
|
|
510
|
+
return !!this.options.find((option) => {
|
|
304
511
|
return option.names.includes(name);
|
|
305
512
|
});
|
|
306
513
|
}
|
|
@@ -376,13 +583,19 @@ ${section.body}` : section.body;
|
|
|
376
583
|
const { name } = this.cli;
|
|
377
584
|
const { versionNumber } = this.cli.globalCommand;
|
|
378
585
|
if (versionNumber) {
|
|
379
|
-
|
|
586
|
+
let platformInfo3;
|
|
587
|
+
if (Bun) {
|
|
588
|
+
platformInfo3 = platformInfo;
|
|
589
|
+
} else {
|
|
590
|
+
platformInfo3 = platformInfo2;
|
|
591
|
+
}
|
|
592
|
+
console.log(`${name}/${versionNumber} ${platformInfo3}`);
|
|
380
593
|
}
|
|
381
594
|
}
|
|
382
595
|
checkRequiredArgs() {
|
|
383
596
|
const minimalArgsCount = this.args.filter((arg) => arg.required).length;
|
|
384
597
|
if (this.cli.args.length < minimalArgsCount) {
|
|
385
|
-
throw new
|
|
598
|
+
throw new ClappError(`missing required args for command \`${this.rawName}\``);
|
|
386
599
|
}
|
|
387
600
|
}
|
|
388
601
|
checkUnknownOptions() {
|
|
@@ -390,7 +603,7 @@ ${section.body}` : section.body;
|
|
|
390
603
|
if (!this.config.allowUnknownOptions) {
|
|
391
604
|
for (const name of Object.keys(options)) {
|
|
392
605
|
if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) {
|
|
393
|
-
throw new
|
|
606
|
+
throw new ClappError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
|
|
394
607
|
}
|
|
395
608
|
}
|
|
396
609
|
}
|
|
@@ -403,7 +616,7 @@ ${section.body}` : section.body;
|
|
|
403
616
|
if (option.required) {
|
|
404
617
|
const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
|
|
405
618
|
if (value === true || value === false && !hasNegated) {
|
|
406
|
-
throw new
|
|
619
|
+
throw new ClappError(`option \`${option.rawName}\` value is missing`);
|
|
407
620
|
}
|
|
408
621
|
}
|
|
409
622
|
}
|
|
@@ -415,9 +628,19 @@ class GlobalCommand extends Command {
|
|
|
415
628
|
super("@@global@@", "", {}, cli);
|
|
416
629
|
}
|
|
417
630
|
}
|
|
418
|
-
var
|
|
631
|
+
var Command_default = Command;
|
|
419
632
|
|
|
420
|
-
class
|
|
633
|
+
class CLI extends EventEmitter {
|
|
634
|
+
name;
|
|
635
|
+
commands;
|
|
636
|
+
globalCommand;
|
|
637
|
+
matchedCommand;
|
|
638
|
+
matchedCommandName;
|
|
639
|
+
rawArgs;
|
|
640
|
+
args;
|
|
641
|
+
options;
|
|
642
|
+
showHelpOnExit;
|
|
643
|
+
showVersionOnExit;
|
|
421
644
|
constructor(name = "") {
|
|
422
645
|
super();
|
|
423
646
|
this.name = name;
|
|
@@ -433,7 +656,10 @@ class CAC extends EventEmitter {
|
|
|
433
656
|
return this;
|
|
434
657
|
}
|
|
435
658
|
command(rawName, description, config) {
|
|
436
|
-
|
|
659
|
+
if (!config) {
|
|
660
|
+
config = {};
|
|
661
|
+
}
|
|
662
|
+
const command = new Command_default(rawName, description || "", config, this);
|
|
437
663
|
command.globalCommand = this.globalCommand;
|
|
438
664
|
this.commands.push(command);
|
|
439
665
|
return command;
|
|
@@ -482,7 +708,7 @@ class CAC extends EventEmitter {
|
|
|
482
708
|
this.matchedCommand = undefined;
|
|
483
709
|
this.matchedCommandName = undefined;
|
|
484
710
|
}
|
|
485
|
-
parse(argv =
|
|
711
|
+
parse(argv = processArgs2, {
|
|
486
712
|
run = true
|
|
487
713
|
} = {}) {
|
|
488
714
|
this.rawArgs = argv;
|
|
@@ -495,9 +721,10 @@ class CAC extends EventEmitter {
|
|
|
495
721
|
const commandName = parsed.args[0];
|
|
496
722
|
if (command.isMatched(commandName)) {
|
|
497
723
|
shouldParse = false;
|
|
498
|
-
const parsedInfo =
|
|
724
|
+
const parsedInfo = {
|
|
725
|
+
...parsed,
|
|
499
726
|
args: parsed.args.slice(1)
|
|
500
|
-
}
|
|
727
|
+
};
|
|
501
728
|
this.setParsedInfo(parsedInfo, command, commandName);
|
|
502
729
|
this.emit(`command:${commandName}`, command);
|
|
503
730
|
}
|
|
@@ -547,18 +774,19 @@ class CAC extends EventEmitter {
|
|
|
547
774
|
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
|
548
775
|
argv = argv.slice(0, doubleDashesIndex);
|
|
549
776
|
}
|
|
550
|
-
let parsed =
|
|
777
|
+
let parsed = import_mri.default(argv, mriOptions);
|
|
551
778
|
parsed = Object.keys(parsed).reduce((res, name) => {
|
|
552
|
-
return
|
|
779
|
+
return {
|
|
780
|
+
...res,
|
|
553
781
|
[camelcaseOptionName(name)]: parsed[name]
|
|
554
|
-
}
|
|
782
|
+
};
|
|
555
783
|
}, { _: [] });
|
|
556
784
|
const args = parsed._;
|
|
557
785
|
const options = {
|
|
558
786
|
"--": argsAfterDoubleDashes
|
|
559
787
|
};
|
|
560
788
|
const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
|
|
561
|
-
|
|
789
|
+
const transforms = Object.create(null);
|
|
562
790
|
for (const cliOption of cliOptions) {
|
|
563
791
|
if (!ignoreDefault && cliOption.config.default !== undefined) {
|
|
564
792
|
for (const name of cliOption.names) {
|
|
@@ -568,8 +796,8 @@ class CAC extends EventEmitter {
|
|
|
568
796
|
if (Array.isArray(cliOption.config.type)) {
|
|
569
797
|
if (transforms[cliOption.name] === undefined) {
|
|
570
798
|
transforms[cliOption.name] = Object.create(null);
|
|
571
|
-
transforms[cliOption.name]
|
|
572
|
-
transforms[cliOption.name]
|
|
799
|
+
transforms[cliOption.name].shouldTransform = true;
|
|
800
|
+
transforms[cliOption.name].transformFunction = cliOption.config.type[0];
|
|
573
801
|
}
|
|
574
802
|
}
|
|
575
803
|
}
|
|
@@ -604,30 +832,2469 @@ class CAC extends EventEmitter {
|
|
|
604
832
|
return command.commandAction.apply(this, actionArgs);
|
|
605
833
|
}
|
|
606
834
|
}
|
|
607
|
-
|
|
608
|
-
var
|
|
835
|
+
var import_picocolors6 = __toESM2(require_picocolors(), 1);
|
|
836
|
+
var actions = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
837
|
+
var settings = {
|
|
838
|
+
actions: new Set(actions),
|
|
839
|
+
aliases: new Map([
|
|
840
|
+
["k", "up"],
|
|
841
|
+
["j", "down"],
|
|
842
|
+
["h", "left"],
|
|
843
|
+
["l", "right"],
|
|
844
|
+
["\x03", "cancel"],
|
|
845
|
+
["escape", "cancel"]
|
|
846
|
+
]),
|
|
847
|
+
messages: {
|
|
848
|
+
cancel: "Canceled",
|
|
849
|
+
error: "Something went wrong"
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
function isActionKey(key, action) {
|
|
853
|
+
if (typeof key === "string") {
|
|
854
|
+
return settings.aliases.get(key) === action;
|
|
855
|
+
}
|
|
856
|
+
for (const value of key) {
|
|
857
|
+
if (value === undefined)
|
|
858
|
+
continue;
|
|
859
|
+
if (isActionKey(value, action)) {
|
|
860
|
+
return true;
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
return false;
|
|
864
|
+
}
|
|
865
|
+
function diffLines(a, b) {
|
|
866
|
+
if (a === b)
|
|
867
|
+
return [];
|
|
868
|
+
const aLines = a.split(`
|
|
869
|
+
`);
|
|
870
|
+
const bLines = b.split(`
|
|
871
|
+
`);
|
|
872
|
+
const diff = [];
|
|
873
|
+
for (let i = 0;i < Math.max(aLines.length, bLines.length); i++) {
|
|
874
|
+
if (aLines[i] !== bLines[i])
|
|
875
|
+
diff.push(i);
|
|
876
|
+
}
|
|
877
|
+
return diff;
|
|
878
|
+
}
|
|
879
|
+
var isWindows = process5.platform.startsWith("win");
|
|
880
|
+
var CANCEL_SYMBOL = Symbol("clapp:cancel");
|
|
881
|
+
function setRawMode(input, value) {
|
|
882
|
+
const i = input;
|
|
883
|
+
if (i.isTTY)
|
|
884
|
+
i.setRawMode(value);
|
|
885
|
+
}
|
|
886
|
+
var import_picocolors = __toESM2(require_picocolors(), 1);
|
|
887
|
+
function ansiRegex({ onlyFirst = false } = {}) {
|
|
888
|
+
const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
|
|
889
|
+
const osc = `(?:\\u001B\\][\\s\\S]*?${ST})`;
|
|
890
|
+
const csi = "[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]";
|
|
891
|
+
const pattern = `${osc}|${csi}`;
|
|
892
|
+
return new RegExp(pattern, onlyFirst ? undefined : "g");
|
|
893
|
+
}
|
|
894
|
+
var regex = ansiRegex();
|
|
895
|
+
function stripAnsi(string2) {
|
|
896
|
+
if (typeof string2 !== "string") {
|
|
897
|
+
throw new TypeError(`Expected a \`string\`, got \`${typeof string2}\``);
|
|
898
|
+
}
|
|
899
|
+
return string2.replace(regex, "");
|
|
900
|
+
}
|
|
901
|
+
function isAmbiguous(x) {
|
|
902
|
+
return x === 161 || x === 164 || x === 167 || x === 168 || x === 170 || x === 173 || x === 174 || x >= 176 && x <= 180 || x >= 182 && x <= 186 || x >= 188 && x <= 191 || x === 198 || x === 208 || x === 215 || x === 216 || x >= 222 && x <= 225 || x === 230 || x >= 232 && x <= 234 || x === 236 || x === 237 || x === 240 || x === 242 || x === 243 || x >= 247 && x <= 250 || x === 252 || x === 254 || x === 257 || x === 273 || x === 275 || x === 283 || x === 294 || x === 295 || x === 299 || x >= 305 && x <= 307 || x === 312 || x >= 319 && x <= 322 || x === 324 || x >= 328 && x <= 331 || x === 333 || x === 338 || x === 339 || x === 358 || x === 359 || x === 363 || x === 462 || x === 464 || x === 466 || x === 468 || x === 470 || x === 472 || x === 474 || x === 476 || x === 593 || x === 609 || x === 708 || x === 711 || x >= 713 && x <= 715 || x === 717 || x === 720 || x >= 728 && x <= 731 || x === 733 || x === 735 || x >= 768 && x <= 879 || x >= 913 && x <= 929 || x >= 931 && x <= 937 || x >= 945 && x <= 961 || x >= 963 && x <= 969 || x === 1025 || x >= 1040 && x <= 1103 || x === 1105 || x === 8208 || x >= 8211 && x <= 8214 || x === 8216 || x === 8217 || x === 8220 || x === 8221 || x >= 8224 && x <= 8226 || x >= 8228 && x <= 8231 || x === 8240 || x === 8242 || x === 8243 || x === 8245 || x === 8251 || x === 8254 || x === 8308 || x === 8319 || x >= 8321 && x <= 8324 || x === 8364 || x === 8451 || x === 8453 || x === 8457 || x === 8467 || x === 8470 || x === 8481 || x === 8482 || x === 8486 || x === 8491 || x === 8531 || x === 8532 || x >= 8539 && x <= 8542 || x >= 8544 && x <= 8555 || x >= 8560 && x <= 8569 || x === 8585 || x >= 8592 && x <= 8601 || x === 8632 || x === 8633 || x === 8658 || x === 8660 || x === 8679 || x === 8704 || x === 8706 || x === 8707 || x === 8711 || x === 8712 || x === 8715 || x === 8719 || x === 8721 || x === 8725 || x === 8730 || x >= 8733 && x <= 8736 || x === 8739 || x === 8741 || x >= 8743 && x <= 8748 || x === 8750 || x >= 8756 && x <= 8759 || x === 8764 || x === 8765 || x === 8776 || x === 8780 || x === 8786 || x === 8800 || x === 8801 || x >= 8804 && x <= 8807 || x === 8810 || x === 8811 || x === 8814 || x === 8815 || x === 8834 || x === 8835 || x === 8838 || x === 8839 || x === 8853 || x === 8857 || x === 8869 || x === 8895 || x === 8978 || x >= 9312 && x <= 9449 || x >= 9451 && x <= 9547 || x >= 9552 && x <= 9587 || x >= 9600 && x <= 9615 || x >= 9618 && x <= 9621 || x === 9632 || x === 9633 || x >= 9635 && x <= 9641 || x === 9650 || x === 9651 || x === 9654 || x === 9655 || x === 9660 || x === 9661 || x === 9664 || x === 9665 || x >= 9670 && x <= 9672 || x === 9675 || x >= 9678 && x <= 9681 || x >= 9698 && x <= 9701 || x === 9711 || x === 9733 || x === 9734 || x === 9737 || x === 9742 || x === 9743 || x === 9756 || x === 9758 || x === 9792 || x === 9794 || x === 9824 || x === 9825 || x >= 9827 && x <= 9829 || x >= 9831 && x <= 9834 || x === 9836 || x === 9837 || x === 9839 || x === 9886 || x === 9887 || x === 9919 || x >= 9926 && x <= 9933 || x >= 9935 && x <= 9939 || x >= 9941 && x <= 9953 || x === 9955 || x === 9960 || x === 9961 || x >= 9963 && x <= 9969 || x === 9972 || x >= 9974 && x <= 9977 || x === 9979 || x === 9980 || x === 9982 || x === 9983 || x === 10045 || x >= 10102 && x <= 10111 || x >= 11094 && x <= 11097 || x >= 12872 && x <= 12879 || x >= 57344 && x <= 63743 || x >= 65024 && x <= 65039 || x === 65533 || x >= 127232 && x <= 127242 || x >= 127248 && x <= 127277 || x >= 127280 && x <= 127337 || x >= 127344 && x <= 127373 || x === 127375 || x === 127376 || x >= 127387 && x <= 127404 || x >= 917760 && x <= 917999 || x >= 983040 && x <= 1048573 || x >= 1048576 && x <= 1114109;
|
|
903
|
+
}
|
|
904
|
+
function isFullWidth(x) {
|
|
905
|
+
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
906
|
+
}
|
|
907
|
+
function isWide(x) {
|
|
908
|
+
return x >= 4352 && x <= 4447 || x === 8986 || x === 8987 || x === 9001 || x === 9002 || x >= 9193 && x <= 9196 || x === 9200 || x === 9203 || x === 9725 || x === 9726 || x === 9748 || x === 9749 || x >= 9776 && x <= 9783 || x >= 9800 && x <= 9811 || x === 9855 || x >= 9866 && x <= 9871 || x === 9875 || x === 9889 || x === 9898 || x === 9899 || x === 9917 || x === 9918 || x === 9924 || x === 9925 || x === 9934 || x === 9940 || x === 9962 || x === 9970 || x === 9971 || x === 9973 || x === 9978 || x === 9981 || x === 9989 || x === 9994 || x === 9995 || x === 10024 || x === 10060 || x === 10062 || x >= 10067 && x <= 10069 || x === 10071 || x >= 10133 && x <= 10135 || x === 10160 || x === 10175 || x === 11035 || x === 11036 || x === 11088 || x === 11093 || x >= 11904 && x <= 11929 || x >= 11931 && x <= 12019 || x >= 12032 && x <= 12245 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12353 && x <= 12438 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12773 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 42124 || x >= 42128 && x <= 42182 || x >= 43360 && x <= 43388 || x >= 44032 && x <= 55203 || x >= 63744 && x <= 64255 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 94176 && x <= 94180 || x === 94192 || x === 94193 || x >= 94208 && x <= 100343 || x >= 100352 && x <= 101589 || x >= 101631 && x <= 101640 || x >= 110576 && x <= 110579 || x >= 110581 && x <= 110587 || x === 110589 || x === 110590 || x >= 110592 && x <= 110882 || x === 110898 || x >= 110928 && x <= 110930 || x === 110933 || x >= 110948 && x <= 110951 || x >= 110960 && x <= 111355 || x >= 119552 && x <= 119638 || x >= 119648 && x <= 119670 || x === 126980 || x === 127183 || x === 127374 || x >= 127377 && x <= 127386 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x === 127568 || x === 127569 || x >= 127584 && x <= 127589 || x >= 127744 && x <= 127776 || x >= 127789 && x <= 127797 || x >= 127799 && x <= 127868 || x >= 127870 && x <= 127891 || x >= 127904 && x <= 127946 || x >= 127951 && x <= 127955 || x >= 127968 && x <= 127984 || x === 127988 || x >= 127992 && x <= 128062 || x === 128064 || x >= 128066 && x <= 128252 || x >= 128255 && x <= 128317 || x >= 128331 && x <= 128334 || x >= 128336 && x <= 128359 || x === 128378 || x === 128405 || x === 128406 || x === 128420 || x >= 128507 && x <= 128591 || x >= 128640 && x <= 128709 || x === 128716 || x >= 128720 && x <= 128722 || x >= 128725 && x <= 128727 || x >= 128732 && x <= 128735 || x === 128747 || x === 128748 || x >= 128756 && x <= 128764 || x >= 128992 && x <= 129003 || x === 129008 || x >= 129292 && x <= 129338 || x >= 129340 && x <= 129349 || x >= 129351 && x <= 129535 || x >= 129648 && x <= 129660 || x >= 129664 && x <= 129673 || x >= 129679 && x <= 129734 || x >= 129742 && x <= 129756 || x >= 129759 && x <= 129769 || x >= 129776 && x <= 129784 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
|
|
909
|
+
}
|
|
910
|
+
function validate(codePoint) {
|
|
911
|
+
if (!Number.isSafeInteger(codePoint)) {
|
|
912
|
+
throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
|
|
916
|
+
validate(codePoint);
|
|
917
|
+
if (isFullWidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) {
|
|
918
|
+
return 2;
|
|
919
|
+
}
|
|
920
|
+
return 1;
|
|
921
|
+
}
|
|
922
|
+
var import_emoji_regex = __toESM2(require_emoji_regex(), 1);
|
|
923
|
+
var segmenter = new Intl.Segmenter;
|
|
924
|
+
var defaultIgnorableCodePointRegex = /^\p{Default_Ignorable_Code_Point}$/u;
|
|
925
|
+
function stringWidth(string2, options = {}) {
|
|
926
|
+
if (typeof string2 !== "string" || string2.length === 0) {
|
|
927
|
+
return 0;
|
|
928
|
+
}
|
|
929
|
+
const {
|
|
930
|
+
ambiguousIsNarrow = true,
|
|
931
|
+
countAnsiEscapeCodes = false
|
|
932
|
+
} = options;
|
|
933
|
+
if (!countAnsiEscapeCodes) {
|
|
934
|
+
string2 = stripAnsi(string2);
|
|
935
|
+
}
|
|
936
|
+
if (string2.length === 0) {
|
|
937
|
+
return 0;
|
|
938
|
+
}
|
|
939
|
+
let width = 0;
|
|
940
|
+
const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
|
|
941
|
+
for (const { segment: character } of segmenter.segment(string2)) {
|
|
942
|
+
const codePoint = character.codePointAt(0);
|
|
943
|
+
if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159) {
|
|
944
|
+
continue;
|
|
945
|
+
}
|
|
946
|
+
if (codePoint >= 8203 && codePoint <= 8207 || codePoint === 65279) {
|
|
947
|
+
continue;
|
|
948
|
+
}
|
|
949
|
+
if (codePoint >= 768 && codePoint <= 879 || codePoint >= 6832 && codePoint <= 6911 || codePoint >= 7616 && codePoint <= 7679 || codePoint >= 8400 && codePoint <= 8447 || codePoint >= 65056 && codePoint <= 65071) {
|
|
950
|
+
continue;
|
|
951
|
+
}
|
|
952
|
+
if (codePoint >= 55296 && codePoint <= 57343) {
|
|
953
|
+
continue;
|
|
954
|
+
}
|
|
955
|
+
if (codePoint >= 65024 && codePoint <= 65039) {
|
|
956
|
+
continue;
|
|
957
|
+
}
|
|
958
|
+
if (defaultIgnorableCodePointRegex.test(character)) {
|
|
959
|
+
continue;
|
|
960
|
+
}
|
|
961
|
+
if (import_emoji_regex.default().test(character)) {
|
|
962
|
+
width += 2;
|
|
963
|
+
continue;
|
|
964
|
+
}
|
|
965
|
+
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
966
|
+
}
|
|
967
|
+
return width;
|
|
968
|
+
}
|
|
969
|
+
var ANSI_BACKGROUND_OFFSET = 10;
|
|
970
|
+
var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
|
971
|
+
var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
|
|
972
|
+
var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
|
|
973
|
+
var styles = {
|
|
974
|
+
modifier: {
|
|
975
|
+
reset: [0, 0],
|
|
976
|
+
bold: [1, 22],
|
|
977
|
+
dim: [2, 22],
|
|
978
|
+
italic: [3, 23],
|
|
979
|
+
underline: [4, 24],
|
|
980
|
+
overline: [53, 55],
|
|
981
|
+
inverse: [7, 27],
|
|
982
|
+
hidden: [8, 28],
|
|
983
|
+
strikethrough: [9, 29]
|
|
984
|
+
},
|
|
985
|
+
color: {
|
|
986
|
+
black: [30, 39],
|
|
987
|
+
red: [31, 39],
|
|
988
|
+
green: [32, 39],
|
|
989
|
+
yellow: [33, 39],
|
|
990
|
+
blue: [34, 39],
|
|
991
|
+
magenta: [35, 39],
|
|
992
|
+
cyan: [36, 39],
|
|
993
|
+
white: [37, 39],
|
|
994
|
+
blackBright: [90, 39],
|
|
995
|
+
gray: [90, 39],
|
|
996
|
+
grey: [90, 39],
|
|
997
|
+
redBright: [91, 39],
|
|
998
|
+
greenBright: [92, 39],
|
|
999
|
+
yellowBright: [93, 39],
|
|
1000
|
+
blueBright: [94, 39],
|
|
1001
|
+
magentaBright: [95, 39],
|
|
1002
|
+
cyanBright: [96, 39],
|
|
1003
|
+
whiteBright: [97, 39]
|
|
1004
|
+
},
|
|
1005
|
+
bgColor: {
|
|
1006
|
+
bgBlack: [40, 49],
|
|
1007
|
+
bgRed: [41, 49],
|
|
1008
|
+
bgGreen: [42, 49],
|
|
1009
|
+
bgYellow: [43, 49],
|
|
1010
|
+
bgBlue: [44, 49],
|
|
1011
|
+
bgMagenta: [45, 49],
|
|
1012
|
+
bgCyan: [46, 49],
|
|
1013
|
+
bgWhite: [47, 49],
|
|
1014
|
+
bgBlackBright: [100, 49],
|
|
1015
|
+
bgGray: [100, 49],
|
|
1016
|
+
bgGrey: [100, 49],
|
|
1017
|
+
bgRedBright: [101, 49],
|
|
1018
|
+
bgGreenBright: [102, 49],
|
|
1019
|
+
bgYellowBright: [103, 49],
|
|
1020
|
+
bgBlueBright: [104, 49],
|
|
1021
|
+
bgMagentaBright: [105, 49],
|
|
1022
|
+
bgCyanBright: [106, 49],
|
|
1023
|
+
bgWhiteBright: [107, 49]
|
|
1024
|
+
}
|
|
1025
|
+
};
|
|
1026
|
+
var modifierNames = Object.keys(styles.modifier);
|
|
1027
|
+
var foregroundColorNames = Object.keys(styles.color);
|
|
1028
|
+
var backgroundColorNames = Object.keys(styles.bgColor);
|
|
1029
|
+
var colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
|
1030
|
+
function assembleStyles() {
|
|
1031
|
+
const codes = new Map;
|
|
1032
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
|
1033
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
1034
|
+
styles[styleName] = {
|
|
1035
|
+
open: `\x1B[${style[0]}m`,
|
|
1036
|
+
close: `\x1B[${style[1]}m`
|
|
1037
|
+
};
|
|
1038
|
+
group[styleName] = styles[styleName];
|
|
1039
|
+
codes.set(style[0], style[1]);
|
|
1040
|
+
}
|
|
1041
|
+
Object.defineProperty(styles, groupName, {
|
|
1042
|
+
value: group,
|
|
1043
|
+
enumerable: false
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
Object.defineProperty(styles, "codes", {
|
|
1047
|
+
value: codes,
|
|
1048
|
+
enumerable: false
|
|
1049
|
+
});
|
|
1050
|
+
styles.color.close = "\x1B[39m";
|
|
1051
|
+
styles.bgColor.close = "\x1B[49m";
|
|
1052
|
+
styles.color.ansi = wrapAnsi16();
|
|
1053
|
+
styles.color.ansi256 = wrapAnsi256();
|
|
1054
|
+
styles.color.ansi16m = wrapAnsi16m();
|
|
1055
|
+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
1056
|
+
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
1057
|
+
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
1058
|
+
Object.defineProperties(styles, {
|
|
1059
|
+
rgbToAnsi256: {
|
|
1060
|
+
value: (red, green, blue) => {
|
|
1061
|
+
if (red === green && green === blue) {
|
|
1062
|
+
if (red < 8) {
|
|
1063
|
+
return 16;
|
|
1064
|
+
}
|
|
1065
|
+
if (red > 248) {
|
|
1066
|
+
return 231;
|
|
1067
|
+
}
|
|
1068
|
+
return Math.round((red - 8) / 247 * 24) + 232;
|
|
1069
|
+
}
|
|
1070
|
+
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
|
|
1071
|
+
},
|
|
1072
|
+
enumerable: false
|
|
1073
|
+
},
|
|
1074
|
+
hexToRgb: {
|
|
1075
|
+
value: (hex) => {
|
|
1076
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
1077
|
+
if (!matches) {
|
|
1078
|
+
return [0, 0, 0];
|
|
1079
|
+
}
|
|
1080
|
+
let [colorString] = matches;
|
|
1081
|
+
if (colorString.length === 3) {
|
|
1082
|
+
colorString = [...colorString].map((character) => character + character).join("");
|
|
1083
|
+
}
|
|
1084
|
+
const integer = Number.parseInt(colorString, 16);
|
|
1085
|
+
return [
|
|
1086
|
+
integer >> 16 & 255,
|
|
1087
|
+
integer >> 8 & 255,
|
|
1088
|
+
integer & 255
|
|
1089
|
+
];
|
|
1090
|
+
},
|
|
1091
|
+
enumerable: false
|
|
1092
|
+
},
|
|
1093
|
+
hexToAnsi256: {
|
|
1094
|
+
value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
1095
|
+
enumerable: false
|
|
1096
|
+
},
|
|
1097
|
+
ansi256ToAnsi: {
|
|
1098
|
+
value: (code) => {
|
|
1099
|
+
if (code < 8) {
|
|
1100
|
+
return 30 + code;
|
|
1101
|
+
}
|
|
1102
|
+
if (code < 16) {
|
|
1103
|
+
return 90 + (code - 8);
|
|
1104
|
+
}
|
|
1105
|
+
let red;
|
|
1106
|
+
let green;
|
|
1107
|
+
let blue;
|
|
1108
|
+
if (code >= 232) {
|
|
1109
|
+
red = ((code - 232) * 10 + 8) / 255;
|
|
1110
|
+
green = red;
|
|
1111
|
+
blue = red;
|
|
1112
|
+
} else {
|
|
1113
|
+
code -= 16;
|
|
1114
|
+
const remainder = code % 36;
|
|
1115
|
+
red = Math.floor(code / 36) / 5;
|
|
1116
|
+
green = Math.floor(remainder / 6) / 5;
|
|
1117
|
+
blue = remainder % 6 / 5;
|
|
1118
|
+
}
|
|
1119
|
+
const value = Math.max(red, green, blue) * 2;
|
|
1120
|
+
if (value === 0) {
|
|
1121
|
+
return 30;
|
|
1122
|
+
}
|
|
1123
|
+
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
|
|
1124
|
+
if (value === 2) {
|
|
1125
|
+
result += 60;
|
|
1126
|
+
}
|
|
1127
|
+
return result;
|
|
1128
|
+
},
|
|
1129
|
+
enumerable: false
|
|
1130
|
+
},
|
|
1131
|
+
rgbToAnsi: {
|
|
1132
|
+
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
1133
|
+
enumerable: false
|
|
1134
|
+
},
|
|
1135
|
+
hexToAnsi: {
|
|
1136
|
+
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
1137
|
+
enumerable: false
|
|
1138
|
+
}
|
|
1139
|
+
});
|
|
1140
|
+
return styles;
|
|
1141
|
+
}
|
|
1142
|
+
var ansiStyles = assembleStyles();
|
|
1143
|
+
var ansi_styles_default = ansiStyles;
|
|
1144
|
+
var ESCAPES = new Set([
|
|
1145
|
+
"\x1B",
|
|
1146
|
+
"\x9B"
|
|
1147
|
+
]);
|
|
1148
|
+
var END_CODE = 39;
|
|
1149
|
+
var ANSI_ESCAPE_BELL = "\x07";
|
|
1150
|
+
var ANSI_CSI = "[";
|
|
1151
|
+
var ANSI_OSC = "]";
|
|
1152
|
+
var ANSI_SGR_TERMINATOR = "m";
|
|
1153
|
+
var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
1154
|
+
var wrapAnsiCode = (code) => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
1155
|
+
var wrapAnsiHyperlink = (url) => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
|
|
1156
|
+
var wordLengths = (string2) => string2.split(" ").map((character) => stringWidth(character));
|
|
1157
|
+
var wrapWord = (rows, word, columns) => {
|
|
1158
|
+
const characters = [...word];
|
|
1159
|
+
let isInsideEscape = false;
|
|
1160
|
+
let isInsideLinkEscape = false;
|
|
1161
|
+
let visible = stringWidth(stripAnsi(rows.at(-1)));
|
|
1162
|
+
for (const [index, character] of characters.entries()) {
|
|
1163
|
+
const characterLength = stringWidth(character);
|
|
1164
|
+
if (visible + characterLength <= columns) {
|
|
1165
|
+
rows[rows.length - 1] += character;
|
|
1166
|
+
} else {
|
|
1167
|
+
rows.push(character);
|
|
1168
|
+
visible = 0;
|
|
1169
|
+
}
|
|
1170
|
+
if (ESCAPES.has(character)) {
|
|
1171
|
+
isInsideEscape = true;
|
|
1172
|
+
const ansiEscapeLinkCandidate = characters.slice(index + 1, index + 1 + ANSI_ESCAPE_LINK.length).join("");
|
|
1173
|
+
isInsideLinkEscape = ansiEscapeLinkCandidate === ANSI_ESCAPE_LINK;
|
|
1174
|
+
}
|
|
1175
|
+
if (isInsideEscape) {
|
|
1176
|
+
if (isInsideLinkEscape) {
|
|
1177
|
+
if (character === ANSI_ESCAPE_BELL) {
|
|
1178
|
+
isInsideEscape = false;
|
|
1179
|
+
isInsideLinkEscape = false;
|
|
1180
|
+
}
|
|
1181
|
+
} else if (character === ANSI_SGR_TERMINATOR) {
|
|
1182
|
+
isInsideEscape = false;
|
|
1183
|
+
}
|
|
1184
|
+
continue;
|
|
1185
|
+
}
|
|
1186
|
+
visible += characterLength;
|
|
1187
|
+
if (visible === columns && index < characters.length - 1) {
|
|
1188
|
+
rows.push("");
|
|
1189
|
+
visible = 0;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
if (!visible && rows.at(-1).length > 0 && rows.length > 1) {
|
|
1193
|
+
rows[rows.length - 2] += rows.pop();
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
var stringVisibleTrimSpacesRight = (string2) => {
|
|
1197
|
+
const words = string2.split(" ");
|
|
1198
|
+
let last = words.length;
|
|
1199
|
+
while (last > 0) {
|
|
1200
|
+
if (stringWidth(words[last - 1]) > 0) {
|
|
1201
|
+
break;
|
|
1202
|
+
}
|
|
1203
|
+
last--;
|
|
1204
|
+
}
|
|
1205
|
+
if (last === words.length) {
|
|
1206
|
+
return string2;
|
|
1207
|
+
}
|
|
1208
|
+
return words.slice(0, last).join(" ") + words.slice(last).join("");
|
|
1209
|
+
};
|
|
1210
|
+
var exec = (string2, columns, options = {}) => {
|
|
1211
|
+
if (options.trim !== false && string2.trim() === "") {
|
|
1212
|
+
return "";
|
|
1213
|
+
}
|
|
1214
|
+
let returnValue = "";
|
|
1215
|
+
let escapeCode;
|
|
1216
|
+
let escapeUrl;
|
|
1217
|
+
const lengths = wordLengths(string2);
|
|
1218
|
+
let rows = [""];
|
|
1219
|
+
for (const [index, word] of string2.split(" ").entries()) {
|
|
1220
|
+
if (options.trim !== false) {
|
|
1221
|
+
rows[rows.length - 1] = rows.at(-1).trimStart();
|
|
1222
|
+
}
|
|
1223
|
+
let rowLength = stringWidth(rows.at(-1));
|
|
1224
|
+
if (index !== 0) {
|
|
1225
|
+
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
1226
|
+
rows.push("");
|
|
1227
|
+
rowLength = 0;
|
|
1228
|
+
}
|
|
1229
|
+
if (rowLength > 0 || options.trim === false) {
|
|
1230
|
+
rows[rows.length - 1] += " ";
|
|
1231
|
+
rowLength++;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
if (options.hard && lengths[index] > columns) {
|
|
1235
|
+
const remainingColumns = columns - rowLength;
|
|
1236
|
+
const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns);
|
|
1237
|
+
const breaksStartingNextLine = Math.floor((lengths[index] - 1) / columns);
|
|
1238
|
+
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
1239
|
+
rows.push("");
|
|
1240
|
+
}
|
|
1241
|
+
wrapWord(rows, word, columns);
|
|
1242
|
+
continue;
|
|
1243
|
+
}
|
|
1244
|
+
if (rowLength + lengths[index] > columns && rowLength > 0 && lengths[index] > 0) {
|
|
1245
|
+
if (options.wordWrap === false && rowLength < columns) {
|
|
1246
|
+
wrapWord(rows, word, columns);
|
|
1247
|
+
continue;
|
|
1248
|
+
}
|
|
1249
|
+
rows.push("");
|
|
1250
|
+
}
|
|
1251
|
+
if (rowLength + lengths[index] > columns && options.wordWrap === false) {
|
|
1252
|
+
wrapWord(rows, word, columns);
|
|
1253
|
+
continue;
|
|
1254
|
+
}
|
|
1255
|
+
rows[rows.length - 1] += word;
|
|
1256
|
+
}
|
|
1257
|
+
if (options.trim !== false) {
|
|
1258
|
+
rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
1259
|
+
}
|
|
1260
|
+
const preString = rows.join(`
|
|
1261
|
+
`);
|
|
1262
|
+
const pre = [...preString];
|
|
1263
|
+
let preStringIndex = 0;
|
|
1264
|
+
for (const [index, character] of pre.entries()) {
|
|
1265
|
+
returnValue += character;
|
|
1266
|
+
if (ESCAPES.has(character)) {
|
|
1267
|
+
const { groups } = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`).exec(preString.slice(preStringIndex)) || { groups: {} };
|
|
1268
|
+
if (groups.code !== undefined) {
|
|
1269
|
+
const code2 = Number.parseFloat(groups.code);
|
|
1270
|
+
escapeCode = code2 === END_CODE ? undefined : code2;
|
|
1271
|
+
} else if (groups.uri !== undefined) {
|
|
1272
|
+
escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
const code = ansi_styles_default.codes.get(Number(escapeCode));
|
|
1276
|
+
if (pre[index + 1] === `
|
|
1277
|
+
`) {
|
|
1278
|
+
if (escapeUrl) {
|
|
1279
|
+
returnValue += wrapAnsiHyperlink("");
|
|
1280
|
+
}
|
|
1281
|
+
if (escapeCode && code) {
|
|
1282
|
+
returnValue += wrapAnsiCode(code);
|
|
1283
|
+
}
|
|
1284
|
+
} else if (character === `
|
|
1285
|
+
`) {
|
|
1286
|
+
if (escapeCode && code) {
|
|
1287
|
+
returnValue += wrapAnsiCode(escapeCode);
|
|
1288
|
+
}
|
|
1289
|
+
if (escapeUrl) {
|
|
1290
|
+
returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
preStringIndex += character.length;
|
|
1294
|
+
}
|
|
1295
|
+
return returnValue;
|
|
1296
|
+
};
|
|
1297
|
+
function wrapAnsi(string2, columns, options) {
|
|
1298
|
+
return String(string2).normalize().replaceAll(`\r
|
|
1299
|
+
`, `
|
|
1300
|
+
`).split(`
|
|
1301
|
+
`).map((line) => exec(line, columns, options)).join(`
|
|
1302
|
+
`);
|
|
1303
|
+
}
|
|
609
1304
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
1305
|
+
class Prompt {
|
|
1306
|
+
input;
|
|
1307
|
+
output;
|
|
1308
|
+
_abortSignal;
|
|
1309
|
+
rl;
|
|
1310
|
+
opts;
|
|
1311
|
+
_render;
|
|
1312
|
+
_track = false;
|
|
1313
|
+
_prevFrame = "";
|
|
1314
|
+
_subscribers = new Map;
|
|
1315
|
+
_cursor = 0;
|
|
1316
|
+
_manualLine = "";
|
|
1317
|
+
state = "initial";
|
|
1318
|
+
error = "";
|
|
1319
|
+
value;
|
|
1320
|
+
userInput = "";
|
|
1321
|
+
constructor(options, trackValue = true) {
|
|
1322
|
+
const { input = stdin2, output = stdout2, render, signal, ...opts } = options;
|
|
1323
|
+
this.opts = opts;
|
|
1324
|
+
this.onKeypress = this.onKeypress.bind(this);
|
|
1325
|
+
this.close = this.close.bind(this);
|
|
1326
|
+
this.render = this.render.bind(this);
|
|
1327
|
+
this._render = render.bind(this);
|
|
1328
|
+
this._track = trackValue;
|
|
1329
|
+
this._abortSignal = signal;
|
|
1330
|
+
this.input = input;
|
|
1331
|
+
this.output = output;
|
|
1332
|
+
}
|
|
1333
|
+
unsubscribe() {
|
|
1334
|
+
this._subscribers.clear();
|
|
1335
|
+
}
|
|
1336
|
+
setSubscriber(event, opts) {
|
|
1337
|
+
const params = this._subscribers.get(event) ?? [];
|
|
1338
|
+
params.push(opts);
|
|
1339
|
+
this._subscribers.set(event, params);
|
|
1340
|
+
}
|
|
1341
|
+
on(event, cb) {
|
|
1342
|
+
this.setSubscriber(event, { cb });
|
|
1343
|
+
return this;
|
|
1344
|
+
}
|
|
1345
|
+
once(event, cb) {
|
|
1346
|
+
this.setSubscriber(event, { cb, once: true });
|
|
1347
|
+
return this;
|
|
1348
|
+
}
|
|
1349
|
+
emit(event, ...data) {
|
|
1350
|
+
const cbs = this._subscribers.get(event) ?? [];
|
|
1351
|
+
const cleanup = [];
|
|
1352
|
+
for (const subscriber of cbs) {
|
|
1353
|
+
subscriber.cb(...data);
|
|
1354
|
+
if (subscriber.once) {
|
|
1355
|
+
cleanup.push(() => cbs.splice(cbs.indexOf(subscriber), 1));
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
for (const cb of cleanup) {
|
|
1359
|
+
cb();
|
|
1360
|
+
}
|
|
1361
|
+
return this;
|
|
1362
|
+
}
|
|
1363
|
+
prompt() {
|
|
1364
|
+
return new Promise((resolve) => {
|
|
1365
|
+
if (this._abortSignal) {
|
|
1366
|
+
if (this._abortSignal.aborted) {
|
|
1367
|
+
this.state = "cancel";
|
|
1368
|
+
this.close();
|
|
1369
|
+
return resolve(CANCEL_SYMBOL);
|
|
1370
|
+
}
|
|
1371
|
+
this._abortSignal.addEventListener("abort", () => {
|
|
1372
|
+
this.state = "cancel";
|
|
1373
|
+
this.close();
|
|
1374
|
+
}, { once: true });
|
|
1375
|
+
}
|
|
1376
|
+
this.rl = readline2.createInterface({
|
|
1377
|
+
input: this.input,
|
|
1378
|
+
tabSize: 2,
|
|
1379
|
+
prompt: "",
|
|
1380
|
+
escapeCodeTimeout: 50,
|
|
1381
|
+
terminal: true
|
|
1382
|
+
});
|
|
1383
|
+
this.rl.prompt();
|
|
1384
|
+
if (this.opts.initialUserInput !== undefined) {
|
|
1385
|
+
this._setUserInput(this.opts.initialUserInput, true);
|
|
1386
|
+
}
|
|
1387
|
+
this.input.on("keypress", this.onKeypress);
|
|
1388
|
+
setRawMode(this.input, true);
|
|
1389
|
+
this.output.on("resize", this.render);
|
|
1390
|
+
this.render();
|
|
1391
|
+
this.once("submit", () => {
|
|
1392
|
+
this.output.write(cursor.show);
|
|
1393
|
+
this.output.off("resize", this.render);
|
|
1394
|
+
setRawMode(this.input, false);
|
|
1395
|
+
resolve(this.value);
|
|
1396
|
+
});
|
|
1397
|
+
this.once("cancel", () => {
|
|
1398
|
+
this.output.write(cursor.show);
|
|
1399
|
+
this.output.off("resize", this.render);
|
|
1400
|
+
setRawMode(this.input, false);
|
|
1401
|
+
resolve(CANCEL_SYMBOL);
|
|
1402
|
+
});
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
_isActionKey(char, _key) {
|
|
1406
|
+
return char === "\t";
|
|
1407
|
+
}
|
|
1408
|
+
_setValue(value) {
|
|
1409
|
+
this.value = value;
|
|
1410
|
+
this.emit("value", this.value);
|
|
1411
|
+
}
|
|
1412
|
+
_setUserInput(value, write) {
|
|
1413
|
+
this.userInput = value ?? "";
|
|
1414
|
+
this.emit("userInput", this.userInput);
|
|
1415
|
+
if (write && this._track && this.rl) {
|
|
1416
|
+
this.rl.write(this.userInput);
|
|
1417
|
+
this._cursor = this.rl.cursor;
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
onKeypress(char, key) {
|
|
1421
|
+
if (this._track && key.name !== "return") {
|
|
1422
|
+
if (key.name && this._isActionKey(char, key)) {
|
|
1423
|
+
this.rl?.write(null, { ctrl: true, name: "h" });
|
|
1424
|
+
}
|
|
1425
|
+
this._cursor = this.rl?.cursor ?? 0;
|
|
1426
|
+
const isSpecialKey = key.name === "tab" || key.name === "escape" || key.name === "backspace" || key.name === "delete" || key.name === "enter" || key.name === "return" || key.name && ["up", "down", "left", "right"].includes(key.name);
|
|
1427
|
+
if (char && !isSpecialKey && char.length === 1 && char >= " ") {
|
|
1428
|
+
this._manualLine += char;
|
|
1429
|
+
} else if (key.name === "backspace" && this._manualLine.length > 0) {
|
|
1430
|
+
this._manualLine = this._manualLine.slice(0, -1);
|
|
1431
|
+
}
|
|
1432
|
+
const effectiveLine = this._manualLine.length >= (this.rl?.line?.length || 0) ? this._manualLine : this.rl?.line;
|
|
1433
|
+
this._setUserInput(effectiveLine);
|
|
1434
|
+
}
|
|
1435
|
+
if (this.state === "error") {
|
|
1436
|
+
this.state = "active";
|
|
1437
|
+
this.error = "";
|
|
1438
|
+
}
|
|
1439
|
+
if (key?.name) {
|
|
1440
|
+
if (!this._track && settings.aliases.has(key.name)) {
|
|
1441
|
+
this.emit("cursor", settings.aliases.get(key.name));
|
|
1442
|
+
}
|
|
1443
|
+
if (settings.actions.has(key.name)) {
|
|
1444
|
+
this.emit("cursor", key.name);
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
if (char && (char.toLowerCase() === "y" || char.toLowerCase() === "n")) {
|
|
1448
|
+
this.emit("confirm", char.toLowerCase() === "y");
|
|
1449
|
+
}
|
|
1450
|
+
this.emit("key", char?.toLowerCase(), key);
|
|
1451
|
+
if (key?.name === "return") {
|
|
1452
|
+
if (this.opts.validate) {
|
|
1453
|
+
const problem = this.opts.validate(this.value);
|
|
1454
|
+
if (problem) {
|
|
1455
|
+
this.error = problem instanceof Error ? problem.message : problem;
|
|
1456
|
+
this.state = "error";
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
if (this.state !== "error") {
|
|
1460
|
+
this.state = "submit";
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
if (isActionKey([char, key?.name, key?.sequence], "cancel")) {
|
|
1464
|
+
this.state = "cancel";
|
|
1465
|
+
}
|
|
1466
|
+
if (this.state === "submit" || this.state === "cancel") {
|
|
1467
|
+
this.emit("finalize");
|
|
1468
|
+
}
|
|
1469
|
+
this.render();
|
|
1470
|
+
if (this.state === "submit" || this.state === "cancel") {
|
|
1471
|
+
this.close();
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
close() {
|
|
1475
|
+
this.input.unpipe();
|
|
1476
|
+
this.input.removeListener("keypress", this.onKeypress);
|
|
1477
|
+
this.output.write(`
|
|
1478
|
+
`);
|
|
1479
|
+
setRawMode(this.input, false);
|
|
1480
|
+
this.rl?.close();
|
|
1481
|
+
this.rl = undefined;
|
|
1482
|
+
this.emit(`${this.state}`, this.value);
|
|
1483
|
+
if (this.state === "cancel") {
|
|
1484
|
+
setTimeout(() => {
|
|
1485
|
+
this.unsubscribe();
|
|
1486
|
+
}, 10);
|
|
619
1487
|
} else {
|
|
620
|
-
|
|
621
|
-
process.exit(1);
|
|
1488
|
+
this.unsubscribe();
|
|
622
1489
|
}
|
|
623
|
-
} catch (error) {
|
|
624
|
-
console.error("Error generating documentation:", error);
|
|
625
|
-
process.exit(1);
|
|
626
1490
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
1491
|
+
restoreCursor() {
|
|
1492
|
+
const lines = wrapAnsi(this._prevFrame, process6.stdout.columns, { hard: true, trim: false }).split(`
|
|
1493
|
+
`).length - 1;
|
|
1494
|
+
this.output.write(cursor.move(-999, lines * -1));
|
|
1495
|
+
}
|
|
1496
|
+
render() {
|
|
1497
|
+
const frame = wrapAnsi(this._render(this) ?? "", process6.stdout.columns, {
|
|
1498
|
+
hard: true,
|
|
1499
|
+
trim: false
|
|
1500
|
+
});
|
|
1501
|
+
if (frame === this._prevFrame) {
|
|
1502
|
+
return;
|
|
1503
|
+
}
|
|
1504
|
+
if (this.state === "initial") {
|
|
1505
|
+
this.output.write(cursor.hide);
|
|
1506
|
+
} else {
|
|
1507
|
+
const diff = diffLines(this._prevFrame, frame);
|
|
1508
|
+
this.restoreCursor();
|
|
1509
|
+
if (diff && diff?.length === 1) {
|
|
1510
|
+
const diffLine = diff[0];
|
|
1511
|
+
this.output.write(cursor.move(0, diffLine));
|
|
1512
|
+
this.output.write(erase.lines(1));
|
|
1513
|
+
const lines = frame.split(`
|
|
1514
|
+
`);
|
|
1515
|
+
this.output.write(lines[diffLine]);
|
|
1516
|
+
this._prevFrame = frame;
|
|
1517
|
+
this.output.write(cursor.move(0, lines.length - diffLine - 1));
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
1520
|
+
if (diff && diff?.length > 1) {
|
|
1521
|
+
const diffLine = diff[0];
|
|
1522
|
+
this.output.write(cursor.move(0, diffLine));
|
|
1523
|
+
this.output.write(erase.down());
|
|
1524
|
+
const lines = frame.split(`
|
|
1525
|
+
`);
|
|
1526
|
+
const newLines = lines.slice(diffLine);
|
|
1527
|
+
this.output.write(newLines.join(`
|
|
1528
|
+
`));
|
|
1529
|
+
this._prevFrame = frame;
|
|
1530
|
+
return;
|
|
1531
|
+
}
|
|
1532
|
+
this.output.write(erase.down());
|
|
1533
|
+
}
|
|
1534
|
+
this.output.write(frame);
|
|
1535
|
+
if (this.state === "initial") {
|
|
1536
|
+
this.state = "active";
|
|
1537
|
+
}
|
|
1538
|
+
this._prevFrame = frame;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
function getCursorForValue(selected, items) {
|
|
1542
|
+
if (selected === undefined) {
|
|
1543
|
+
return 0;
|
|
1544
|
+
}
|
|
1545
|
+
const currLength = items.length;
|
|
1546
|
+
if (currLength === 0) {
|
|
1547
|
+
return 0;
|
|
1548
|
+
}
|
|
1549
|
+
const index = items.findIndex((item) => item.value === selected);
|
|
1550
|
+
return index !== -1 ? index : 0;
|
|
1551
|
+
}
|
|
1552
|
+
function defaultFilter(input, option) {
|
|
1553
|
+
const label = option.label ?? String(option.value);
|
|
1554
|
+
return label.toLowerCase().includes(input.toLowerCase());
|
|
1555
|
+
}
|
|
1556
|
+
function normalisedValue(multiple, values) {
|
|
1557
|
+
if (!values) {
|
|
1558
|
+
return;
|
|
1559
|
+
}
|
|
1560
|
+
if (multiple) {
|
|
1561
|
+
return values;
|
|
1562
|
+
}
|
|
1563
|
+
return values[0];
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
class AutocompletePrompt extends Prompt {
|
|
1567
|
+
filteredOptions;
|
|
1568
|
+
multiple;
|
|
1569
|
+
isNavigating = false;
|
|
1570
|
+
selectedValues = [];
|
|
1571
|
+
focusedValue;
|
|
1572
|
+
#cursor = 0;
|
|
1573
|
+
#lastUserInput = "";
|
|
1574
|
+
#filterFn;
|
|
1575
|
+
#options;
|
|
1576
|
+
get cursor() {
|
|
1577
|
+
return this.#cursor;
|
|
1578
|
+
}
|
|
1579
|
+
get userInputWithCursor() {
|
|
1580
|
+
if (!this.userInput) {
|
|
1581
|
+
return import_picocolors.default.inverse(import_picocolors.default.hidden("_"));
|
|
1582
|
+
}
|
|
1583
|
+
if (this._cursor >= this.userInput.length) {
|
|
1584
|
+
return `${this.userInput}\u2588`;
|
|
1585
|
+
}
|
|
1586
|
+
const s1 = this.userInput.slice(0, this._cursor);
|
|
1587
|
+
const [s2, ...s3] = this.userInput.slice(this._cursor);
|
|
1588
|
+
return `${s1}${import_picocolors.default.inverse(s2)}${s3.join("")}`;
|
|
1589
|
+
}
|
|
1590
|
+
get options() {
|
|
1591
|
+
if (typeof this.#options === "function") {
|
|
1592
|
+
return this.#options();
|
|
1593
|
+
}
|
|
1594
|
+
return this.#options;
|
|
1595
|
+
}
|
|
1596
|
+
constructor(opts) {
|
|
1597
|
+
super(opts);
|
|
1598
|
+
this.#options = opts.options;
|
|
1599
|
+
const options = this.options;
|
|
1600
|
+
this.filteredOptions = [...options];
|
|
1601
|
+
this.multiple = opts.multiple === true;
|
|
1602
|
+
this.#filterFn = opts.filter ?? defaultFilter;
|
|
1603
|
+
let initialValues;
|
|
1604
|
+
if (opts.initialValue && Array.isArray(opts.initialValue)) {
|
|
1605
|
+
if (this.multiple) {
|
|
1606
|
+
initialValues = opts.initialValue;
|
|
1607
|
+
} else {
|
|
1608
|
+
initialValues = opts.initialValue.slice(0, 1);
|
|
1609
|
+
}
|
|
1610
|
+
} else {
|
|
1611
|
+
if (!this.multiple && this.options.length > 0) {
|
|
1612
|
+
initialValues = [this.options[0].value];
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
if (initialValues) {
|
|
1616
|
+
for (const selectedValue of initialValues) {
|
|
1617
|
+
const selectedIndex = options.findIndex((opt) => opt.value === selectedValue);
|
|
1618
|
+
if (selectedIndex !== -1) {
|
|
1619
|
+
this.toggleSelected(selectedValue);
|
|
1620
|
+
this.#cursor = selectedIndex;
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
this.focusedValue = this.options[this.#cursor]?.value;
|
|
1625
|
+
this.on("key", (char, key) => this.#onKey(char, key));
|
|
1626
|
+
this.on("userInput", (value) => this.#onUserInputChanged(value));
|
|
1627
|
+
}
|
|
1628
|
+
_isActionKey(char, key) {
|
|
1629
|
+
return char === "\t" || this.multiple && this.isNavigating && key.name === "space" && char !== undefined && char !== "";
|
|
1630
|
+
}
|
|
1631
|
+
#onKey(_char, key) {
|
|
1632
|
+
const isUpKey = key.name === "up";
|
|
1633
|
+
const isDownKey = key.name === "down";
|
|
1634
|
+
const isReturnKey = key.name === "return";
|
|
1635
|
+
if (isUpKey || isDownKey) {
|
|
1636
|
+
this.#cursor = Math.max(0, Math.min(this.#cursor + (isUpKey ? -1 : 1), this.filteredOptions.length - 1));
|
|
1637
|
+
this.focusedValue = this.filteredOptions[this.#cursor]?.value;
|
|
1638
|
+
if (!this.multiple) {
|
|
1639
|
+
this.selectedValues = [this.focusedValue];
|
|
1640
|
+
}
|
|
1641
|
+
this.isNavigating = true;
|
|
1642
|
+
} else if (isReturnKey) {
|
|
1643
|
+
this.value = normalisedValue(this.multiple, this.selectedValues);
|
|
1644
|
+
} else {
|
|
1645
|
+
if (this.multiple) {
|
|
1646
|
+
if (this.focusedValue !== undefined && (key.name === "tab" || this.isNavigating && key.name === "space")) {
|
|
1647
|
+
this.toggleSelected(this.focusedValue);
|
|
1648
|
+
} else {
|
|
1649
|
+
this.isNavigating = false;
|
|
1650
|
+
}
|
|
1651
|
+
} else {
|
|
1652
|
+
if (this.focusedValue) {
|
|
1653
|
+
this.selectedValues = [this.focusedValue];
|
|
1654
|
+
}
|
|
1655
|
+
this.isNavigating = false;
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
deselectAll() {
|
|
1660
|
+
this.selectedValues = [];
|
|
1661
|
+
}
|
|
1662
|
+
toggleSelected(value) {
|
|
1663
|
+
if (this.filteredOptions.length === 0) {
|
|
1664
|
+
return;
|
|
1665
|
+
}
|
|
1666
|
+
if (this.multiple) {
|
|
1667
|
+
if (this.selectedValues.includes(value)) {
|
|
1668
|
+
this.selectedValues = this.selectedValues.filter((v) => v !== value);
|
|
1669
|
+
} else {
|
|
1670
|
+
this.selectedValues = [...this.selectedValues, value];
|
|
1671
|
+
}
|
|
1672
|
+
} else {
|
|
1673
|
+
this.selectedValues = [value];
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
#onUserInputChanged(value) {
|
|
1677
|
+
if (value !== this.#lastUserInput) {
|
|
1678
|
+
this.#lastUserInput = value;
|
|
1679
|
+
const options = this.options;
|
|
1680
|
+
if (value) {
|
|
1681
|
+
this.filteredOptions = options.filter((opt) => this.#filterFn(value, opt));
|
|
1682
|
+
} else {
|
|
1683
|
+
this.filteredOptions = [...options];
|
|
1684
|
+
}
|
|
1685
|
+
this.#cursor = getCursorForValue(this.focusedValue, this.filteredOptions);
|
|
1686
|
+
this.focusedValue = this.filteredOptions[this.#cursor]?.value;
|
|
1687
|
+
if (!this.multiple) {
|
|
1688
|
+
if (this.focusedValue !== undefined) {
|
|
1689
|
+
this.toggleSelected(this.focusedValue);
|
|
1690
|
+
} else {
|
|
1691
|
+
this.deselectAll();
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
class GroupMultiSelectPrompt extends Prompt {
|
|
1698
|
+
options;
|
|
1699
|
+
cursor = 0;
|
|
1700
|
+
#selectableGroups;
|
|
1701
|
+
getGroupItems(group) {
|
|
1702
|
+
return this.options.filter((o) => o.group === group);
|
|
1703
|
+
}
|
|
1704
|
+
isGroupSelected(group) {
|
|
1705
|
+
const items = this.getGroupItems(group);
|
|
1706
|
+
const value = this.value;
|
|
1707
|
+
if (value === undefined) {
|
|
1708
|
+
return false;
|
|
1709
|
+
}
|
|
1710
|
+
return items.every((i) => value.includes(i.value));
|
|
1711
|
+
}
|
|
1712
|
+
toggleValue() {
|
|
1713
|
+
const item = this.options[this.cursor];
|
|
1714
|
+
if (this.value === undefined) {
|
|
1715
|
+
this.value = [];
|
|
1716
|
+
}
|
|
1717
|
+
if (item.group === true) {
|
|
1718
|
+
const group = item.value;
|
|
1719
|
+
const groupedItems = this.getGroupItems(group);
|
|
1720
|
+
if (this.isGroupSelected(group)) {
|
|
1721
|
+
this.value = this.value.filter((v) => groupedItems.findIndex((i) => i.value === v) === -1);
|
|
1722
|
+
} else {
|
|
1723
|
+
this.value = [...this.value, ...groupedItems.map((i) => i.value)];
|
|
1724
|
+
}
|
|
1725
|
+
this.value = Array.from(new Set(this.value));
|
|
1726
|
+
} else {
|
|
1727
|
+
const selected = this.value.includes(item.value);
|
|
1728
|
+
this.value = selected ? this.value.filter((v) => v !== item.value) : [...this.value, item.value];
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
constructor(opts) {
|
|
1732
|
+
super(opts, false);
|
|
1733
|
+
const { options } = opts;
|
|
1734
|
+
this.#selectableGroups = opts.selectableGroups !== false;
|
|
1735
|
+
this.options = Object.entries(options).flatMap(([key, option]) => [
|
|
1736
|
+
{ value: key, group: true, label: key },
|
|
1737
|
+
...option.map((opt) => ({ ...opt, group: key }))
|
|
1738
|
+
]);
|
|
1739
|
+
this.value = [...opts.initialValues ?? []];
|
|
1740
|
+
this.cursor = Math.max(this.options.findIndex(({ value }) => value === opts.cursorAt), this.#selectableGroups ? 0 : 1);
|
|
1741
|
+
this.on("cursor", (key) => {
|
|
1742
|
+
switch (key) {
|
|
1743
|
+
case "left":
|
|
1744
|
+
case "up": {
|
|
1745
|
+
this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
|
|
1746
|
+
const currentIsGroup = this.options[this.cursor]?.group === true;
|
|
1747
|
+
if (!this.#selectableGroups && currentIsGroup) {
|
|
1748
|
+
this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
|
|
1749
|
+
}
|
|
1750
|
+
break;
|
|
1751
|
+
}
|
|
1752
|
+
case "down":
|
|
1753
|
+
case "right": {
|
|
1754
|
+
this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
|
|
1755
|
+
const currentIsGroup = this.options[this.cursor]?.group === true;
|
|
1756
|
+
if (!this.#selectableGroups && currentIsGroup) {
|
|
1757
|
+
this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
|
|
1758
|
+
}
|
|
1759
|
+
break;
|
|
1760
|
+
}
|
|
1761
|
+
case "space":
|
|
1762
|
+
this.toggleValue();
|
|
1763
|
+
break;
|
|
1764
|
+
}
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
var import_picocolors2 = __toESM2(require_picocolors(), 1);
|
|
1769
|
+
var import_picocolors3 = __toESM2(require_picocolors(), 1);
|
|
1770
|
+
var import_picocolors4 = __toESM2(require_picocolors(), 1);
|
|
1771
|
+
var codes = {
|
|
1772
|
+
red: ["\x1B[31m", "\x1B[39m"],
|
|
1773
|
+
green: ["\x1B[32m", "\x1B[39m"],
|
|
1774
|
+
blue: ["\x1B[34m", "\x1B[39m"],
|
|
1775
|
+
yellow: ["\x1B[33m", "\x1B[39m"],
|
|
1776
|
+
cyan: ["\x1B[36m", "\x1B[39m"],
|
|
1777
|
+
magenta: ["\x1B[35m", "\x1B[39m"],
|
|
1778
|
+
white: ["\x1B[37m", "\x1B[39m"],
|
|
1779
|
+
gray: ["\x1B[90m", "\x1B[39m"],
|
|
1780
|
+
bgRed: ["\x1B[41m", "\x1B[49m"],
|
|
1781
|
+
bgGreen: ["\x1B[42m", "\x1B[49m"],
|
|
1782
|
+
bgBlue: ["\x1B[44m", "\x1B[49m"],
|
|
1783
|
+
bgYellow: ["\x1B[43m", "\x1B[49m"],
|
|
1784
|
+
bgCyan: ["\x1B[46m", "\x1B[49m"],
|
|
1785
|
+
bgMagenta: ["\x1B[45m", "\x1B[49m"],
|
|
1786
|
+
bold: ["\x1B[1m", "\x1B[22m"],
|
|
1787
|
+
italic: ["\x1B[3m", "\x1B[23m"],
|
|
1788
|
+
underline: ["\x1B[4m", "\x1B[24m"],
|
|
1789
|
+
dim: ["\x1B[2m", "\x1B[22m"],
|
|
1790
|
+
inverse: ["\x1B[7m", "\x1B[27m"],
|
|
1791
|
+
hidden: ["\x1B[8m", "\x1B[28m"],
|
|
1792
|
+
strikethrough: ["\x1B[9m", "\x1B[29m"]
|
|
1793
|
+
};
|
|
1794
|
+
var theme = {
|
|
1795
|
+
primary: "blue",
|
|
1796
|
+
secondary: "cyan",
|
|
1797
|
+
success: "green",
|
|
1798
|
+
warning: "yellow",
|
|
1799
|
+
error: "red",
|
|
1800
|
+
info: "magenta",
|
|
1801
|
+
muted: "gray"
|
|
1802
|
+
};
|
|
1803
|
+
function detectColorSupport() {
|
|
1804
|
+
return true;
|
|
1805
|
+
}
|
|
1806
|
+
function createStyler() {
|
|
1807
|
+
const styler = {};
|
|
1808
|
+
styler.supportsColor = detectColorSupport();
|
|
1809
|
+
function createStyleFunction(styleName, styles2 = []) {
|
|
1810
|
+
const styleList = styleName === "" ? [] : [...styles2, styleName];
|
|
1811
|
+
const fn = function(text) {
|
|
1812
|
+
if (!styler.supportsColor)
|
|
1813
|
+
return text;
|
|
1814
|
+
let openCodes = "";
|
|
1815
|
+
let closeCodes = "";
|
|
1816
|
+
for (const style of styleList) {
|
|
1817
|
+
if (style in theme && theme[style] in codes) {
|
|
1818
|
+
const themeStyle = theme[style];
|
|
1819
|
+
openCodes += codes[themeStyle][0];
|
|
1820
|
+
closeCodes = codes[themeStyle][1] + closeCodes;
|
|
1821
|
+
} else if (style in codes) {
|
|
1822
|
+
openCodes += codes[style][0];
|
|
1823
|
+
closeCodes = codes[style][1] + closeCodes;
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
return openCodes + text + closeCodes;
|
|
1827
|
+
};
|
|
1828
|
+
const allStyles2 = [...Object.keys(codes), ...Object.keys(theme)];
|
|
1829
|
+
for (const style of allStyles2) {
|
|
1830
|
+
if (!(style in fn)) {
|
|
1831
|
+
Object.defineProperty(fn, style, {
|
|
1832
|
+
get() {
|
|
1833
|
+
return createStyleFunction(style, styleList);
|
|
1834
|
+
}
|
|
1835
|
+
});
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
return fn;
|
|
1839
|
+
}
|
|
1840
|
+
const allStyles = [...Object.keys(codes), ...Object.keys(theme)];
|
|
1841
|
+
for (const style of allStyles) {
|
|
1842
|
+
if (!(style in styler)) {
|
|
1843
|
+
Object.defineProperty(styler, style, {
|
|
1844
|
+
get() {
|
|
1845
|
+
return createStyleFunction(style);
|
|
1846
|
+
}
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
return styler;
|
|
1851
|
+
}
|
|
1852
|
+
var style = createStyler();
|
|
1853
|
+
var unicode = isUnicodeSupported();
|
|
1854
|
+
var unicodeOr = (c, fallback) => unicode ? c : fallback;
|
|
1855
|
+
var S_STEP_ACTIVE = unicodeOr("\u25C6", "*");
|
|
1856
|
+
var S_STEP_CANCEL = unicodeOr("\u25A0", "x");
|
|
1857
|
+
var S_STEP_ERROR = unicodeOr("\u25B2", "x");
|
|
1858
|
+
var S_STEP_SUBMIT = unicodeOr("\u25C7", "o");
|
|
1859
|
+
var S_BAR_START = unicodeOr("\u250C", "T");
|
|
1860
|
+
var S_BAR = unicodeOr("\u2502", "|");
|
|
1861
|
+
var S_BAR_END = unicodeOr("\u2514", "\u2014");
|
|
1862
|
+
var S_RADIO_ACTIVE = unicodeOr("\u25CF", ">");
|
|
1863
|
+
var S_RADIO_INACTIVE = unicodeOr("\u25CB", " ");
|
|
1864
|
+
var S_CHECKBOX_ACTIVE = unicodeOr("\u25FB", "[\u2022]");
|
|
1865
|
+
var S_CHECKBOX_SELECTED = unicodeOr("\u25FC", "[+]");
|
|
1866
|
+
var S_CHECKBOX_INACTIVE = unicodeOr("\u25FB", "[ ]");
|
|
1867
|
+
var S_PASSWORD_MASK = unicodeOr("\u25AA", "\u2022");
|
|
1868
|
+
var S_BAR_H = unicodeOr("\u2500", "-");
|
|
1869
|
+
var S_CORNER_TOP_RIGHT = unicodeOr("\u256E", "+");
|
|
1870
|
+
var S_CONNECT_LEFT = unicodeOr("\u251C", "+");
|
|
1871
|
+
var S_CORNER_BOTTOM_RIGHT = unicodeOr("\u256F", "+");
|
|
1872
|
+
var S_INFO = unicodeOr("\u25CF", "\u2022");
|
|
1873
|
+
var S_SUCCESS = unicodeOr("\u25C6", "*");
|
|
1874
|
+
var S_WARN = unicodeOr("\u25B2", "!");
|
|
1875
|
+
var S_ERROR = unicodeOr("\u25A0", "x");
|
|
1876
|
+
var import_picocolors5 = __toESM2(require_picocolors(), 1);
|
|
1877
|
+
var import_picocolors7 = __toESM2(require_picocolors(), 1);
|
|
1878
|
+
var import_picocolors8 = __toESM2(require_picocolors(), 1);
|
|
1879
|
+
var import_picocolors9 = __toESM2(require_picocolors(), 1);
|
|
1880
|
+
var import_picocolors10 = __toESM2(require_picocolors(), 1);
|
|
1881
|
+
var import_picocolors11 = __toESM2(require_picocolors(), 1);
|
|
1882
|
+
var import_picocolors12 = __toESM2(require_picocolors(), 1);
|
|
1883
|
+
var import_picocolors13 = __toESM2(require_picocolors(), 1);
|
|
1884
|
+
var import_picocolors15 = __toESM2(require_picocolors(), 1);
|
|
1885
|
+
var import_picocolors14 = __toESM2(require_picocolors(), 1);
|
|
1886
|
+
var S_PROGRESS_CHAR = {
|
|
1887
|
+
light: unicodeOr("\u2500", "-"),
|
|
1888
|
+
heavy: unicodeOr("\u2501", "="),
|
|
1889
|
+
block: unicodeOr("\u2588", "#")
|
|
1890
|
+
};
|
|
1891
|
+
var import_picocolors16 = __toESM2(require_picocolors(), 1);
|
|
1892
|
+
var import_picocolors17 = __toESM2(require_picocolors(), 1);
|
|
1893
|
+
var import_picocolors18 = __toESM2(require_picocolors(), 1);
|
|
1894
|
+
function getPrefix() {
|
|
1895
|
+
return `${import_picocolors18.default.gray(S_BAR)} `;
|
|
1896
|
+
}
|
|
1897
|
+
var prefix = getPrefix();
|
|
1898
|
+
var color18 = __toESM2(require_picocolors(), 1);
|
|
1899
|
+
var import_picocolors19 = __toESM2(require_picocolors(), 1);
|
|
1900
|
+
// package.json
|
|
1901
|
+
var version = "0.1.7";
|
|
1902
|
+
|
|
1903
|
+
// bin/cli.ts
|
|
1904
|
+
var __dirname = "/home/runner/work/stx/stx/packages/stx/bin";
|
|
1905
|
+
var cli = new CLI("stx");
|
|
1906
|
+
function validatePort(port) {
|
|
1907
|
+
const portNum = typeof port === "string" ? Number.parseInt(port, 10) : port;
|
|
1908
|
+
if (Number.isNaN(portNum)) {
|
|
1909
|
+
return { isValid: false, error: "Port must be a valid number", suggestion: "Try using a number between 1024 and 65535" };
|
|
1910
|
+
}
|
|
1911
|
+
if (portNum < 1024 || portNum > 65535) {
|
|
1912
|
+
return { isValid: false, error: "Port must be between 1024 and 65535", suggestion: "Try using a port between 1024 and 65535" };
|
|
1913
|
+
}
|
|
1914
|
+
return { isValid: true };
|
|
1915
|
+
}
|
|
1916
|
+
function validateFileExists(filePath) {
|
|
1917
|
+
try {
|
|
1918
|
+
if (!fs.existsSync(filePath)) {
|
|
1919
|
+
const dir = path.dirname(filePath);
|
|
1920
|
+
const filename = path.basename(filePath);
|
|
1921
|
+
if (fs.existsSync(dir)) {
|
|
1922
|
+
const files = fs.readdirSync(dir);
|
|
1923
|
+
const similarFiles = files.filter((f) => f.toLowerCase().includes(filename.toLowerCase().substring(0, 3)) || f.endsWith(".stx") || f.endsWith(".md"));
|
|
1924
|
+
const suggestion = similarFiles.length > 0 ? `File not found. Similar files in ${dir}: ${similarFiles.slice(0, 3).join(", ")}` : `File not found. Directory ${dir} exists but doesn't contain the specified file.`;
|
|
1925
|
+
return { isValid: false, error: `File does not exist: ${filePath}`, suggestion };
|
|
1926
|
+
}
|
|
1927
|
+
return { isValid: false, error: `File does not exist: ${filePath}`, suggestion: "Check the file path and try again" };
|
|
1928
|
+
}
|
|
1929
|
+
const stats = fs.statSync(filePath);
|
|
1930
|
+
if (stats.isDirectory()) {
|
|
1931
|
+
return { isValid: false, error: `Expected file but got directory: ${filePath}`, suggestion: "Specify a .stx or .md file path" };
|
|
1932
|
+
}
|
|
1933
|
+
return { isValid: true };
|
|
1934
|
+
} catch (error) {
|
|
1935
|
+
return { isValid: false, error: `Cannot access file: ${filePath}`, suggestion: "Check file permissions and path" };
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
function validateTimeout(timeout) {
|
|
1939
|
+
const timeoutNum = typeof timeout === "string" ? Number.parseInt(timeout, 10) : timeout;
|
|
1940
|
+
if (Number.isNaN(timeoutNum)) {
|
|
1941
|
+
return { isValid: false, error: "Timeout must be a valid number", suggestion: "Specify timeout in milliseconds (e.g., 5000 for 5 seconds)" };
|
|
1942
|
+
}
|
|
1943
|
+
if (timeoutNum < 100) {
|
|
1944
|
+
return { isValid: false, error: "Timeout too short (minimum 100ms)", suggestion: "Use a timeout of at least 100ms" };
|
|
1945
|
+
}
|
|
1946
|
+
if (timeoutNum > 300000) {
|
|
1947
|
+
return { isValid: false, error: "Timeout too long (maximum 5 minutes)", suggestion: "Use a timeout of less than 300000ms (5 minutes)" };
|
|
1948
|
+
}
|
|
1949
|
+
return { isValid: true };
|
|
1950
|
+
}
|
|
1951
|
+
var isGlob = (arg) => arg.includes("*") || arg.includes("?") || arg.includes("{") || arg.includes("[");
|
|
1952
|
+
var isSupportedFileType = (arg) => arg.endsWith(".stx") || arg.endsWith(".md");
|
|
1953
|
+
function reportValidationError(validation, exitCode = 1) {
|
|
1954
|
+
console.error(`\u274C ${validation.error}`);
|
|
1955
|
+
if (validation.suggestion) {
|
|
1956
|
+
console.error(`\uD83D\uDCA1 suggestion: ${validation.suggestion}`);
|
|
1957
|
+
}
|
|
1958
|
+
process7.exit(exitCode);
|
|
1959
|
+
}
|
|
1960
|
+
async function runTests(patterns, options) {
|
|
1961
|
+
try {
|
|
1962
|
+
const args = ["test"];
|
|
1963
|
+
const expandedPatterns = [];
|
|
1964
|
+
if (patterns && patterns.length > 0) {
|
|
1965
|
+
for (const pattern of patterns) {
|
|
1966
|
+
if (isGlob(pattern)) {
|
|
1967
|
+
try {
|
|
1968
|
+
const matches = await Array.fromAsync(new Bun.Glob(pattern).scan({ onlyFiles: true, absolute: true }));
|
|
1969
|
+
if (matches.length === 0) {
|
|
1970
|
+
console.warn(`Warning: No files found matching pattern: ${pattern}`);
|
|
1971
|
+
} else {
|
|
1972
|
+
expandedPatterns.push(...matches);
|
|
1973
|
+
if (options.verbose) {
|
|
1974
|
+
console.log(`Found ${matches.length} file(s) matching pattern: ${pattern}`);
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
} catch (error) {
|
|
1978
|
+
console.error(`Error expanding glob pattern ${pattern}:`, error);
|
|
1979
|
+
return false;
|
|
1980
|
+
}
|
|
1981
|
+
} else {
|
|
1982
|
+
expandedPatterns.push(pattern);
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
if (expandedPatterns.length === 0) {
|
|
1987
|
+
console.error("Error: No test files found matching the provided patterns.");
|
|
1988
|
+
return false;
|
|
1989
|
+
}
|
|
1990
|
+
args.push(...expandedPatterns);
|
|
1991
|
+
if (options.filter) {
|
|
1992
|
+
args.push("--pattern", options.filter);
|
|
1993
|
+
}
|
|
1994
|
+
if (options.timeout) {
|
|
1995
|
+
args.push("--timeout", options.timeout.toString());
|
|
1996
|
+
}
|
|
1997
|
+
if (options.reporter && options.reporter !== "default") {
|
|
1998
|
+
if (options.reporter === "junit") {
|
|
1999
|
+
const junitOutputFile = path.join(os.tmpdir(), `stx-test-report-${Date.now()}.xml`);
|
|
2000
|
+
args.push("--reporter", options.reporter);
|
|
2001
|
+
args.push("--reporter-outfile", junitOutputFile);
|
|
2002
|
+
} else {
|
|
2003
|
+
console.warn(`Warning: Reporter '${options.reporter}' is not supported. Using default reporter.`);
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
if (options.coverage) {
|
|
2007
|
+
args.push("--coverage");
|
|
2008
|
+
}
|
|
2009
|
+
if (options.watch) {
|
|
2010
|
+
args.push("--watch");
|
|
2011
|
+
}
|
|
2012
|
+
args.push("--preload", path.join(__dirname, "../../../test-utils/happy-dom.ts"));
|
|
2013
|
+
const env = {
|
|
2014
|
+
...process7.env,
|
|
2015
|
+
STX_TEST_MODE: "true",
|
|
2016
|
+
STX_TEST_UI: options.ui ? "true" : "false",
|
|
2017
|
+
STX_TEST_VERBOSE: options.verbose ? "true" : "false"
|
|
2018
|
+
};
|
|
2019
|
+
const command = "bun";
|
|
2020
|
+
if (options.verbose) {
|
|
2021
|
+
console.log(`Running: ${command} ${args.join(" ")}`);
|
|
2022
|
+
}
|
|
2023
|
+
const startTime = performance.now();
|
|
2024
|
+
const child = spawn(command, args, {
|
|
2025
|
+
stdio: "inherit",
|
|
2026
|
+
shell: false,
|
|
2027
|
+
env
|
|
2028
|
+
});
|
|
2029
|
+
return new Promise((resolve) => {
|
|
2030
|
+
child.on("close", (code) => {
|
|
2031
|
+
const endTime = performance.now();
|
|
2032
|
+
const _duration = ((endTime - startTime) / 1000).toFixed(2);
|
|
2033
|
+
if (code === 0) {
|
|
2034
|
+
resolve(true);
|
|
2035
|
+
} else {
|
|
2036
|
+
resolve(false);
|
|
2037
|
+
}
|
|
2038
|
+
});
|
|
2039
|
+
process7.on("SIGINT", () => {
|
|
2040
|
+
console.log(`
|
|
2041
|
+
Test run interrupted`);
|
|
2042
|
+
child.kill("SIGINT");
|
|
2043
|
+
process7.exit(1);
|
|
2044
|
+
});
|
|
2045
|
+
});
|
|
2046
|
+
} catch (error) {
|
|
2047
|
+
console.error("Error running tests:", error instanceof Error ? error.message : String(error));
|
|
2048
|
+
return false;
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
var isDirectMode = process7.argv.length >= 3 && (isSupportedFileType(process7.argv[2]) && fs.existsSync(process7.argv[2]) || isGlob(process7.argv[2]));
|
|
2052
|
+
if (isDirectMode) {
|
|
2053
|
+
const fileArg = process7.argv[2];
|
|
2054
|
+
const options = {
|
|
2055
|
+
port: 3000,
|
|
2056
|
+
watch: true,
|
|
2057
|
+
cache: true,
|
|
2058
|
+
markdown: {
|
|
2059
|
+
syntaxHighlighting: {
|
|
2060
|
+
enabled: true,
|
|
2061
|
+
serverSide: true,
|
|
2062
|
+
defaultTheme: "github-dark",
|
|
2063
|
+
highlightUnknownLanguages: true
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
};
|
|
2067
|
+
for (let i = 3;i < process7.argv.length; i++) {
|
|
2068
|
+
const arg = process7.argv[i];
|
|
2069
|
+
if (arg === "--port" && i + 1 < process7.argv.length) {
|
|
2070
|
+
const portValidation = validatePort(process7.argv[++i]);
|
|
2071
|
+
if (!portValidation.isValid) {
|
|
2072
|
+
reportValidationError(portValidation);
|
|
2073
|
+
}
|
|
2074
|
+
options.port = Number.parseInt(process7.argv[i], 10);
|
|
2075
|
+
} else if (arg === "--no-watch") {
|
|
2076
|
+
options.watch = false;
|
|
2077
|
+
} else if (arg === "--highlight-theme" && i + 1 < process7.argv.length) {
|
|
2078
|
+
if (!options.markdown)
|
|
2079
|
+
options.markdown = {};
|
|
2080
|
+
if (!options.markdown.syntaxHighlighting)
|
|
2081
|
+
options.markdown.syntaxHighlighting = {};
|
|
2082
|
+
options.markdown.syntaxHighlighting.defaultTheme = process7.argv[++i];
|
|
2083
|
+
} else if (arg === "--no-highlight") {
|
|
2084
|
+
if (!options.markdown)
|
|
2085
|
+
options.markdown = {};
|
|
2086
|
+
if (!options.markdown.syntaxHighlighting)
|
|
2087
|
+
options.markdown.syntaxHighlighting = {};
|
|
2088
|
+
options.markdown.syntaxHighlighting.enabled = false;
|
|
2089
|
+
} else if (arg === "--no-highlight-unknown") {
|
|
2090
|
+
if (!options.markdown)
|
|
2091
|
+
options.markdown = {};
|
|
2092
|
+
if (!options.markdown.syntaxHighlighting)
|
|
2093
|
+
options.markdown.syntaxHighlighting = {};
|
|
2094
|
+
options.markdown.syntaxHighlighting.highlightUnknownLanguages = false;
|
|
2095
|
+
} else if (arg === "--no-cache") {
|
|
2096
|
+
options.cache = false;
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
if (isGlob(fileArg)) {
|
|
2100
|
+
try {
|
|
2101
|
+
const files = await Array.fromAsync(new Bun.Glob(fileArg).scan({ onlyFiles: true, absolute: true }));
|
|
2102
|
+
const supportedFiles = fileArg.endsWith(".stx") ? files.filter((file) => file.endsWith(".stx")) : fileArg.endsWith(".md") ? files.filter((file) => file.endsWith(".md")) : files.filter((file) => file.endsWith(".stx") || file.endsWith(".md"));
|
|
2103
|
+
if (supportedFiles.length === 0) {
|
|
2104
|
+
console.error(`Error: No STX or Markdown files found matching pattern: ${fileArg}`);
|
|
2105
|
+
process7.exit(1);
|
|
2106
|
+
}
|
|
2107
|
+
const success = await serveMultipleStxFiles(supportedFiles, options);
|
|
2108
|
+
if (!success) {
|
|
2109
|
+
process7.exit(1);
|
|
2110
|
+
}
|
|
2111
|
+
} catch (error) {
|
|
2112
|
+
console.error("Failed to process files:", error);
|
|
2113
|
+
process7.exit(1);
|
|
2114
|
+
}
|
|
2115
|
+
} else {
|
|
2116
|
+
serveStxFile(fileArg, options).catch((error) => {
|
|
2117
|
+
console.error("Failed to start dev server:", error);
|
|
2118
|
+
process7.exit(1);
|
|
2119
|
+
});
|
|
2120
|
+
}
|
|
2121
|
+
} else {
|
|
2122
|
+
let levenshteinDistance = function(a, b) {
|
|
2123
|
+
const matrix = [];
|
|
2124
|
+
for (let i = 0;i <= b.length; i++) {
|
|
2125
|
+
matrix[i] = [i];
|
|
2126
|
+
}
|
|
2127
|
+
for (let j = 0;j <= a.length; j++) {
|
|
2128
|
+
matrix[0][j] = j;
|
|
2129
|
+
}
|
|
2130
|
+
for (let i = 1;i <= b.length; i++) {
|
|
2131
|
+
for (let j = 1;j <= a.length; j++) {
|
|
2132
|
+
if (b.charAt(i - 1) === a.charAt(j - 1)) {
|
|
2133
|
+
matrix[i][j] = matrix[i - 1][j - 1];
|
|
2134
|
+
} else {
|
|
2135
|
+
matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j] + 1);
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
return matrix[b.length][a.length];
|
|
2140
|
+
};
|
|
2141
|
+
cli.command("docs", "Generate documentation for components, templates, and directives").option("--output <dir>", "Output directory for documentation", { default: "docs" }).option("--format <format>", "Documentation format (markdown, html, json)", { default: "markdown" }).option("--components-dir <dir>", "Components directory", { default: "components" }).option("--templates-dir <dir>", "Templates directory", { default: "." }).option("--no-components", "Disable components documentation").option("--no-templates", "Disable templates documentation").option("--no-directives", "Disable directives documentation").option("--extra-content <content>", "Extra content to include in documentation").example("stx docs --output docs --format html").action(async (options) => {
|
|
2142
|
+
try {
|
|
2143
|
+
const result = await docsCommand(options);
|
|
2144
|
+
if (result) {
|
|
2145
|
+
console.log("Documentation generated successfully.");
|
|
2146
|
+
process7.exit(0);
|
|
2147
|
+
} else {
|
|
2148
|
+
console.error("Documentation generation failed.");
|
|
2149
|
+
process7.exit(1);
|
|
2150
|
+
}
|
|
2151
|
+
} catch (error) {
|
|
2152
|
+
console.error("Error generating documentation:", error);
|
|
2153
|
+
process7.exit(1);
|
|
2154
|
+
}
|
|
2155
|
+
});
|
|
2156
|
+
cli.command("iconify <command>", "Generate Iconify icon packages").option("--output <dir>", "Output directory for generated packages", { default: "packages" }).option("--icons <icons>", "Comma-separated list of specific icons to generate").example("stx iconify list").example("stx iconify generate mdi").example("stx iconify generate lucide --icons home,settings,user").action(async (command, options) => {
|
|
2157
|
+
try {
|
|
2158
|
+
const { fetchCollections, generatePackage } = await import("../chunk-vsbm352h.js");
|
|
2159
|
+
if (command === "list") {
|
|
2160
|
+
console.log(`
|
|
2161
|
+
\uD83D\uDCDA Fetching available icon collections...
|
|
2162
|
+
`);
|
|
2163
|
+
const collections = await fetchCollections();
|
|
2164
|
+
const sortedCollections = Object.entries(collections).sort((a, b) => b[1].total - a[1].total);
|
|
2165
|
+
console.log(`Available collections:
|
|
2166
|
+
`);
|
|
2167
|
+
for (const [prefix2, info] of sortedCollections) {
|
|
2168
|
+
const collectionInfo = info;
|
|
2169
|
+
console.log(` ${prefix2.padEnd(30)} ${collectionInfo.name} (${collectionInfo.total} icons)`);
|
|
2170
|
+
}
|
|
2171
|
+
console.log(`
|
|
2172
|
+
Total: ${sortedCollections.length} collections`);
|
|
2173
|
+
} else if (command.startsWith("generate")) {
|
|
2174
|
+
const prefix2 = command === "generate" ? "" : command.replace("generate:", "").replace("generate-", "").replace("generate", "").trim();
|
|
2175
|
+
if (!prefix2) {
|
|
2176
|
+
console.error("Error: Please specify a collection prefix");
|
|
2177
|
+
console.error("Usage: stx iconify generate <prefix> [--icons icon1,icon2,...]");
|
|
2178
|
+
process7.exit(1);
|
|
2179
|
+
}
|
|
2180
|
+
const outputDir = options.output || path.join(process7.cwd(), "packages/collections");
|
|
2181
|
+
const icons = options.icons ? options.icons.split(",").map((i) => i.trim()) : undefined;
|
|
2182
|
+
await generatePackage(prefix2, outputDir, icons);
|
|
2183
|
+
console.log(`
|
|
2184
|
+
\u2713 Package generated successfully!`);
|
|
2185
|
+
console.log(`
|
|
2186
|
+
To use the package:`);
|
|
2187
|
+
console.log(` 1. cd packages/collections/iconify-${prefix2}`);
|
|
2188
|
+
console.log(` 2. bun install`);
|
|
2189
|
+
console.log(` 3. bun run build`);
|
|
2190
|
+
} else {
|
|
2191
|
+
console.error(`Unknown iconify command: ${command}`);
|
|
2192
|
+
console.error("Available commands: list, generate");
|
|
2193
|
+
process7.exit(1);
|
|
2194
|
+
}
|
|
2195
|
+
} catch (error) {
|
|
2196
|
+
console.error("Error:", error instanceof Error ? error.message : String(error));
|
|
2197
|
+
process7.exit(1);
|
|
2198
|
+
}
|
|
2199
|
+
});
|
|
2200
|
+
cli.command("dev <file>", "Start a development server for an STX file").option("--port <port>", "Port to use for the dev server", { default: 3000 }).option("--no-watch", "Disable file watching and auto-reload").option("--highlight-theme <theme>", "Syntax highlighting theme for Markdown code blocks", { default: "github-dark" }).option("--no-highlight", "Disable syntax highlighting for Markdown code blocks").option("--no-highlight-unknown", "Disable syntax highlighting for unknown languages in Markdown").option("--no-cache", "Disable caching of parsed files").example("stx dev template.stx").example("stx dev components/hero.stx --port 8080").example("stx dev **/*.stx").example("stx dev docs/guide.md").example("stx dev **/*.md").example("stx dev docs/guide.md --highlight-theme atom-one-dark").action(async (filePattern, options) => {
|
|
2201
|
+
try {
|
|
2202
|
+
if (options.port !== undefined) {
|
|
2203
|
+
const portValidation = validatePort(options.port);
|
|
2204
|
+
if (!portValidation.isValid) {
|
|
2205
|
+
reportValidationError(portValidation);
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
if (options.timeout !== undefined) {
|
|
2209
|
+
const timeoutValidation = validateTimeout(options.timeout);
|
|
2210
|
+
if (!timeoutValidation.isValid) {
|
|
2211
|
+
reportValidationError(timeoutValidation);
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
const markdownOptions = {
|
|
2215
|
+
syntaxHighlighting: {
|
|
2216
|
+
enabled: options.highlight !== false,
|
|
2217
|
+
serverSide: true,
|
|
2218
|
+
defaultTheme: options.highlightTheme || "github-dark",
|
|
2219
|
+
highlightUnknownLanguages: options.highlightUnknown !== false
|
|
2220
|
+
}
|
|
2221
|
+
};
|
|
2222
|
+
if (isGlob(filePattern)) {
|
|
2223
|
+
console.log(`Expanding glob pattern: ${filePattern}`);
|
|
2224
|
+
const files = await performanceMonitor.timeAsync("glob-expansion", async () => {
|
|
2225
|
+
return Array.fromAsync(new Bun.Glob(filePattern).scan({ onlyFiles: true, absolute: true }));
|
|
2226
|
+
});
|
|
2227
|
+
const supportedFiles = filePattern.endsWith(".stx") ? files.filter((file) => file.endsWith(".stx")) : filePattern.endsWith(".md") ? files.filter((file) => file.endsWith(".md")) : files.filter((file) => file.endsWith(".stx") || file.endsWith(".md"));
|
|
2228
|
+
if (supportedFiles.length === 0) {
|
|
2229
|
+
console.error(`\u274C No STX or Markdown files found matching pattern: ${filePattern}`);
|
|
2230
|
+
console.error(`\uD83D\uDCA1 Try using patterns like '*.stx' or 'components/**/*.stx'`);
|
|
2231
|
+
process7.exit(1);
|
|
2232
|
+
}
|
|
2233
|
+
console.log(`Found ${supportedFiles.length} ${supportedFiles.length === 1 ? "file" : "files"} matching ${filePattern}`);
|
|
2234
|
+
const success = await serveMultipleStxFiles(supportedFiles, {
|
|
2235
|
+
port: options.port,
|
|
2236
|
+
watch: options.watch !== false,
|
|
2237
|
+
markdown: markdownOptions,
|
|
2238
|
+
cache: options.cache !== false
|
|
2239
|
+
});
|
|
2240
|
+
if (!success) {
|
|
2241
|
+
process7.exit(1);
|
|
2242
|
+
}
|
|
2243
|
+
} else {
|
|
2244
|
+
if (!isGlob(filePattern)) {
|
|
2245
|
+
const fileValidation = validateFileExists(filePattern);
|
|
2246
|
+
if (!fileValidation.isValid) {
|
|
2247
|
+
reportValidationError(fileValidation);
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
const success = await serveStxFile(filePattern, {
|
|
2251
|
+
port: options.port,
|
|
2252
|
+
watch: options.watch !== false,
|
|
2253
|
+
markdown: markdownOptions,
|
|
2254
|
+
cache: options.cache !== false
|
|
2255
|
+
});
|
|
2256
|
+
if (!success) {
|
|
2257
|
+
process7.exit(1);
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
} catch (error) {
|
|
2261
|
+
console.error("Error starting dev server:", error);
|
|
2262
|
+
process7.exit(1);
|
|
2263
|
+
}
|
|
2264
|
+
});
|
|
2265
|
+
cli.command("a11y [directory]", "Scan STX files for accessibility issues").option("--no-recursive", "Disable recursive scanning of directories").option("--ignore <paths>", "Comma-separated paths to ignore", { default: "" }).option("--json", "Output results as JSON").option("--output <file>", "Write results to a file instead of stdout").option("--fix", "Automatically fix common accessibility issues").example("stx a11y ./templates").example("stx a11y --json --output a11y-report.json").action(async (directory = ".", options) => {
|
|
2266
|
+
try {
|
|
2267
|
+
console.log(`Scanning ${directory} for accessibility issues...`);
|
|
2268
|
+
const ignorePaths = options.ignore ? options.ignore.split(",").map((p) => p.trim()) : [];
|
|
2269
|
+
const results = await scanA11yIssues(directory, {
|
|
2270
|
+
recursive: options.recursive !== false,
|
|
2271
|
+
ignorePaths
|
|
2272
|
+
});
|
|
2273
|
+
const totalFiles = Object.keys(results).length;
|
|
2274
|
+
const totalIssues = Object.values(results).reduce((sum, issues) => sum + issues.length, 0);
|
|
2275
|
+
if (options.json) {
|
|
2276
|
+
const jsonOutput = JSON.stringify(results, null, 2);
|
|
2277
|
+
if (options.output) {
|
|
2278
|
+
await Bun.write(options.output, jsonOutput);
|
|
2279
|
+
console.log(`A11y scan results written to ${options.output}`);
|
|
2280
|
+
} else {
|
|
2281
|
+
console.log(jsonOutput);
|
|
2282
|
+
}
|
|
2283
|
+
} else {
|
|
2284
|
+
if (totalFiles === 0) {
|
|
2285
|
+
console.log("\u2713 No accessibility issues found!");
|
|
2286
|
+
} else {
|
|
2287
|
+
console.log(`Found ${totalIssues} accessibility issues in ${totalFiles} files:
|
|
2288
|
+
`);
|
|
2289
|
+
for (const [file, issues] of Object.entries(results)) {
|
|
2290
|
+
const relativePath = path.relative(process7.cwd(), file);
|
|
2291
|
+
console.log(`
|
|
2292
|
+
${relativePath} (${issues.length} issues):`);
|
|
2293
|
+
for (const issue of issues) {
|
|
2294
|
+
console.log(` \u2022 ${issue.impact.toUpperCase()}: ${issue.message}`);
|
|
2295
|
+
console.log(` ${issue.help}`);
|
|
2296
|
+
if (issue.helpUrl) {
|
|
2297
|
+
console.log(` More info: ${issue.helpUrl}`);
|
|
2298
|
+
}
|
|
2299
|
+
console.log(` Element: ${issue.element.substring(0, 100)}${issue.element.length > 100 ? "..." : ""}`);
|
|
2300
|
+
console.log("");
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
console.log(`
|
|
2304
|
+
Total: ${totalIssues} issues in ${totalFiles} files`);
|
|
2305
|
+
if (options.output) {
|
|
2306
|
+
const htmlReport = `
|
|
2307
|
+
<!DOCTYPE html>
|
|
2308
|
+
<html lang="en">
|
|
2309
|
+
<head>
|
|
2310
|
+
<meta charset="UTF-8">
|
|
2311
|
+
<title>STX Accessibility Report</title>
|
|
2312
|
+
<style>
|
|
2313
|
+
body { font-family: system-ui, -apple-system, sans-serif; line-height: 1.6; max-width: 1200px; margin: 0 auto; padding: 20px; }
|
|
2314
|
+
h1 { color: #333; }
|
|
2315
|
+
.summary { margin-bottom: 30px; padding: 15px; background: #f5f5f5; border-radius: 5px; }
|
|
2316
|
+
.file { margin-bottom: 30px; border: 1px solid #ddd; border-radius: 5px; overflow: hidden; }
|
|
2317
|
+
.file-header { padding: 10px 15px; background: #eee; font-weight: bold; border-bottom: 1px solid #ddd; }
|
|
2318
|
+
.issue { padding: 15px; border-bottom: 1px solid #eee; }
|
|
2319
|
+
.issue:last-child { border-bottom: none; }
|
|
2320
|
+
.issue-impact { display: inline-block; padding: 2px 8px; border-radius: 3px; font-size: 12px; font-weight: bold; color: white; margin-right: 10px; }
|
|
2321
|
+
.critical { background-color: #d00; }
|
|
2322
|
+
.serious { background-color: #f50; }
|
|
2323
|
+
.moderate { background-color: #e90; }
|
|
2324
|
+
.minor { background-color: #0a7; }
|
|
2325
|
+
.issue-element { font-family: monospace; padding: 8px; background: #f5f5f5; margin-top: 10px; border-radius: 3px; overflow: auto; }
|
|
2326
|
+
.help-url { font-size: 14px; }
|
|
2327
|
+
</style>
|
|
2328
|
+
</head>
|
|
2329
|
+
<body>
|
|
2330
|
+
<h1>STX Accessibility Report</h1>
|
|
2331
|
+
|
|
2332
|
+
<div class="summary">
|
|
2333
|
+
<p>Found ${totalIssues} accessibility issues in ${totalFiles} files</p>
|
|
2334
|
+
<p>Generated on ${new Date().toLocaleString()}</p>
|
|
2335
|
+
</div>
|
|
2336
|
+
|
|
2337
|
+
${Object.entries(results).map(([file, issues]) => `
|
|
2338
|
+
<div class="file">
|
|
2339
|
+
<div class="file-header">${path.relative(process7.cwd(), file)} (${issues.length} issues)</div>
|
|
2340
|
+
${issues.map((issue) => `
|
|
2341
|
+
<div class="issue">
|
|
2342
|
+
<span class="issue-impact ${issue.impact}">${issue.impact.toUpperCase()}</span>
|
|
2343
|
+
<strong>${issue.message}</strong>
|
|
2344
|
+
<p>${issue.help}</p>
|
|
2345
|
+
${issue.helpUrl ? `<a class="help-url" href="${issue.helpUrl}" target="_blank">More information</a>` : ""}
|
|
2346
|
+
<pre class="issue-element">${issue.element.replace(/</g, "<").replace(/>/g, ">")}</pre>
|
|
2347
|
+
</div>
|
|
2348
|
+
`).join("")}
|
|
2349
|
+
</div>
|
|
2350
|
+
`).join("")}
|
|
2351
|
+
</body>
|
|
2352
|
+
</html>
|
|
2353
|
+
`.trim();
|
|
2354
|
+
await Bun.write(options.output, htmlReport);
|
|
2355
|
+
console.log(`A11y scan results written to ${options.output}`);
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
process7.exit(totalIssues > 0 ? 1 : 0);
|
|
2360
|
+
} catch (error) {
|
|
2361
|
+
console.error("Error scanning for accessibility issues:", error);
|
|
2362
|
+
process7.exit(1);
|
|
2363
|
+
}
|
|
2364
|
+
});
|
|
2365
|
+
cli.command("build [entrypoints...]", "Bundle your STX files using Bun's bundler").option("--outdir <dir>", "Output directory for bundled files", { default: "dist" }).option("--outfile <file>", "Output file name (for single entrypoint)").option("--target <target>", "Target environment: browser, bun, or node", { default: "browser" }).option("--format <format>", "Output format: esm, cjs, or iife", { default: "esm" }).option("--port <port>", "Port for dev server integration (validation only)").option("--timeout <ms>", "Timeout for build operations").option("--minify", "Enable minification").option("--no-minify", "Disable minification").option("--sourcemap <type>", "Sourcemap type: none, linked, inline, or external", { default: "none" }).option("--splitting", "Enable code splitting").option("--no-splitting", "Disable code splitting").option("--external <modules>", "Comma-separated list of modules to exclude from bundle").option("--packages <mode>", "Package handling mode: bundle or external", { default: "bundle" }).option("--watch", "Watch for changes and rebuild").option("--public-path <path>", "Public path for assets").option("--env <mode>", "How to handle environment variables: inline, disable, or prefix*").option("--compile", "Generate a standalone executable").option("--root <dir>", "Project root directory").option("--verbose", "Show verbose build output").example("stx build ./src/index.stx --outfile bundle.js").example("stx build ./components/*.stx --outdir dist --minify").example("stx build ./src/index.stx --outfile bundle.js --target bun").example("stx build **/*.stx --outdir dist").action(async (entrypoints, options) => {
|
|
2366
|
+
try {
|
|
2367
|
+
if (options.port !== undefined) {
|
|
2368
|
+
const portValidation = validatePort(options.port);
|
|
2369
|
+
if (!portValidation.isValid) {
|
|
2370
|
+
reportValidationError(portValidation);
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
if (options.timeout !== undefined) {
|
|
2374
|
+
const timeoutValidation = validateTimeout(options.timeout);
|
|
2375
|
+
if (!timeoutValidation.isValid) {
|
|
2376
|
+
reportValidationError(timeoutValidation);
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
console.log("Building STX files...");
|
|
2380
|
+
let entrypointArray = [];
|
|
2381
|
+
if (typeof entrypoints === "string") {
|
|
2382
|
+
entrypointArray = [entrypoints];
|
|
2383
|
+
} else if (Array.isArray(entrypoints)) {
|
|
2384
|
+
entrypointArray = entrypoints;
|
|
2385
|
+
} else {
|
|
2386
|
+
entrypointArray = [];
|
|
2387
|
+
}
|
|
2388
|
+
if (entrypointArray.length === 0) {
|
|
2389
|
+
console.error("Error: No entrypoints specified");
|
|
2390
|
+
process7.exit(1);
|
|
2391
|
+
}
|
|
2392
|
+
for (const entrypoint of entrypointArray) {
|
|
2393
|
+
if (!isGlob(entrypoint)) {
|
|
2394
|
+
const fileValidation = validateFileExists(entrypoint);
|
|
2395
|
+
if (!fileValidation.isValid) {
|
|
2396
|
+
console.error("\u274C File not found");
|
|
2397
|
+
if (fileValidation.suggestion) {
|
|
2398
|
+
console.error(`\uD83D\uDCA1 suggestion: ${fileValidation.suggestion}`);
|
|
2399
|
+
}
|
|
2400
|
+
process7.exit(1);
|
|
2401
|
+
}
|
|
2402
|
+
if (!entrypoint.endsWith(".stx")) {
|
|
2403
|
+
console.error("\u274C File must have .stx extension");
|
|
2404
|
+
console.error("\uD83D\uDCA1 suggestion: Only .stx files can be built");
|
|
2405
|
+
process7.exit(1);
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
const tempDir = path.join(process7.cwd(), ".stx-build-temp");
|
|
2410
|
+
const outputDir = path.resolve(options.outdir);
|
|
2411
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
2412
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
2413
|
+
const expandedFiles = [];
|
|
2414
|
+
for (const entrypoint of entrypointArray) {
|
|
2415
|
+
if (isGlob(entrypoint)) {
|
|
2416
|
+
console.log(`Expanding glob pattern: ${entrypoint}`);
|
|
2417
|
+
try {
|
|
2418
|
+
const matchedFiles = await Array.fromAsync(new Bun.Glob(entrypoint).scan({
|
|
2419
|
+
onlyFiles: true,
|
|
2420
|
+
absolute: false
|
|
2421
|
+
}));
|
|
2422
|
+
const stxFiles = entrypoint.endsWith(".stx") ? matchedFiles : matchedFiles.filter((file) => file.endsWith(".stx"));
|
|
2423
|
+
if (stxFiles.length === 0) {
|
|
2424
|
+
console.warn(`Warning: No .stx files found matching pattern: ${entrypoint}`);
|
|
2425
|
+
} else {
|
|
2426
|
+
console.log(`Found ${stxFiles.length} STX ${stxFiles.length === 1 ? "file" : "files"} matching ${entrypoint}`);
|
|
2427
|
+
expandedFiles.push(...stxFiles);
|
|
2428
|
+
}
|
|
2429
|
+
} catch (error) {
|
|
2430
|
+
console.error(`Error expanding glob pattern ${entrypoint}:`, error);
|
|
2431
|
+
process7.exit(1);
|
|
2432
|
+
}
|
|
2433
|
+
} else if (entrypoint.endsWith(".stx")) {
|
|
2434
|
+
expandedFiles.push(entrypoint);
|
|
2435
|
+
} else {
|
|
2436
|
+
console.warn(`Warning: Skipping non-STX file: ${entrypoint}`);
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
if (expandedFiles.length === 0) {
|
|
2440
|
+
console.error("Error: No valid .stx files found to build");
|
|
2441
|
+
process7.exit(1);
|
|
2442
|
+
}
|
|
2443
|
+
console.log(`Building ${expandedFiles.length} STX ${expandedFiles.length === 1 ? "file" : "files"}...`);
|
|
2444
|
+
const results = [];
|
|
2445
|
+
let successCount = 0;
|
|
2446
|
+
for (const file of expandedFiles) {
|
|
2447
|
+
const absolutePath = path.resolve(file);
|
|
2448
|
+
const relativePath = path.relative(process7.cwd(), absolutePath);
|
|
2449
|
+
if (options.verbose) {
|
|
2450
|
+
console.log(`Processing: ${relativePath}`);
|
|
2451
|
+
}
|
|
2452
|
+
try {
|
|
2453
|
+
const buildResult = await Bun.build({
|
|
2454
|
+
entrypoints: [absolutePath],
|
|
2455
|
+
outdir: tempDir,
|
|
2456
|
+
plugins: [plugin],
|
|
2457
|
+
target: options.target || "browser",
|
|
2458
|
+
format: options.format || "esm",
|
|
2459
|
+
minify: options.minify !== false,
|
|
2460
|
+
sourcemap: options.sourcemap || "none",
|
|
2461
|
+
splitting: options.splitting !== false,
|
|
2462
|
+
define: {
|
|
2463
|
+
"process.env.NODE_ENV": '"production"'
|
|
2464
|
+
}
|
|
2465
|
+
});
|
|
2466
|
+
if (!buildResult.success) {
|
|
2467
|
+
console.error(`Build failed for ${relativePath}:`, buildResult.logs);
|
|
2468
|
+
continue;
|
|
2469
|
+
}
|
|
2470
|
+
const htmlOutput = buildResult.outputs.find((o) => o.path.endsWith(".html"));
|
|
2471
|
+
const jsOutputs = buildResult.outputs.filter((o) => o.path.endsWith(".js"));
|
|
2472
|
+
const otherOutputs = buildResult.outputs.filter((o) => !o.path.endsWith(".html") && !o.path.endsWith(".js"));
|
|
2473
|
+
const result = {
|
|
2474
|
+
inputFile: relativePath,
|
|
2475
|
+
otherOutputs: otherOutputs.map((o) => o.path)
|
|
2476
|
+
};
|
|
2477
|
+
if (htmlOutput) {
|
|
2478
|
+
result.outputHtml = htmlOutput.path;
|
|
2479
|
+
const htmlContent = await Bun.file(htmlOutput.path).text();
|
|
2480
|
+
const scriptMatches = htmlContent.match(/<script[^>]*src="([^"]+)"[^>]*><\/script>/g) || [];
|
|
2481
|
+
const scriptSources = scriptMatches.map((script) => {
|
|
2482
|
+
const srcMatch = script.match(/src="([^"]+)"/);
|
|
2483
|
+
return srcMatch ? srcMatch[1] : null;
|
|
2484
|
+
}).filter((src) => src !== null).filter((src) => src.includes("chunk-"));
|
|
2485
|
+
if (options.verbose && scriptSources.length > 0) {
|
|
2486
|
+
console.log(` Script references found in HTML: ${scriptSources.join(", ")}`);
|
|
2487
|
+
}
|
|
2488
|
+
result.scriptSources = scriptSources;
|
|
2489
|
+
try {
|
|
2490
|
+
const originalContent = await Bun.file(absolutePath).text();
|
|
2491
|
+
const scriptMatch = originalContent.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);
|
|
2492
|
+
if (scriptMatch) {
|
|
2493
|
+
const scriptContent = scriptMatch[1];
|
|
2494
|
+
try {
|
|
2495
|
+
const evalFn = new Function(`${scriptContent}
|
|
2496
|
+
// Return all variables defined in this scope
|
|
2497
|
+
return {
|
|
2498
|
+
name: typeof name !== 'undefined' ? name : undefined,
|
|
2499
|
+
items: typeof items !== 'undefined' ? items : undefined,
|
|
2500
|
+
count: typeof count !== 'undefined' ? count : undefined
|
|
2501
|
+
};
|
|
2502
|
+
`);
|
|
2503
|
+
const context = evalFn();
|
|
2504
|
+
if (options.verbose) {
|
|
2505
|
+
console.log(` Extracted variables:`, Object.keys(context).filter((k) => context[k] !== undefined));
|
|
2506
|
+
}
|
|
2507
|
+
let processedHtml = htmlContent;
|
|
2508
|
+
const itemsMapRegex = /\{items\.map\(item\s*=>\s*`[\s\S]*?<li>\{item\}<\/li>[\s\S]*?`\)\.join\(['"]*\)\}/g;
|
|
2509
|
+
processedHtml = processedHtml.replace(itemsMapRegex, () => {
|
|
2510
|
+
try {
|
|
2511
|
+
if (!context.items || !Array.isArray(context.items)) {
|
|
2512
|
+
if (options.verbose) {
|
|
2513
|
+
console.warn(" Warning: items is not an array in context");
|
|
2514
|
+
}
|
|
2515
|
+
return "<!-- Error: items not found -->";
|
|
2516
|
+
}
|
|
2517
|
+
const renderedItems = context.items.map((item) => `
|
|
2518
|
+
<li>${item}</li>
|
|
2519
|
+
`).join("");
|
|
2520
|
+
if (options.verbose) {
|
|
2521
|
+
console.log(` Rendered items.map() with ${context.items.length} items`);
|
|
2522
|
+
}
|
|
2523
|
+
return renderedItems;
|
|
2524
|
+
} catch (err) {
|
|
2525
|
+
if (options.verbose) {
|
|
2526
|
+
console.warn(` Warning: Failed to render items.map(): ${err}`);
|
|
2527
|
+
}
|
|
2528
|
+
return "<!-- Error rendering items -->";
|
|
2529
|
+
}
|
|
2530
|
+
});
|
|
2531
|
+
processedHtml = processedHtml.replace(/\{([^{}]+)\}/g, (match, expr) => {
|
|
2532
|
+
if (expr.includes(".map(") || expr.includes(".join(")) {
|
|
2533
|
+
return match;
|
|
2534
|
+
}
|
|
2535
|
+
try {
|
|
2536
|
+
if (expr.trim() in context) {
|
|
2537
|
+
return String(context[expr.trim()]);
|
|
2538
|
+
}
|
|
2539
|
+
return match;
|
|
2540
|
+
} catch (err) {
|
|
2541
|
+
if (options.verbose) {
|
|
2542
|
+
console.warn(` Warning: Error processing expression ${expr}: ${err}`);
|
|
2543
|
+
}
|
|
2544
|
+
return match;
|
|
2545
|
+
}
|
|
2546
|
+
});
|
|
2547
|
+
await Bun.write(htmlOutput.path, processedHtml);
|
|
2548
|
+
if (options.verbose) {
|
|
2549
|
+
console.log(` Processed expressions in HTML output`);
|
|
2550
|
+
}
|
|
2551
|
+
} catch (scriptError) {
|
|
2552
|
+
if (options.verbose) {
|
|
2553
|
+
console.warn(` Warning: Could not extract variables from script: ${scriptError}`);
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
} catch (processError) {
|
|
2558
|
+
if (options.verbose) {
|
|
2559
|
+
console.warn(` Warning: Could not process expressions in HTML: ${processError}`);
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
if (jsOutputs.length > 0) {
|
|
2564
|
+
result.outputJs = jsOutputs[0].path;
|
|
2565
|
+
}
|
|
2566
|
+
if (!htmlOutput) {
|
|
2567
|
+
console.warn(`Warning: No HTML output generated for ${relativePath}`);
|
|
2568
|
+
}
|
|
2569
|
+
results.push(result);
|
|
2570
|
+
successCount++;
|
|
2571
|
+
if (options.verbose) {
|
|
2572
|
+
console.log(` Success: ${relativePath}`);
|
|
2573
|
+
if (htmlOutput)
|
|
2574
|
+
console.log(` HTML: ${path.basename(htmlOutput.path)}`);
|
|
2575
|
+
if (jsOutputs.length > 0)
|
|
2576
|
+
console.log(` JS: ${jsOutputs.map((o) => path.basename(o.path)).join(", ")}`);
|
|
2577
|
+
if (otherOutputs.length > 0)
|
|
2578
|
+
console.log(` Other: ${otherOutputs.length} file(s)`);
|
|
2579
|
+
}
|
|
2580
|
+
} catch (error) {
|
|
2581
|
+
console.error(`Error building ${relativePath}:`, error);
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
if (successCount === 0) {
|
|
2585
|
+
console.error("Error: No files were successfully built");
|
|
2586
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
2587
|
+
process7.exit(1);
|
|
2588
|
+
}
|
|
2589
|
+
console.log(`Copying output files to ${outputDir}...`);
|
|
2590
|
+
let copiedFilesCount = 0;
|
|
2591
|
+
for (const result of results) {
|
|
2592
|
+
const inputDir = path.dirname(result.inputFile);
|
|
2593
|
+
const baseName = path.basename(result.inputFile, ".stx");
|
|
2594
|
+
const targetDir = path.join(outputDir, inputDir);
|
|
2595
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
2596
|
+
if (result.outputHtml) {
|
|
2597
|
+
const htmlContent = await Bun.file(result.outputHtml).text();
|
|
2598
|
+
const targetHtmlPath = path.join(targetDir, `${baseName}.html`);
|
|
2599
|
+
const scriptRegex = /<script[^>]*src="([^"]+)"[^>]*><\/script>/g;
|
|
2600
|
+
const matches = [...htmlContent.matchAll(scriptRegex)];
|
|
2601
|
+
const scriptSrcs = matches.map((match) => match[1]);
|
|
2602
|
+
const chunksToCopy = new Map;
|
|
2603
|
+
for (const src of scriptSrcs) {
|
|
2604
|
+
if (src.startsWith("./") && src.includes("chunk-")) {
|
|
2605
|
+
const srcFileName = path.basename(src);
|
|
2606
|
+
const tempChunkPath = path.join(path.dirname(result.outputHtml), srcFileName);
|
|
2607
|
+
if (fs.existsSync(tempChunkPath)) {
|
|
2608
|
+
chunksToCopy.set(srcFileName, tempChunkPath);
|
|
2609
|
+
} else if (options.verbose) {
|
|
2610
|
+
console.warn(` Warning: Referenced chunk file not found: ${tempChunkPath}`);
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
if (chunksToCopy.size > 0) {
|
|
2615
|
+
fs.copyFileSync(result.outputHtml, targetHtmlPath);
|
|
2616
|
+
for (const [chunkName, chunkPath] of chunksToCopy.entries()) {
|
|
2617
|
+
const targetChunkPath = path.join(targetDir, chunkName);
|
|
2618
|
+
fs.copyFileSync(chunkPath, targetChunkPath);
|
|
2619
|
+
copiedFilesCount++;
|
|
2620
|
+
if (options.verbose) {
|
|
2621
|
+
console.log(` Copied chunk: ${path.relative(outputDir, targetChunkPath)}`);
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
} else {
|
|
2625
|
+
fs.copyFileSync(result.outputHtml, targetHtmlPath);
|
|
2626
|
+
}
|
|
2627
|
+
copiedFilesCount++;
|
|
2628
|
+
}
|
|
2629
|
+
if (result.outputJs) {
|
|
2630
|
+
const targetJsPath = path.join(targetDir, `${baseName}.js`);
|
|
2631
|
+
fs.copyFileSync(result.outputJs, targetJsPath);
|
|
2632
|
+
copiedFilesCount++;
|
|
2633
|
+
}
|
|
2634
|
+
for (const otherPath of result.otherOutputs) {
|
|
2635
|
+
const otherName = path.basename(otherPath);
|
|
2636
|
+
const targetOtherPath = path.join(targetDir, otherName);
|
|
2637
|
+
fs.copyFileSync(otherPath, targetOtherPath);
|
|
2638
|
+
copiedFilesCount++;
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
try {
|
|
2642
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
2643
|
+
} catch {
|
|
2644
|
+
console.warn("Warning: Failed to clean up temporary directory");
|
|
2645
|
+
}
|
|
2646
|
+
console.log(`\u2713 Build successful! Built ${successCount} STX ${successCount === 1 ? "file" : "files"} with ${copiedFilesCount} output ${copiedFilesCount === 1 ? "file" : "files"}`);
|
|
2647
|
+
let totalChunkCount = 0;
|
|
2648
|
+
if (results.length > 0 && results.length <= 10) {
|
|
2649
|
+
console.log(`
|
|
2650
|
+
Generated files:`);
|
|
2651
|
+
for (const result of results) {
|
|
2652
|
+
const inputDir = path.dirname(result.inputFile);
|
|
2653
|
+
const baseName = path.basename(result.inputFile, ".stx");
|
|
2654
|
+
console.log(` ${result.inputFile} \u2192`);
|
|
2655
|
+
if (result.outputHtml) {
|
|
2656
|
+
console.log(` HTML: ${path.join(options.outdir, inputDir, `${baseName}.html`)}`);
|
|
2657
|
+
}
|
|
2658
|
+
if (result.outputJs) {
|
|
2659
|
+
console.log(` JS: ${path.join(options.outdir, inputDir, `${baseName}.js`)}`);
|
|
2660
|
+
}
|
|
2661
|
+
if (result.scriptSources && result.scriptSources.length > 0) {
|
|
2662
|
+
totalChunkCount += result.scriptSources.length;
|
|
2663
|
+
console.log(` Chunks: ${result.scriptSources.length} chunk file(s)`);
|
|
2664
|
+
if (options.verbose) {
|
|
2665
|
+
for (const src of result.scriptSources) {
|
|
2666
|
+
const chunkName = path.basename(src);
|
|
2667
|
+
console.log(` - ${path.join(inputDir, chunkName)}`);
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
console.log(`
|
|
2674
|
+
To view these files, you can use a local HTTP server:`);
|
|
2675
|
+
console.log(` cd ${options.outdir} && npx serve`);
|
|
2676
|
+
if (totalChunkCount > 0) {
|
|
2677
|
+
console.log(`
|
|
2678
|
+
Note: The build includes JavaScript chunks that need to be served over HTTP for proper functioning.`);
|
|
2679
|
+
console.log(`Opening the HTML files directly may not work correctly due to browser security restrictions.`);
|
|
2680
|
+
}
|
|
2681
|
+
if (options.watch) {
|
|
2682
|
+
console.log(`
|
|
2683
|
+
Watch mode enabled. Waiting for changes...`);
|
|
2684
|
+
const watchDirs = new Set(expandedFiles.map((file) => path.dirname(path.resolve(file))));
|
|
2685
|
+
for (const dir of watchDirs) {
|
|
2686
|
+
fs.watch(dir, { recursive: true }, async (eventType, filename) => {
|
|
2687
|
+
if (!filename)
|
|
2688
|
+
return;
|
|
2689
|
+
if (filename.endsWith(".stx") || filename.endsWith(".js") || filename.endsWith(".ts")) {
|
|
2690
|
+
console.log(`
|
|
2691
|
+
File changed: ${filename}, rebuilding...`);
|
|
2692
|
+
const changedFile = path.join(dir, filename);
|
|
2693
|
+
const relativeChanged = path.relative(process7.cwd(), changedFile);
|
|
2694
|
+
const filesToRebuild = filename.endsWith(".stx") ? [relativeChanged] : expandedFiles.filter((f) => {
|
|
2695
|
+
const fileDir = path.dirname(path.resolve(f));
|
|
2696
|
+
return fileDir === dir;
|
|
2697
|
+
});
|
|
2698
|
+
if (filesToRebuild.length === 0) {
|
|
2699
|
+
console.log("No STX files to rebuild");
|
|
2700
|
+
return;
|
|
2701
|
+
}
|
|
2702
|
+
console.log(`Rebuilding ${filesToRebuild.length} file(s)...`);
|
|
2703
|
+
for (const file of filesToRebuild) {
|
|
2704
|
+
try {
|
|
2705
|
+
const absolutePath = path.resolve(file);
|
|
2706
|
+
const buildResult = await Bun.build({
|
|
2707
|
+
entrypoints: [absolutePath],
|
|
2708
|
+
outdir: options.outdir,
|
|
2709
|
+
plugins: [plugin],
|
|
2710
|
+
target: options.target || "browser",
|
|
2711
|
+
format: options.format || "esm",
|
|
2712
|
+
minify: options.minify !== false,
|
|
2713
|
+
sourcemap: options.sourcemap || "none",
|
|
2714
|
+
splitting: options.splitting !== false,
|
|
2715
|
+
define: {
|
|
2716
|
+
"process.env.NODE_ENV": '"production"'
|
|
2717
|
+
}
|
|
2718
|
+
});
|
|
2719
|
+
if (buildResult.success) {
|
|
2720
|
+
console.log(` \u2713 Rebuilt ${file}`);
|
|
2721
|
+
} else {
|
|
2722
|
+
console.error(` \u2717 Failed to rebuild ${file}`);
|
|
2723
|
+
}
|
|
2724
|
+
} catch (error) {
|
|
2725
|
+
console.error(`Error rebuilding ${file}:`, error);
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
console.log("Rebuild complete");
|
|
2729
|
+
}
|
|
2730
|
+
});
|
|
2731
|
+
}
|
|
2732
|
+
console.log(`Watching ${watchDirs.size} ${watchDirs.size === 1 ? "directory" : "directories"} for changes...`);
|
|
2733
|
+
console.log("Press Ctrl+C to stop");
|
|
2734
|
+
}
|
|
2735
|
+
} catch (error) {
|
|
2736
|
+
console.error("Build failed:", error instanceof Error ? error.message : String(error));
|
|
2737
|
+
process7.exit(1);
|
|
2738
|
+
}
|
|
2739
|
+
});
|
|
2740
|
+
cli.command("test [patterns...]", "Run tests with Bun test runner and browser environment").option("--watch", "Watch for changes and rerun tests").option("--filter <pattern>", "Only run tests matching the given pattern").option("--reporter <reporter>", "Test reporter to use: default or junit (junit requires Bun v1.0+)", { default: "default" }).option("--timeout <ms>", "Test timeout in milliseconds", { default: 5000 }).option("--coverage", "Enable code coverage").option("--ui", "Coming soon").option("--verbose", "Show verbose output including test command").example("stx test").example("stx test packages/stx/test/").example("stx test **/*.test.ts --verbose").example('stx test --filter "should process"').example("stx test --watch --verbose").example("stx test --reporter junit").action(async (patterns, options) => {
|
|
2741
|
+
try {
|
|
2742
|
+
console.log(`\x1B[1mstx test\x1B[0m \x1B[2mv${version} (${gitHash})\x1B[0m`);
|
|
2743
|
+
if (options.timeout) {
|
|
2744
|
+
const timeoutValidation = validateTimeout(options.timeout);
|
|
2745
|
+
if (!timeoutValidation.isValid) {
|
|
2746
|
+
reportValidationError(timeoutValidation);
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
const patternArray = typeof patterns === "string" ? [patterns] : patterns || [];
|
|
2750
|
+
if (patternArray.length === 0) {
|
|
2751
|
+
patternArray.push("**/*.test.ts", "**/*.test.js", "**/*.spec.ts", "**/*.spec.js");
|
|
2752
|
+
}
|
|
2753
|
+
if (options.verbose) {
|
|
2754
|
+
console.log("Test patterns:", patternArray);
|
|
2755
|
+
console.log("Options:", JSON.stringify({
|
|
2756
|
+
watch: options.watch || false,
|
|
2757
|
+
filter: options.filter || "none",
|
|
2758
|
+
reporter: options.reporter || "default",
|
|
2759
|
+
timeout: options.timeout || 5000,
|
|
2760
|
+
coverage: options.coverage || false,
|
|
2761
|
+
ui: options.ui || false
|
|
2762
|
+
}, null, 2));
|
|
2763
|
+
}
|
|
2764
|
+
const success = await performanceMonitor.timeAsync("test-execution", () => runTests(patternArray, options));
|
|
2765
|
+
if (!success && !options.watch) {
|
|
2766
|
+
process7.exit(1);
|
|
2767
|
+
}
|
|
2768
|
+
} catch (error) {
|
|
2769
|
+
console.error("Error running tests:", error);
|
|
2770
|
+
process7.exit(1);
|
|
2771
|
+
}
|
|
2772
|
+
});
|
|
2773
|
+
cli.command("init [file]", "Create a new STX file").alias("new").option("--force", "Overwrite existing file").option("--template <file>", "Path to a template file to use as a base").example("stx init").example("stx init page.stx").example("stx new contact.stx").example("stx new components/button.stx --template examples/components/button.stx").action(async (file = "index.stx", options) => {
|
|
2774
|
+
try {
|
|
2775
|
+
const success = await initFile(file, {
|
|
2776
|
+
force: options.force,
|
|
2777
|
+
template: options.template
|
|
2778
|
+
});
|
|
2779
|
+
if (success) {
|
|
2780
|
+
console.log(`
|
|
2781
|
+
\u2728 Successfully created file: ${file}`);
|
|
2782
|
+
console.log(`
|
|
2783
|
+
To view it in the development server:`);
|
|
2784
|
+
console.log(` stx dev ${file}
|
|
2785
|
+
`);
|
|
2786
|
+
} else {
|
|
2787
|
+
console.error(`
|
|
2788
|
+
\u274C Failed to create file: ${file}`);
|
|
2789
|
+
process7.exit(1);
|
|
2790
|
+
}
|
|
2791
|
+
} catch (error) {
|
|
2792
|
+
console.error("Error creating file:", error);
|
|
2793
|
+
process7.exit(1);
|
|
2794
|
+
}
|
|
2795
|
+
});
|
|
2796
|
+
cli.command("format [patterns...]", "Format STX files automatically").option("--check", "Check if files are formatted (exit with error if not)").option("--write", "Write formatted files back to disk (default)").option("--diff", "Show diff of changes that would be made").option("--ignore <patterns>", "Comma-separated patterns to ignore").example("stx format").example("stx format **/*.stx").example("stx format --check").example("stx format --diff --ignore node_modules/**").action(async (patterns, options) => {
|
|
2797
|
+
try {
|
|
2798
|
+
if (options.check && options.write) {
|
|
2799
|
+
console.error("\u274C Options --check and --write are mutually exclusive");
|
|
2800
|
+
console.error("\uD83D\uDCA1 Use --check to verify formatting or --write to apply changes, but not both");
|
|
2801
|
+
process7.exit(1);
|
|
2802
|
+
}
|
|
2803
|
+
const patternArray = patterns && patterns.length > 0 ? patterns : ["**/*.stx"];
|
|
2804
|
+
const ignorePatterns = options.ignore ? options.ignore.split(",").map((p) => p.trim()) : [];
|
|
2805
|
+
let allFiles = [];
|
|
2806
|
+
for (const pattern of patternArray) {
|
|
2807
|
+
const files = await Array.fromAsync(new Bun.Glob(pattern).scan({ onlyFiles: true, absolute: true }));
|
|
2808
|
+
allFiles.push(...files.filter((f) => f.endsWith(".stx")));
|
|
2809
|
+
}
|
|
2810
|
+
allFiles = allFiles.filter((file) => {
|
|
2811
|
+
return !ignorePatterns.some((ignore) => file.includes(ignore));
|
|
2812
|
+
});
|
|
2813
|
+
if (allFiles.length === 0) {
|
|
2814
|
+
console.log("No STX files found to format.");
|
|
2815
|
+
return;
|
|
2816
|
+
}
|
|
2817
|
+
console.log(`Formatting ${allFiles.length} STX files...`);
|
|
2818
|
+
let formattedCount = 0;
|
|
2819
|
+
let errorCount = 0;
|
|
2820
|
+
for (const file of allFiles) {
|
|
2821
|
+
try {
|
|
2822
|
+
const content = await Bun.file(file).text();
|
|
2823
|
+
const formatted = formatStxContent(content);
|
|
2824
|
+
if (content !== formatted) {
|
|
2825
|
+
if (options.check) {
|
|
2826
|
+
console.log(`\u274C ${path.relative(process7.cwd(), file)} needs formatting`);
|
|
2827
|
+
errorCount++;
|
|
2828
|
+
} else if (options.diff) {
|
|
2829
|
+
console.log(`
|
|
2830
|
+
\uD83D\uDCDD ${path.relative(process7.cwd(), file)}:`);
|
|
2831
|
+
console.log("--- Original");
|
|
2832
|
+
console.log("+++ Formatted");
|
|
2833
|
+
console.log(`@@ Changes in ${path.basename(file)} @@`);
|
|
2834
|
+
console.log("+ Formatted content would be applied");
|
|
2835
|
+
} else {
|
|
2836
|
+
await Bun.write(file, formatted);
|
|
2837
|
+
console.log(`\u2705 Formatted ${path.relative(process7.cwd(), file)}`);
|
|
2838
|
+
formattedCount++;
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
} catch (error) {
|
|
2842
|
+
console.error(`\u274C Error formatting ${path.relative(process7.cwd(), file)}:`, error);
|
|
2843
|
+
errorCount++;
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
if (options.check && errorCount > 0) {
|
|
2847
|
+
console.log(`
|
|
2848
|
+
${errorCount} files need formatting. Run 'stx format' to fix.`);
|
|
2849
|
+
process7.exit(1);
|
|
2850
|
+
} else if (!options.check && !options.diff) {
|
|
2851
|
+
console.log(`\u2728 Formatted ${formattedCount} files successfully`);
|
|
2852
|
+
}
|
|
2853
|
+
} catch (error) {
|
|
2854
|
+
console.error("Error formatting files:", error);
|
|
2855
|
+
process7.exit(1);
|
|
2856
|
+
}
|
|
2857
|
+
});
|
|
2858
|
+
cli.command("perf [command...]", "Show performance statistics for STX operations").option("--clear", "Clear performance statistics").option("--json", "Output as JSON").example("stx perf").example("stx perf --clear").example("stx perf --json").action(async (command, options) => {
|
|
2859
|
+
try {
|
|
2860
|
+
if (options.clear) {
|
|
2861
|
+
performanceMonitor.clear();
|
|
2862
|
+
console.log("\u2705 Performance statistics cleared");
|
|
2863
|
+
return;
|
|
2864
|
+
}
|
|
2865
|
+
const stats = performanceMonitor.getStats();
|
|
2866
|
+
if (Object.keys(stats).length === 0) {
|
|
2867
|
+
if (options.json) {
|
|
2868
|
+
console.log(JSON.stringify({}, null, 2));
|
|
2869
|
+
return;
|
|
2870
|
+
}
|
|
2871
|
+
console.log("No performance data available. Run some STX commands first.");
|
|
2872
|
+
return;
|
|
2873
|
+
}
|
|
2874
|
+
if (options.json) {
|
|
2875
|
+
console.log(JSON.stringify(stats, null, 2));
|
|
2876
|
+
} else {
|
|
2877
|
+
console.log(`
|
|
2878
|
+
\uD83D\uDCCA STX Performance Statistics
|
|
2879
|
+
`);
|
|
2880
|
+
for (const [operation, metrics] of Object.entries(stats)) {
|
|
2881
|
+
console.log(`\uD83D\uDD27 ${operation}:`);
|
|
2882
|
+
console.log(` Count: ${metrics.count}`);
|
|
2883
|
+
console.log(` Average: ${metrics.avgTime.toFixed(2)}ms`);
|
|
2884
|
+
console.log(` Total: ${metrics.totalTime.toFixed(2)}ms`);
|
|
2885
|
+
console.log(` Min: ${metrics.minTime.toFixed(2)}ms`);
|
|
2886
|
+
console.log(` Max: ${metrics.maxTime.toFixed(2)}ms`);
|
|
2887
|
+
console.log("");
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
} catch (error) {
|
|
2891
|
+
console.error("Error showing performance stats:", error);
|
|
2892
|
+
process7.exit(1);
|
|
2893
|
+
}
|
|
2894
|
+
});
|
|
2895
|
+
cli.command("debug <file>", "Debug STX template processing step by step").option("--step", "Step through processing stages interactively").option("--verbose", "Show detailed processing information").option("--context <data>", "JSON string of context data to use").option("--save-report <file>", "Save debug report to file").example("stx debug template.stx").example("stx debug template.stx --step").example(`stx debug template.stx --context '{"name": "John", "items": [1,2,3]}'`).action(async (file, options) => {
|
|
2896
|
+
try {
|
|
2897
|
+
const fileValidation = validateFileExists(file);
|
|
2898
|
+
if (!fileValidation.isValid) {
|
|
2899
|
+
reportValidationError(fileValidation);
|
|
2900
|
+
}
|
|
2901
|
+
console.log(`\uD83D\uDD0D Debugging stx template: ${file}
|
|
2902
|
+
`);
|
|
2903
|
+
let context = {};
|
|
2904
|
+
if (options.context) {
|
|
2905
|
+
try {
|
|
2906
|
+
context = JSON.parse(options.context);
|
|
2907
|
+
} catch (error) {
|
|
2908
|
+
console.error("\u274C Invalid JSON in --context option");
|
|
2909
|
+
process7.exit(1);
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
const content = await Bun.file(file).text();
|
|
2913
|
+
console.log(`\uD83D\uDCC4 Template Content (${content.length} chars):`);
|
|
2914
|
+
console.log("\u2500".repeat(50));
|
|
2915
|
+
console.log(content.substring(0, 500) + (content.length > 500 ? `
|
|
2916
|
+
...
|
|
2917
|
+
` : ""));
|
|
2918
|
+
console.log("\u2500".repeat(50));
|
|
2919
|
+
const scriptMatch = content.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);
|
|
2920
|
+
if (scriptMatch) {
|
|
2921
|
+
console.log(`
|
|
2922
|
+
\uD83D\uDCDC Script Section Found:`);
|
|
2923
|
+
console.log("\u2500".repeat(30));
|
|
2924
|
+
console.log(scriptMatch[1].trim());
|
|
2925
|
+
console.log("\u2500".repeat(30));
|
|
2926
|
+
}
|
|
2927
|
+
console.log(`
|
|
2928
|
+
\uD83D\uDCCA Processing Context:`);
|
|
2929
|
+
console.log(JSON.stringify(context, null, 2));
|
|
2930
|
+
if (options.step) {
|
|
2931
|
+
console.log(`
|
|
2932
|
+
\u26A0\uFE0F Interactive step-through not yet implemented. Use --verbose for detailed output.`);
|
|
2933
|
+
}
|
|
2934
|
+
if (options.verbose) {
|
|
2935
|
+
console.log(`
|
|
2936
|
+
\uD83D\uDD27 Verbose processing information will be shown during template processing.`);
|
|
2937
|
+
}
|
|
2938
|
+
console.log(`
|
|
2939
|
+
\u2728 Debug analysis complete. Full step-by-step debugging coming soon!`);
|
|
2940
|
+
if (options.saveReport) {
|
|
2941
|
+
const report = {
|
|
2942
|
+
file,
|
|
2943
|
+
timestamp: new Date().toISOString(),
|
|
2944
|
+
templateLength: content.length,
|
|
2945
|
+
hasScript: !!scriptMatch,
|
|
2946
|
+
context
|
|
2947
|
+
};
|
|
2948
|
+
await Bun.write(options.saveReport, JSON.stringify(report, null, 2));
|
|
2949
|
+
console.log(`\uD83D\uDCCB Debug report saved to: ${options.saveReport}`);
|
|
2950
|
+
}
|
|
2951
|
+
} catch (error) {
|
|
2952
|
+
console.error("Error debugging template:", error);
|
|
2953
|
+
process7.exit(1);
|
|
2954
|
+
}
|
|
2955
|
+
});
|
|
2956
|
+
cli.command("status [directory]", "Show status of STX project and files").option("--verbose", "Show detailed information").option("--json", "Output as JSON").example("stx status").example("stx status ./src --verbose").action(async (directory = ".", options) => {
|
|
2957
|
+
try {
|
|
2958
|
+
const projectRoot = path.resolve(directory);
|
|
2959
|
+
const configPath = path.join(projectRoot, "stx.config.ts");
|
|
2960
|
+
const packageJsonPath = path.join(projectRoot, "package.json");
|
|
2961
|
+
const stxFiles = await Array.fromAsync(new Bun.Glob("**/*.stx").scan({
|
|
2962
|
+
cwd: projectRoot,
|
|
2963
|
+
onlyFiles: true,
|
|
2964
|
+
absolute: true
|
|
2965
|
+
}));
|
|
2966
|
+
const mdFiles = await Array.fromAsync(new Bun.Glob("**/*.md").scan({
|
|
2967
|
+
cwd: projectRoot,
|
|
2968
|
+
onlyFiles: true,
|
|
2969
|
+
absolute: true
|
|
2970
|
+
}));
|
|
2971
|
+
const status = {
|
|
2972
|
+
projectRoot,
|
|
2973
|
+
hasConfig: fs.existsSync(configPath),
|
|
2974
|
+
hasPackageJson: fs.existsSync(packageJsonPath),
|
|
2975
|
+
stxFiles: stxFiles.length,
|
|
2976
|
+
markdownFiles: mdFiles.length,
|
|
2977
|
+
totalFiles: stxFiles.length + mdFiles.length
|
|
2978
|
+
};
|
|
2979
|
+
if (options.verbose) {
|
|
2980
|
+
status.stxFileList = stxFiles.map((f) => path.relative(projectRoot, f));
|
|
2981
|
+
status.markdownFileList = mdFiles.map((f) => path.relative(projectRoot, f));
|
|
2982
|
+
}
|
|
2983
|
+
if (options.json) {
|
|
2984
|
+
console.log(JSON.stringify(status, null, 2));
|
|
2985
|
+
} else {
|
|
2986
|
+
console.log(`
|
|
2987
|
+
\uD83D\uDCCB stx Project Status
|
|
2988
|
+
`);
|
|
2989
|
+
console.log(`\uD83D\uDCC1 Project Root: ${projectRoot}`);
|
|
2990
|
+
console.log(`\u2699\uFE0F Config File: ${status.hasConfig ? "\u2705 Found" : "\u274C Not found"}`);
|
|
2991
|
+
console.log(`\uD83D\uDCE6 Package.json: ${status.hasPackageJson ? "\u2705 Found" : "\u274C Not found"}`);
|
|
2992
|
+
console.log(`\uD83D\uDCC4 stx Files: ${status.stxFiles}`);
|
|
2993
|
+
console.log(`\uD83D\uDCDD Markdown Files: ${status.markdownFiles}`);
|
|
2994
|
+
console.log(`\uD83D\uDCCA Total Files: ${status.totalFiles}`);
|
|
2995
|
+
if (options.verbose && stxFiles.length > 0) {
|
|
2996
|
+
console.log(`
|
|
2997
|
+
\uD83D\uDCC4 STX Files:`);
|
|
2998
|
+
stxFiles.forEach((file) => {
|
|
2999
|
+
console.log(` ${path.relative(projectRoot, file)}`);
|
|
3000
|
+
});
|
|
3001
|
+
}
|
|
3002
|
+
if (options.verbose && mdFiles.length > 0) {
|
|
3003
|
+
console.log(`
|
|
3004
|
+
\uD83D\uDCDD Markdown Files:`);
|
|
3005
|
+
mdFiles.forEach((file) => {
|
|
3006
|
+
console.log(` ${path.relative(projectRoot, file)}`);
|
|
3007
|
+
});
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
} catch (error) {
|
|
3011
|
+
console.error("Error getting project status:", error);
|
|
3012
|
+
process7.exit(1);
|
|
3013
|
+
}
|
|
3014
|
+
});
|
|
3015
|
+
cli.command("watch [patterns...]", "Watch STX files for changes and run commands").option("--command <cmd>", "Command to run on file changes", { default: "build" }).option("--ignore <patterns>", "Comma-separated patterns to ignore").option("--debounce <ms>", "Debounce delay before running command after change", { default: 300 }).option("--output <dir>", "Output directory for command results").option("--verbose", "Show detailed file change information").option("--clear", "Clear console before running command").example("stx watch").example('stx watch **/*.stx --command "stx build"').example('stx watch --ignore "node_modules/**,dist/**"').action(async (patterns, options) => {
|
|
3016
|
+
try {
|
|
3017
|
+
if (!patterns || patterns.length === 0) {
|
|
3018
|
+
console.error("\u274C Input file or pattern is required");
|
|
3019
|
+
console.error("\uD83D\uDCA1 Specify a file pattern to watch (e.g., stx watch *.stx)");
|
|
3020
|
+
process7.exit(1);
|
|
3021
|
+
}
|
|
3022
|
+
const watchPatterns = Array.isArray(patterns) ? patterns : [patterns];
|
|
3023
|
+
const ignorePatterns = options.ignore ? options.ignore.split(",").map((p) => p.trim()) : ["node_modules/**", "dist/**", ".git/**"];
|
|
3024
|
+
if (options.debounce !== undefined) {
|
|
3025
|
+
const debounceValidation = validateTimeout(options.debounce);
|
|
3026
|
+
if (!debounceValidation.isValid) {
|
|
3027
|
+
console.error("\u274C Debounce must be a valid number");
|
|
3028
|
+
console.error("\uD83D\uDCA1 Specify debounce in milliseconds (e.g., --debounce 300)");
|
|
3029
|
+
process7.exit(1);
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
if (options.output) {
|
|
3033
|
+
const upCount = (options.output.match(/\.\.\//g) || []).length;
|
|
3034
|
+
if (upCount >= 3) {
|
|
3035
|
+
console.error("\u274C Invalid output directory");
|
|
3036
|
+
console.error("\uD83D\uDCA1 Specify a valid output directory path");
|
|
3037
|
+
process7.exit(1);
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
3040
|
+
const debounce = options.debounce || 300;
|
|
3041
|
+
console.log(`\uD83D\uDC40 Watching files: ${watchPatterns.join(", ")}`);
|
|
3042
|
+
console.log(`\uD83D\uDEAB Ignoring: ${ignorePatterns.join(", ")}`);
|
|
3043
|
+
console.log(`\u23F1\uFE0F Debounce: ${debounce}ms`);
|
|
3044
|
+
console.log(`\uD83D\uDD27 Command: ${options.command}`);
|
|
3045
|
+
console.log(`
|
|
3046
|
+
Press Ctrl+C to stop watching...
|
|
3047
|
+
`);
|
|
3048
|
+
let timeoutId;
|
|
3049
|
+
let isRunning = false;
|
|
3050
|
+
const watchDirs = new Set;
|
|
3051
|
+
watchDirs.add(process7.cwd());
|
|
3052
|
+
for (const pattern of watchPatterns) {
|
|
3053
|
+
const files = await Array.fromAsync(new Bun.Glob(pattern).scan({ onlyFiles: true, absolute: true }));
|
|
3054
|
+
files.forEach((file) => {
|
|
3055
|
+
watchDirs.add(path.dirname(file));
|
|
3056
|
+
});
|
|
3057
|
+
}
|
|
3058
|
+
const runCommand = async () => {
|
|
3059
|
+
if (isRunning)
|
|
3060
|
+
return;
|
|
3061
|
+
isRunning = true;
|
|
3062
|
+
if (options.clear) {
|
|
3063
|
+
console.clear();
|
|
3064
|
+
}
|
|
3065
|
+
console.log(`\uD83D\uDD04 Running: ${options.command}`);
|
|
3066
|
+
const startTime = Date.now();
|
|
3067
|
+
try {
|
|
3068
|
+
const [command, ...args2] = options.command.split(" ");
|
|
3069
|
+
const result = spawn(command, args2, {
|
|
3070
|
+
stdio: "inherit",
|
|
3071
|
+
shell: true
|
|
3072
|
+
});
|
|
3073
|
+
result.on("close", (code) => {
|
|
3074
|
+
const duration = Date.now() - startTime;
|
|
3075
|
+
if (code === 0) {
|
|
3076
|
+
console.log(`\u2705 Command completed successfully in ${duration}ms`);
|
|
3077
|
+
} else {
|
|
3078
|
+
console.log(`\u274C Command failed with exit code ${code} after ${duration}ms`);
|
|
3079
|
+
}
|
|
3080
|
+
isRunning = false;
|
|
3081
|
+
});
|
|
3082
|
+
} catch (error) {
|
|
3083
|
+
console.error(`\u274C Error running command:`, error);
|
|
3084
|
+
isRunning = false;
|
|
3085
|
+
}
|
|
3086
|
+
};
|
|
3087
|
+
const handleFileChange = (eventType, filename) => {
|
|
3088
|
+
if (!filename)
|
|
3089
|
+
return;
|
|
3090
|
+
const shouldIgnore = ignorePatterns.some((pattern) => {
|
|
3091
|
+
if (pattern.includes("*")) {
|
|
3092
|
+
return filename.match(pattern.replace(/\*/g, ".*"));
|
|
3093
|
+
}
|
|
3094
|
+
return filename.includes(pattern);
|
|
3095
|
+
});
|
|
3096
|
+
if (shouldIgnore) {
|
|
3097
|
+
if (options.verbose) {
|
|
3098
|
+
console.log(`\uD83D\uDEAB Ignoring: ${filename}`);
|
|
3099
|
+
}
|
|
3100
|
+
return;
|
|
3101
|
+
}
|
|
3102
|
+
const shouldWatch = watchPatterns.some((pattern) => {
|
|
3103
|
+
if (pattern.includes("*")) {
|
|
3104
|
+
return filename.match(pattern.replace(/\*/g, ".*"));
|
|
3105
|
+
}
|
|
3106
|
+
return filename.endsWith(pattern);
|
|
3107
|
+
});
|
|
3108
|
+
if (!shouldWatch) {
|
|
3109
|
+
if (options.verbose) {
|
|
3110
|
+
console.log(`\u23ED\uFE0F Skipping: ${filename} (doesn't match patterns)`);
|
|
3111
|
+
}
|
|
3112
|
+
return;
|
|
3113
|
+
}
|
|
3114
|
+
if (options.verbose) {
|
|
3115
|
+
console.log(`\uD83D\uDCDD ${eventType.toUpperCase()}: ${filename}`);
|
|
3116
|
+
}
|
|
3117
|
+
if (timeoutId) {
|
|
3118
|
+
clearTimeout(timeoutId);
|
|
3119
|
+
}
|
|
3120
|
+
timeoutId = setTimeout(runCommand, debounce);
|
|
3121
|
+
};
|
|
3122
|
+
const watchers = [];
|
|
3123
|
+
for (const dir of watchDirs) {
|
|
3124
|
+
try {
|
|
3125
|
+
const watcher = fs.watch(dir, { recursive: true }, handleFileChange);
|
|
3126
|
+
watchers.push(watcher);
|
|
3127
|
+
if (options.verbose) {
|
|
3128
|
+
console.log(`\uD83D\uDCC1 Watching directory: ${dir}`);
|
|
3129
|
+
}
|
|
3130
|
+
} catch (error) {
|
|
3131
|
+
console.warn(`\u26A0\uFE0F Could not watch directory: ${dir}`);
|
|
3132
|
+
}
|
|
3133
|
+
}
|
|
3134
|
+
process7.on("SIGINT", () => {
|
|
3135
|
+
console.log(`
|
|
3136
|
+
\uD83D\uDED1 Stopping file watcher...`);
|
|
3137
|
+
watchers.forEach((watcher) => watcher.close());
|
|
3138
|
+
process7.exit(0);
|
|
3139
|
+
});
|
|
3140
|
+
} catch (error) {
|
|
3141
|
+
console.error("Error setting up file watcher:", error);
|
|
3142
|
+
process7.exit(1);
|
|
3143
|
+
}
|
|
3144
|
+
});
|
|
3145
|
+
cli.command("analyze [patterns...]", "Analyze STX templates for performance and best practices").option("--json", "Output results as JSON").option("--detailed", "Show detailed analysis for each file").option("--only-issues", "Only show files with issues").option("--save-report <file>", "Save analysis report to file").option("--threshold <level>", "Only show issues at or above this level (info, warning, error)", { default: "info" }).example("stx analyze").example("stx analyze **/*.stx --detailed").example("stx analyze --only-issues --threshold warning").action(async (patterns, options) => {
|
|
3146
|
+
try {
|
|
3147
|
+
const analysisPatterns = patterns && patterns.length > 0 ? patterns : ["**/*.stx"];
|
|
3148
|
+
const threshold = options.threshold || "info";
|
|
3149
|
+
const thresholdLevels = { info: 0, warning: 1, error: 2 };
|
|
3150
|
+
const minLevel = thresholdLevels[threshold];
|
|
3151
|
+
if (!options.json) {
|
|
3152
|
+
console.log(`\uD83D\uDD0D Analyzing stx templates...`);
|
|
3153
|
+
}
|
|
3154
|
+
const { results, summary } = await analyzeProject(analysisPatterns);
|
|
3155
|
+
if (results.length === 0) {
|
|
3156
|
+
console.log("No STX files found to analyze.");
|
|
3157
|
+
return;
|
|
3158
|
+
}
|
|
3159
|
+
const filteredResults = options.onlyIssues ? results.filter((r) => r.issues.some((issue) => thresholdLevels[issue.type] >= minLevel)) : results;
|
|
3160
|
+
if (options.json) {
|
|
3161
|
+
const jsonOutput = {
|
|
3162
|
+
summary,
|
|
3163
|
+
results: filteredResults,
|
|
3164
|
+
generatedAt: new Date().toISOString()
|
|
3165
|
+
};
|
|
3166
|
+
if (options.saveReport) {
|
|
3167
|
+
await Bun.write(options.saveReport, JSON.stringify(jsonOutput, null, 2));
|
|
3168
|
+
console.log(`\uD83D\uDCCB Analysis report saved to: ${options.saveReport}`);
|
|
3169
|
+
} else {
|
|
3170
|
+
console.log(JSON.stringify(jsonOutput, null, 2));
|
|
3171
|
+
}
|
|
3172
|
+
return;
|
|
3173
|
+
}
|
|
3174
|
+
console.log(`
|
|
3175
|
+
\uD83D\uDCCA Analysis Summary`);
|
|
3176
|
+
console.log(`\u2500`.repeat(50));
|
|
3177
|
+
console.log(`\uD83D\uDCC1 Files analyzed: ${summary.totalFiles}`);
|
|
3178
|
+
console.log(`\uD83D\uDCCF Total lines: ${summary.totalLines.toLocaleString()}`);
|
|
3179
|
+
console.log(`\uD83E\uDDEE Average complexity: ${summary.avgComplexity}/10`);
|
|
3180
|
+
console.log(`\u26A0\uFE0F Total issues: ${summary.totalIssues}`);
|
|
3181
|
+
console.log(`\uD83D\uDE80 Performance score: ${summary.performanceScore}/10`);
|
|
3182
|
+
if (Object.keys(summary.issuesByCategory).length > 0) {
|
|
3183
|
+
console.log(`
|
|
3184
|
+
\uD83D\uDCCB Issues by category:`);
|
|
3185
|
+
for (const [category, count] of Object.entries(summary.issuesByCategory)) {
|
|
3186
|
+
console.log(` ${category}: ${count}`);
|
|
3187
|
+
}
|
|
3188
|
+
}
|
|
3189
|
+
if (summary.recommendations.length > 0) {
|
|
3190
|
+
console.log(`
|
|
3191
|
+
\uD83D\uDCA1 Project recommendations:`);
|
|
3192
|
+
summary.recommendations.forEach((rec) => {
|
|
3193
|
+
console.log(` \u2022 ${rec}`);
|
|
3194
|
+
});
|
|
3195
|
+
}
|
|
3196
|
+
if (options.detailed) {
|
|
3197
|
+
console.log(`
|
|
3198
|
+
\uD83D\uDCC4 Detailed File Analysis`);
|
|
3199
|
+
console.log(`\u2550`.repeat(60));
|
|
3200
|
+
for (const result of filteredResults) {
|
|
3201
|
+
console.log(`
|
|
3202
|
+
\uD83D\uDCDD ${path.relative(process7.cwd(), result.file)}`);
|
|
3203
|
+
console.log(` Lines: ${result.metrics.lines} | Complexity: ${result.metrics.complexity}/10 | Estimated render: ${result.performance.estimatedRenderTime}ms`);
|
|
3204
|
+
if (result.issues.length > 0) {
|
|
3205
|
+
const relevantIssues = result.issues.filter((issue) => thresholdLevels[issue.type] >= minLevel);
|
|
3206
|
+
if (relevantIssues.length > 0) {
|
|
3207
|
+
console.log(` Issues (${relevantIssues.length}):`);
|
|
3208
|
+
relevantIssues.forEach((issue) => {
|
|
3209
|
+
const icon = issue.type === "error" ? "\u274C" : issue.type === "warning" ? "\u26A0\uFE0F" : "\u2139\uFE0F";
|
|
3210
|
+
console.log(` ${icon} ${issue.message}`);
|
|
3211
|
+
if (issue.suggestion) {
|
|
3212
|
+
console.log(` \uD83D\uDCA1 ${issue.suggestion}`);
|
|
3213
|
+
}
|
|
3214
|
+
});
|
|
3215
|
+
}
|
|
3216
|
+
}
|
|
3217
|
+
if (result.suggestions.length > 0) {
|
|
3218
|
+
console.log(` Suggestions (${result.suggestions.length}):`);
|
|
3219
|
+
result.suggestions.forEach((suggestion) => {
|
|
3220
|
+
const icon = suggestion.impact === "high" ? "\uD83D\uDD25" : suggestion.impact === "medium" ? "\u26A1" : "\uD83D\uDCAB";
|
|
3221
|
+
console.log(` ${icon} ${suggestion.message} (${suggestion.impact} impact, ${suggestion.effort} effort)`);
|
|
3222
|
+
});
|
|
3223
|
+
}
|
|
3224
|
+
}
|
|
3225
|
+
} else if (filteredResults.length > 0 && !options.onlyIssues) {
|
|
3226
|
+
console.log(`
|
|
3227
|
+
\uD83D\uDCC4 Files with issues:`);
|
|
3228
|
+
filteredResults.forEach((result) => {
|
|
3229
|
+
const issueCount = result.issues.filter((issue) => thresholdLevels[issue.type] >= minLevel).length;
|
|
3230
|
+
if (issueCount > 0) {
|
|
3231
|
+
console.log(` ${path.relative(process7.cwd(), result.file)} (${issueCount} issues)`);
|
|
3232
|
+
}
|
|
3233
|
+
});
|
|
3234
|
+
}
|
|
3235
|
+
if (options.saveReport) {
|
|
3236
|
+
const report = {
|
|
3237
|
+
summary,
|
|
3238
|
+
results: filteredResults,
|
|
3239
|
+
generatedAt: new Date().toISOString(),
|
|
3240
|
+
commandOptions: options
|
|
3241
|
+
};
|
|
3242
|
+
await Bun.write(options.saveReport, JSON.stringify(report, null, 2));
|
|
3243
|
+
console.log(`
|
|
3244
|
+
\uD83D\uDCCB Analysis report saved to: ${options.saveReport}`);
|
|
3245
|
+
}
|
|
3246
|
+
console.log(`
|
|
3247
|
+
\u2728 Analysis complete! Use --detailed for more information.`);
|
|
3248
|
+
} catch (error) {
|
|
3249
|
+
console.error("Error analyzing templates:", error);
|
|
3250
|
+
process7.exit(1);
|
|
3251
|
+
}
|
|
3252
|
+
});
|
|
3253
|
+
cli.command("version", "Show the version of the CLI").action(() => {
|
|
3254
|
+
console.log(version);
|
|
3255
|
+
});
|
|
3256
|
+
const knownCommands = [
|
|
3257
|
+
"docs",
|
|
3258
|
+
"iconify",
|
|
3259
|
+
"dev",
|
|
3260
|
+
"a11y",
|
|
3261
|
+
"build",
|
|
3262
|
+
"test",
|
|
3263
|
+
"init",
|
|
3264
|
+
"new",
|
|
3265
|
+
"format",
|
|
3266
|
+
"perf",
|
|
3267
|
+
"debug",
|
|
3268
|
+
"status",
|
|
3269
|
+
"watch",
|
|
3270
|
+
"analyze",
|
|
3271
|
+
"version"
|
|
3272
|
+
];
|
|
3273
|
+
const args = process7.argv.slice(2);
|
|
3274
|
+
if (args.length > 0 && !args[0].startsWith("-")) {
|
|
3275
|
+
const command = args[0];
|
|
3276
|
+
if (command === "") {
|
|
3277
|
+
console.error("\u274C No command provided");
|
|
3278
|
+
console.error("\uD83D\uDCA1 Use --help to see available commands");
|
|
3279
|
+
process7.exit(1);
|
|
3280
|
+
}
|
|
3281
|
+
if (!knownCommands.includes(command)) {
|
|
3282
|
+
const distances = knownCommands.map((cmd) => ({
|
|
3283
|
+
command: cmd,
|
|
3284
|
+
distance: levenshteinDistance(command, cmd)
|
|
3285
|
+
}));
|
|
3286
|
+
distances.sort((a, b) => a.distance - b.distance);
|
|
3287
|
+
const closest = distances[0];
|
|
3288
|
+
if (closest.distance <= 3) {
|
|
3289
|
+
console.error(`\u274C Unknown command: ${command}`);
|
|
3290
|
+
console.error(`\uD83D\uDCA1 Did you mean: ${closest.command}?`);
|
|
3291
|
+
console.error(`
|
|
3292
|
+
Run 'stx --help' to see available commands.`);
|
|
3293
|
+
process7.exit(1);
|
|
3294
|
+
}
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
cli.help();
|
|
3298
|
+
cli.version(version);
|
|
3299
|
+
cli.parse();
|
|
3300
|
+
}
|