mux-cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/README.md +1 -0
- package/dist/index.js +3230 -0
- package/index.js +3 -0
- package/package.json +35 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3230 @@
|
|
|
1
|
+
import * as path$1 from "node:path";
|
|
2
|
+
import path, { dirname, join } from "node:path";
|
|
3
|
+
import P, { stdin, stdout } from "node:process";
|
|
4
|
+
import * as k$1 from "node:readline";
|
|
5
|
+
import ot from "node:readline";
|
|
6
|
+
import { ReadStream } from "node:tty";
|
|
7
|
+
import * as fs$1 from "node:fs";
|
|
8
|
+
import fs, { existsSync, lstatSync, readdirSync } from "node:fs";
|
|
9
|
+
import { stripVTControlCharacters } from "node:util";
|
|
10
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
11
|
+
|
|
12
|
+
//#region \0rolldown/runtime.js
|
|
13
|
+
var __create = Object.create;
|
|
14
|
+
var __defProp = Object.defineProperty;
|
|
15
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
16
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
17
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
18
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
19
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
23
|
+
key = keys[i];
|
|
24
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
25
|
+
__defProp(to, key, {
|
|
26
|
+
get: ((k) => from[k]).bind(null, key),
|
|
27
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return to;
|
|
33
|
+
};
|
|
34
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
35
|
+
value: mod,
|
|
36
|
+
enumerable: true
|
|
37
|
+
}) : target, mod));
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region ../node_modules/.pnpm/mri@1.2.0/node_modules/mri/lib/index.js
|
|
41
|
+
var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
42
|
+
function toArr(any) {
|
|
43
|
+
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
44
|
+
}
|
|
45
|
+
function toVal(out, key, val, opts) {
|
|
46
|
+
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;
|
|
47
|
+
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
|
48
|
+
}
|
|
49
|
+
module.exports = function(args, opts) {
|
|
50
|
+
args = args || [];
|
|
51
|
+
opts = opts || {};
|
|
52
|
+
var k, arr, arg, name, val, out = { _: [] };
|
|
53
|
+
var i = 0, j = 0, idx = 0, len = args.length;
|
|
54
|
+
const alibi = opts.alias !== void 0;
|
|
55
|
+
const strict = opts.unknown !== void 0;
|
|
56
|
+
const defaults = opts.default !== void 0;
|
|
57
|
+
opts.alias = opts.alias || {};
|
|
58
|
+
opts.string = toArr(opts.string);
|
|
59
|
+
opts.boolean = toArr(opts.boolean);
|
|
60
|
+
if (alibi) for (k in opts.alias) {
|
|
61
|
+
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
62
|
+
for (i = 0; i < arr.length; i++) (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
63
|
+
}
|
|
64
|
+
for (i = opts.boolean.length; i-- > 0;) {
|
|
65
|
+
arr = opts.alias[opts.boolean[i]] || [];
|
|
66
|
+
for (j = arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
|
67
|
+
}
|
|
68
|
+
for (i = opts.string.length; i-- > 0;) {
|
|
69
|
+
arr = opts.alias[opts.string[i]] || [];
|
|
70
|
+
for (j = arr.length; j-- > 0;) opts.string.push(arr[j]);
|
|
71
|
+
}
|
|
72
|
+
if (defaults) for (k in opts.default) {
|
|
73
|
+
name = typeof opts.default[k];
|
|
74
|
+
arr = opts.alias[k] = opts.alias[k] || [];
|
|
75
|
+
if (opts[name] !== void 0) {
|
|
76
|
+
opts[name].push(k);
|
|
77
|
+
for (i = 0; i < arr.length; i++) opts[name].push(arr[i]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const keys = strict ? Object.keys(opts.alias) : [];
|
|
81
|
+
for (i = 0; i < len; i++) {
|
|
82
|
+
arg = args[i];
|
|
83
|
+
if (arg === "--") {
|
|
84
|
+
out._ = out._.concat(args.slice(++i));
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
for (j = 0; j < arg.length; j++) if (arg.charCodeAt(j) !== 45) break;
|
|
88
|
+
if (j === 0) out._.push(arg);
|
|
89
|
+
else if (arg.substring(j, j + 3) === "no-") {
|
|
90
|
+
name = arg.substring(j + 3);
|
|
91
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
|
|
92
|
+
out[name] = false;
|
|
93
|
+
} else {
|
|
94
|
+
for (idx = j + 1; idx < arg.length; idx++) if (arg.charCodeAt(idx) === 61) break;
|
|
95
|
+
name = arg.substring(j, idx);
|
|
96
|
+
val = arg.substring(++idx) || i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i];
|
|
97
|
+
arr = j === 2 ? [name] : name;
|
|
98
|
+
for (idx = 0; idx < arr.length; idx++) {
|
|
99
|
+
name = arr[idx];
|
|
100
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
|
|
101
|
+
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (defaults) {
|
|
106
|
+
for (k in opts.default) if (out[k] === void 0) out[k] = opts.default[k];
|
|
107
|
+
}
|
|
108
|
+
if (alibi) for (k in out) {
|
|
109
|
+
arr = opts.alias[k] || [];
|
|
110
|
+
while (arr.length > 0) out[arr.shift()] = out[k];
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
113
|
+
};
|
|
114
|
+
}));
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region ../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
|
|
118
|
+
var require_picocolors = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
119
|
+
let p = process || {}, argv = p.argv || [], env = p.env || {};
|
|
120
|
+
let 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);
|
|
121
|
+
let formatter = (open, close, replace = open) => (input) => {
|
|
122
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
123
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
124
|
+
};
|
|
125
|
+
let replaceClose = (string, close, replace, index) => {
|
|
126
|
+
let result = "", cursor = 0;
|
|
127
|
+
do {
|
|
128
|
+
result += string.substring(cursor, index) + replace;
|
|
129
|
+
cursor = index + close.length;
|
|
130
|
+
index = string.indexOf(close, cursor);
|
|
131
|
+
} while (~index);
|
|
132
|
+
return result + string.substring(cursor);
|
|
133
|
+
};
|
|
134
|
+
let createColors = (enabled = isColorSupported) => {
|
|
135
|
+
let f = enabled ? formatter : () => String;
|
|
136
|
+
return {
|
|
137
|
+
isColorSupported: enabled,
|
|
138
|
+
reset: f("\x1B[0m", "\x1B[0m"),
|
|
139
|
+
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
140
|
+
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
141
|
+
italic: f("\x1B[3m", "\x1B[23m"),
|
|
142
|
+
underline: f("\x1B[4m", "\x1B[24m"),
|
|
143
|
+
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
144
|
+
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
145
|
+
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
146
|
+
black: f("\x1B[30m", "\x1B[39m"),
|
|
147
|
+
red: f("\x1B[31m", "\x1B[39m"),
|
|
148
|
+
green: f("\x1B[32m", "\x1B[39m"),
|
|
149
|
+
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
150
|
+
blue: f("\x1B[34m", "\x1B[39m"),
|
|
151
|
+
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
152
|
+
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
153
|
+
white: f("\x1B[37m", "\x1B[39m"),
|
|
154
|
+
gray: f("\x1B[90m", "\x1B[39m"),
|
|
155
|
+
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
156
|
+
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
157
|
+
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
158
|
+
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
159
|
+
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
160
|
+
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
161
|
+
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
162
|
+
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
163
|
+
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
164
|
+
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
165
|
+
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
166
|
+
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
167
|
+
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
168
|
+
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
169
|
+
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
170
|
+
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
171
|
+
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
172
|
+
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
173
|
+
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
174
|
+
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
175
|
+
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
176
|
+
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
177
|
+
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
178
|
+
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
module.exports = createColors();
|
|
182
|
+
module.exports.createColors = createColors;
|
|
183
|
+
}));
|
|
184
|
+
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region ../node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
|
|
187
|
+
var require_src = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
188
|
+
const ESC = "\x1B";
|
|
189
|
+
const CSI = `${ESC}[`;
|
|
190
|
+
const beep = "\x07";
|
|
191
|
+
const cursor = {
|
|
192
|
+
to(x, y) {
|
|
193
|
+
if (!y) return `${CSI}${x + 1}G`;
|
|
194
|
+
return `${CSI}${y + 1};${x + 1}H`;
|
|
195
|
+
},
|
|
196
|
+
move(x, y) {
|
|
197
|
+
let ret = "";
|
|
198
|
+
if (x < 0) ret += `${CSI}${-x}D`;
|
|
199
|
+
else if (x > 0) ret += `${CSI}${x}C`;
|
|
200
|
+
if (y < 0) ret += `${CSI}${-y}A`;
|
|
201
|
+
else if (y > 0) ret += `${CSI}${y}B`;
|
|
202
|
+
return ret;
|
|
203
|
+
},
|
|
204
|
+
up: (count = 1) => `${CSI}${count}A`,
|
|
205
|
+
down: (count = 1) => `${CSI}${count}B`,
|
|
206
|
+
forward: (count = 1) => `${CSI}${count}C`,
|
|
207
|
+
backward: (count = 1) => `${CSI}${count}D`,
|
|
208
|
+
nextLine: (count = 1) => `${CSI}E`.repeat(count),
|
|
209
|
+
prevLine: (count = 1) => `${CSI}F`.repeat(count),
|
|
210
|
+
left: `${CSI}G`,
|
|
211
|
+
hide: `${CSI}?25l`,
|
|
212
|
+
show: `${CSI}?25h`,
|
|
213
|
+
save: `${ESC}7`,
|
|
214
|
+
restore: `${ESC}8`
|
|
215
|
+
};
|
|
216
|
+
const scroll = {
|
|
217
|
+
up: (count = 1) => `${CSI}S`.repeat(count),
|
|
218
|
+
down: (count = 1) => `${CSI}T`.repeat(count)
|
|
219
|
+
};
|
|
220
|
+
const erase = {
|
|
221
|
+
screen: `${CSI}2J`,
|
|
222
|
+
up: (count = 1) => `${CSI}1J`.repeat(count),
|
|
223
|
+
down: (count = 1) => `${CSI}J`.repeat(count),
|
|
224
|
+
line: `${CSI}2K`,
|
|
225
|
+
lineEnd: `${CSI}K`,
|
|
226
|
+
lineStart: `${CSI}1K`,
|
|
227
|
+
lines(count) {
|
|
228
|
+
let clear = "";
|
|
229
|
+
for (let i = 0; i < count; i++) clear += this.line + (i < count - 1 ? cursor.up() : "");
|
|
230
|
+
if (count) clear += cursor.left;
|
|
231
|
+
return clear;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
module.exports = {
|
|
235
|
+
cursor,
|
|
236
|
+
scroll,
|
|
237
|
+
erase,
|
|
238
|
+
beep
|
|
239
|
+
};
|
|
240
|
+
}));
|
|
241
|
+
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region ../node_modules/.pnpm/@clack+core@1.0.0/node_modules/@clack/core/dist/index.mjs
|
|
244
|
+
var import_lib = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
245
|
+
var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
|
|
246
|
+
var import_src = require_src();
|
|
247
|
+
const at = (t) => t === 161 || t === 164 || t === 167 || t === 168 || t === 170 || t === 173 || t === 174 || t >= 176 && t <= 180 || t >= 182 && t <= 186 || t >= 188 && t <= 191 || t === 198 || t === 208 || t === 215 || t === 216 || t >= 222 && t <= 225 || t === 230 || t >= 232 && t <= 234 || t === 236 || t === 237 || t === 240 || t === 242 || t === 243 || t >= 247 && t <= 250 || t === 252 || t === 254 || t === 257 || t === 273 || t === 275 || t === 283 || t === 294 || t === 295 || t === 299 || t >= 305 && t <= 307 || t === 312 || t >= 319 && t <= 322 || t === 324 || t >= 328 && t <= 331 || t === 333 || t === 338 || t === 339 || t === 358 || t === 359 || t === 363 || t === 462 || t === 464 || t === 466 || t === 468 || t === 470 || t === 472 || t === 474 || t === 476 || t === 593 || t === 609 || t === 708 || t === 711 || t >= 713 && t <= 715 || t === 717 || t === 720 || t >= 728 && t <= 731 || t === 733 || t === 735 || t >= 768 && t <= 879 || t >= 913 && t <= 929 || t >= 931 && t <= 937 || t >= 945 && t <= 961 || t >= 963 && t <= 969 || t === 1025 || t >= 1040 && t <= 1103 || t === 1105 || t === 8208 || t >= 8211 && t <= 8214 || t === 8216 || t === 8217 || t === 8220 || t === 8221 || t >= 8224 && t <= 8226 || t >= 8228 && t <= 8231 || t === 8240 || t === 8242 || t === 8243 || t === 8245 || t === 8251 || t === 8254 || t === 8308 || t === 8319 || t >= 8321 && t <= 8324 || t === 8364 || t === 8451 || t === 8453 || t === 8457 || t === 8467 || t === 8470 || t === 8481 || t === 8482 || t === 8486 || t === 8491 || t === 8531 || t === 8532 || t >= 8539 && t <= 8542 || t >= 8544 && t <= 8555 || t >= 8560 && t <= 8569 || t === 8585 || t >= 8592 && t <= 8601 || t === 8632 || t === 8633 || t === 8658 || t === 8660 || t === 8679 || t === 8704 || t === 8706 || t === 8707 || t === 8711 || t === 8712 || t === 8715 || t === 8719 || t === 8721 || t === 8725 || t === 8730 || t >= 8733 && t <= 8736 || t === 8739 || t === 8741 || t >= 8743 && t <= 8748 || t === 8750 || t >= 8756 && t <= 8759 || t === 8764 || t === 8765 || t === 8776 || t === 8780 || t === 8786 || t === 8800 || t === 8801 || t >= 8804 && t <= 8807 || t === 8810 || t === 8811 || t === 8814 || t === 8815 || t === 8834 || t === 8835 || t === 8838 || t === 8839 || t === 8853 || t === 8857 || t === 8869 || t === 8895 || t === 8978 || t >= 9312 && t <= 9449 || t >= 9451 && t <= 9547 || t >= 9552 && t <= 9587 || t >= 9600 && t <= 9615 || t >= 9618 && t <= 9621 || t === 9632 || t === 9633 || t >= 9635 && t <= 9641 || t === 9650 || t === 9651 || t === 9654 || t === 9655 || t === 9660 || t === 9661 || t === 9664 || t === 9665 || t >= 9670 && t <= 9672 || t === 9675 || t >= 9678 && t <= 9681 || t >= 9698 && t <= 9701 || t === 9711 || t === 9733 || t === 9734 || t === 9737 || t === 9742 || t === 9743 || t === 9756 || t === 9758 || t === 9792 || t === 9794 || t === 9824 || t === 9825 || t >= 9827 && t <= 9829 || t >= 9831 && t <= 9834 || t === 9836 || t === 9837 || t === 9839 || t === 9886 || t === 9887 || t === 9919 || t >= 9926 && t <= 9933 || t >= 9935 && t <= 9939 || t >= 9941 && t <= 9953 || t === 9955 || t === 9960 || t === 9961 || t >= 9963 && t <= 9969 || t === 9972 || t >= 9974 && t <= 9977 || t === 9979 || t === 9980 || t === 9982 || t === 9983 || t === 10045 || t >= 10102 && t <= 10111 || t >= 11094 && t <= 11097 || t >= 12872 && t <= 12879 || t >= 57344 && t <= 63743 || t >= 65024 && t <= 65039 || t === 65533 || t >= 127232 && t <= 127242 || t >= 127248 && t <= 127277 || t >= 127280 && t <= 127337 || t >= 127344 && t <= 127373 || t === 127375 || t === 127376 || t >= 127387 && t <= 127404 || t >= 917760 && t <= 917999 || t >= 983040 && t <= 1048573 || t >= 1048576 && t <= 1114109, lt = (t) => t === 12288 || t >= 65281 && t <= 65376 || t >= 65504 && t <= 65510, ht$1 = (t) => t >= 4352 && t <= 4447 || t === 8986 || t === 8987 || t === 9001 || t === 9002 || t >= 9193 && t <= 9196 || t === 9200 || t === 9203 || t === 9725 || t === 9726 || t === 9748 || t === 9749 || t >= 9800 && t <= 9811 || t === 9855 || t === 9875 || t === 9889 || t === 9898 || t === 9899 || t === 9917 || t === 9918 || t === 9924 || t === 9925 || t === 9934 || t === 9940 || t === 9962 || t === 9970 || t === 9971 || t === 9973 || t === 9978 || t === 9981 || t === 9989 || t === 9994 || t === 9995 || t === 10024 || t === 10060 || t === 10062 || t >= 10067 && t <= 10069 || t === 10071 || t >= 10133 && t <= 10135 || t === 10160 || t === 10175 || t === 11035 || t === 11036 || t === 11088 || t === 11093 || t >= 11904 && t <= 11929 || t >= 11931 && t <= 12019 || t >= 12032 && t <= 12245 || t >= 12272 && t <= 12287 || t >= 12289 && t <= 12350 || t >= 12353 && t <= 12438 || t >= 12441 && t <= 12543 || t >= 12549 && t <= 12591 || t >= 12593 && t <= 12686 || t >= 12688 && t <= 12771 || t >= 12783 && t <= 12830 || t >= 12832 && t <= 12871 || t >= 12880 && t <= 19903 || t >= 19968 && t <= 42124 || t >= 42128 && t <= 42182 || t >= 43360 && t <= 43388 || t >= 44032 && t <= 55203 || t >= 63744 && t <= 64255 || t >= 65040 && t <= 65049 || t >= 65072 && t <= 65106 || t >= 65108 && t <= 65126 || t >= 65128 && t <= 65131 || t >= 94176 && t <= 94180 || t === 94192 || t === 94193 || t >= 94208 && t <= 100343 || t >= 100352 && t <= 101589 || t >= 101632 && t <= 101640 || t >= 110576 && t <= 110579 || t >= 110581 && t <= 110587 || t === 110589 || t === 110590 || t >= 110592 && t <= 110882 || t === 110898 || t >= 110928 && t <= 110930 || t === 110933 || t >= 110948 && t <= 110951 || t >= 110960 && t <= 111355 || t === 126980 || t === 127183 || t === 127374 || t >= 127377 && t <= 127386 || t >= 127488 && t <= 127490 || t >= 127504 && t <= 127547 || t >= 127552 && t <= 127560 || t === 127568 || t === 127569 || t >= 127584 && t <= 127589 || t >= 127744 && t <= 127776 || t >= 127789 && t <= 127797 || t >= 127799 && t <= 127868 || t >= 127870 && t <= 127891 || t >= 127904 && t <= 127946 || t >= 127951 && t <= 127955 || t >= 127968 && t <= 127984 || t === 127988 || t >= 127992 && t <= 128062 || t === 128064 || t >= 128066 && t <= 128252 || t >= 128255 && t <= 128317 || t >= 128331 && t <= 128334 || t >= 128336 && t <= 128359 || t === 128378 || t === 128405 || t === 128406 || t === 128420 || t >= 128507 && t <= 128591 || t >= 128640 && t <= 128709 || t === 128716 || t >= 128720 && t <= 128722 || t >= 128725 && t <= 128727 || t >= 128732 && t <= 128735 || t === 128747 || t === 128748 || t >= 128756 && t <= 128764 || t >= 128992 && t <= 129003 || t === 129008 || t >= 129292 && t <= 129338 || t >= 129340 && t <= 129349 || t >= 129351 && t <= 129535 || t >= 129648 && t <= 129660 || t >= 129664 && t <= 129672 || t >= 129680 && t <= 129725 || t >= 129727 && t <= 129733 || t >= 129742 && t <= 129755 || t >= 129760 && t <= 129768 || t >= 129776 && t <= 129784 || t >= 131072 && t <= 196605 || t >= 196608 && t <= 262141, O = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y, y = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y, M$1 = /\t{1,1000}/y, P$1 = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/uy, L = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y, ct = /\p{M}+/gu, pt$1 = {
|
|
248
|
+
limit: Infinity,
|
|
249
|
+
ellipsis: ""
|
|
250
|
+
}, X = (t, e = {}, s = {}) => {
|
|
251
|
+
const i = e.limit ?? Infinity, r = e.ellipsis ?? "", n = e?.ellipsisWidth ?? (r ? X(r, pt$1, s).width : 0), u = s.ansiWidth ?? 0, a = s.controlWidth ?? 0, l = s.tabWidth ?? 8, E = s.ambiguousWidth ?? 1, g = s.emojiWidth ?? 2, m = s.fullWidthWidth ?? 2, A = s.regularWidth ?? 1, V = s.wideWidth ?? 2;
|
|
252
|
+
let h = 0, o = 0, f = t.length, v = 0, F = !1, d = f, b = Math.max(0, i - n), C = 0, B = 0, c = 0, p = 0;
|
|
253
|
+
t: for (;;) {
|
|
254
|
+
if (B > C || o >= f && o > h) {
|
|
255
|
+
const ut = t.slice(C, B) || t.slice(h, o);
|
|
256
|
+
v = 0;
|
|
257
|
+
for (const Y of ut.replaceAll(ct, "")) {
|
|
258
|
+
const $ = Y.codePointAt(0) || 0;
|
|
259
|
+
if (lt($) ? p = m : ht$1($) ? p = V : E !== A && at($) ? p = E : p = A, c + p > b && (d = Math.min(d, Math.max(C, h) + v)), c + p > i) {
|
|
260
|
+
F = !0;
|
|
261
|
+
break t;
|
|
262
|
+
}
|
|
263
|
+
v += Y.length, c += p;
|
|
264
|
+
}
|
|
265
|
+
C = B = 0;
|
|
266
|
+
}
|
|
267
|
+
if (o >= f) break;
|
|
268
|
+
if (L.lastIndex = o, L.test(t)) {
|
|
269
|
+
if (v = L.lastIndex - o, p = v * A, c + p > b && (d = Math.min(d, o + Math.floor((b - c) / A))), c + p > i) {
|
|
270
|
+
F = !0;
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
c += p, C = h, B = o, o = h = L.lastIndex;
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if (O.lastIndex = o, O.test(t)) {
|
|
277
|
+
if (c + u > b && (d = Math.min(d, o)), c + u > i) {
|
|
278
|
+
F = !0;
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
c += u, C = h, B = o, o = h = O.lastIndex;
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (y.lastIndex = o, y.test(t)) {
|
|
285
|
+
if (v = y.lastIndex - o, p = v * a, c + p > b && (d = Math.min(d, o + Math.floor((b - c) / a))), c + p > i) {
|
|
286
|
+
F = !0;
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
c += p, C = h, B = o, o = h = y.lastIndex;
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (M$1.lastIndex = o, M$1.test(t)) {
|
|
293
|
+
if (v = M$1.lastIndex - o, p = v * l, c + p > b && (d = Math.min(d, o + Math.floor((b - c) / l))), c + p > i) {
|
|
294
|
+
F = !0;
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
c += p, C = h, B = o, o = h = M$1.lastIndex;
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
if (P$1.lastIndex = o, P$1.test(t)) {
|
|
301
|
+
if (c + g > b && (d = Math.min(d, o)), c + g > i) {
|
|
302
|
+
F = !0;
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
c += g, C = h, B = o, o = h = P$1.lastIndex;
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
o += 1;
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
width: F ? b : c,
|
|
312
|
+
index: F ? d : f,
|
|
313
|
+
truncated: F,
|
|
314
|
+
ellipsed: F && i >= n
|
|
315
|
+
};
|
|
316
|
+
}, ft$1 = {
|
|
317
|
+
limit: Infinity,
|
|
318
|
+
ellipsis: "",
|
|
319
|
+
ellipsisWidth: 0
|
|
320
|
+
}, S = (t, e = {}) => X(t, ft$1, e).width, W = "\x1B", Z = "", Ft$1 = 39, j = "\x07", Q$1 = "[", dt = "]", tt = "m", U = `${dt}8;;`, et = new RegExp(`(?:\\${Q$1}(?<code>\\d+)m|\\${U}(?<uri>.*)${j})`, "y"), mt$1 = (t) => {
|
|
321
|
+
if (t >= 30 && t <= 37 || t >= 90 && t <= 97) return 39;
|
|
322
|
+
if (t >= 40 && t <= 47 || t >= 100 && t <= 107) return 49;
|
|
323
|
+
if (t === 1 || t === 2) return 22;
|
|
324
|
+
if (t === 3) return 23;
|
|
325
|
+
if (t === 4) return 24;
|
|
326
|
+
if (t === 7) return 27;
|
|
327
|
+
if (t === 8) return 28;
|
|
328
|
+
if (t === 9) return 29;
|
|
329
|
+
if (t === 0) return 0;
|
|
330
|
+
}, st = (t) => `${W}${Q$1}${t}${tt}`, it = (t) => `${W}${U}${t}${j}`, gt$1 = (t) => t.map((e) => S(e)), G$1 = (t, e, s) => {
|
|
331
|
+
const i = e[Symbol.iterator]();
|
|
332
|
+
let r = !1, n = !1, u = t.at(-1), a = u === void 0 ? 0 : S(u), l = i.next(), E = i.next(), g = 0;
|
|
333
|
+
for (; !l.done;) {
|
|
334
|
+
const m = l.value, A = S(m);
|
|
335
|
+
a + A <= s ? t[t.length - 1] += m : (t.push(m), a = 0), (m === W || m === Z) && (r = !0, n = e.startsWith(U, g + 1)), r ? n ? m === j && (r = !1, n = !1) : m === tt && (r = !1) : (a += A, a === s && !E.done && (t.push(""), a = 0)), l = E, E = i.next(), g += m.length;
|
|
336
|
+
}
|
|
337
|
+
u = t.at(-1), !a && u !== void 0 && u.length > 0 && t.length > 1 && (t[t.length - 2] += t.pop());
|
|
338
|
+
}, vt$1 = (t) => {
|
|
339
|
+
const e = t.split(" ");
|
|
340
|
+
let s = e.length;
|
|
341
|
+
for (; s > 0 && !(S(e[s - 1]) > 0);) s--;
|
|
342
|
+
return s === e.length ? t : e.slice(0, s).join(" ") + e.slice(s).join("");
|
|
343
|
+
}, Et$1 = (t, e, s = {}) => {
|
|
344
|
+
if (s.trim !== !1 && t.trim() === "") return "";
|
|
345
|
+
let i = "", r, n;
|
|
346
|
+
const u = t.split(" "), a = gt$1(u);
|
|
347
|
+
let l = [""];
|
|
348
|
+
for (const [h, o] of u.entries()) {
|
|
349
|
+
s.trim !== !1 && (l[l.length - 1] = (l.at(-1) ?? "").trimStart());
|
|
350
|
+
let f = S(l.at(-1) ?? "");
|
|
351
|
+
if (h !== 0 && (f >= e && (s.wordWrap === !1 || s.trim === !1) && (l.push(""), f = 0), (f > 0 || s.trim === !1) && (l[l.length - 1] += " ", f++)), s.hard && a[h] > e) {
|
|
352
|
+
const v = e - f, F = 1 + Math.floor((a[h] - v - 1) / e);
|
|
353
|
+
Math.floor((a[h] - 1) / e) < F && l.push(""), G$1(l, o, e);
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
if (f + a[h] > e && f > 0 && a[h] > 0) {
|
|
357
|
+
if (s.wordWrap === !1 && f < e) {
|
|
358
|
+
G$1(l, o, e);
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
l.push("");
|
|
362
|
+
}
|
|
363
|
+
if (f + a[h] > e && s.wordWrap === !1) {
|
|
364
|
+
G$1(l, o, e);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
l[l.length - 1] += o;
|
|
368
|
+
}
|
|
369
|
+
s.trim !== !1 && (l = l.map((h) => vt$1(h)));
|
|
370
|
+
const E = l.join(`
|
|
371
|
+
`), g = E[Symbol.iterator]();
|
|
372
|
+
let m = g.next(), A = g.next(), V = 0;
|
|
373
|
+
for (; !m.done;) {
|
|
374
|
+
const h = m.value, o = A.value;
|
|
375
|
+
if (i += h, h === W || h === Z) {
|
|
376
|
+
et.lastIndex = V + 1;
|
|
377
|
+
const F = et.exec(E)?.groups;
|
|
378
|
+
if (F?.code !== void 0) {
|
|
379
|
+
const d = Number.parseFloat(F.code);
|
|
380
|
+
r = d === Ft$1 ? void 0 : d;
|
|
381
|
+
} else F?.uri !== void 0 && (n = F.uri.length === 0 ? void 0 : F.uri);
|
|
382
|
+
}
|
|
383
|
+
const f = r ? mt$1(r) : void 0;
|
|
384
|
+
o === `
|
|
385
|
+
` ? (n && (i += it("")), r && f && (i += st(f))) : h === `
|
|
386
|
+
` && (r && f && (i += st(r)), n && (i += it(n))), V += h.length, m = A, A = g.next();
|
|
387
|
+
}
|
|
388
|
+
return i;
|
|
389
|
+
};
|
|
390
|
+
function K$1(t, e, s) {
|
|
391
|
+
return String(t).normalize().replaceAll(`\r
|
|
392
|
+
`, `
|
|
393
|
+
`).split(`
|
|
394
|
+
`).map((i) => Et$1(i, e, s)).join(`
|
|
395
|
+
`);
|
|
396
|
+
}
|
|
397
|
+
const _ = {
|
|
398
|
+
actions: new Set([
|
|
399
|
+
"up",
|
|
400
|
+
"down",
|
|
401
|
+
"left",
|
|
402
|
+
"right",
|
|
403
|
+
"space",
|
|
404
|
+
"enter",
|
|
405
|
+
"cancel"
|
|
406
|
+
]),
|
|
407
|
+
aliases: new Map([
|
|
408
|
+
["k", "up"],
|
|
409
|
+
["j", "down"],
|
|
410
|
+
["h", "left"],
|
|
411
|
+
["l", "right"],
|
|
412
|
+
["", "cancel"],
|
|
413
|
+
["escape", "cancel"]
|
|
414
|
+
]),
|
|
415
|
+
messages: {
|
|
416
|
+
cancel: "Canceled",
|
|
417
|
+
error: "Something went wrong"
|
|
418
|
+
},
|
|
419
|
+
withGuide: !0
|
|
420
|
+
};
|
|
421
|
+
function H$1(t, e) {
|
|
422
|
+
if (typeof t == "string") return _.aliases.get(t) === e;
|
|
423
|
+
for (const s of t) if (s !== void 0 && H$1(s, e)) return !0;
|
|
424
|
+
return !1;
|
|
425
|
+
}
|
|
426
|
+
function _t$1(t, e) {
|
|
427
|
+
if (t === e) return;
|
|
428
|
+
const s = t.split(`
|
|
429
|
+
`), i = e.split(`
|
|
430
|
+
`), r = Math.max(s.length, i.length), n = [];
|
|
431
|
+
for (let u = 0; u < r; u++) s[u] !== i[u] && n.push(u);
|
|
432
|
+
return {
|
|
433
|
+
lines: n,
|
|
434
|
+
numLinesBefore: s.length,
|
|
435
|
+
numLinesAfter: i.length,
|
|
436
|
+
numLines: r
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
const bt$1 = globalThis.process.platform.startsWith("win"), z$1 = Symbol("clack:cancel");
|
|
440
|
+
function Ct$1(t) {
|
|
441
|
+
return t === z$1;
|
|
442
|
+
}
|
|
443
|
+
function T(t, e) {
|
|
444
|
+
const s = t;
|
|
445
|
+
s.isTTY && s.setRawMode(e);
|
|
446
|
+
}
|
|
447
|
+
function xt$1({ input: t = stdin, output: e = stdout, overwrite: s = !0, hideCursor: i = !0 } = {}) {
|
|
448
|
+
const r = k$1.createInterface({
|
|
449
|
+
input: t,
|
|
450
|
+
output: e,
|
|
451
|
+
prompt: "",
|
|
452
|
+
tabSize: 1
|
|
453
|
+
});
|
|
454
|
+
k$1.emitKeypressEvents(t, r), t instanceof ReadStream && t.isTTY && t.setRawMode(!0);
|
|
455
|
+
const n = (u, { name: a, sequence: l }) => {
|
|
456
|
+
if (H$1([
|
|
457
|
+
String(u),
|
|
458
|
+
a,
|
|
459
|
+
l
|
|
460
|
+
], "cancel")) {
|
|
461
|
+
i && e.write(import_src.cursor.show), process.exit(0);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
if (!s) return;
|
|
465
|
+
const g = a === "return" ? 0 : -1, m = a === "return" ? -1 : 0;
|
|
466
|
+
k$1.moveCursor(e, g, m, () => {
|
|
467
|
+
k$1.clearLine(e, 1, () => {
|
|
468
|
+
t.once("keypress", n);
|
|
469
|
+
});
|
|
470
|
+
});
|
|
471
|
+
};
|
|
472
|
+
return i && e.write(import_src.cursor.hide), t.once("keypress", n), () => {
|
|
473
|
+
t.off("keypress", n), i && e.write(import_src.cursor.show), t instanceof ReadStream && t.isTTY && !bt$1 && t.setRawMode(!1), r.terminal = !1, r.close();
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
const rt = (t) => "columns" in t && typeof t.columns == "number" ? t.columns : 80, nt = (t) => "rows" in t && typeof t.rows == "number" ? t.rows : 20;
|
|
477
|
+
function Bt$1(t, e, s, i = s) {
|
|
478
|
+
return K$1(e, rt(t ?? stdout) - s.length, {
|
|
479
|
+
hard: !0,
|
|
480
|
+
trim: !1
|
|
481
|
+
}).split(`
|
|
482
|
+
`).map((n, u) => `${u === 0 ? i : s}${n}`).join(`
|
|
483
|
+
`);
|
|
484
|
+
}
|
|
485
|
+
var x$1 = class {
|
|
486
|
+
input;
|
|
487
|
+
output;
|
|
488
|
+
_abortSignal;
|
|
489
|
+
rl;
|
|
490
|
+
opts;
|
|
491
|
+
_render;
|
|
492
|
+
_track = !1;
|
|
493
|
+
_prevFrame = "";
|
|
494
|
+
_subscribers = /* @__PURE__ */ new Map();
|
|
495
|
+
_cursor = 0;
|
|
496
|
+
state = "initial";
|
|
497
|
+
error = "";
|
|
498
|
+
value;
|
|
499
|
+
userInput = "";
|
|
500
|
+
constructor(e, s = !0) {
|
|
501
|
+
const { input: i = stdin, output: r = stdout, render: n, signal: u, ...a } = e;
|
|
502
|
+
this.opts = a, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = n.bind(this), this._track = s, this._abortSignal = u, this.input = i, this.output = r;
|
|
503
|
+
}
|
|
504
|
+
unsubscribe() {
|
|
505
|
+
this._subscribers.clear();
|
|
506
|
+
}
|
|
507
|
+
setSubscriber(e, s) {
|
|
508
|
+
const i = this._subscribers.get(e) ?? [];
|
|
509
|
+
i.push(s), this._subscribers.set(e, i);
|
|
510
|
+
}
|
|
511
|
+
on(e, s) {
|
|
512
|
+
this.setSubscriber(e, { cb: s });
|
|
513
|
+
}
|
|
514
|
+
once(e, s) {
|
|
515
|
+
this.setSubscriber(e, {
|
|
516
|
+
cb: s,
|
|
517
|
+
once: !0
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
emit(e, ...s) {
|
|
521
|
+
const i = this._subscribers.get(e) ?? [], r = [];
|
|
522
|
+
for (const n of i) n.cb(...s), n.once && r.push(() => i.splice(i.indexOf(n), 1));
|
|
523
|
+
for (const n of r) n();
|
|
524
|
+
}
|
|
525
|
+
prompt() {
|
|
526
|
+
return new Promise((e) => {
|
|
527
|
+
if (this._abortSignal) {
|
|
528
|
+
if (this._abortSignal.aborted) return this.state = "cancel", this.close(), e(z$1);
|
|
529
|
+
this._abortSignal.addEventListener("abort", () => {
|
|
530
|
+
this.state = "cancel", this.close();
|
|
531
|
+
}, { once: !0 });
|
|
532
|
+
}
|
|
533
|
+
this.rl = ot.createInterface({
|
|
534
|
+
input: this.input,
|
|
535
|
+
tabSize: 2,
|
|
536
|
+
prompt: "",
|
|
537
|
+
escapeCodeTimeout: 50,
|
|
538
|
+
terminal: !0
|
|
539
|
+
}), this.rl.prompt(), this.opts.initialUserInput !== void 0 && this._setUserInput(this.opts.initialUserInput, !0), this.input.on("keypress", this.onKeypress), T(this.input, !0), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
|
|
540
|
+
this.output.write(import_src.cursor.show), this.output.off("resize", this.render), T(this.input, !1), e(this.value);
|
|
541
|
+
}), this.once("cancel", () => {
|
|
542
|
+
this.output.write(import_src.cursor.show), this.output.off("resize", this.render), T(this.input, !1), e(z$1);
|
|
543
|
+
});
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
_isActionKey(e, s) {
|
|
547
|
+
return e === " ";
|
|
548
|
+
}
|
|
549
|
+
_setValue(e) {
|
|
550
|
+
this.value = e, this.emit("value", this.value);
|
|
551
|
+
}
|
|
552
|
+
_setUserInput(e, s) {
|
|
553
|
+
this.userInput = e ?? "", this.emit("userInput", this.userInput), s && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
|
|
554
|
+
}
|
|
555
|
+
_clearUserInput() {
|
|
556
|
+
this.rl?.write(null, {
|
|
557
|
+
ctrl: !0,
|
|
558
|
+
name: "u"
|
|
559
|
+
}), this._setUserInput("");
|
|
560
|
+
}
|
|
561
|
+
onKeypress(e, s) {
|
|
562
|
+
if (this._track && s.name !== "return" && (s.name && this._isActionKey(e, s) && this.rl?.write(null, {
|
|
563
|
+
ctrl: !0,
|
|
564
|
+
name: "h"
|
|
565
|
+
}), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), s?.name && (!this._track && _.aliases.has(s.name) && this.emit("cursor", _.aliases.get(s.name)), _.actions.has(s.name) && this.emit("cursor", s.name)), e && (e.toLowerCase() === "y" || e.toLowerCase() === "n") && this.emit("confirm", e.toLowerCase() === "y"), this.emit("key", e?.toLowerCase(), s), s?.name === "return") {
|
|
566
|
+
if (this.opts.validate) {
|
|
567
|
+
const i = this.opts.validate(this.value);
|
|
568
|
+
i && (this.error = i instanceof Error ? i.message : i, this.state = "error", this.rl?.write(this.userInput));
|
|
569
|
+
}
|
|
570
|
+
this.state !== "error" && (this.state = "submit");
|
|
571
|
+
}
|
|
572
|
+
H$1([
|
|
573
|
+
e,
|
|
574
|
+
s?.name,
|
|
575
|
+
s?.sequence
|
|
576
|
+
], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
577
|
+
}
|
|
578
|
+
close() {
|
|
579
|
+
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
580
|
+
`), T(this.input, !1), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
581
|
+
}
|
|
582
|
+
restoreCursor() {
|
|
583
|
+
const e = K$1(this._prevFrame, process.stdout.columns, {
|
|
584
|
+
hard: !0,
|
|
585
|
+
trim: !1
|
|
586
|
+
}).split(`
|
|
587
|
+
`).length - 1;
|
|
588
|
+
this.output.write(import_src.cursor.move(-999, e * -1));
|
|
589
|
+
}
|
|
590
|
+
render() {
|
|
591
|
+
const e = K$1(this._render(this) ?? "", process.stdout.columns, {
|
|
592
|
+
hard: !0,
|
|
593
|
+
trim: !1
|
|
594
|
+
});
|
|
595
|
+
if (e !== this._prevFrame) {
|
|
596
|
+
if (this.state === "initial") this.output.write(import_src.cursor.hide);
|
|
597
|
+
else {
|
|
598
|
+
const s = _t$1(this._prevFrame, e), i = nt(this.output);
|
|
599
|
+
if (this.restoreCursor(), s) {
|
|
600
|
+
const r = Math.max(0, s.numLinesAfter - i), n = Math.max(0, s.numLinesBefore - i);
|
|
601
|
+
let u = s.lines.find((a) => a >= r);
|
|
602
|
+
if (u === void 0) {
|
|
603
|
+
this._prevFrame = e;
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
if (s.lines.length === 1) {
|
|
607
|
+
this.output.write(import_src.cursor.move(0, u - n)), this.output.write(import_src.erase.lines(1));
|
|
608
|
+
const a = e.split(`
|
|
609
|
+
`);
|
|
610
|
+
this.output.write(a[u]), this._prevFrame = e, this.output.write(import_src.cursor.move(0, a.length - u - 1));
|
|
611
|
+
return;
|
|
612
|
+
} else if (s.lines.length > 1) {
|
|
613
|
+
if (r < n) u = r;
|
|
614
|
+
else {
|
|
615
|
+
const l = u - n;
|
|
616
|
+
l > 0 && this.output.write(import_src.cursor.move(0, l));
|
|
617
|
+
}
|
|
618
|
+
this.output.write(import_src.erase.down());
|
|
619
|
+
const a = e.split(`
|
|
620
|
+
`).slice(u);
|
|
621
|
+
this.output.write(a.join(`
|
|
622
|
+
`)), this._prevFrame = e;
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
this.output.write(import_src.erase.down());
|
|
627
|
+
}
|
|
628
|
+
this.output.write(e), this.state === "initial" && (this.state = "active"), this._prevFrame = e;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
function wt$1(t, e) {
|
|
633
|
+
if (t === void 0 || e.length === 0) return 0;
|
|
634
|
+
const s = e.findIndex((i) => i.value === t);
|
|
635
|
+
return s !== -1 ? s : 0;
|
|
636
|
+
}
|
|
637
|
+
function Dt$1(t, e) {
|
|
638
|
+
return (e.label ?? String(e.value)).toLowerCase().includes(t.toLowerCase());
|
|
639
|
+
}
|
|
640
|
+
function St$1(t, e) {
|
|
641
|
+
if (e) return t ? e : e[0];
|
|
642
|
+
}
|
|
643
|
+
var Vt$1 = class extends x$1 {
|
|
644
|
+
filteredOptions;
|
|
645
|
+
multiple;
|
|
646
|
+
isNavigating = !1;
|
|
647
|
+
selectedValues = [];
|
|
648
|
+
focusedValue;
|
|
649
|
+
#t = 0;
|
|
650
|
+
#s = "";
|
|
651
|
+
#i;
|
|
652
|
+
#e;
|
|
653
|
+
get cursor() {
|
|
654
|
+
return this.#t;
|
|
655
|
+
}
|
|
656
|
+
get userInputWithCursor() {
|
|
657
|
+
if (!this.userInput) return import_picocolors.default.inverse(import_picocolors.default.hidden("_"));
|
|
658
|
+
if (this._cursor >= this.userInput.length) return `${this.userInput}\u2588`;
|
|
659
|
+
const e = this.userInput.slice(0, this._cursor), [s, ...i] = this.userInput.slice(this._cursor);
|
|
660
|
+
return `${e}${import_picocolors.default.inverse(s)}${i.join("")}`;
|
|
661
|
+
}
|
|
662
|
+
get options() {
|
|
663
|
+
return typeof this.#e == "function" ? this.#e() : this.#e;
|
|
664
|
+
}
|
|
665
|
+
constructor(e) {
|
|
666
|
+
super(e), this.#e = e.options;
|
|
667
|
+
const s = this.options;
|
|
668
|
+
this.filteredOptions = [...s], this.multiple = e.multiple === !0, this.#i = e.filter ?? Dt$1;
|
|
669
|
+
let i;
|
|
670
|
+
if (e.initialValue && Array.isArray(e.initialValue) ? this.multiple ? i = e.initialValue : i = e.initialValue.slice(0, 1) : !this.multiple && this.options.length > 0 && (i = [this.options[0].value]), i) for (const r of i) {
|
|
671
|
+
const n = s.findIndex((u) => u.value === r);
|
|
672
|
+
n !== -1 && (this.toggleSelected(r), this.#t = n);
|
|
673
|
+
}
|
|
674
|
+
this.focusedValue = this.options[this.#t]?.value, this.on("key", (r, n) => this.#r(r, n)), this.on("userInput", (r) => this.#n(r));
|
|
675
|
+
}
|
|
676
|
+
_isActionKey(e, s) {
|
|
677
|
+
return e === " " || this.multiple && this.isNavigating && s.name === "space" && e !== void 0 && e !== "";
|
|
678
|
+
}
|
|
679
|
+
#r(e, s) {
|
|
680
|
+
const i = s.name === "up", r = s.name === "down", n = s.name === "return";
|
|
681
|
+
i || r ? (this.#t = Math.max(0, Math.min(this.#t + (i ? -1 : 1), this.filteredOptions.length - 1)), this.focusedValue = this.filteredOptions[this.#t]?.value, this.multiple || (this.selectedValues = [this.focusedValue]), this.isNavigating = !0) : n ? this.value = St$1(this.multiple, this.selectedValues) : this.multiple ? this.focusedValue !== void 0 && (s.name === "tab" || this.isNavigating && s.name === "space") ? this.toggleSelected(this.focusedValue) : this.isNavigating = !1 : (this.focusedValue && (this.selectedValues = [this.focusedValue]), this.isNavigating = !1);
|
|
682
|
+
}
|
|
683
|
+
deselectAll() {
|
|
684
|
+
this.selectedValues = [];
|
|
685
|
+
}
|
|
686
|
+
toggleSelected(e) {
|
|
687
|
+
this.filteredOptions.length !== 0 && (this.multiple ? this.selectedValues.includes(e) ? this.selectedValues = this.selectedValues.filter((s) => s !== e) : this.selectedValues = [...this.selectedValues, e] : this.selectedValues = [e]);
|
|
688
|
+
}
|
|
689
|
+
#n(e) {
|
|
690
|
+
if (e !== this.#s) {
|
|
691
|
+
this.#s = e;
|
|
692
|
+
const s = this.options;
|
|
693
|
+
e ? this.filteredOptions = s.filter((i) => this.#i(e, i)) : this.filteredOptions = [...s], this.#t = wt$1(this.focusedValue, this.filteredOptions), this.focusedValue = this.filteredOptions[this.#t]?.value, this.multiple || (this.focusedValue !== void 0 ? this.toggleSelected(this.focusedValue) : this.deselectAll());
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
var kt$1 = class extends x$1 {
|
|
698
|
+
get cursor() {
|
|
699
|
+
return this.value ? 0 : 1;
|
|
700
|
+
}
|
|
701
|
+
get _value() {
|
|
702
|
+
return this.cursor === 0;
|
|
703
|
+
}
|
|
704
|
+
constructor(e) {
|
|
705
|
+
super(e, !1), this.value = !!e.initialValue, this.on("userInput", () => {
|
|
706
|
+
this.value = this._value;
|
|
707
|
+
}), this.on("confirm", (s) => {
|
|
708
|
+
this.output.write(import_src.cursor.move(0, -1)), this.value = s, this.state = "submit", this.close();
|
|
709
|
+
}), this.on("cursor", () => {
|
|
710
|
+
this.value = !this.value;
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
var yt$1 = class extends x$1 {
|
|
715
|
+
options;
|
|
716
|
+
cursor = 0;
|
|
717
|
+
#t;
|
|
718
|
+
getGroupItems(e) {
|
|
719
|
+
return this.options.filter((s) => s.group === e);
|
|
720
|
+
}
|
|
721
|
+
isGroupSelected(e) {
|
|
722
|
+
const s = this.getGroupItems(e), i = this.value;
|
|
723
|
+
return i === void 0 ? !1 : s.every((r) => i.includes(r.value));
|
|
724
|
+
}
|
|
725
|
+
toggleValue() {
|
|
726
|
+
const e = this.options[this.cursor];
|
|
727
|
+
if (this.value === void 0 && (this.value = []), e.group === !0) {
|
|
728
|
+
const s = e.value, i = this.getGroupItems(s);
|
|
729
|
+
this.isGroupSelected(s) ? this.value = this.value.filter((r) => i.findIndex((n) => n.value === r) === -1) : this.value = [...this.value, ...i.map((r) => r.value)], this.value = Array.from(new Set(this.value));
|
|
730
|
+
} else this.value = this.value.includes(e.value) ? this.value.filter((i) => i !== e.value) : [...this.value, e.value];
|
|
731
|
+
}
|
|
732
|
+
constructor(e) {
|
|
733
|
+
super(e, !1);
|
|
734
|
+
const { options: s } = e;
|
|
735
|
+
this.#t = e.selectableGroups !== !1, this.options = Object.entries(s).flatMap(([i, r]) => [{
|
|
736
|
+
value: i,
|
|
737
|
+
group: !0,
|
|
738
|
+
label: i
|
|
739
|
+
}, ...r.map((n) => ({
|
|
740
|
+
...n,
|
|
741
|
+
group: i
|
|
742
|
+
}))]), this.value = [...e.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: i }) => i === e.cursorAt), this.#t ? 0 : 1), this.on("cursor", (i) => {
|
|
743
|
+
switch (i) {
|
|
744
|
+
case "left":
|
|
745
|
+
case "up": {
|
|
746
|
+
this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
|
|
747
|
+
const r = this.options[this.cursor]?.group === !0;
|
|
748
|
+
!this.#t && r && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
|
|
749
|
+
break;
|
|
750
|
+
}
|
|
751
|
+
case "down":
|
|
752
|
+
case "right": {
|
|
753
|
+
this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
|
|
754
|
+
const r = this.options[this.cursor]?.group === !0;
|
|
755
|
+
!this.#t && r && (this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1);
|
|
756
|
+
break;
|
|
757
|
+
}
|
|
758
|
+
case "space":
|
|
759
|
+
this.toggleValue();
|
|
760
|
+
break;
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
function D(t, e, s) {
|
|
766
|
+
const i = t + e, r = Math.max(s.length - 1, 0), n = i < 0 ? r : i > r ? 0 : i;
|
|
767
|
+
return s[n].disabled ? D(n, e < 0 ? -1 : 1, s) : n;
|
|
768
|
+
}
|
|
769
|
+
var Mt$1 = class extends x$1 {
|
|
770
|
+
options;
|
|
771
|
+
cursor = 0;
|
|
772
|
+
get _value() {
|
|
773
|
+
return this.options[this.cursor].value;
|
|
774
|
+
}
|
|
775
|
+
get _enabledOptions() {
|
|
776
|
+
return this.options.filter((e) => e.disabled !== !0);
|
|
777
|
+
}
|
|
778
|
+
toggleAll() {
|
|
779
|
+
const e = this._enabledOptions;
|
|
780
|
+
this.value = this.value !== void 0 && this.value.length === e.length ? [] : e.map((i) => i.value);
|
|
781
|
+
}
|
|
782
|
+
toggleInvert() {
|
|
783
|
+
const e = this.value;
|
|
784
|
+
if (!e) return;
|
|
785
|
+
this.value = this._enabledOptions.filter((i) => !e.includes(i.value)).map((i) => i.value);
|
|
786
|
+
}
|
|
787
|
+
toggleValue() {
|
|
788
|
+
this.value === void 0 && (this.value = []);
|
|
789
|
+
this.value = this.value.includes(this._value) ? this.value.filter((s) => s !== this._value) : [...this.value, this._value];
|
|
790
|
+
}
|
|
791
|
+
constructor(e) {
|
|
792
|
+
super(e, !1), this.options = e.options, this.value = [...e.initialValues ?? []];
|
|
793
|
+
const s = Math.max(this.options.findIndex(({ value: i }) => i === e.cursorAt), 0);
|
|
794
|
+
this.cursor = this.options[s].disabled ? D(s, 1, this.options) : s, this.on("key", (i) => {
|
|
795
|
+
i === "a" && this.toggleAll(), i === "i" && this.toggleInvert();
|
|
796
|
+
}), this.on("cursor", (i) => {
|
|
797
|
+
switch (i) {
|
|
798
|
+
case "left":
|
|
799
|
+
case "up":
|
|
800
|
+
this.cursor = D(this.cursor, -1, this.options);
|
|
801
|
+
break;
|
|
802
|
+
case "down":
|
|
803
|
+
case "right":
|
|
804
|
+
this.cursor = D(this.cursor, 1, this.options);
|
|
805
|
+
break;
|
|
806
|
+
case "space":
|
|
807
|
+
this.toggleValue();
|
|
808
|
+
break;
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
let Lt$1 = class extends x$1 {
|
|
814
|
+
_mask = "•";
|
|
815
|
+
get cursor() {
|
|
816
|
+
return this._cursor;
|
|
817
|
+
}
|
|
818
|
+
get masked() {
|
|
819
|
+
return this.userInput.replaceAll(/./g, this._mask);
|
|
820
|
+
}
|
|
821
|
+
get userInputWithCursor() {
|
|
822
|
+
if (this.state === "submit" || this.state === "cancel") return this.masked;
|
|
823
|
+
const e = this.userInput;
|
|
824
|
+
if (this.cursor >= e.length) return `${this.masked}${import_picocolors.default.inverse(import_picocolors.default.hidden("_"))}`;
|
|
825
|
+
const s = this.masked, i = s.slice(0, this.cursor), r = s.slice(this.cursor);
|
|
826
|
+
return `${i}${import_picocolors.default.inverse(r[0])}${r.slice(1)}`;
|
|
827
|
+
}
|
|
828
|
+
clear() {
|
|
829
|
+
this._clearUserInput();
|
|
830
|
+
}
|
|
831
|
+
constructor({ mask: e, ...s }) {
|
|
832
|
+
super(s), this._mask = e ?? "•", this.on("userInput", (i) => {
|
|
833
|
+
this._setValue(i);
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
var Wt$1 = class extends x$1 {
|
|
838
|
+
options;
|
|
839
|
+
cursor = 0;
|
|
840
|
+
get _selectedValue() {
|
|
841
|
+
return this.options[this.cursor];
|
|
842
|
+
}
|
|
843
|
+
changeValue() {
|
|
844
|
+
this.value = this._selectedValue.value;
|
|
845
|
+
}
|
|
846
|
+
constructor(e) {
|
|
847
|
+
super(e, !1), this.options = e.options;
|
|
848
|
+
const s = this.options.findIndex(({ value: r }) => r === e.initialValue), i = s === -1 ? 0 : s;
|
|
849
|
+
this.cursor = this.options[i].disabled ? D(i, 1, this.options) : i, this.changeValue(), this.on("cursor", (r) => {
|
|
850
|
+
switch (r) {
|
|
851
|
+
case "left":
|
|
852
|
+
case "up":
|
|
853
|
+
this.cursor = D(this.cursor, -1, this.options);
|
|
854
|
+
break;
|
|
855
|
+
case "down":
|
|
856
|
+
case "right":
|
|
857
|
+
this.cursor = D(this.cursor, 1, this.options);
|
|
858
|
+
break;
|
|
859
|
+
}
|
|
860
|
+
this.changeValue();
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
var Tt$1 = class extends x$1 {
|
|
865
|
+
options;
|
|
866
|
+
cursor = 0;
|
|
867
|
+
constructor(e) {
|
|
868
|
+
super(e, !1), this.options = e.options;
|
|
869
|
+
const s = e.caseSensitive === !0, i = this.options.map(({ value: [r] }) => s ? r : r?.toLowerCase());
|
|
870
|
+
this.cursor = Math.max(i.indexOf(e.initialValue), 0), this.on("key", (r, n) => {
|
|
871
|
+
if (!r) return;
|
|
872
|
+
const u = s && n.shift ? r.toUpperCase() : r;
|
|
873
|
+
if (!i.includes(u)) return;
|
|
874
|
+
const a = this.options.find(({ value: [l] }) => s ? l === u : l?.toLowerCase() === r);
|
|
875
|
+
a && (this.value = a.value, this.state = "submit", this.emit("submit"));
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
};
|
|
879
|
+
var $t = class extends x$1 {
|
|
880
|
+
get userInputWithCursor() {
|
|
881
|
+
if (this.state === "submit") return this.userInput;
|
|
882
|
+
const e = this.userInput;
|
|
883
|
+
if (this.cursor >= e.length) return `${this.userInput}\u2588`;
|
|
884
|
+
const s = e.slice(0, this.cursor), [i, ...r] = e.slice(this.cursor);
|
|
885
|
+
return `${s}${import_picocolors.default.inverse(i)}${r.join("")}`;
|
|
886
|
+
}
|
|
887
|
+
get cursor() {
|
|
888
|
+
return this._cursor;
|
|
889
|
+
}
|
|
890
|
+
constructor(e) {
|
|
891
|
+
super({
|
|
892
|
+
...e,
|
|
893
|
+
initialUserInput: e.initialUserInput ?? e.initialValue
|
|
894
|
+
}), this.on("userInput", (s) => {
|
|
895
|
+
this._setValue(s);
|
|
896
|
+
}), this.on("finalize", () => {
|
|
897
|
+
this.value || (this.value = e.defaultValue), this.value === void 0 && (this.value = "");
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
|
|
902
|
+
//#endregion
|
|
903
|
+
//#region ../node_modules/.pnpm/@clack+prompts@1.0.0/node_modules/@clack/prompts/dist/index.mjs
|
|
904
|
+
function ht() {
|
|
905
|
+
return P.platform !== "win32" ? P.env.TERM !== "linux" : !!P.env.CI || !!P.env.WT_SESSION || !!P.env.TERMINUS_SUBLIME || P.env.ConEmuTask === "{cmd::Cmder}" || P.env.TERM_PROGRAM === "Terminus-Sublime" || P.env.TERM_PROGRAM === "vscode" || P.env.TERM === "xterm-256color" || P.env.TERM === "alacritty" || P.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
906
|
+
}
|
|
907
|
+
const ee = ht(), ue = () => process.env.CI === "true", Te = (e) => e.isTTY === !0, w = (e, r) => ee ? e : r, Me = w("◆", "*"), ce = w("■", "x"), de = w("▲", "x"), k = w("◇", "o"), $e = w("┌", "T"), h = w("│", "|"), x = w("└", "—"), Re = w("┐", "T"), Oe = w("┘", "—"), Y = w("●", ">"), K = w("○", " "), te = w("◻", "[•]"), G = w("◼", "[+]"), z = w("◻", "[ ]"), Pe = w("▪", "•"), se = w("─", "-"), he = w("╮", "+"), Ne = w("├", "+"), me = w("╯", "+"), pe = w("╰", "+"), We = w("╭", "+"), ge = w("●", "•"), fe = w("◆", "*"), Fe = w("▲", "!"), ye = w("■", "x"), N = (e) => {
|
|
908
|
+
switch (e) {
|
|
909
|
+
case "initial":
|
|
910
|
+
case "active": return import_picocolors.default.cyan(Me);
|
|
911
|
+
case "cancel": return import_picocolors.default.red(ce);
|
|
912
|
+
case "error": return import_picocolors.default.yellow(de);
|
|
913
|
+
case "submit": return import_picocolors.default.green(k);
|
|
914
|
+
}
|
|
915
|
+
}, Ee = (e) => {
|
|
916
|
+
switch (e) {
|
|
917
|
+
case "initial":
|
|
918
|
+
case "active": return import_picocolors.default.cyan(h);
|
|
919
|
+
case "cancel": return import_picocolors.default.red(h);
|
|
920
|
+
case "error": return import_picocolors.default.yellow(h);
|
|
921
|
+
case "submit": return import_picocolors.default.green(h);
|
|
922
|
+
}
|
|
923
|
+
}, mt = (e) => e === 161 || e === 164 || e === 167 || e === 168 || e === 170 || e === 173 || e === 174 || e >= 176 && e <= 180 || e >= 182 && e <= 186 || e >= 188 && e <= 191 || e === 198 || e === 208 || e === 215 || e === 216 || e >= 222 && e <= 225 || e === 230 || e >= 232 && e <= 234 || e === 236 || e === 237 || e === 240 || e === 242 || e === 243 || e >= 247 && e <= 250 || e === 252 || e === 254 || e === 257 || e === 273 || e === 275 || e === 283 || e === 294 || e === 295 || e === 299 || e >= 305 && e <= 307 || e === 312 || e >= 319 && e <= 322 || e === 324 || e >= 328 && e <= 331 || e === 333 || e === 338 || e === 339 || e === 358 || e === 359 || e === 363 || e === 462 || e === 464 || e === 466 || e === 468 || e === 470 || e === 472 || e === 474 || e === 476 || e === 593 || e === 609 || e === 708 || e === 711 || e >= 713 && e <= 715 || e === 717 || e === 720 || e >= 728 && e <= 731 || e === 733 || e === 735 || e >= 768 && e <= 879 || e >= 913 && e <= 929 || e >= 931 && e <= 937 || e >= 945 && e <= 961 || e >= 963 && e <= 969 || e === 1025 || e >= 1040 && e <= 1103 || e === 1105 || e === 8208 || e >= 8211 && e <= 8214 || e === 8216 || e === 8217 || e === 8220 || e === 8221 || e >= 8224 && e <= 8226 || e >= 8228 && e <= 8231 || e === 8240 || e === 8242 || e === 8243 || e === 8245 || e === 8251 || e === 8254 || e === 8308 || e === 8319 || e >= 8321 && e <= 8324 || e === 8364 || e === 8451 || e === 8453 || e === 8457 || e === 8467 || e === 8470 || e === 8481 || e === 8482 || e === 8486 || e === 8491 || e === 8531 || e === 8532 || e >= 8539 && e <= 8542 || e >= 8544 && e <= 8555 || e >= 8560 && e <= 8569 || e === 8585 || e >= 8592 && e <= 8601 || e === 8632 || e === 8633 || e === 8658 || e === 8660 || e === 8679 || e === 8704 || e === 8706 || e === 8707 || e === 8711 || e === 8712 || e === 8715 || e === 8719 || e === 8721 || e === 8725 || e === 8730 || e >= 8733 && e <= 8736 || e === 8739 || e === 8741 || e >= 8743 && e <= 8748 || e === 8750 || e >= 8756 && e <= 8759 || e === 8764 || e === 8765 || e === 8776 || e === 8780 || e === 8786 || e === 8800 || e === 8801 || e >= 8804 && e <= 8807 || e === 8810 || e === 8811 || e === 8814 || e === 8815 || e === 8834 || e === 8835 || e === 8838 || e === 8839 || e === 8853 || e === 8857 || e === 8869 || e === 8895 || e === 8978 || e >= 9312 && e <= 9449 || e >= 9451 && e <= 9547 || e >= 9552 && e <= 9587 || e >= 9600 && e <= 9615 || e >= 9618 && e <= 9621 || e === 9632 || e === 9633 || e >= 9635 && e <= 9641 || e === 9650 || e === 9651 || e === 9654 || e === 9655 || e === 9660 || e === 9661 || e === 9664 || e === 9665 || e >= 9670 && e <= 9672 || e === 9675 || e >= 9678 && e <= 9681 || e >= 9698 && e <= 9701 || e === 9711 || e === 9733 || e === 9734 || e === 9737 || e === 9742 || e === 9743 || e === 9756 || e === 9758 || e === 9792 || e === 9794 || e === 9824 || e === 9825 || e >= 9827 && e <= 9829 || e >= 9831 && e <= 9834 || e === 9836 || e === 9837 || e === 9839 || e === 9886 || e === 9887 || e === 9919 || e >= 9926 && e <= 9933 || e >= 9935 && e <= 9939 || e >= 9941 && e <= 9953 || e === 9955 || e === 9960 || e === 9961 || e >= 9963 && e <= 9969 || e === 9972 || e >= 9974 && e <= 9977 || e === 9979 || e === 9980 || e === 9982 || e === 9983 || e === 10045 || e >= 10102 && e <= 10111 || e >= 11094 && e <= 11097 || e >= 12872 && e <= 12879 || e >= 57344 && e <= 63743 || e >= 65024 && e <= 65039 || e === 65533 || e >= 127232 && e <= 127242 || e >= 127248 && e <= 127277 || e >= 127280 && e <= 127337 || e >= 127344 && e <= 127373 || e === 127375 || e === 127376 || e >= 127387 && e <= 127404 || e >= 917760 && e <= 917999 || e >= 983040 && e <= 1048573 || e >= 1048576 && e <= 1114109, pt = (e) => e === 12288 || e >= 65281 && e <= 65376 || e >= 65504 && e <= 65510, gt = (e) => e >= 4352 && e <= 4447 || e === 8986 || e === 8987 || e === 9001 || e === 9002 || e >= 9193 && e <= 9196 || e === 9200 || e === 9203 || e === 9725 || e === 9726 || e === 9748 || e === 9749 || e >= 9800 && e <= 9811 || e === 9855 || e === 9875 || e === 9889 || e === 9898 || e === 9899 || e === 9917 || e === 9918 || e === 9924 || e === 9925 || e === 9934 || e === 9940 || e === 9962 || e === 9970 || e === 9971 || e === 9973 || e === 9978 || e === 9981 || e === 9989 || e === 9994 || e === 9995 || e === 10024 || e === 10060 || e === 10062 || e >= 10067 && e <= 10069 || e === 10071 || e >= 10133 && e <= 10135 || e === 10160 || e === 10175 || e === 11035 || e === 11036 || e === 11088 || e === 11093 || e >= 11904 && e <= 11929 || e >= 11931 && e <= 12019 || e >= 12032 && e <= 12245 || e >= 12272 && e <= 12287 || e >= 12289 && e <= 12350 || e >= 12353 && e <= 12438 || e >= 12441 && e <= 12543 || e >= 12549 && e <= 12591 || e >= 12593 && e <= 12686 || e >= 12688 && e <= 12771 || e >= 12783 && e <= 12830 || e >= 12832 && e <= 12871 || e >= 12880 && e <= 19903 || e >= 19968 && e <= 42124 || e >= 42128 && e <= 42182 || e >= 43360 && e <= 43388 || e >= 44032 && e <= 55203 || e >= 63744 && e <= 64255 || e >= 65040 && e <= 65049 || e >= 65072 && e <= 65106 || e >= 65108 && e <= 65126 || e >= 65128 && e <= 65131 || e >= 94176 && e <= 94180 || e === 94192 || e === 94193 || e >= 94208 && e <= 100343 || e >= 100352 && e <= 101589 || e >= 101632 && e <= 101640 || e >= 110576 && e <= 110579 || e >= 110581 && e <= 110587 || e === 110589 || e === 110590 || e >= 110592 && e <= 110882 || e === 110898 || e >= 110928 && e <= 110930 || e === 110933 || e >= 110948 && e <= 110951 || e >= 110960 && e <= 111355 || e === 126980 || e === 127183 || e === 127374 || e >= 127377 && e <= 127386 || e >= 127488 && e <= 127490 || e >= 127504 && e <= 127547 || e >= 127552 && e <= 127560 || e === 127568 || e === 127569 || e >= 127584 && e <= 127589 || e >= 127744 && e <= 127776 || e >= 127789 && e <= 127797 || e >= 127799 && e <= 127868 || e >= 127870 && e <= 127891 || e >= 127904 && e <= 127946 || e >= 127951 && e <= 127955 || e >= 127968 && e <= 127984 || e === 127988 || e >= 127992 && e <= 128062 || e === 128064 || e >= 128066 && e <= 128252 || e >= 128255 && e <= 128317 || e >= 128331 && e <= 128334 || e >= 128336 && e <= 128359 || e === 128378 || e === 128405 || e === 128406 || e === 128420 || e >= 128507 && e <= 128591 || e >= 128640 && e <= 128709 || e === 128716 || e >= 128720 && e <= 128722 || e >= 128725 && e <= 128727 || e >= 128732 && e <= 128735 || e === 128747 || e === 128748 || e >= 128756 && e <= 128764 || e >= 128992 && e <= 129003 || e === 129008 || e >= 129292 && e <= 129338 || e >= 129340 && e <= 129349 || e >= 129351 && e <= 129535 || e >= 129648 && e <= 129660 || e >= 129664 && e <= 129672 || e >= 129680 && e <= 129725 || e >= 129727 && e <= 129733 || e >= 129742 && e <= 129755 || e >= 129760 && e <= 129768 || e >= 129776 && e <= 129784 || e >= 131072 && e <= 196605 || e >= 196608 && e <= 262141, ve = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y, re = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y, ie = /\t{1,1000}/y, Ae = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/uy, ne = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y, ft = /\p{M}+/gu, Ft = {
|
|
924
|
+
limit: Infinity,
|
|
925
|
+
ellipsis: ""
|
|
926
|
+
}, Le = (e, r = {}, s = {}) => {
|
|
927
|
+
const i = r.limit ?? Infinity, n = r.ellipsis ?? "", o = r?.ellipsisWidth ?? (n ? Le(n, Ft, s).width : 0), u = s.ansiWidth ?? 0, l = s.controlWidth ?? 0, a = s.tabWidth ?? 8, d = s.ambiguousWidth ?? 1, g = s.emojiWidth ?? 2, E = s.fullWidthWidth ?? 2, p = s.regularWidth ?? 1, y = s.wideWidth ?? 2;
|
|
928
|
+
let $ = 0, c = 0, m = e.length, f = 0, F = !1, v = m, S = Math.max(0, i - o), B = 0, b = 0, A = 0, C = 0;
|
|
929
|
+
e: for (;;) {
|
|
930
|
+
if (b > B || c >= m && c > $) {
|
|
931
|
+
const _ = e.slice(B, b) || e.slice($, c);
|
|
932
|
+
f = 0;
|
|
933
|
+
for (const D of _.replaceAll(ft, "")) {
|
|
934
|
+
const T = D.codePointAt(0) || 0;
|
|
935
|
+
if (pt(T) ? C = E : gt(T) ? C = y : d !== p && mt(T) ? C = d : C = p, A + C > S && (v = Math.min(v, Math.max(B, $) + f)), A + C > i) {
|
|
936
|
+
F = !0;
|
|
937
|
+
break e;
|
|
938
|
+
}
|
|
939
|
+
f += D.length, A += C;
|
|
940
|
+
}
|
|
941
|
+
B = b = 0;
|
|
942
|
+
}
|
|
943
|
+
if (c >= m) break;
|
|
944
|
+
if (ne.lastIndex = c, ne.test(e)) {
|
|
945
|
+
if (f = ne.lastIndex - c, C = f * p, A + C > S && (v = Math.min(v, c + Math.floor((S - A) / p))), A + C > i) {
|
|
946
|
+
F = !0;
|
|
947
|
+
break;
|
|
948
|
+
}
|
|
949
|
+
A += C, B = $, b = c, c = $ = ne.lastIndex;
|
|
950
|
+
continue;
|
|
951
|
+
}
|
|
952
|
+
if (ve.lastIndex = c, ve.test(e)) {
|
|
953
|
+
if (A + u > S && (v = Math.min(v, c)), A + u > i) {
|
|
954
|
+
F = !0;
|
|
955
|
+
break;
|
|
956
|
+
}
|
|
957
|
+
A += u, B = $, b = c, c = $ = ve.lastIndex;
|
|
958
|
+
continue;
|
|
959
|
+
}
|
|
960
|
+
if (re.lastIndex = c, re.test(e)) {
|
|
961
|
+
if (f = re.lastIndex - c, C = f * l, A + C > S && (v = Math.min(v, c + Math.floor((S - A) / l))), A + C > i) {
|
|
962
|
+
F = !0;
|
|
963
|
+
break;
|
|
964
|
+
}
|
|
965
|
+
A += C, B = $, b = c, c = $ = re.lastIndex;
|
|
966
|
+
continue;
|
|
967
|
+
}
|
|
968
|
+
if (ie.lastIndex = c, ie.test(e)) {
|
|
969
|
+
if (f = ie.lastIndex - c, C = f * a, A + C > S && (v = Math.min(v, c + Math.floor((S - A) / a))), A + C > i) {
|
|
970
|
+
F = !0;
|
|
971
|
+
break;
|
|
972
|
+
}
|
|
973
|
+
A += C, B = $, b = c, c = $ = ie.lastIndex;
|
|
974
|
+
continue;
|
|
975
|
+
}
|
|
976
|
+
if (Ae.lastIndex = c, Ae.test(e)) {
|
|
977
|
+
if (A + g > S && (v = Math.min(v, c)), A + g > i) {
|
|
978
|
+
F = !0;
|
|
979
|
+
break;
|
|
980
|
+
}
|
|
981
|
+
A += g, B = $, b = c, c = $ = Ae.lastIndex;
|
|
982
|
+
continue;
|
|
983
|
+
}
|
|
984
|
+
c += 1;
|
|
985
|
+
}
|
|
986
|
+
return {
|
|
987
|
+
width: F ? S : A,
|
|
988
|
+
index: F ? v : m,
|
|
989
|
+
truncated: F,
|
|
990
|
+
ellipsed: F && i >= o
|
|
991
|
+
};
|
|
992
|
+
}, yt = {
|
|
993
|
+
limit: Infinity,
|
|
994
|
+
ellipsis: "",
|
|
995
|
+
ellipsisWidth: 0
|
|
996
|
+
}, M = (e, r = {}) => Le(e, yt, r).width, ae = "\x1B", je = "", Et = 39, Ce = "\x07", Ve = "[", vt = "]", ke = "m", we = `${vt}8;;`, Ge = new RegExp(`(?:\\${Ve}(?<code>\\d+)m|\\${we}(?<uri>.*)${Ce})`, "y"), At = (e) => {
|
|
997
|
+
if (e >= 30 && e <= 37 || e >= 90 && e <= 97) return 39;
|
|
998
|
+
if (e >= 40 && e <= 47 || e >= 100 && e <= 107) return 49;
|
|
999
|
+
if (e === 1 || e === 2) return 22;
|
|
1000
|
+
if (e === 3) return 23;
|
|
1001
|
+
if (e === 4) return 24;
|
|
1002
|
+
if (e === 7) return 27;
|
|
1003
|
+
if (e === 8) return 28;
|
|
1004
|
+
if (e === 9) return 29;
|
|
1005
|
+
if (e === 0) return 0;
|
|
1006
|
+
}, He = (e) => `${ae}${Ve}${e}${ke}`, Ue = (e) => `${ae}${we}${e}${Ce}`, Ct = (e) => e.map((r) => M(r)), Se = (e, r, s) => {
|
|
1007
|
+
const i = r[Symbol.iterator]();
|
|
1008
|
+
let n = !1, o = !1, u = e.at(-1), l = u === void 0 ? 0 : M(u), a = i.next(), d = i.next(), g = 0;
|
|
1009
|
+
for (; !a.done;) {
|
|
1010
|
+
const E = a.value, p = M(E);
|
|
1011
|
+
l + p <= s ? e[e.length - 1] += E : (e.push(E), l = 0), (E === ae || E === je) && (n = !0, o = r.startsWith(we, g + 1)), n ? o ? E === Ce && (n = !1, o = !1) : E === ke && (n = !1) : (l += p, l === s && !d.done && (e.push(""), l = 0)), a = d, d = i.next(), g += E.length;
|
|
1012
|
+
}
|
|
1013
|
+
u = e.at(-1), !l && u !== void 0 && u.length > 0 && e.length > 1 && (e[e.length - 2] += e.pop());
|
|
1014
|
+
}, wt = (e) => {
|
|
1015
|
+
const r = e.split(" ");
|
|
1016
|
+
let s = r.length;
|
|
1017
|
+
for (; s > 0 && !(M(r[s - 1]) > 0);) s--;
|
|
1018
|
+
return s === r.length ? e : r.slice(0, s).join(" ") + r.slice(s).join("");
|
|
1019
|
+
}, St = (e, r, s = {}) => {
|
|
1020
|
+
if (s.trim !== !1 && e.trim() === "") return "";
|
|
1021
|
+
let i = "", n, o;
|
|
1022
|
+
const u = e.split(" "), l = Ct(u);
|
|
1023
|
+
let a = [""];
|
|
1024
|
+
for (const [$, c] of u.entries()) {
|
|
1025
|
+
s.trim !== !1 && (a[a.length - 1] = (a.at(-1) ?? "").trimStart());
|
|
1026
|
+
let m = M(a.at(-1) ?? "");
|
|
1027
|
+
if ($ !== 0 && (m >= r && (s.wordWrap === !1 || s.trim === !1) && (a.push(""), m = 0), (m > 0 || s.trim === !1) && (a[a.length - 1] += " ", m++)), s.hard && l[$] > r) {
|
|
1028
|
+
const f = r - m, F = 1 + Math.floor((l[$] - f - 1) / r);
|
|
1029
|
+
Math.floor((l[$] - 1) / r) < F && a.push(""), Se(a, c, r);
|
|
1030
|
+
continue;
|
|
1031
|
+
}
|
|
1032
|
+
if (m + l[$] > r && m > 0 && l[$] > 0) {
|
|
1033
|
+
if (s.wordWrap === !1 && m < r) {
|
|
1034
|
+
Se(a, c, r);
|
|
1035
|
+
continue;
|
|
1036
|
+
}
|
|
1037
|
+
a.push("");
|
|
1038
|
+
}
|
|
1039
|
+
if (m + l[$] > r && s.wordWrap === !1) {
|
|
1040
|
+
Se(a, c, r);
|
|
1041
|
+
continue;
|
|
1042
|
+
}
|
|
1043
|
+
a[a.length - 1] += c;
|
|
1044
|
+
}
|
|
1045
|
+
s.trim !== !1 && (a = a.map(($) => wt($)));
|
|
1046
|
+
const d = a.join(`
|
|
1047
|
+
`), g = d[Symbol.iterator]();
|
|
1048
|
+
let E = g.next(), p = g.next(), y = 0;
|
|
1049
|
+
for (; !E.done;) {
|
|
1050
|
+
const $ = E.value, c = p.value;
|
|
1051
|
+
if (i += $, $ === ae || $ === je) {
|
|
1052
|
+
Ge.lastIndex = y + 1;
|
|
1053
|
+
const F = Ge.exec(d)?.groups;
|
|
1054
|
+
if (F?.code !== void 0) {
|
|
1055
|
+
const v = Number.parseFloat(F.code);
|
|
1056
|
+
n = v === Et ? void 0 : v;
|
|
1057
|
+
} else F?.uri !== void 0 && (o = F.uri.length === 0 ? void 0 : F.uri);
|
|
1058
|
+
}
|
|
1059
|
+
const m = n ? At(n) : void 0;
|
|
1060
|
+
c === `
|
|
1061
|
+
` ? (o && (i += Ue("")), n && m && (i += He(m))) : $ === `
|
|
1062
|
+
` && (n && m && (i += He(n)), o && (i += Ue(o))), y += $.length, E = p, p = g.next();
|
|
1063
|
+
}
|
|
1064
|
+
return i;
|
|
1065
|
+
};
|
|
1066
|
+
function q(e, r, s) {
|
|
1067
|
+
return String(e).normalize().replaceAll(`\r
|
|
1068
|
+
`, `
|
|
1069
|
+
`).split(`
|
|
1070
|
+
`).map((i) => St(i, r, s)).join(`
|
|
1071
|
+
`);
|
|
1072
|
+
}
|
|
1073
|
+
const It = (e, r, s, i, n) => {
|
|
1074
|
+
let o = r, u = 0;
|
|
1075
|
+
for (let l = s; l < i; l++) {
|
|
1076
|
+
const a = e[l];
|
|
1077
|
+
if (o = o - a.length, u++, o <= n) break;
|
|
1078
|
+
}
|
|
1079
|
+
return {
|
|
1080
|
+
lineCount: o,
|
|
1081
|
+
removals: u
|
|
1082
|
+
};
|
|
1083
|
+
}, J = (e) => {
|
|
1084
|
+
const { cursor: r, options: s, style: i } = e, n = e.output ?? process.stdout, o = rt(n), u = e.columnPadding ?? 0, l = e.rowPadding ?? 4, a = o - u, d = nt(n), g = import_picocolors.default.dim("..."), E = e.maxItems ?? Number.POSITIVE_INFINITY, p = Math.max(d - l, 0), y = Math.max(Math.min(E, p), 5);
|
|
1085
|
+
let $ = 0;
|
|
1086
|
+
r >= y - 3 && ($ = Math.max(Math.min(r - y + 3, s.length - y), 0));
|
|
1087
|
+
let c = y < s.length && $ > 0, m = y < s.length && $ + y < s.length;
|
|
1088
|
+
const f = Math.min($ + y, s.length), F = [];
|
|
1089
|
+
let v = 0;
|
|
1090
|
+
c && v++, m && v++;
|
|
1091
|
+
const S = $ + (c ? 1 : 0), B = f - (m ? 1 : 0);
|
|
1092
|
+
for (let A = S; A < B; A++) {
|
|
1093
|
+
const C = q(i(s[A], A === r), a, {
|
|
1094
|
+
hard: !0,
|
|
1095
|
+
trim: !1
|
|
1096
|
+
}).split(`
|
|
1097
|
+
`);
|
|
1098
|
+
F.push(C), v += C.length;
|
|
1099
|
+
}
|
|
1100
|
+
if (v > p) {
|
|
1101
|
+
let A = 0, C = 0, _ = v;
|
|
1102
|
+
const D = r - S, T = (W, I) => It(F, _, W, I, p);
|
|
1103
|
+
c ? ({lineCount: _, removals: A} = T(0, D), _ > p && ({lineCount: _, removals: C} = T(D + 1, F.length))) : ({lineCount: _, removals: C} = T(D + 1, F.length), _ > p && ({lineCount: _, removals: A} = T(0, D))), A > 0 && (c = !0, F.splice(0, A)), C > 0 && (m = !0, F.splice(F.length - C, C));
|
|
1104
|
+
}
|
|
1105
|
+
const b = [];
|
|
1106
|
+
c && b.push(g);
|
|
1107
|
+
for (const A of F) for (const C of A) b.push(C);
|
|
1108
|
+
return m && b.push(g), b;
|
|
1109
|
+
};
|
|
1110
|
+
function Ke(e) {
|
|
1111
|
+
return e.label ?? String(e.value ?? "");
|
|
1112
|
+
}
|
|
1113
|
+
function qe(e, r) {
|
|
1114
|
+
if (!e) return !0;
|
|
1115
|
+
const s = (r.label ?? String(r.value ?? "")).toLowerCase(), i = (r.hint ?? "").toLowerCase(), n = String(r.value).toLowerCase(), o = e.toLowerCase();
|
|
1116
|
+
return s.includes(o) || i.includes(o) || n.includes(o);
|
|
1117
|
+
}
|
|
1118
|
+
function Bt(e, r) {
|
|
1119
|
+
const s = [];
|
|
1120
|
+
for (const i of r) e.includes(i.value) && s.push(i);
|
|
1121
|
+
return s;
|
|
1122
|
+
}
|
|
1123
|
+
const Je = (e) => new Vt$1({
|
|
1124
|
+
options: e.options,
|
|
1125
|
+
initialValue: e.initialValue ? [e.initialValue] : void 0,
|
|
1126
|
+
initialUserInput: e.initialUserInput,
|
|
1127
|
+
filter: e.filter ?? ((r, s) => qe(r, s)),
|
|
1128
|
+
signal: e.signal,
|
|
1129
|
+
input: e.input,
|
|
1130
|
+
output: e.output,
|
|
1131
|
+
validate: e.validate,
|
|
1132
|
+
render() {
|
|
1133
|
+
const r = [`${import_picocolors.default.gray(h)}`, `${N(this.state)} ${e.message}`], s = this.userInput, i = this.options, n = e.placeholder, o = s === "" && n !== void 0;
|
|
1134
|
+
switch (this.state) {
|
|
1135
|
+
case "submit": {
|
|
1136
|
+
const u = Bt(this.selectedValues, i), l = u.length > 0 ? ` ${import_picocolors.default.dim(u.map(Ke).join(", "))}` : "";
|
|
1137
|
+
return `${r.join(`
|
|
1138
|
+
`)}
|
|
1139
|
+
${import_picocolors.default.gray(h)}${l}`;
|
|
1140
|
+
}
|
|
1141
|
+
case "cancel": {
|
|
1142
|
+
const u = s ? ` ${import_picocolors.default.strikethrough(import_picocolors.default.dim(s))}` : "";
|
|
1143
|
+
return `${r.join(`
|
|
1144
|
+
`)}
|
|
1145
|
+
${import_picocolors.default.gray(h)}${u}`;
|
|
1146
|
+
}
|
|
1147
|
+
default: {
|
|
1148
|
+
const u = `${(this.state === "error" ? import_picocolors.default.yellow : import_picocolors.default.cyan)(h)} `, l = (this.state === "error" ? import_picocolors.default.yellow : import_picocolors.default.cyan)(x);
|
|
1149
|
+
let a = "";
|
|
1150
|
+
if (this.isNavigating || o) {
|
|
1151
|
+
const c = o ? n : s;
|
|
1152
|
+
a = c !== "" ? ` ${import_picocolors.default.dim(c)}` : "";
|
|
1153
|
+
} else a = ` ${this.userInputWithCursor}`;
|
|
1154
|
+
const d = this.filteredOptions.length !== i.length ? import_picocolors.default.dim(` (${this.filteredOptions.length} match${this.filteredOptions.length === 1 ? "" : "es"})`) : "", g = this.filteredOptions.length === 0 && s ? [`${u}${import_picocolors.default.yellow("No matches found")}`] : [], E = this.state === "error" ? [`${u}${import_picocolors.default.yellow(this.error)}`] : [];
|
|
1155
|
+
r.push(`${u.trimEnd()}`, `${u}${import_picocolors.default.dim("Search:")}${a}${d}`, ...g, ...E);
|
|
1156
|
+
const p = [
|
|
1157
|
+
`${import_picocolors.default.dim("↑/↓")} to select`,
|
|
1158
|
+
`${import_picocolors.default.dim("Enter:")} confirm`,
|
|
1159
|
+
`${import_picocolors.default.dim("Type:")} to search`
|
|
1160
|
+
], y = [`${u}${import_picocolors.default.dim(p.join(" • "))}`, `${l}`], $ = this.filteredOptions.length === 0 ? [] : J({
|
|
1161
|
+
cursor: this.cursor,
|
|
1162
|
+
options: this.filteredOptions,
|
|
1163
|
+
columnPadding: 3,
|
|
1164
|
+
rowPadding: r.length + y.length,
|
|
1165
|
+
style: (c, m) => {
|
|
1166
|
+
const f = Ke(c), F = c.hint && c.value === this.focusedValue ? import_picocolors.default.dim(` (${c.hint})`) : "";
|
|
1167
|
+
return m ? `${import_picocolors.default.green(Y)} ${f}${F}` : `${import_picocolors.default.dim(K)} ${import_picocolors.default.dim(f)}${F}`;
|
|
1168
|
+
},
|
|
1169
|
+
maxItems: e.maxItems,
|
|
1170
|
+
output: e.output
|
|
1171
|
+
});
|
|
1172
|
+
return [
|
|
1173
|
+
...r,
|
|
1174
|
+
...$.map((c) => `${u}${c}`),
|
|
1175
|
+
...y
|
|
1176
|
+
].join(`
|
|
1177
|
+
`);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
}).prompt(), bt = (e) => {
|
|
1182
|
+
const r = (i, n, o, u) => {
|
|
1183
|
+
const l = o.includes(i.value), a = i.label ?? String(i.value ?? ""), d = i.hint && u !== void 0 && i.value === u ? import_picocolors.default.dim(` (${i.hint})`) : "", g = l ? import_picocolors.default.green(G) : import_picocolors.default.dim(z);
|
|
1184
|
+
return n ? `${g} ${a}${d}` : `${g} ${import_picocolors.default.dim(a)}`;
|
|
1185
|
+
}, s = new Vt$1({
|
|
1186
|
+
options: e.options,
|
|
1187
|
+
multiple: !0,
|
|
1188
|
+
filter: e.filter ?? ((i, n) => qe(i, n)),
|
|
1189
|
+
validate: () => {
|
|
1190
|
+
if (e.required && s.selectedValues.length === 0) return "Please select at least one item";
|
|
1191
|
+
},
|
|
1192
|
+
initialValue: e.initialValues,
|
|
1193
|
+
signal: e.signal,
|
|
1194
|
+
input: e.input,
|
|
1195
|
+
output: e.output,
|
|
1196
|
+
render() {
|
|
1197
|
+
const i = `${import_picocolors.default.gray(h)}
|
|
1198
|
+
${N(this.state)} ${e.message}
|
|
1199
|
+
`, n = this.userInput, o = e.placeholder, u = n === "" && o !== void 0, l = this.isNavigating || u ? import_picocolors.default.dim(u ? o : n) : this.userInputWithCursor, a = this.options, d = this.filteredOptions.length !== a.length ? import_picocolors.default.dim(` (${this.filteredOptions.length} match${this.filteredOptions.length === 1 ? "" : "es"})`) : "";
|
|
1200
|
+
switch (this.state) {
|
|
1201
|
+
case "submit": return `${i}${import_picocolors.default.gray(h)} ${import_picocolors.default.dim(`${this.selectedValues.length} items selected`)}`;
|
|
1202
|
+
case "cancel": return `${i}${import_picocolors.default.gray(h)} ${import_picocolors.default.strikethrough(import_picocolors.default.dim(n))}`;
|
|
1203
|
+
default: {
|
|
1204
|
+
const g = this.state === "error" ? import_picocolors.default.yellow : import_picocolors.default.cyan, E = [
|
|
1205
|
+
`${import_picocolors.default.dim("↑/↓")} to navigate`,
|
|
1206
|
+
`${import_picocolors.default.dim(this.isNavigating ? "Space/Tab:" : "Tab:")} select`,
|
|
1207
|
+
`${import_picocolors.default.dim("Enter:")} confirm`,
|
|
1208
|
+
`${import_picocolors.default.dim("Type:")} to search`
|
|
1209
|
+
], p = this.filteredOptions.length === 0 && n ? [`${g(h)} ${import_picocolors.default.yellow("No matches found")}`] : [], y = this.state === "error" ? [`${g(h)} ${import_picocolors.default.yellow(this.error)}`] : [], $ = [
|
|
1210
|
+
...`${i}${g(h)}`.split(`
|
|
1211
|
+
`),
|
|
1212
|
+
`${g(h)} ${import_picocolors.default.dim("Search:")} ${l}${d}`,
|
|
1213
|
+
...p,
|
|
1214
|
+
...y
|
|
1215
|
+
], c = [`${g(h)} ${import_picocolors.default.dim(E.join(" • "))}`, `${g(x)}`], m = J({
|
|
1216
|
+
cursor: this.cursor,
|
|
1217
|
+
options: this.filteredOptions,
|
|
1218
|
+
style: (f, F) => r(f, F, this.selectedValues, this.focusedValue),
|
|
1219
|
+
maxItems: e.maxItems,
|
|
1220
|
+
output: e.output,
|
|
1221
|
+
rowPadding: $.length + c.length
|
|
1222
|
+
});
|
|
1223
|
+
return [
|
|
1224
|
+
...$,
|
|
1225
|
+
...m.map((f) => `${g(h)} ${f}`),
|
|
1226
|
+
...c
|
|
1227
|
+
].join(`
|
|
1228
|
+
`);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
});
|
|
1233
|
+
return s.prompt();
|
|
1234
|
+
}, xt = [
|
|
1235
|
+
We,
|
|
1236
|
+
he,
|
|
1237
|
+
pe,
|
|
1238
|
+
me
|
|
1239
|
+
], _t = [
|
|
1240
|
+
$e,
|
|
1241
|
+
Re,
|
|
1242
|
+
x,
|
|
1243
|
+
Oe
|
|
1244
|
+
];
|
|
1245
|
+
function Xe(e, r, s, i) {
|
|
1246
|
+
let n = s, o = s;
|
|
1247
|
+
return i === "center" ? n = Math.floor((r - e) / 2) : i === "right" && (n = r - e - s), o = r - n - e, [n, o];
|
|
1248
|
+
}
|
|
1249
|
+
const Dt = (e) => e, Tt = (e = "", r = "", s) => {
|
|
1250
|
+
const i = s?.output ?? process.stdout, n = rt(i), o = 2, u = s?.titlePadding ?? 1, l = s?.contentPadding ?? 2, a = s?.width === void 0 || s.width === "auto" ? 1 : Math.min(1, s.width), d = (s?.withGuide ?? _.withGuide) !== !1 ? `${h} ` : "", g = s?.formatBorder ?? Dt, E = (s?.rounded ? xt : _t).map(g), p = g(se), y = g(h), $ = M(d), c = M(r), m = n - $;
|
|
1251
|
+
let f = Math.floor(n * a) - $;
|
|
1252
|
+
if (s?.width === "auto") {
|
|
1253
|
+
const _ = e.split(`
|
|
1254
|
+
`);
|
|
1255
|
+
let D = c + u * 2;
|
|
1256
|
+
for (const W of _) {
|
|
1257
|
+
const I = M(W) + l * 2;
|
|
1258
|
+
I > D && (D = I);
|
|
1259
|
+
}
|
|
1260
|
+
const T = D + o;
|
|
1261
|
+
T < f && (f = T);
|
|
1262
|
+
}
|
|
1263
|
+
f % 2 !== 0 && (f < m ? f++ : f--);
|
|
1264
|
+
const F = f - o, v = F - u * 2, S = c > v ? `${r.slice(0, v - 3)}...` : r, [B, b] = Xe(M(S), F, u, s?.titleAlign), A = q(e, F - l * 2, {
|
|
1265
|
+
hard: !0,
|
|
1266
|
+
trim: !1
|
|
1267
|
+
});
|
|
1268
|
+
i.write(`${d}${E[0]}${p.repeat(B)}${S}${p.repeat(b)}${E[1]}
|
|
1269
|
+
`);
|
|
1270
|
+
const C = A.split(`
|
|
1271
|
+
`);
|
|
1272
|
+
for (const _ of C) {
|
|
1273
|
+
const [D, T] = Xe(M(_), F, l, s?.contentAlign);
|
|
1274
|
+
i.write(`${d}${y}${" ".repeat(D)}${_}${" ".repeat(T)}${y}
|
|
1275
|
+
`);
|
|
1276
|
+
}
|
|
1277
|
+
i.write(`${d}${E[2]}${p.repeat(F)}${E[3]}
|
|
1278
|
+
`);
|
|
1279
|
+
}, Mt = (e) => {
|
|
1280
|
+
const r = e.active ?? "Yes", s = e.inactive ?? "No";
|
|
1281
|
+
return new kt$1({
|
|
1282
|
+
active: r,
|
|
1283
|
+
inactive: s,
|
|
1284
|
+
signal: e.signal,
|
|
1285
|
+
input: e.input,
|
|
1286
|
+
output: e.output,
|
|
1287
|
+
initialValue: e.initialValue ?? !0,
|
|
1288
|
+
render() {
|
|
1289
|
+
const i = `${import_picocolors.default.gray(h)}
|
|
1290
|
+
${N(this.state)} ${e.message}
|
|
1291
|
+
`, n = this.value ? r : s;
|
|
1292
|
+
switch (this.state) {
|
|
1293
|
+
case "submit": return `${i}${import_picocolors.default.gray(h)} ${import_picocolors.default.dim(n)}`;
|
|
1294
|
+
case "cancel": return `${i}${import_picocolors.default.gray(h)} ${import_picocolors.default.strikethrough(import_picocolors.default.dim(n))}
|
|
1295
|
+
${import_picocolors.default.gray(h)}`;
|
|
1296
|
+
default: return `${i}${import_picocolors.default.cyan(h)} ${this.value ? `${import_picocolors.default.green(Y)} ${r}` : `${import_picocolors.default.dim(K)} ${import_picocolors.default.dim(r)}`} ${import_picocolors.default.dim("/")} ${this.value ? `${import_picocolors.default.dim(K)} ${import_picocolors.default.dim(s)}` : `${import_picocolors.default.green(Y)} ${s}`}
|
|
1297
|
+
${import_picocolors.default.cyan(x)}
|
|
1298
|
+
`;
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
}).prompt();
|
|
1302
|
+
}, Rt = async (e, r) => {
|
|
1303
|
+
const s = {}, i = Object.keys(e);
|
|
1304
|
+
for (const n of i) {
|
|
1305
|
+
const o = e[n], u = await o({ results: s })?.catch((l) => {
|
|
1306
|
+
throw l;
|
|
1307
|
+
});
|
|
1308
|
+
if (typeof r?.onCancel == "function" && Ct$1(u)) {
|
|
1309
|
+
s[n] = "canceled", r.onCancel({ results: s });
|
|
1310
|
+
continue;
|
|
1311
|
+
}
|
|
1312
|
+
s[n] = u;
|
|
1313
|
+
}
|
|
1314
|
+
return s;
|
|
1315
|
+
}, Ot = (e) => {
|
|
1316
|
+
const { selectableGroups: r = !0, groupSpacing: s = 0 } = e, i = (o, u, l = []) => {
|
|
1317
|
+
const a = o.label ?? String(o.value), d = typeof o.group == "string", g = d && (l[l.indexOf(o) + 1] ?? { group: !0 }), E = d && g && g.group === !0, p = d ? r ? `${E ? x : h} ` : " " : "";
|
|
1318
|
+
let y = "";
|
|
1319
|
+
if (s > 0 && !d) {
|
|
1320
|
+
const c = `
|
|
1321
|
+
${import_picocolors.default.cyan(h)}`;
|
|
1322
|
+
y = `${c.repeat(s - 1)}${c} `;
|
|
1323
|
+
}
|
|
1324
|
+
if (u === "active") return `${y}${import_picocolors.default.dim(p)}${import_picocolors.default.cyan(te)} ${a}${o.hint ? ` ${import_picocolors.default.dim(`(${o.hint})`)}` : ""}`;
|
|
1325
|
+
if (u === "group-active") return `${y}${p}${import_picocolors.default.cyan(te)} ${import_picocolors.default.dim(a)}`;
|
|
1326
|
+
if (u === "group-active-selected") return `${y}${p}${import_picocolors.default.green(G)} ${import_picocolors.default.dim(a)}`;
|
|
1327
|
+
if (u === "selected") {
|
|
1328
|
+
const c = d || r ? import_picocolors.default.green(G) : "";
|
|
1329
|
+
return `${y}${import_picocolors.default.dim(p)}${c} ${import_picocolors.default.dim(a)}${o.hint ? ` ${import_picocolors.default.dim(`(${o.hint})`)}` : ""}`;
|
|
1330
|
+
}
|
|
1331
|
+
if (u === "cancelled") return `${import_picocolors.default.strikethrough(import_picocolors.default.dim(a))}`;
|
|
1332
|
+
if (u === "active-selected") return `${y}${import_picocolors.default.dim(p)}${import_picocolors.default.green(G)} ${a}${o.hint ? ` ${import_picocolors.default.dim(`(${o.hint})`)}` : ""}`;
|
|
1333
|
+
if (u === "submitted") return `${import_picocolors.default.dim(a)}`;
|
|
1334
|
+
const $ = d || r ? import_picocolors.default.dim(z) : "";
|
|
1335
|
+
return `${y}${import_picocolors.default.dim(p)}${$} ${import_picocolors.default.dim(a)}`;
|
|
1336
|
+
}, n = e.required ?? !0;
|
|
1337
|
+
return new yt$1({
|
|
1338
|
+
options: e.options,
|
|
1339
|
+
signal: e.signal,
|
|
1340
|
+
input: e.input,
|
|
1341
|
+
output: e.output,
|
|
1342
|
+
initialValues: e.initialValues,
|
|
1343
|
+
required: n,
|
|
1344
|
+
cursorAt: e.cursorAt,
|
|
1345
|
+
selectableGroups: r,
|
|
1346
|
+
validate(o) {
|
|
1347
|
+
if (n && (o === void 0 || o.length === 0)) return `Please select at least one option.
|
|
1348
|
+
${import_picocolors.default.reset(import_picocolors.default.dim(`Press ${import_picocolors.default.gray(import_picocolors.default.bgWhite(import_picocolors.default.inverse(" space ")))} to select, ${import_picocolors.default.gray(import_picocolors.default.bgWhite(import_picocolors.default.inverse(" enter ")))} to submit`))}`;
|
|
1349
|
+
},
|
|
1350
|
+
render() {
|
|
1351
|
+
const o = `${import_picocolors.default.gray(h)}
|
|
1352
|
+
${N(this.state)} ${e.message}
|
|
1353
|
+
`, u = this.value ?? [];
|
|
1354
|
+
switch (this.state) {
|
|
1355
|
+
case "submit": {
|
|
1356
|
+
const l = this.options.filter(({ value: d }) => u.includes(d)).map((d) => i(d, "submitted")), a = l.length === 0 ? "" : ` ${l.join(import_picocolors.default.dim(", "))}`;
|
|
1357
|
+
return `${o}${import_picocolors.default.gray(h)}${a}`;
|
|
1358
|
+
}
|
|
1359
|
+
case "cancel": {
|
|
1360
|
+
const l = this.options.filter(({ value: a }) => u.includes(a)).map((a) => i(a, "cancelled")).join(import_picocolors.default.dim(", "));
|
|
1361
|
+
return `${o}${import_picocolors.default.gray(h)} ${l.trim() ? `${l}
|
|
1362
|
+
${import_picocolors.default.gray(h)}` : ""}`;
|
|
1363
|
+
}
|
|
1364
|
+
case "error": {
|
|
1365
|
+
const l = this.error.split(`
|
|
1366
|
+
`).map((a, d) => d === 0 ? `${import_picocolors.default.yellow(x)} ${import_picocolors.default.yellow(a)}` : ` ${a}`).join(`
|
|
1367
|
+
`);
|
|
1368
|
+
return `${o}${import_picocolors.default.yellow(h)} ${this.options.map((a, d, g) => {
|
|
1369
|
+
const E = u.includes(a.value) || a.group === !0 && this.isGroupSelected(`${a.value}`), p = d === this.cursor;
|
|
1370
|
+
return !p && typeof a.group == "string" && this.options[this.cursor].value === a.group ? i(a, E ? "group-active-selected" : "group-active", g) : p && E ? i(a, "active-selected", g) : E ? i(a, "selected", g) : i(a, p ? "active" : "inactive", g);
|
|
1371
|
+
}).join(`
|
|
1372
|
+
${import_picocolors.default.yellow(h)} `)}
|
|
1373
|
+
${l}
|
|
1374
|
+
`;
|
|
1375
|
+
}
|
|
1376
|
+
default: {
|
|
1377
|
+
const l = this.options.map((d, g, E) => {
|
|
1378
|
+
const p = u.includes(d.value) || d.group === !0 && this.isGroupSelected(`${d.value}`), y = g === this.cursor, $ = !y && typeof d.group == "string" && this.options[this.cursor].value === d.group;
|
|
1379
|
+
let c = "";
|
|
1380
|
+
return $ ? c = i(d, p ? "group-active-selected" : "group-active", E) : y && p ? c = i(d, "active-selected", E) : p ? c = i(d, "selected", E) : c = i(d, y ? "active" : "inactive", E), `${g !== 0 && !c.startsWith(`
|
|
1381
|
+
`) ? " " : ""}${c}`;
|
|
1382
|
+
}).join(`
|
|
1383
|
+
${import_picocolors.default.cyan(h)}`), a = l.startsWith(`
|
|
1384
|
+
`) ? "" : " ";
|
|
1385
|
+
return `${o}${import_picocolors.default.cyan(h)}${a}${l}
|
|
1386
|
+
${import_picocolors.default.cyan(x)}
|
|
1387
|
+
`;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
}).prompt();
|
|
1392
|
+
}, R = {
|
|
1393
|
+
message: (e = [], { symbol: r = import_picocolors.default.gray(h), secondarySymbol: s = import_picocolors.default.gray(h), output: i = process.stdout, spacing: n = 1, withGuide: o } = {}) => {
|
|
1394
|
+
const u = [], l = (o ?? _.withGuide) !== !1, a = l ? s : "", d = l ? `${r} ` : "", g = l ? `${s} ` : "";
|
|
1395
|
+
for (let p = 0; p < n; p++) u.push(a);
|
|
1396
|
+
const E = Array.isArray(e) ? e : e.split(`
|
|
1397
|
+
`);
|
|
1398
|
+
if (E.length > 0) {
|
|
1399
|
+
const [p, ...y] = E;
|
|
1400
|
+
p.length > 0 ? u.push(`${d}${p}`) : u.push(l ? r : "");
|
|
1401
|
+
for (const $ of y) $.length > 0 ? u.push(`${g}${$}`) : u.push(l ? s : "");
|
|
1402
|
+
}
|
|
1403
|
+
i.write(`${u.join(`
|
|
1404
|
+
`)}
|
|
1405
|
+
`);
|
|
1406
|
+
},
|
|
1407
|
+
info: (e, r) => {
|
|
1408
|
+
R.message(e, {
|
|
1409
|
+
...r,
|
|
1410
|
+
symbol: import_picocolors.default.blue(ge)
|
|
1411
|
+
});
|
|
1412
|
+
},
|
|
1413
|
+
success: (e, r) => {
|
|
1414
|
+
R.message(e, {
|
|
1415
|
+
...r,
|
|
1416
|
+
symbol: import_picocolors.default.green(fe)
|
|
1417
|
+
});
|
|
1418
|
+
},
|
|
1419
|
+
step: (e, r) => {
|
|
1420
|
+
R.message(e, {
|
|
1421
|
+
...r,
|
|
1422
|
+
symbol: import_picocolors.default.green(k)
|
|
1423
|
+
});
|
|
1424
|
+
},
|
|
1425
|
+
warn: (e, r) => {
|
|
1426
|
+
R.message(e, {
|
|
1427
|
+
...r,
|
|
1428
|
+
symbol: import_picocolors.default.yellow(Fe)
|
|
1429
|
+
});
|
|
1430
|
+
},
|
|
1431
|
+
warning: (e, r) => {
|
|
1432
|
+
R.warn(e, r);
|
|
1433
|
+
},
|
|
1434
|
+
error: (e, r) => {
|
|
1435
|
+
R.message(e, {
|
|
1436
|
+
...r,
|
|
1437
|
+
symbol: import_picocolors.default.red(ye)
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
}, Pt = (e = "", r) => {
|
|
1441
|
+
(r?.output ?? process.stdout).write(`${import_picocolors.default.gray(x)} ${import_picocolors.default.red(e)}
|
|
1442
|
+
|
|
1443
|
+
`);
|
|
1444
|
+
}, Nt = (e = "", r) => {
|
|
1445
|
+
(r?.output ?? process.stdout).write(`${import_picocolors.default.gray($e)} ${e}
|
|
1446
|
+
`);
|
|
1447
|
+
}, Wt = (e = "", r) => {
|
|
1448
|
+
(r?.output ?? process.stdout).write(`${import_picocolors.default.gray(h)}
|
|
1449
|
+
${import_picocolors.default.gray(x)} ${e}
|
|
1450
|
+
|
|
1451
|
+
`);
|
|
1452
|
+
}, Q = (e, r) => e.split(`
|
|
1453
|
+
`).map((s) => r(s)).join(`
|
|
1454
|
+
`), Lt = (e) => {
|
|
1455
|
+
const r = (i, n) => {
|
|
1456
|
+
const o = i.label ?? String(i.value);
|
|
1457
|
+
return n === "disabled" ? `${import_picocolors.default.gray(z)} ${Q(o, (u) => import_picocolors.default.strikethrough(import_picocolors.default.gray(u)))}${i.hint ? ` ${import_picocolors.default.dim(`(${i.hint ?? "disabled"})`)}` : ""}` : n === "active" ? `${import_picocolors.default.cyan(te)} ${o}${i.hint ? ` ${import_picocolors.default.dim(`(${i.hint})`)}` : ""}` : n === "selected" ? `${import_picocolors.default.green(G)} ${Q(o, import_picocolors.default.dim)}${i.hint ? ` ${import_picocolors.default.dim(`(${i.hint})`)}` : ""}` : n === "cancelled" ? `${Q(o, (u) => import_picocolors.default.strikethrough(import_picocolors.default.dim(u)))}` : n === "active-selected" ? `${import_picocolors.default.green(G)} ${o}${i.hint ? ` ${import_picocolors.default.dim(`(${i.hint})`)}` : ""}` : n === "submitted" ? `${Q(o, import_picocolors.default.dim)}` : `${import_picocolors.default.dim(z)} ${Q(o, import_picocolors.default.dim)}`;
|
|
1458
|
+
}, s = e.required ?? !0;
|
|
1459
|
+
return new Mt$1({
|
|
1460
|
+
options: e.options,
|
|
1461
|
+
signal: e.signal,
|
|
1462
|
+
input: e.input,
|
|
1463
|
+
output: e.output,
|
|
1464
|
+
initialValues: e.initialValues,
|
|
1465
|
+
required: s,
|
|
1466
|
+
cursorAt: e.cursorAt,
|
|
1467
|
+
validate(i) {
|
|
1468
|
+
if (s && (i === void 0 || i.length === 0)) return `Please select at least one option.
|
|
1469
|
+
${import_picocolors.default.reset(import_picocolors.default.dim(`Press ${import_picocolors.default.gray(import_picocolors.default.bgWhite(import_picocolors.default.inverse(" space ")))} to select, ${import_picocolors.default.gray(import_picocolors.default.bgWhite(import_picocolors.default.inverse(" enter ")))} to submit`))}`;
|
|
1470
|
+
},
|
|
1471
|
+
render() {
|
|
1472
|
+
const i = Bt$1(e.output, e.message, `${Ee(this.state)} `, `${N(this.state)} `), n = `${import_picocolors.default.gray(h)}
|
|
1473
|
+
${i}
|
|
1474
|
+
`, o = this.value ?? [], u = (l, a) => {
|
|
1475
|
+
if (l.disabled) return r(l, "disabled");
|
|
1476
|
+
const d = o.includes(l.value);
|
|
1477
|
+
return a && d ? r(l, "active-selected") : d ? r(l, "selected") : r(l, a ? "active" : "inactive");
|
|
1478
|
+
};
|
|
1479
|
+
switch (this.state) {
|
|
1480
|
+
case "submit": {
|
|
1481
|
+
const l = this.options.filter(({ value: d }) => o.includes(d)).map((d) => r(d, "submitted")).join(import_picocolors.default.dim(", ")) || import_picocolors.default.dim("none");
|
|
1482
|
+
return `${n}${Bt$1(e.output, l, `${import_picocolors.default.gray(h)} `)}`;
|
|
1483
|
+
}
|
|
1484
|
+
case "cancel": {
|
|
1485
|
+
const l = this.options.filter(({ value: d }) => o.includes(d)).map((d) => r(d, "cancelled")).join(import_picocolors.default.dim(", "));
|
|
1486
|
+
if (l.trim() === "") return `${n}${import_picocolors.default.gray(h)}`;
|
|
1487
|
+
return `${n}${Bt$1(e.output, l, `${import_picocolors.default.gray(h)} `)}
|
|
1488
|
+
${import_picocolors.default.gray(h)}`;
|
|
1489
|
+
}
|
|
1490
|
+
case "error": {
|
|
1491
|
+
const l = `${import_picocolors.default.yellow(h)} `, a = this.error.split(`
|
|
1492
|
+
`).map((E, p) => p === 0 ? `${import_picocolors.default.yellow(x)} ${import_picocolors.default.yellow(E)}` : ` ${E}`).join(`
|
|
1493
|
+
`), d = n.split(`
|
|
1494
|
+
`).length, g = a.split(`
|
|
1495
|
+
`).length + 1;
|
|
1496
|
+
return `${n}${l}${J({
|
|
1497
|
+
output: e.output,
|
|
1498
|
+
options: this.options,
|
|
1499
|
+
cursor: this.cursor,
|
|
1500
|
+
maxItems: e.maxItems,
|
|
1501
|
+
columnPadding: l.length,
|
|
1502
|
+
rowPadding: d + g,
|
|
1503
|
+
style: u
|
|
1504
|
+
}).join(`
|
|
1505
|
+
${l}`)}
|
|
1506
|
+
${a}
|
|
1507
|
+
`;
|
|
1508
|
+
}
|
|
1509
|
+
default: {
|
|
1510
|
+
const l = `${import_picocolors.default.cyan(h)} `, a = n.split(`
|
|
1511
|
+
`).length;
|
|
1512
|
+
return `${n}${l}${J({
|
|
1513
|
+
output: e.output,
|
|
1514
|
+
options: this.options,
|
|
1515
|
+
cursor: this.cursor,
|
|
1516
|
+
maxItems: e.maxItems,
|
|
1517
|
+
columnPadding: l.length,
|
|
1518
|
+
rowPadding: a + 2,
|
|
1519
|
+
style: u
|
|
1520
|
+
}).join(`
|
|
1521
|
+
${l}`)}
|
|
1522
|
+
${import_picocolors.default.cyan(x)}
|
|
1523
|
+
`;
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
}).prompt();
|
|
1528
|
+
}, jt = (e) => import_picocolors.default.dim(e), Vt = (e, r, s) => {
|
|
1529
|
+
const i = {
|
|
1530
|
+
hard: !0,
|
|
1531
|
+
trim: !1
|
|
1532
|
+
}, n = q(e, r, i).split(`
|
|
1533
|
+
`), o = n.reduce((a, d) => Math.max(M(d), a), 0);
|
|
1534
|
+
return q(e, r - (n.map(s).reduce((a, d) => Math.max(M(d), a), 0) - o), i);
|
|
1535
|
+
}, kt = (e = "", r = "", s) => {
|
|
1536
|
+
const i = s?.output ?? P.stdout, n = (s?.withGuide ?? _.withGuide) !== !1, o = s?.format ?? jt, u = [
|
|
1537
|
+
"",
|
|
1538
|
+
...Vt(e, rt(i) - 6, o).split(`
|
|
1539
|
+
`).map(o),
|
|
1540
|
+
""
|
|
1541
|
+
], l = M(r), a = Math.max(u.reduce((p, y) => {
|
|
1542
|
+
const $ = M(y);
|
|
1543
|
+
return $ > p ? $ : p;
|
|
1544
|
+
}, 0), l) + 2, d = u.map((p) => `${import_picocolors.default.gray(h)} ${p}${" ".repeat(a - M(p))}${import_picocolors.default.gray(h)}`).join(`
|
|
1545
|
+
`), g = n ? `${import_picocolors.default.gray(h)}
|
|
1546
|
+
` : "", E = n ? Ne : pe;
|
|
1547
|
+
i.write(`${g}${import_picocolors.default.green(k)} ${import_picocolors.default.reset(r)} ${import_picocolors.default.gray(se.repeat(Math.max(a - l - 1, 1)) + he)}
|
|
1548
|
+
${d}
|
|
1549
|
+
${import_picocolors.default.gray(E + se.repeat(a + 2) + me)}
|
|
1550
|
+
`);
|
|
1551
|
+
}, Gt = (e) => new Lt$1({
|
|
1552
|
+
validate: e.validate,
|
|
1553
|
+
mask: e.mask ?? Pe,
|
|
1554
|
+
signal: e.signal,
|
|
1555
|
+
input: e.input,
|
|
1556
|
+
output: e.output,
|
|
1557
|
+
render() {
|
|
1558
|
+
const r = `${import_picocolors.default.gray(h)}
|
|
1559
|
+
${N(this.state)} ${e.message}
|
|
1560
|
+
`, s = this.userInputWithCursor, i = this.masked;
|
|
1561
|
+
switch (this.state) {
|
|
1562
|
+
case "error": {
|
|
1563
|
+
const n = i ? ` ${i}` : "";
|
|
1564
|
+
return e.clearOnError && this.clear(), `${r.trim()}
|
|
1565
|
+
${import_picocolors.default.yellow(h)}${n}
|
|
1566
|
+
${import_picocolors.default.yellow(x)} ${import_picocolors.default.yellow(this.error)}
|
|
1567
|
+
`;
|
|
1568
|
+
}
|
|
1569
|
+
case "submit": {
|
|
1570
|
+
const n = i ? ` ${import_picocolors.default.dim(i)}` : "";
|
|
1571
|
+
return `${r}${import_picocolors.default.gray(h)}${n}`;
|
|
1572
|
+
}
|
|
1573
|
+
case "cancel": {
|
|
1574
|
+
const n = i ? ` ${import_picocolors.default.strikethrough(import_picocolors.default.dim(i))}` : "";
|
|
1575
|
+
return `${r}${import_picocolors.default.gray(h)}${n}${i ? `
|
|
1576
|
+
${import_picocolors.default.gray(h)}` : ""}`;
|
|
1577
|
+
}
|
|
1578
|
+
default: return `${r}${import_picocolors.default.cyan(h)} ${s}
|
|
1579
|
+
${import_picocolors.default.cyan(x)}
|
|
1580
|
+
`;
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
}).prompt(), Ht = (e) => {
|
|
1584
|
+
const r = e.validate;
|
|
1585
|
+
return Je({
|
|
1586
|
+
...e,
|
|
1587
|
+
initialUserInput: e.initialValue ?? e.root ?? process.cwd(),
|
|
1588
|
+
maxItems: 5,
|
|
1589
|
+
validate(s) {
|
|
1590
|
+
if (!Array.isArray(s)) {
|
|
1591
|
+
if (!s) return "Please select a path";
|
|
1592
|
+
if (r) return r(s);
|
|
1593
|
+
}
|
|
1594
|
+
},
|
|
1595
|
+
options() {
|
|
1596
|
+
const s = this.userInput;
|
|
1597
|
+
if (s === "") return [];
|
|
1598
|
+
try {
|
|
1599
|
+
let i;
|
|
1600
|
+
return existsSync(s) ? lstatSync(s).isDirectory() ? i = s : i = dirname(s) : i = dirname(s), readdirSync(i).map((n) => {
|
|
1601
|
+
const o = join(i, n);
|
|
1602
|
+
return {
|
|
1603
|
+
name: n,
|
|
1604
|
+
path: o,
|
|
1605
|
+
isDirectory: lstatSync(o).isDirectory()
|
|
1606
|
+
};
|
|
1607
|
+
}).filter(({ path: n, isDirectory: o }) => n.startsWith(s) && (e.directory || !o)).map((n) => ({ value: n.path }));
|
|
1608
|
+
} catch {
|
|
1609
|
+
return [];
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
});
|
|
1613
|
+
}, Ut = import_picocolors.default.magenta, Ie = ({ indicator: e = "dots", onCancel: r, output: s = process.stdout, cancelMessage: i, errorMessage: n, frames: o = ee ? [
|
|
1614
|
+
"◒",
|
|
1615
|
+
"◐",
|
|
1616
|
+
"◓",
|
|
1617
|
+
"◑"
|
|
1618
|
+
] : [
|
|
1619
|
+
"•",
|
|
1620
|
+
"o",
|
|
1621
|
+
"O",
|
|
1622
|
+
"0"
|
|
1623
|
+
], delay: u = ee ? 80 : 120, signal: l, ...a } = {}) => {
|
|
1624
|
+
const d = ue();
|
|
1625
|
+
let g, E, p = !1, y = !1, $ = "", c, m = performance.now();
|
|
1626
|
+
const f = rt(s), F = a?.styleFrame ?? Ut, v = (I) => {
|
|
1627
|
+
const O = I > 1 ? n ?? _.messages.error : i ?? _.messages.cancel;
|
|
1628
|
+
y = I === 1, p && (W(O, I), y && typeof r == "function" && r());
|
|
1629
|
+
}, S = () => v(2), B = () => v(1), b = () => {
|
|
1630
|
+
process.on("uncaughtExceptionMonitor", S), process.on("unhandledRejection", S), process.on("SIGINT", B), process.on("SIGTERM", B), process.on("exit", v), l && l.addEventListener("abort", B);
|
|
1631
|
+
}, A = () => {
|
|
1632
|
+
process.removeListener("uncaughtExceptionMonitor", S), process.removeListener("unhandledRejection", S), process.removeListener("SIGINT", B), process.removeListener("SIGTERM", B), process.removeListener("exit", v), l && l.removeEventListener("abort", B);
|
|
1633
|
+
}, C = () => {
|
|
1634
|
+
if (c === void 0) return;
|
|
1635
|
+
d && s.write(`
|
|
1636
|
+
`);
|
|
1637
|
+
const I = q(c, f, {
|
|
1638
|
+
hard: !0,
|
|
1639
|
+
trim: !1
|
|
1640
|
+
}).split(`
|
|
1641
|
+
`);
|
|
1642
|
+
I.length > 1 && s.write(import_src.cursor.up(I.length - 1)), s.write(import_src.cursor.to(0)), s.write(import_src.erase.down());
|
|
1643
|
+
}, _$1 = (I) => I.replace(/\.+$/, ""), D = (I) => {
|
|
1644
|
+
const O = (performance.now() - I) / 1e3, L = Math.floor(O / 60), j = Math.floor(O % 60);
|
|
1645
|
+
return L > 0 ? `[${L}m ${j}s]` : `[${j}s]`;
|
|
1646
|
+
}, T = (I = "") => {
|
|
1647
|
+
p = !0, g = xt$1({ output: s }), $ = _$1(I), m = performance.now(), s.write(`${import_picocolors.default.gray(h)}
|
|
1648
|
+
`);
|
|
1649
|
+
let O = 0, L = 0;
|
|
1650
|
+
b(), E = setInterval(() => {
|
|
1651
|
+
if (d && $ === c) return;
|
|
1652
|
+
C(), c = $;
|
|
1653
|
+
const j = F(o[O]);
|
|
1654
|
+
let Z;
|
|
1655
|
+
if (d) Z = `${j} ${$}...`;
|
|
1656
|
+
else if (e === "timer") Z = `${j} ${$} ${D(m)}`;
|
|
1657
|
+
else {
|
|
1658
|
+
const Ze = ".".repeat(Math.floor(L)).slice(0, 3);
|
|
1659
|
+
Z = `${j} ${$}${Ze}`;
|
|
1660
|
+
}
|
|
1661
|
+
const Qe = q(Z, f, {
|
|
1662
|
+
hard: !0,
|
|
1663
|
+
trim: !1
|
|
1664
|
+
});
|
|
1665
|
+
s.write(Qe), O = O + 1 < o.length ? O + 1 : 0, L = L < 4 ? L + .125 : 0;
|
|
1666
|
+
}, u);
|
|
1667
|
+
}, W = (I = "", O = 0, L = !1) => {
|
|
1668
|
+
if (!p) return;
|
|
1669
|
+
p = !1, clearInterval(E), C();
|
|
1670
|
+
const j = O === 0 ? import_picocolors.default.green(k) : O === 1 ? import_picocolors.default.red(ce) : import_picocolors.default.red(de);
|
|
1671
|
+
$ = I ?? $, L || (e === "timer" ? s.write(`${j} ${$} ${D(m)}
|
|
1672
|
+
`) : s.write(`${j} ${$}
|
|
1673
|
+
`)), A(), g();
|
|
1674
|
+
};
|
|
1675
|
+
return {
|
|
1676
|
+
start: T,
|
|
1677
|
+
stop: (I = "") => W(I, 0),
|
|
1678
|
+
message: (I = "") => {
|
|
1679
|
+
$ = _$1(I ?? $);
|
|
1680
|
+
},
|
|
1681
|
+
cancel: (I = "") => W(I, 1),
|
|
1682
|
+
error: (I = "") => W(I, 2),
|
|
1683
|
+
clear: () => W("", 0, !0),
|
|
1684
|
+
get isCancelled() {
|
|
1685
|
+
return y;
|
|
1686
|
+
}
|
|
1687
|
+
};
|
|
1688
|
+
}, Ye = {
|
|
1689
|
+
light: w("─", "-"),
|
|
1690
|
+
heavy: w("━", "="),
|
|
1691
|
+
block: w("█", "#")
|
|
1692
|
+
};
|
|
1693
|
+
const oe = (e, r) => e.includes(`
|
|
1694
|
+
`) ? e.split(`
|
|
1695
|
+
`).map((s) => r(s)).join(`
|
|
1696
|
+
`) : r(e), qt = (e) => {
|
|
1697
|
+
const r = (s, i) => {
|
|
1698
|
+
const n = s.label ?? String(s.value);
|
|
1699
|
+
switch (i) {
|
|
1700
|
+
case "disabled": return `${import_picocolors.default.gray(K)} ${oe(n, import_picocolors.default.gray)}${s.hint ? ` ${import_picocolors.default.dim(`(${s.hint ?? "disabled"})`)}` : ""}`;
|
|
1701
|
+
case "selected": return `${oe(n, import_picocolors.default.dim)}`;
|
|
1702
|
+
case "active": return `${import_picocolors.default.green(Y)} ${n}${s.hint ? ` ${import_picocolors.default.dim(`(${s.hint})`)}` : ""}`;
|
|
1703
|
+
case "cancelled": return `${oe(n, (o) => import_picocolors.default.strikethrough(import_picocolors.default.dim(o)))}`;
|
|
1704
|
+
default: return `${import_picocolors.default.dim(K)} ${oe(n, import_picocolors.default.dim)}`;
|
|
1705
|
+
}
|
|
1706
|
+
};
|
|
1707
|
+
return new Wt$1({
|
|
1708
|
+
options: e.options,
|
|
1709
|
+
signal: e.signal,
|
|
1710
|
+
input: e.input,
|
|
1711
|
+
output: e.output,
|
|
1712
|
+
initialValue: e.initialValue,
|
|
1713
|
+
render() {
|
|
1714
|
+
const s = `${N(this.state)} `, i = `${Ee(this.state)} `, n = Bt$1(e.output, e.message, i, s), o = `${import_picocolors.default.gray(h)}
|
|
1715
|
+
${n}
|
|
1716
|
+
`;
|
|
1717
|
+
switch (this.state) {
|
|
1718
|
+
case "submit": {
|
|
1719
|
+
const u = `${import_picocolors.default.gray(h)} `;
|
|
1720
|
+
return `${o}${Bt$1(e.output, r(this.options[this.cursor], "selected"), u)}`;
|
|
1721
|
+
}
|
|
1722
|
+
case "cancel": {
|
|
1723
|
+
const u = `${import_picocolors.default.gray(h)} `;
|
|
1724
|
+
return `${o}${Bt$1(e.output, r(this.options[this.cursor], "cancelled"), u)}
|
|
1725
|
+
${import_picocolors.default.gray(h)}`;
|
|
1726
|
+
}
|
|
1727
|
+
default: {
|
|
1728
|
+
const u = `${import_picocolors.default.cyan(h)} `, l = o.split(`
|
|
1729
|
+
`).length;
|
|
1730
|
+
return `${o}${u}${J({
|
|
1731
|
+
output: e.output,
|
|
1732
|
+
cursor: this.cursor,
|
|
1733
|
+
options: this.options,
|
|
1734
|
+
maxItems: e.maxItems,
|
|
1735
|
+
columnPadding: u.length,
|
|
1736
|
+
rowPadding: l + 2,
|
|
1737
|
+
style: (a, d) => r(a, a.disabled ? "disabled" : d ? "active" : "inactive")
|
|
1738
|
+
}).join(`
|
|
1739
|
+
${u}`)}
|
|
1740
|
+
${import_picocolors.default.cyan(x)}
|
|
1741
|
+
`;
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
}).prompt();
|
|
1746
|
+
}, Jt = (e) => {
|
|
1747
|
+
const r = (s, i = "inactive") => {
|
|
1748
|
+
const n = s.label ?? String(s.value);
|
|
1749
|
+
return i === "selected" ? `${import_picocolors.default.dim(n)}` : i === "cancelled" ? `${import_picocolors.default.strikethrough(import_picocolors.default.dim(n))}` : i === "active" ? `${import_picocolors.default.bgCyan(import_picocolors.default.gray(` ${s.value} `))} ${n}${s.hint ? ` ${import_picocolors.default.dim(`(${s.hint})`)}` : ""}` : `${import_picocolors.default.gray(import_picocolors.default.bgWhite(import_picocolors.default.inverse(` ${s.value} `)))} ${n}${s.hint ? ` ${import_picocolors.default.dim(`(${s.hint})`)}` : ""}`;
|
|
1750
|
+
};
|
|
1751
|
+
return new Tt$1({
|
|
1752
|
+
options: e.options,
|
|
1753
|
+
signal: e.signal,
|
|
1754
|
+
input: e.input,
|
|
1755
|
+
output: e.output,
|
|
1756
|
+
initialValue: e.initialValue,
|
|
1757
|
+
caseSensitive: e.caseSensitive,
|
|
1758
|
+
render() {
|
|
1759
|
+
const s = `${import_picocolors.default.gray(h)}
|
|
1760
|
+
${N(this.state)} ${e.message}
|
|
1761
|
+
`;
|
|
1762
|
+
switch (this.state) {
|
|
1763
|
+
case "submit": {
|
|
1764
|
+
const i = `${import_picocolors.default.gray(h)} `, n = this.options.find((u) => u.value === this.value) ?? e.options[0];
|
|
1765
|
+
return `${s}${Bt$1(e.output, r(n, "selected"), i)}`;
|
|
1766
|
+
}
|
|
1767
|
+
case "cancel": {
|
|
1768
|
+
const i = `${import_picocolors.default.gray(h)} `;
|
|
1769
|
+
return `${s}${Bt$1(e.output, r(this.options[0], "cancelled"), i)}
|
|
1770
|
+
${import_picocolors.default.gray(h)}`;
|
|
1771
|
+
}
|
|
1772
|
+
default: {
|
|
1773
|
+
const i = `${import_picocolors.default.cyan(h)} `;
|
|
1774
|
+
return `${s}${this.options.map((o, u) => Bt$1(e.output, r(o, u === this.cursor ? "active" : "inactive"), i)).join(`
|
|
1775
|
+
`)}
|
|
1776
|
+
${import_picocolors.default.cyan(x)}
|
|
1777
|
+
`;
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
}).prompt();
|
|
1782
|
+
}, ze = `${import_picocolors.default.gray(h)} `, H = {
|
|
1783
|
+
message: async (e, { symbol: r = import_picocolors.default.gray(h) } = {}) => {
|
|
1784
|
+
process.stdout.write(`${import_picocolors.default.gray(h)}
|
|
1785
|
+
${r} `);
|
|
1786
|
+
let s = 3;
|
|
1787
|
+
for await (let i of e) {
|
|
1788
|
+
i = i.replace(/\n/g, `
|
|
1789
|
+
${ze}`), i.includes(`
|
|
1790
|
+
`) && (s = 3 + stripVTControlCharacters(i.slice(i.lastIndexOf(`
|
|
1791
|
+
`))).length);
|
|
1792
|
+
const n = stripVTControlCharacters(i).length;
|
|
1793
|
+
s + n < process.stdout.columns ? (s += n, process.stdout.write(i)) : (process.stdout.write(`
|
|
1794
|
+
${ze}${i.trimStart()}`), s = 3 + stripVTControlCharacters(i.trimStart()).length);
|
|
1795
|
+
}
|
|
1796
|
+
process.stdout.write(`
|
|
1797
|
+
`);
|
|
1798
|
+
},
|
|
1799
|
+
info: (e) => H.message(e, { symbol: import_picocolors.default.blue(ge) }),
|
|
1800
|
+
success: (e) => H.message(e, { symbol: import_picocolors.default.green(fe) }),
|
|
1801
|
+
step: (e) => H.message(e, { symbol: import_picocolors.default.green(k) }),
|
|
1802
|
+
warn: (e) => H.message(e, { symbol: import_picocolors.default.yellow(Fe) }),
|
|
1803
|
+
warning: (e) => H.warn(e),
|
|
1804
|
+
error: (e) => H.message(e, { symbol: import_picocolors.default.red(ye) })
|
|
1805
|
+
}, Xt = async (e, r) => {
|
|
1806
|
+
for (const s of e) {
|
|
1807
|
+
if (s.enabled === !1) continue;
|
|
1808
|
+
const i = Ie(r);
|
|
1809
|
+
i.start(s.title);
|
|
1810
|
+
const n = await s.task(i.message);
|
|
1811
|
+
i.stop(n || s.title);
|
|
1812
|
+
}
|
|
1813
|
+
}, Yt = (e) => e.replace(/\x1b\[(?:\d+;)*\d*[ABCDEFGHfJKSTsu]|\x1b\[(s|u)/g, ""), zt = (e) => {
|
|
1814
|
+
const r = e.output ?? process.stdout, s = rt(r), i = import_picocolors.default.gray(h), n = e.spacing ?? 1, o = 3, u = e.retainLog === !0, l = !ue() && Te(r);
|
|
1815
|
+
r.write(`${i}
|
|
1816
|
+
`), r.write(`${import_picocolors.default.green(k)} ${e.title}
|
|
1817
|
+
`);
|
|
1818
|
+
for (let m = 0; m < n; m++) r.write(`${i}
|
|
1819
|
+
`);
|
|
1820
|
+
const a = [{
|
|
1821
|
+
value: "",
|
|
1822
|
+
full: ""
|
|
1823
|
+
}];
|
|
1824
|
+
let d = !1;
|
|
1825
|
+
const g = (m) => {
|
|
1826
|
+
if (a.length === 0) return;
|
|
1827
|
+
let f = 0;
|
|
1828
|
+
m && (f += n + 2);
|
|
1829
|
+
for (const F of a) {
|
|
1830
|
+
const { value: v, result: S } = F;
|
|
1831
|
+
let B = S?.message ?? v;
|
|
1832
|
+
if (B.length === 0) continue;
|
|
1833
|
+
S === void 0 && F.header !== void 0 && F.header !== "" && (B += `
|
|
1834
|
+
${F.header}`);
|
|
1835
|
+
const b = B.split(`
|
|
1836
|
+
`).reduce((A, C) => C === "" ? A + 1 : A + Math.ceil((C.length + o) / s), 0);
|
|
1837
|
+
f += b;
|
|
1838
|
+
}
|
|
1839
|
+
f > 0 && (f += 1, r.write(import_src.erase.lines(f)));
|
|
1840
|
+
}, E = (m, f, F) => {
|
|
1841
|
+
const v = F ? `${m.full}
|
|
1842
|
+
${m.value}` : m.value;
|
|
1843
|
+
m.header !== void 0 && m.header !== "" && R.message(m.header.split(`
|
|
1844
|
+
`).map(import_picocolors.default.bold), {
|
|
1845
|
+
output: r,
|
|
1846
|
+
secondarySymbol: i,
|
|
1847
|
+
symbol: i,
|
|
1848
|
+
spacing: 0
|
|
1849
|
+
}), R.message(v.split(`
|
|
1850
|
+
`).map(import_picocolors.default.dim), {
|
|
1851
|
+
output: r,
|
|
1852
|
+
secondarySymbol: i,
|
|
1853
|
+
symbol: i,
|
|
1854
|
+
spacing: f ?? n
|
|
1855
|
+
});
|
|
1856
|
+
}, p = () => {
|
|
1857
|
+
for (const m of a) {
|
|
1858
|
+
const { header: f, value: F, full: v } = m;
|
|
1859
|
+
(f === void 0 || f.length === 0) && F.length === 0 || E(m, void 0, u === !0 && v.length > 0);
|
|
1860
|
+
}
|
|
1861
|
+
}, y = (m, f, F) => {
|
|
1862
|
+
if (g(!1), (F?.raw !== !0 || !d) && m.value !== "" && (m.value += `
|
|
1863
|
+
`), m.value += Yt(f), d = F?.raw === !0, e.limit !== void 0) {
|
|
1864
|
+
const v = m.value.split(`
|
|
1865
|
+
`), S = v.length - e.limit;
|
|
1866
|
+
if (S > 0) {
|
|
1867
|
+
const B = v.splice(0, S);
|
|
1868
|
+
u && (m.full += (m.full === "" ? "" : `
|
|
1869
|
+
`) + B.join(`
|
|
1870
|
+
`));
|
|
1871
|
+
}
|
|
1872
|
+
m.value = v.join(`
|
|
1873
|
+
`);
|
|
1874
|
+
}
|
|
1875
|
+
l && $();
|
|
1876
|
+
}, $ = () => {
|
|
1877
|
+
for (const m of a) m.result ? m.result.status === "error" ? R.error(m.result.message, {
|
|
1878
|
+
output: r,
|
|
1879
|
+
secondarySymbol: i,
|
|
1880
|
+
spacing: 0
|
|
1881
|
+
}) : R.success(m.result.message, {
|
|
1882
|
+
output: r,
|
|
1883
|
+
secondarySymbol: i,
|
|
1884
|
+
spacing: 0
|
|
1885
|
+
}) : m.value !== "" && E(m, 0);
|
|
1886
|
+
}, c = (m, f) => {
|
|
1887
|
+
g(!1), m.result = f, l && $();
|
|
1888
|
+
};
|
|
1889
|
+
return {
|
|
1890
|
+
message(m, f) {
|
|
1891
|
+
y(a[0], m, f);
|
|
1892
|
+
},
|
|
1893
|
+
group(m) {
|
|
1894
|
+
const f = {
|
|
1895
|
+
header: m,
|
|
1896
|
+
value: "",
|
|
1897
|
+
full: ""
|
|
1898
|
+
};
|
|
1899
|
+
return a.push(f), {
|
|
1900
|
+
message(F, v) {
|
|
1901
|
+
y(f, F, v);
|
|
1902
|
+
},
|
|
1903
|
+
error(F) {
|
|
1904
|
+
c(f, {
|
|
1905
|
+
status: "error",
|
|
1906
|
+
message: F
|
|
1907
|
+
});
|
|
1908
|
+
},
|
|
1909
|
+
success(F) {
|
|
1910
|
+
c(f, {
|
|
1911
|
+
status: "success",
|
|
1912
|
+
message: F
|
|
1913
|
+
});
|
|
1914
|
+
}
|
|
1915
|
+
};
|
|
1916
|
+
},
|
|
1917
|
+
error(m, f) {
|
|
1918
|
+
g(!0), R.error(m, {
|
|
1919
|
+
output: r,
|
|
1920
|
+
secondarySymbol: i,
|
|
1921
|
+
spacing: 1
|
|
1922
|
+
}), f?.showLog !== !1 && p(), a.splice(1, a.length - 1), a[0].value = "", a[0].full = "";
|
|
1923
|
+
},
|
|
1924
|
+
success(m, f) {
|
|
1925
|
+
g(!0), R.success(m, {
|
|
1926
|
+
output: r,
|
|
1927
|
+
secondarySymbol: i,
|
|
1928
|
+
spacing: 1
|
|
1929
|
+
}), f?.showLog === !0 && p(), a.splice(1, a.length - 1), a[0].value = "", a[0].full = "";
|
|
1930
|
+
}
|
|
1931
|
+
};
|
|
1932
|
+
}, Qt = (e) => new $t({
|
|
1933
|
+
validate: e.validate,
|
|
1934
|
+
placeholder: e.placeholder,
|
|
1935
|
+
defaultValue: e.defaultValue,
|
|
1936
|
+
initialValue: e.initialValue,
|
|
1937
|
+
output: e.output,
|
|
1938
|
+
signal: e.signal,
|
|
1939
|
+
input: e.input,
|
|
1940
|
+
render() {
|
|
1941
|
+
const r = (e?.withGuide ?? _.withGuide) !== !1, s = `${`${r ? `${import_picocolors.default.gray(h)}
|
|
1942
|
+
` : ""}${N(this.state)} `}${e.message}
|
|
1943
|
+
`, i = e.placeholder ? import_picocolors.default.inverse(e.placeholder[0]) + import_picocolors.default.dim(e.placeholder.slice(1)) : import_picocolors.default.inverse(import_picocolors.default.hidden("_")), n = this.userInput ? this.userInputWithCursor : i, o = this.value ?? "";
|
|
1944
|
+
switch (this.state) {
|
|
1945
|
+
case "error": {
|
|
1946
|
+
const u = this.error ? ` ${import_picocolors.default.yellow(this.error)}` : "", l = r ? `${import_picocolors.default.yellow(h)} ` : "", a = r ? import_picocolors.default.yellow(x) : "";
|
|
1947
|
+
return `${s.trim()}
|
|
1948
|
+
${l}${n}
|
|
1949
|
+
${a}${u}
|
|
1950
|
+
`;
|
|
1951
|
+
}
|
|
1952
|
+
case "submit": {
|
|
1953
|
+
const u = o ? ` ${import_picocolors.default.dim(o)}` : "";
|
|
1954
|
+
return `${s}${r ? import_picocolors.default.gray(h) : ""}${u}`;
|
|
1955
|
+
}
|
|
1956
|
+
case "cancel": {
|
|
1957
|
+
const u = o ? ` ${import_picocolors.default.strikethrough(import_picocolors.default.dim(o))}` : "", l = r ? import_picocolors.default.gray(h) : "";
|
|
1958
|
+
return `${s}${l}${u}${o.trim() ? `
|
|
1959
|
+
${l}` : ""}`;
|
|
1960
|
+
}
|
|
1961
|
+
default: return `${s}${r ? `${import_picocolors.default.cyan(h)} ` : ""}${n}
|
|
1962
|
+
${r ? import_picocolors.default.cyan(x) : ""}
|
|
1963
|
+
`;
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
}).prompt();
|
|
1967
|
+
|
|
1968
|
+
//#endregion
|
|
1969
|
+
//#region src/utils/index.ts
|
|
1970
|
+
function formatTargetDir(targetDir) {
|
|
1971
|
+
return targetDir.trim().replace(/\/+$/g, "");
|
|
1972
|
+
}
|
|
1973
|
+
function isValidPackageName(projectName) {
|
|
1974
|
+
return /^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(projectName);
|
|
1975
|
+
}
|
|
1976
|
+
function toValidPackageName(projectName) {
|
|
1977
|
+
return projectName.trim().toLowerCase().replace(/\s+/g, "-").replace(/^[._]/, "").replace(/[^a-z\d\-~]+/g, "-");
|
|
1978
|
+
}
|
|
1979
|
+
function copy(src, target) {
|
|
1980
|
+
if (fs.statSync(src).isDirectory()) copyDir(src, target);
|
|
1981
|
+
else fs.copyFileSync(src, target);
|
|
1982
|
+
}
|
|
1983
|
+
function copyDir(srcDir, targetDir) {
|
|
1984
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
1985
|
+
for (const file of fs.readdirSync(srcDir)) copy(path.resolve(srcDir, file), path.resolve(targetDir, file));
|
|
1986
|
+
}
|
|
1987
|
+
function emptyDir(dir) {
|
|
1988
|
+
if (!fs.existsSync(dir)) return;
|
|
1989
|
+
for (const file of fs.readdirSync(dir)) {
|
|
1990
|
+
if (file === ".git") continue;
|
|
1991
|
+
fs.rmSync(path.resolve(dir, file), {
|
|
1992
|
+
recursive: true,
|
|
1993
|
+
force: true
|
|
1994
|
+
});
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
function pkgFromUserAgent(userAgent) {
|
|
1998
|
+
if (!userAgent) return void 0;
|
|
1999
|
+
const pkgSpecArr = userAgent.split(" ")[0].split("/");
|
|
2000
|
+
return {
|
|
2001
|
+
name: pkgSpecArr[0],
|
|
2002
|
+
version: pkgSpecArr[1]
|
|
2003
|
+
};
|
|
2004
|
+
}
|
|
2005
|
+
function isEmpty(path) {
|
|
2006
|
+
const files = fs.readdirSync(path);
|
|
2007
|
+
return files.length === 0 || files.length === 1 && files[0] === ".git";
|
|
2008
|
+
}
|
|
2009
|
+
const renameFiles = { _gitignore: ".gitignore" };
|
|
2010
|
+
function getInstallCommand(agent = "pnpm") {
|
|
2011
|
+
if (agent === "yarn") return [agent];
|
|
2012
|
+
return [agent, "install"];
|
|
2013
|
+
}
|
|
2014
|
+
function getRunCommand(agent, script) {
|
|
2015
|
+
switch (agent) {
|
|
2016
|
+
case "yarn":
|
|
2017
|
+
case "pnpm":
|
|
2018
|
+
case "bun": return [agent, script];
|
|
2019
|
+
case "deno": return [
|
|
2020
|
+
agent,
|
|
2021
|
+
"task",
|
|
2022
|
+
script
|
|
2023
|
+
];
|
|
2024
|
+
default: return [
|
|
2025
|
+
agent,
|
|
2026
|
+
"run",
|
|
2027
|
+
script
|
|
2028
|
+
];
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
//#endregion
|
|
2033
|
+
//#region src/utils/deepMerge.ts
|
|
2034
|
+
const isObject = (val) => val && typeof val === "object";
|
|
2035
|
+
const mergeArrayWithDedupe = (a, b) => Array.from(new Set([...a, ...b]));
|
|
2036
|
+
/**
|
|
2037
|
+
* Recursively merge the content of the new object to the existing one
|
|
2038
|
+
* @param {Object} target the existing object
|
|
2039
|
+
* @param {Object} obj the new object
|
|
2040
|
+
*/
|
|
2041
|
+
function deepMerge(target, obj) {
|
|
2042
|
+
for (const key of Object.keys(obj)) {
|
|
2043
|
+
const oldVal = target[key];
|
|
2044
|
+
const newVal = obj[key];
|
|
2045
|
+
if (Array.isArray(oldVal) && Array.isArray(newVal)) target[key] = mergeArrayWithDedupe(oldVal, newVal);
|
|
2046
|
+
else if (isObject(oldVal) && isObject(newVal)) target[key] = deepMerge(oldVal, newVal);
|
|
2047
|
+
else target[key] = newVal;
|
|
2048
|
+
}
|
|
2049
|
+
return target;
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
//#endregion
|
|
2053
|
+
//#region src/utils/sortDependencies.ts
|
|
2054
|
+
function sortDependencies(packageJson) {
|
|
2055
|
+
const sorted = {};
|
|
2056
|
+
for (const depType of [
|
|
2057
|
+
"dependencies",
|
|
2058
|
+
"devDependencies",
|
|
2059
|
+
"peerDependencies",
|
|
2060
|
+
"optionalDependencies"
|
|
2061
|
+
]) if (packageJson[depType]) {
|
|
2062
|
+
sorted[depType] = {};
|
|
2063
|
+
Object.keys(packageJson[depType]).sort().forEach((name) => {
|
|
2064
|
+
sorted[depType][name] = packageJson[depType][name];
|
|
2065
|
+
});
|
|
2066
|
+
}
|
|
2067
|
+
return {
|
|
2068
|
+
...packageJson,
|
|
2069
|
+
...sorted
|
|
2070
|
+
};
|
|
2071
|
+
}
|
|
2072
|
+
|
|
2073
|
+
//#endregion
|
|
2074
|
+
//#region src/utils/renderTemplate.ts
|
|
2075
|
+
/**
|
|
2076
|
+
* Renders a template folder/file to the file system,
|
|
2077
|
+
* by recursively copying all files under the `src` directory,
|
|
2078
|
+
* with the following exception:
|
|
2079
|
+
* - `_filename` should be renamed to `.filename`
|
|
2080
|
+
* - Fields in `package.json` should be recursively merged
|
|
2081
|
+
* @param {string} src source filename to copy
|
|
2082
|
+
* @param {string} dest destination filename of the copy operation
|
|
2083
|
+
*/
|
|
2084
|
+
function renderTemplate(src, dest, callbacks) {
|
|
2085
|
+
if (fs$1.statSync(src).isDirectory()) {
|
|
2086
|
+
if (path$1.basename(src) === "node_modules") return;
|
|
2087
|
+
fs$1.mkdirSync(dest, { recursive: true });
|
|
2088
|
+
for (const file of fs$1.readdirSync(src)) renderTemplate(path$1.resolve(src, file), path$1.resolve(dest, file), callbacks);
|
|
2089
|
+
return;
|
|
2090
|
+
}
|
|
2091
|
+
const filename = path$1.basename(src);
|
|
2092
|
+
if (filename === "package.json" && fs$1.existsSync(dest)) {
|
|
2093
|
+
const existing = JSON.parse(fs$1.readFileSync(dest, "utf8"));
|
|
2094
|
+
const newPackage = JSON.parse(fs$1.readFileSync(src, "utf8"));
|
|
2095
|
+
console.log(existing, newPackage);
|
|
2096
|
+
const pkg = sortDependencies(deepMerge(existing, newPackage));
|
|
2097
|
+
console.log(pkg);
|
|
2098
|
+
fs$1.writeFileSync(dest, JSON.stringify(pkg, null, 2) + "\n");
|
|
2099
|
+
return;
|
|
2100
|
+
}
|
|
2101
|
+
if (filename.startsWith("_")) dest = path$1.resolve(path$1.dirname(dest), filename.replace(/^_/, "."));
|
|
2102
|
+
if (filename === "_gitignore" && fs$1.existsSync(dest)) {
|
|
2103
|
+
const existing = fs$1.readFileSync(dest, "utf8");
|
|
2104
|
+
const newGitignore = fs$1.readFileSync(src, "utf8");
|
|
2105
|
+
fs$1.writeFileSync(dest, existing + "\n" + newGitignore);
|
|
2106
|
+
return;
|
|
2107
|
+
}
|
|
2108
|
+
if (filename.endsWith(".data.mjs")) {
|
|
2109
|
+
dest = dest.replace(/\.data\.mjs$/, "");
|
|
2110
|
+
callbacks.push(async (dataStore) => {
|
|
2111
|
+
const getData = (await import(pathToFileURL(src).toString())).default;
|
|
2112
|
+
dataStore[dest] = await getData({ oldData: dataStore[dest] || {} });
|
|
2113
|
+
});
|
|
2114
|
+
return;
|
|
2115
|
+
}
|
|
2116
|
+
fs$1.copyFileSync(src, dest);
|
|
2117
|
+
}
|
|
2118
|
+
|
|
2119
|
+
//#endregion
|
|
2120
|
+
//#region src/utils/directoryTraverse.ts
|
|
2121
|
+
function preOrderDirectoryTraverse(dir, dirCallback, fileCallback) {
|
|
2122
|
+
for (const filename of fs$1.readdirSync(dir)) {
|
|
2123
|
+
if (filename === ".git") continue;
|
|
2124
|
+
const fullpath = path$1.resolve(dir, filename);
|
|
2125
|
+
if (fs$1.lstatSync(fullpath).isDirectory()) {
|
|
2126
|
+
dirCallback(fullpath);
|
|
2127
|
+
if (fs$1.existsSync(fullpath)) preOrderDirectoryTraverse(fullpath, dirCallback, fileCallback);
|
|
2128
|
+
continue;
|
|
2129
|
+
}
|
|
2130
|
+
fileCallback(fullpath);
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
//#endregion
|
|
2135
|
+
//#region ../node_modules/.pnpm/ejs@4.0.1/node_modules/ejs/lib/esm/utils.js
|
|
2136
|
+
/**
|
|
2137
|
+
* Private utility functions
|
|
2138
|
+
* @module utils
|
|
2139
|
+
* @private
|
|
2140
|
+
*/
|
|
2141
|
+
const utils = {};
|
|
2142
|
+
var regExpChars = /[|\\{}()[\]^$+*?.]/g;
|
|
2143
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
2144
|
+
var hasOwn = function(obj, key) {
|
|
2145
|
+
return hasOwnProperty.apply(obj, [key]);
|
|
2146
|
+
};
|
|
2147
|
+
/**
|
|
2148
|
+
* Escape characters reserved in regular expressions.
|
|
2149
|
+
*
|
|
2150
|
+
* If `string` is `undefined` or `null`, the empty string is returned.
|
|
2151
|
+
*
|
|
2152
|
+
* @param {String} string Input string
|
|
2153
|
+
* @return {String} Escaped string
|
|
2154
|
+
* @static
|
|
2155
|
+
* @private
|
|
2156
|
+
*/
|
|
2157
|
+
utils.escapeRegExpChars = function(string) {
|
|
2158
|
+
// istanbul ignore if
|
|
2159
|
+
if (!string) return "";
|
|
2160
|
+
return String(string).replace(regExpChars, "\\$&");
|
|
2161
|
+
};
|
|
2162
|
+
var _ENCODE_HTML_RULES = {
|
|
2163
|
+
"&": "&",
|
|
2164
|
+
"<": "<",
|
|
2165
|
+
">": ">",
|
|
2166
|
+
"\"": """,
|
|
2167
|
+
"'": "'"
|
|
2168
|
+
};
|
|
2169
|
+
var _MATCH_HTML = /[&<>'"]/g;
|
|
2170
|
+
function encode_char(c) {
|
|
2171
|
+
return _ENCODE_HTML_RULES[c] || c;
|
|
2172
|
+
}
|
|
2173
|
+
/**
|
|
2174
|
+
* Stringified version of constants used by {@link module:utils.escapeXML}.
|
|
2175
|
+
*
|
|
2176
|
+
* It is used in the process of generating {@link ClientFunction}s.
|
|
2177
|
+
*
|
|
2178
|
+
* @readonly
|
|
2179
|
+
* @type {String}
|
|
2180
|
+
*/
|
|
2181
|
+
var escapeFuncStr = "var _ENCODE_HTML_RULES = {\n \"&\": \"&\"\n , \"<\": \"<\"\n , \">\": \">\"\n , '\"': \""\"\n , \"'\": \"'\"\n }\n , _MATCH_HTML = /[&<>'\"]/g;\nfunction encode_char(c) {\n return _ENCODE_HTML_RULES[c] || c;\n};\n";
|
|
2182
|
+
/**
|
|
2183
|
+
* Escape characters reserved in XML.
|
|
2184
|
+
*
|
|
2185
|
+
* If `markup` is `undefined` or `null`, the empty string is returned.
|
|
2186
|
+
*
|
|
2187
|
+
* @implements {EscapeCallback}
|
|
2188
|
+
* @param {String} markup Input string
|
|
2189
|
+
* @return {String} Escaped string
|
|
2190
|
+
* @static
|
|
2191
|
+
* @private
|
|
2192
|
+
*/
|
|
2193
|
+
utils.escapeXML = function(markup) {
|
|
2194
|
+
return markup == void 0 ? "" : String(markup).replace(_MATCH_HTML, encode_char);
|
|
2195
|
+
};
|
|
2196
|
+
function escapeXMLToString() {
|
|
2197
|
+
return Function.prototype.toString.call(this) + ";\n" + escapeFuncStr;
|
|
2198
|
+
}
|
|
2199
|
+
try {
|
|
2200
|
+
if (typeof Object.defineProperty === "function") Object.defineProperty(utils.escapeXML, "toString", { value: escapeXMLToString });
|
|
2201
|
+
else utils.escapeXML.toString = escapeXMLToString;
|
|
2202
|
+
} catch (err) {
|
|
2203
|
+
console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)");
|
|
2204
|
+
}
|
|
2205
|
+
/**
|
|
2206
|
+
* Naive copy of properties from one object to another.
|
|
2207
|
+
* Does not recurse into non-scalar properties
|
|
2208
|
+
* Does not check to see if the property has a value before copying
|
|
2209
|
+
*
|
|
2210
|
+
* @param {Object} to Destination object
|
|
2211
|
+
* @param {Object} from Source object
|
|
2212
|
+
* @return {Object} Destination object
|
|
2213
|
+
* @static
|
|
2214
|
+
* @private
|
|
2215
|
+
*/
|
|
2216
|
+
utils.shallowCopy = function(to, from) {
|
|
2217
|
+
from = from || {};
|
|
2218
|
+
if (to !== null && to !== void 0) for (var p in from) {
|
|
2219
|
+
if (!hasOwn(from, p)) continue;
|
|
2220
|
+
if (p === "__proto__" || p === "constructor") continue;
|
|
2221
|
+
to[p] = from[p];
|
|
2222
|
+
}
|
|
2223
|
+
return to;
|
|
2224
|
+
};
|
|
2225
|
+
/**
|
|
2226
|
+
* Naive copy of a list of key names, from one object to another.
|
|
2227
|
+
* Only copies property if it is actually defined
|
|
2228
|
+
* Does not recurse into non-scalar properties
|
|
2229
|
+
*
|
|
2230
|
+
* @param {Object} to Destination object
|
|
2231
|
+
* @param {Object} from Source object
|
|
2232
|
+
* @param {Array} list List of properties to copy
|
|
2233
|
+
* @return {Object} Destination object
|
|
2234
|
+
* @static
|
|
2235
|
+
* @private
|
|
2236
|
+
*/
|
|
2237
|
+
utils.shallowCopyFromList = function(to, from, list) {
|
|
2238
|
+
list = list || [];
|
|
2239
|
+
from = from || {};
|
|
2240
|
+
if (to !== null && to !== void 0) for (var i = 0; i < list.length; i++) {
|
|
2241
|
+
var p = list[i];
|
|
2242
|
+
if (typeof from[p] != "undefined") {
|
|
2243
|
+
if (!hasOwn(from, p)) continue;
|
|
2244
|
+
if (p === "__proto__" || p === "constructor") continue;
|
|
2245
|
+
to[p] = from[p];
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
return to;
|
|
2249
|
+
};
|
|
2250
|
+
/**
|
|
2251
|
+
* Simple in-process cache implementation. Does not implement limits of any
|
|
2252
|
+
* sort.
|
|
2253
|
+
*
|
|
2254
|
+
* @implements {Cache}
|
|
2255
|
+
* @static
|
|
2256
|
+
* @private
|
|
2257
|
+
*/
|
|
2258
|
+
utils.cache = {
|
|
2259
|
+
_data: {},
|
|
2260
|
+
set: function(key, val) {
|
|
2261
|
+
this._data[key] = val;
|
|
2262
|
+
},
|
|
2263
|
+
get: function(key) {
|
|
2264
|
+
return this._data[key];
|
|
2265
|
+
},
|
|
2266
|
+
remove: function(key) {
|
|
2267
|
+
delete this._data[key];
|
|
2268
|
+
},
|
|
2269
|
+
reset: function() {
|
|
2270
|
+
this._data = {};
|
|
2271
|
+
}
|
|
2272
|
+
};
|
|
2273
|
+
/**
|
|
2274
|
+
* Transforms hyphen case variable into camel case.
|
|
2275
|
+
*
|
|
2276
|
+
* @param {String} string Hyphen case string
|
|
2277
|
+
* @return {String} Camel case string
|
|
2278
|
+
* @static
|
|
2279
|
+
* @private
|
|
2280
|
+
*/
|
|
2281
|
+
utils.hyphenToCamel = function(str) {
|
|
2282
|
+
return str.replace(/-[a-z]/g, function(match) {
|
|
2283
|
+
return match[1].toUpperCase();
|
|
2284
|
+
});
|
|
2285
|
+
};
|
|
2286
|
+
/**
|
|
2287
|
+
* Returns a null-prototype object in runtimes that support it
|
|
2288
|
+
*
|
|
2289
|
+
* @return {Object} Object, prototype will be set to null where possible
|
|
2290
|
+
* @static
|
|
2291
|
+
* @private
|
|
2292
|
+
*/
|
|
2293
|
+
utils.createNullProtoObjWherePossible = (function() {
|
|
2294
|
+
if (typeof Object.create == "function") return function() {
|
|
2295
|
+
return Object.create(null);
|
|
2296
|
+
};
|
|
2297
|
+
if (!({ __proto__: null } instanceof Object)) return function() {
|
|
2298
|
+
return { __proto__: null };
|
|
2299
|
+
};
|
|
2300
|
+
return function() {
|
|
2301
|
+
return {};
|
|
2302
|
+
};
|
|
2303
|
+
})();
|
|
2304
|
+
/**
|
|
2305
|
+
* Copies own-properties from one object to a null-prototype object for basic
|
|
2306
|
+
* protection against prototype pollution
|
|
2307
|
+
*
|
|
2308
|
+
* @return {Object} Object with own-properties of input object
|
|
2309
|
+
* @static
|
|
2310
|
+
* @private
|
|
2311
|
+
*/
|
|
2312
|
+
utils.hasOwnOnlyObject = function(obj) {
|
|
2313
|
+
var o = utils.createNullProtoObjWherePossible();
|
|
2314
|
+
for (var p in obj) if (hasOwn(obj, p)) o[p] = obj[p];
|
|
2315
|
+
return o;
|
|
2316
|
+
};
|
|
2317
|
+
if (typeof exports != "undefined") module.exports = utils;
|
|
2318
|
+
|
|
2319
|
+
//#endregion
|
|
2320
|
+
//#region ../node_modules/.pnpm/ejs@4.0.1/node_modules/ejs/lib/esm/ejs.js
|
|
2321
|
+
/**
|
|
2322
|
+
* @file Embedded JavaScript templating engine. {@link http://ejs.co}
|
|
2323
|
+
* @author Matthew Eernisse <mde@fleegix.org>
|
|
2324
|
+
* @project EJS
|
|
2325
|
+
* @license {@link http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0}
|
|
2326
|
+
*/
|
|
2327
|
+
/**
|
|
2328
|
+
* EJS internal functions.
|
|
2329
|
+
*
|
|
2330
|
+
* Technically this "module" lies in the same file as {@link module:ejs}, for
|
|
2331
|
+
* the sake of organization all the private functions re grouped into this
|
|
2332
|
+
* module.
|
|
2333
|
+
*
|
|
2334
|
+
* @module ejs-internal
|
|
2335
|
+
* @private
|
|
2336
|
+
*/
|
|
2337
|
+
/**
|
|
2338
|
+
* Embedded JavaScript templating engine.
|
|
2339
|
+
*
|
|
2340
|
+
* @module ejs
|
|
2341
|
+
* @public
|
|
2342
|
+
*/
|
|
2343
|
+
const DECLARATION_KEYWORD = "let";
|
|
2344
|
+
const ejs = {};
|
|
2345
|
+
/** @type {string} */
|
|
2346
|
+
let _DEFAULT_OPEN_DELIMITER = "<";
|
|
2347
|
+
let _DEFAULT_CLOSE_DELIMITER = ">";
|
|
2348
|
+
let _DEFAULT_DELIMITER = "%";
|
|
2349
|
+
let _DEFAULT_LOCALS_NAME = "locals";
|
|
2350
|
+
let _REGEX_STRING = "(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)";
|
|
2351
|
+
let _OPTS_PASSABLE_WITH_DATA = [
|
|
2352
|
+
"delimiter",
|
|
2353
|
+
"scope",
|
|
2354
|
+
"context",
|
|
2355
|
+
"debug",
|
|
2356
|
+
"compileDebug",
|
|
2357
|
+
"client",
|
|
2358
|
+
"_with",
|
|
2359
|
+
"rmWhitespace",
|
|
2360
|
+
"strict",
|
|
2361
|
+
"filename",
|
|
2362
|
+
"async"
|
|
2363
|
+
];
|
|
2364
|
+
let _OPTS_PASSABLE_WITH_DATA_EXPRESS = _OPTS_PASSABLE_WITH_DATA.concat("cache");
|
|
2365
|
+
let _BOM = /^\uFEFF/;
|
|
2366
|
+
let _JS_IDENTIFIER = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
|
2367
|
+
/**
|
|
2368
|
+
* EJS template function cache. This can be a LRU object from lru-cache NPM
|
|
2369
|
+
* module. By default, it is {@link module:utils.cache}, a simple in-process
|
|
2370
|
+
* cache that grows continuously.
|
|
2371
|
+
*
|
|
2372
|
+
* @type {Cache}
|
|
2373
|
+
*/
|
|
2374
|
+
ejs.cache = utils.cache;
|
|
2375
|
+
/**
|
|
2376
|
+
* Custom file loader. Useful for template preprocessing or restricting access
|
|
2377
|
+
* to a certain part of the filesystem.
|
|
2378
|
+
*
|
|
2379
|
+
* @type {fileLoader}
|
|
2380
|
+
*/
|
|
2381
|
+
ejs.fileLoader = fs.readFileSync;
|
|
2382
|
+
/**
|
|
2383
|
+
* Name of the object containing the locals.
|
|
2384
|
+
*
|
|
2385
|
+
* This variable is overridden by {@link Options}`.localsName` if it is not
|
|
2386
|
+
* `undefined`.
|
|
2387
|
+
*
|
|
2388
|
+
* @type {String}
|
|
2389
|
+
* @public
|
|
2390
|
+
*/
|
|
2391
|
+
ejs.localsName = _DEFAULT_LOCALS_NAME;
|
|
2392
|
+
/**
|
|
2393
|
+
* Promise implementation -- defaults to the native implementation if available
|
|
2394
|
+
* This is mostly just for testability
|
|
2395
|
+
*
|
|
2396
|
+
* @type {PromiseConstructorLike}
|
|
2397
|
+
* @public
|
|
2398
|
+
*/
|
|
2399
|
+
ejs.promiseImpl = new Function("return this;")().Promise;
|
|
2400
|
+
/**
|
|
2401
|
+
* Get the path to the included file from the parent file path and the
|
|
2402
|
+
* specified path.
|
|
2403
|
+
*
|
|
2404
|
+
* @param {String} name specified path
|
|
2405
|
+
* @param {String} filename parent file path
|
|
2406
|
+
* @param {Boolean} [isDir=false] whether the parent file path is a directory
|
|
2407
|
+
* @return {String}
|
|
2408
|
+
*/
|
|
2409
|
+
ejs.resolveInclude = function(name, filename, isDir) {
|
|
2410
|
+
let dirname = path.dirname;
|
|
2411
|
+
let extname = path.extname;
|
|
2412
|
+
let resolve = path.resolve;
|
|
2413
|
+
let includePath = resolve(isDir ? filename : dirname(filename), name);
|
|
2414
|
+
if (!extname(name)) includePath += ".ejs";
|
|
2415
|
+
return includePath;
|
|
2416
|
+
};
|
|
2417
|
+
/**
|
|
2418
|
+
* Try to resolve file path on multiple directories
|
|
2419
|
+
*
|
|
2420
|
+
* @param {String} name specified path
|
|
2421
|
+
* @param {Array<String>} paths list of possible parent directory paths
|
|
2422
|
+
* @return {String}
|
|
2423
|
+
*/
|
|
2424
|
+
function resolvePaths(name, paths) {
|
|
2425
|
+
let filePath;
|
|
2426
|
+
if (paths.some(function(v) {
|
|
2427
|
+
filePath = ejs.resolveInclude(name, v, true);
|
|
2428
|
+
return fs.existsSync(filePath);
|
|
2429
|
+
})) return filePath;
|
|
2430
|
+
}
|
|
2431
|
+
/**
|
|
2432
|
+
* Get the path to the included file by Options
|
|
2433
|
+
*
|
|
2434
|
+
* @param {String} path specified path
|
|
2435
|
+
* @param {Options} options compilation options
|
|
2436
|
+
* @return {String}
|
|
2437
|
+
*/
|
|
2438
|
+
function getIncludePath(path, options) {
|
|
2439
|
+
let includePath;
|
|
2440
|
+
let filePath;
|
|
2441
|
+
let views = options.views;
|
|
2442
|
+
let match = /^[A-Za-z]+:\\|^\//.exec(path);
|
|
2443
|
+
if (match && match.length) {
|
|
2444
|
+
path = path.replace(/^\/*/, "");
|
|
2445
|
+
if (Array.isArray(options.root)) includePath = resolvePaths(path, options.root);
|
|
2446
|
+
else includePath = ejs.resolveInclude(path, options.root || "/", true);
|
|
2447
|
+
} else {
|
|
2448
|
+
if (options.filename) {
|
|
2449
|
+
filePath = ejs.resolveInclude(path, options.filename);
|
|
2450
|
+
if (fs.existsSync(filePath)) includePath = filePath;
|
|
2451
|
+
}
|
|
2452
|
+
if (!includePath && Array.isArray(views)) includePath = resolvePaths(path, views);
|
|
2453
|
+
if (!includePath && typeof options.includer !== "function") throw new Error("Could not find the include file \"" + options.escapeFunction(path) + "\"");
|
|
2454
|
+
}
|
|
2455
|
+
return includePath;
|
|
2456
|
+
}
|
|
2457
|
+
/**
|
|
2458
|
+
* Get the template from a string or a file, either compiled on-the-fly or
|
|
2459
|
+
* read from cache (if enabled), and cache the template if needed.
|
|
2460
|
+
*
|
|
2461
|
+
* If `template` is not set, the file specified in `options.filename` will be
|
|
2462
|
+
* read.
|
|
2463
|
+
*
|
|
2464
|
+
* If `options.cache` is true, this function reads the file from
|
|
2465
|
+
* `options.filename` so it must be set prior to calling this function.
|
|
2466
|
+
*
|
|
2467
|
+
* @memberof module:ejs-internal
|
|
2468
|
+
* @param {Options} options compilation options
|
|
2469
|
+
* @param {String} [template] template source
|
|
2470
|
+
* @return {(TemplateFunction|ClientFunction)}
|
|
2471
|
+
* Depending on the value of `options.client`, either type might be returned.
|
|
2472
|
+
* @static
|
|
2473
|
+
*/
|
|
2474
|
+
function handleCache(options, template) {
|
|
2475
|
+
let func;
|
|
2476
|
+
let filename = options.filename;
|
|
2477
|
+
let hasTemplate = arguments.length > 1;
|
|
2478
|
+
if (options.cache) {
|
|
2479
|
+
if (!filename) throw new Error("cache option requires a filename");
|
|
2480
|
+
func = ejs.cache.get(filename);
|
|
2481
|
+
if (func) return func;
|
|
2482
|
+
if (!hasTemplate) template = fileLoader(filename).toString().replace(_BOM, "");
|
|
2483
|
+
} else if (!hasTemplate) {
|
|
2484
|
+
// istanbul ignore if: should not happen at all
|
|
2485
|
+
if (!filename) throw new Error("Internal EJS error: no file name or template provided");
|
|
2486
|
+
template = fileLoader(filename).toString().replace(_BOM, "");
|
|
2487
|
+
}
|
|
2488
|
+
func = ejs.compile(template, options);
|
|
2489
|
+
if (options.cache) ejs.cache.set(filename, func);
|
|
2490
|
+
return func;
|
|
2491
|
+
}
|
|
2492
|
+
/**
|
|
2493
|
+
* Try calling handleCache with the given options and data and call the
|
|
2494
|
+
* callback with the result. If an error occurs, call the callback with
|
|
2495
|
+
* the error. Used by renderFile().
|
|
2496
|
+
*
|
|
2497
|
+
* @memberof module:ejs-internal
|
|
2498
|
+
* @param {Options} options compilation options
|
|
2499
|
+
* @param {Object} data template data
|
|
2500
|
+
* @param {RenderFileCallback} cb callback
|
|
2501
|
+
* @static
|
|
2502
|
+
*/
|
|
2503
|
+
function tryHandleCache(options, data, cb) {
|
|
2504
|
+
let result;
|
|
2505
|
+
if (!cb) if (typeof ejs.promiseImpl == "function") return new ejs.promiseImpl(function(resolve, reject) {
|
|
2506
|
+
try {
|
|
2507
|
+
result = handleCache(options)(data);
|
|
2508
|
+
resolve(result);
|
|
2509
|
+
} catch (err) {
|
|
2510
|
+
reject(err);
|
|
2511
|
+
}
|
|
2512
|
+
});
|
|
2513
|
+
else throw new Error("Please provide a callback function");
|
|
2514
|
+
else {
|
|
2515
|
+
try {
|
|
2516
|
+
result = handleCache(options)(data);
|
|
2517
|
+
} catch (err) {
|
|
2518
|
+
return cb(err);
|
|
2519
|
+
}
|
|
2520
|
+
cb(null, result);
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
/**
|
|
2524
|
+
* fileLoader is independent
|
|
2525
|
+
*
|
|
2526
|
+
* @param {String} filePath ejs file path.
|
|
2527
|
+
* @return {String} The contents of the specified file.
|
|
2528
|
+
* @static
|
|
2529
|
+
*/
|
|
2530
|
+
function fileLoader(filePath) {
|
|
2531
|
+
return ejs.fileLoader(filePath);
|
|
2532
|
+
}
|
|
2533
|
+
/**
|
|
2534
|
+
* Get the template function.
|
|
2535
|
+
*
|
|
2536
|
+
* If `options.cache` is `true`, then the template is cached.
|
|
2537
|
+
*
|
|
2538
|
+
* @memberof module:ejs-internal
|
|
2539
|
+
* @param {String} path path for the specified file
|
|
2540
|
+
* @param {Options} options compilation options
|
|
2541
|
+
* @return {(TemplateFunction|ClientFunction)}
|
|
2542
|
+
* Depending on the value of `options.client`, either type might be returned
|
|
2543
|
+
* @static
|
|
2544
|
+
*/
|
|
2545
|
+
function includeFile(path, options) {
|
|
2546
|
+
let opts = utils.shallowCopy(utils.createNullProtoObjWherePossible(), options);
|
|
2547
|
+
opts.filename = getIncludePath(path, opts);
|
|
2548
|
+
if (typeof options.includer === "function") {
|
|
2549
|
+
let includerResult = options.includer(path, opts.filename);
|
|
2550
|
+
if (includerResult) {
|
|
2551
|
+
if (includerResult.filename) opts.filename = includerResult.filename;
|
|
2552
|
+
if (includerResult.template) return handleCache(opts, includerResult.template);
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
return handleCache(opts);
|
|
2556
|
+
}
|
|
2557
|
+
/**
|
|
2558
|
+
* Re-throw the given `err` in context to the `str` of ejs, `filename`, and
|
|
2559
|
+
* `lineno`.
|
|
2560
|
+
*
|
|
2561
|
+
* @implements {RethrowCallback}
|
|
2562
|
+
* @memberof module:ejs-internal
|
|
2563
|
+
* @param {Error} err Error object
|
|
2564
|
+
* @param {String} str EJS source
|
|
2565
|
+
* @param {String} flnm file name of the EJS file
|
|
2566
|
+
* @param {Number} lineno line number of the error
|
|
2567
|
+
* @param {EscapeCallback} esc
|
|
2568
|
+
* @static
|
|
2569
|
+
*/
|
|
2570
|
+
function rethrow(err, str, flnm, lineno, esc) {
|
|
2571
|
+
let lines = str.split("\n");
|
|
2572
|
+
let start = Math.max(lineno - 3, 0);
|
|
2573
|
+
let end = Math.min(lines.length, lineno + 3);
|
|
2574
|
+
let filename = esc(flnm);
|
|
2575
|
+
let context = lines.slice(start, end).map(function(line, i) {
|
|
2576
|
+
let curr = i + start + 1;
|
|
2577
|
+
return (curr == lineno ? " >> " : " ") + curr + "| " + line;
|
|
2578
|
+
}).join("\n");
|
|
2579
|
+
err.path = filename;
|
|
2580
|
+
err.message = (filename || "ejs") + ":" + lineno + "\n" + context + "\n\n" + err.message;
|
|
2581
|
+
throw err;
|
|
2582
|
+
}
|
|
2583
|
+
function stripSemi(str) {
|
|
2584
|
+
return str.replace(/;(\s*$)/, "$1");
|
|
2585
|
+
}
|
|
2586
|
+
/**
|
|
2587
|
+
* Compile the given `str` of ejs into a template function.
|
|
2588
|
+
*
|
|
2589
|
+
* @param {String} template EJS template
|
|
2590
|
+
*
|
|
2591
|
+
* @param {Options} [opts] compilation options
|
|
2592
|
+
*
|
|
2593
|
+
* @return {(TemplateFunction|ClientFunction)}
|
|
2594
|
+
* Depending on the value of `opts.client`, either type might be returned.
|
|
2595
|
+
* Note that the return type of the function also depends on the value of `opts.async`.
|
|
2596
|
+
* @public
|
|
2597
|
+
*/
|
|
2598
|
+
ejs.compile = function compile(template, opts) {
|
|
2599
|
+
let templ;
|
|
2600
|
+
if (opts && opts.scope) {
|
|
2601
|
+
console.warn("`scope` option is deprecated and will be removed in future EJS");
|
|
2602
|
+
if (!opts.context) opts.context = opts.scope;
|
|
2603
|
+
delete opts.scope;
|
|
2604
|
+
}
|
|
2605
|
+
templ = new Template(template, opts);
|
|
2606
|
+
return templ.compile();
|
|
2607
|
+
};
|
|
2608
|
+
/**
|
|
2609
|
+
* Render the given `template` of ejs.
|
|
2610
|
+
*
|
|
2611
|
+
* If you would like to include options but not data, you need to explicitly
|
|
2612
|
+
* call this function with `data` being an empty object or `null`.
|
|
2613
|
+
*
|
|
2614
|
+
* @param {String} template EJS template
|
|
2615
|
+
* @param {Object} [data={}] template data
|
|
2616
|
+
* @param {Options} [opts={}] compilation and rendering options
|
|
2617
|
+
* @return {(String|Promise<String>)}
|
|
2618
|
+
* Return value type depends on `opts.async`.
|
|
2619
|
+
* @public
|
|
2620
|
+
*/
|
|
2621
|
+
ejs.render = function(template, d, o) {
|
|
2622
|
+
let data = d || utils.createNullProtoObjWherePossible();
|
|
2623
|
+
let opts = o || utils.createNullProtoObjWherePossible();
|
|
2624
|
+
if (arguments.length == 2) utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA);
|
|
2625
|
+
return handleCache(opts, template)(data);
|
|
2626
|
+
};
|
|
2627
|
+
/**
|
|
2628
|
+
* Render an EJS file at the given `path` and callback `cb(err, str)`.
|
|
2629
|
+
*
|
|
2630
|
+
* If you would like to include options but not data, you need to explicitly
|
|
2631
|
+
* call this function with `data` being an empty object or `null`.
|
|
2632
|
+
*
|
|
2633
|
+
* @param {String} path path to the EJS file
|
|
2634
|
+
* @param {Object} [data={}] template data
|
|
2635
|
+
* @param {Options} [opts={}] compilation and rendering options
|
|
2636
|
+
* @param {RenderFileCallback} cb callback
|
|
2637
|
+
* @public
|
|
2638
|
+
*/
|
|
2639
|
+
ejs.renderFile = function() {
|
|
2640
|
+
let args = Array.prototype.slice.call(arguments);
|
|
2641
|
+
let filename = args.shift();
|
|
2642
|
+
let cb;
|
|
2643
|
+
let opts = { filename };
|
|
2644
|
+
let data;
|
|
2645
|
+
let viewOpts;
|
|
2646
|
+
if (typeof arguments[arguments.length - 1] == "function") cb = args.pop();
|
|
2647
|
+
if (args.length) {
|
|
2648
|
+
data = args.shift();
|
|
2649
|
+
if (args.length) utils.shallowCopy(opts, args.pop());
|
|
2650
|
+
else {
|
|
2651
|
+
if (data.settings) {
|
|
2652
|
+
if (data.settings.views) opts.views = data.settings.views;
|
|
2653
|
+
if (data.settings["view cache"]) opts.cache = true;
|
|
2654
|
+
viewOpts = data.settings["view options"];
|
|
2655
|
+
if (viewOpts) utils.shallowCopy(opts, viewOpts);
|
|
2656
|
+
}
|
|
2657
|
+
utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA_EXPRESS);
|
|
2658
|
+
}
|
|
2659
|
+
opts.filename = filename;
|
|
2660
|
+
} else data = utils.createNullProtoObjWherePossible();
|
|
2661
|
+
return tryHandleCache(opts, data, cb);
|
|
2662
|
+
};
|
|
2663
|
+
/**
|
|
2664
|
+
* Clear intermediate JavaScript cache. Calls {@link Cache#reset}.
|
|
2665
|
+
* @public
|
|
2666
|
+
*/
|
|
2667
|
+
/**
|
|
2668
|
+
* EJS template class
|
|
2669
|
+
* @public
|
|
2670
|
+
*/
|
|
2671
|
+
ejs.Template = Template;
|
|
2672
|
+
ejs.clearCache = function() {
|
|
2673
|
+
ejs.cache.reset();
|
|
2674
|
+
};
|
|
2675
|
+
function Template(text, optsParam) {
|
|
2676
|
+
let opts = utils.hasOwnOnlyObject(optsParam);
|
|
2677
|
+
let options = utils.createNullProtoObjWherePossible();
|
|
2678
|
+
this.templateText = text;
|
|
2679
|
+
/** @type {string | null} */
|
|
2680
|
+
this.mode = null;
|
|
2681
|
+
this.truncate = false;
|
|
2682
|
+
this.currentLine = 1;
|
|
2683
|
+
this.source = "";
|
|
2684
|
+
options.client = opts.client || false;
|
|
2685
|
+
options.escapeFunction = opts.escape || opts.escapeFunction || utils.escapeXML;
|
|
2686
|
+
options.compileDebug = opts.compileDebug !== false;
|
|
2687
|
+
options.debug = !!opts.debug;
|
|
2688
|
+
options.filename = opts.filename;
|
|
2689
|
+
options.openDelimiter = opts.openDelimiter || ejs.openDelimiter || _DEFAULT_OPEN_DELIMITER;
|
|
2690
|
+
options.closeDelimiter = opts.closeDelimiter || ejs.closeDelimiter || _DEFAULT_CLOSE_DELIMITER;
|
|
2691
|
+
options.delimiter = opts.delimiter || ejs.delimiter || _DEFAULT_DELIMITER;
|
|
2692
|
+
options.strict = opts.strict || false;
|
|
2693
|
+
options.context = opts.context;
|
|
2694
|
+
options.cache = opts.cache || false;
|
|
2695
|
+
options.rmWhitespace = opts.rmWhitespace;
|
|
2696
|
+
options.root = opts.root;
|
|
2697
|
+
options.includer = opts.includer;
|
|
2698
|
+
options.outputFunctionName = opts.outputFunctionName;
|
|
2699
|
+
options.localsName = opts.localsName || ejs.localsName || _DEFAULT_LOCALS_NAME;
|
|
2700
|
+
options.views = opts.views;
|
|
2701
|
+
options.async = opts.async;
|
|
2702
|
+
options.destructuredLocals = opts.destructuredLocals;
|
|
2703
|
+
options.legacyInclude = typeof opts.legacyInclude != "undefined" ? !!opts.legacyInclude : true;
|
|
2704
|
+
if (options.strict) options._with = false;
|
|
2705
|
+
else options._with = typeof opts._with != "undefined" ? opts._with : true;
|
|
2706
|
+
this.opts = options;
|
|
2707
|
+
this.regex = this.createRegex();
|
|
2708
|
+
}
|
|
2709
|
+
Template.modes = {
|
|
2710
|
+
EVAL: "eval",
|
|
2711
|
+
ESCAPED: "escaped",
|
|
2712
|
+
RAW: "raw",
|
|
2713
|
+
COMMENT: "comment",
|
|
2714
|
+
LITERAL: "literal"
|
|
2715
|
+
};
|
|
2716
|
+
Template.prototype = {
|
|
2717
|
+
createRegex: function() {
|
|
2718
|
+
let str = _REGEX_STRING;
|
|
2719
|
+
let delim = utils.escapeRegExpChars(this.opts.delimiter);
|
|
2720
|
+
let open = utils.escapeRegExpChars(this.opts.openDelimiter);
|
|
2721
|
+
let close = utils.escapeRegExpChars(this.opts.closeDelimiter);
|
|
2722
|
+
str = str.replace(/%/g, delim).replace(/</g, open).replace(/>/g, close);
|
|
2723
|
+
return new RegExp(str);
|
|
2724
|
+
},
|
|
2725
|
+
compile: function() {
|
|
2726
|
+
/** @type {string} */
|
|
2727
|
+
let src;
|
|
2728
|
+
/** @type {ClientFunction} */
|
|
2729
|
+
let fn;
|
|
2730
|
+
let opts = this.opts;
|
|
2731
|
+
let prepended = "";
|
|
2732
|
+
let appended = "";
|
|
2733
|
+
/** @type {EscapeCallback} */
|
|
2734
|
+
let escapeFn = opts.escapeFunction;
|
|
2735
|
+
/** @type {FunctionConstructor} */
|
|
2736
|
+
let ctor;
|
|
2737
|
+
/** @type {string} */
|
|
2738
|
+
let sanitizedFilename = opts.filename ? JSON.stringify(opts.filename) : "undefined";
|
|
2739
|
+
if (!this.source) {
|
|
2740
|
+
this.generateSource();
|
|
2741
|
+
prepended += ` ${DECLARATION_KEYWORD} __output = "";\n function __append(s) { if (s !== undefined && s !== null) __output += s }
|
|
2742
|
+
`;
|
|
2743
|
+
if (opts.outputFunctionName) {
|
|
2744
|
+
if (!_JS_IDENTIFIER.test(opts.outputFunctionName)) throw new Error("outputFunctionName is not a valid JS identifier.");
|
|
2745
|
+
prepended += ` ${DECLARATION_KEYWORD} ` + opts.outputFunctionName + " = __append;\n";
|
|
2746
|
+
}
|
|
2747
|
+
if (opts.localsName && !_JS_IDENTIFIER.test(opts.localsName)) throw new Error("localsName is not a valid JS identifier.");
|
|
2748
|
+
if (opts.destructuredLocals && opts.destructuredLocals.length) {
|
|
2749
|
+
let destructuring = ` ${DECLARATION_KEYWORD} __locals = (` + opts.localsName + " || {}),\n";
|
|
2750
|
+
for (let i = 0; i < opts.destructuredLocals.length; i++) {
|
|
2751
|
+
let name = opts.destructuredLocals[i];
|
|
2752
|
+
if (!_JS_IDENTIFIER.test(name)) throw new Error("destructuredLocals[" + i + "] is not a valid JS identifier.");
|
|
2753
|
+
if (i > 0) destructuring += ",\n ";
|
|
2754
|
+
destructuring += name + " = __locals." + name;
|
|
2755
|
+
}
|
|
2756
|
+
prepended += destructuring + ";\n";
|
|
2757
|
+
}
|
|
2758
|
+
if (opts._with !== false) {
|
|
2759
|
+
prepended += " with (" + opts.localsName + " || {}) {\n";
|
|
2760
|
+
appended += " }\n";
|
|
2761
|
+
}
|
|
2762
|
+
appended += " return __output;\n";
|
|
2763
|
+
this.source = prepended + this.source + appended;
|
|
2764
|
+
}
|
|
2765
|
+
if (opts.compileDebug) src = `${DECLARATION_KEYWORD} __line = 1
|
|
2766
|
+
, __lines = ` + JSON.stringify(this.templateText) + "\n , __filename = " + sanitizedFilename + ";\ntry {\n" + this.source + "} catch (e) {\n rethrow(e, __lines, __filename, __line, escapeFn);\n}\n";
|
|
2767
|
+
else src = this.source;
|
|
2768
|
+
if (opts.client) {
|
|
2769
|
+
src = "escapeFn = escapeFn || " + escapeFn.toString() + ";\n" + src;
|
|
2770
|
+
if (opts.compileDebug) src = "rethrow = rethrow || " + rethrow.toString() + ";\n" + src;
|
|
2771
|
+
}
|
|
2772
|
+
if (opts.strict) src = "\"use strict\";\n" + src;
|
|
2773
|
+
if (opts.debug) console.log(src);
|
|
2774
|
+
if (opts.compileDebug && opts.filename) src = src + "\n//# sourceURL=" + sanitizedFilename + "\n";
|
|
2775
|
+
try {
|
|
2776
|
+
if (opts.async) try {
|
|
2777
|
+
ctor = new Function("return (async function(){}).constructor;")();
|
|
2778
|
+
} catch (e) {
|
|
2779
|
+
if (e instanceof SyntaxError) throw new Error("This environment does not support async/await");
|
|
2780
|
+
else throw e;
|
|
2781
|
+
}
|
|
2782
|
+
else ctor = Function;
|
|
2783
|
+
fn = new ctor(opts.localsName + ", escapeFn, include, rethrow", src);
|
|
2784
|
+
} catch (e) {
|
|
2785
|
+
// istanbul ignore else
|
|
2786
|
+
if (e instanceof SyntaxError) {
|
|
2787
|
+
if (opts.filename) e.message += " in " + opts.filename;
|
|
2788
|
+
e.message += " while compiling ejs\n\n";
|
|
2789
|
+
e.message += "If the above error is not helpful, you may want to try EJS-Lint:\n";
|
|
2790
|
+
e.message += "https://github.com/RyanZim/EJS-Lint";
|
|
2791
|
+
if (!opts.async) {
|
|
2792
|
+
e.message += "\n";
|
|
2793
|
+
e.message += "Or, if you meant to create an async function, pass `async: true` as an option.";
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
throw e;
|
|
2797
|
+
}
|
|
2798
|
+
let returnedFn = opts.client ? fn : function anonymous(data) {
|
|
2799
|
+
let include = function(path, includeData) {
|
|
2800
|
+
let d = utils.shallowCopy(utils.createNullProtoObjWherePossible(), data);
|
|
2801
|
+
if (includeData) d = utils.shallowCopy(d, includeData);
|
|
2802
|
+
return includeFile(path, opts)(d);
|
|
2803
|
+
};
|
|
2804
|
+
return fn.apply(opts.context, [
|
|
2805
|
+
data || utils.createNullProtoObjWherePossible(),
|
|
2806
|
+
escapeFn,
|
|
2807
|
+
include,
|
|
2808
|
+
rethrow
|
|
2809
|
+
]);
|
|
2810
|
+
};
|
|
2811
|
+
if (opts.filename && typeof Object.defineProperty === "function") {
|
|
2812
|
+
let filename = opts.filename;
|
|
2813
|
+
let basename = path.basename(filename, path.extname(filename));
|
|
2814
|
+
try {
|
|
2815
|
+
Object.defineProperty(returnedFn, "name", {
|
|
2816
|
+
value: basename,
|
|
2817
|
+
writable: false,
|
|
2818
|
+
enumerable: false,
|
|
2819
|
+
configurable: true
|
|
2820
|
+
});
|
|
2821
|
+
} catch (e) {}
|
|
2822
|
+
}
|
|
2823
|
+
return returnedFn;
|
|
2824
|
+
},
|
|
2825
|
+
generateSource: function() {
|
|
2826
|
+
if (this.opts.rmWhitespace) this.templateText = this.templateText.replace(/[\r\n]+/g, "\n").replace(/^\s+|\s+$/gm, "");
|
|
2827
|
+
this.templateText = this.templateText.replace(/[ \t]*<%_/gm, "<%_").replace(/_%>[ \t]*/gm, "_%>");
|
|
2828
|
+
let self = this;
|
|
2829
|
+
let matches = this.parseTemplateText();
|
|
2830
|
+
let d = this.opts.delimiter;
|
|
2831
|
+
let o = this.opts.openDelimiter;
|
|
2832
|
+
let c = this.opts.closeDelimiter;
|
|
2833
|
+
if (matches && matches.length) matches.forEach(function(line, index) {
|
|
2834
|
+
let closing;
|
|
2835
|
+
if (line.indexOf(o + d) === 0 && line.indexOf(o + d + d) !== 0) {
|
|
2836
|
+
closing = matches[index + 2];
|
|
2837
|
+
if (!(closing == d + c || closing == "-" + d + c || closing == "_" + d + c)) throw new Error("Could not find matching close tag for \"" + line + "\".");
|
|
2838
|
+
}
|
|
2839
|
+
self.scanLine(line);
|
|
2840
|
+
});
|
|
2841
|
+
},
|
|
2842
|
+
parseTemplateText: function() {
|
|
2843
|
+
let str = this.templateText;
|
|
2844
|
+
let pat = this.regex;
|
|
2845
|
+
let result = pat.exec(str);
|
|
2846
|
+
let arr = [];
|
|
2847
|
+
let firstPos;
|
|
2848
|
+
while (result) {
|
|
2849
|
+
firstPos = result.index;
|
|
2850
|
+
if (firstPos !== 0) {
|
|
2851
|
+
arr.push(str.substring(0, firstPos));
|
|
2852
|
+
str = str.slice(firstPos);
|
|
2853
|
+
}
|
|
2854
|
+
arr.push(result[0]);
|
|
2855
|
+
str = str.slice(result[0].length);
|
|
2856
|
+
result = pat.exec(str);
|
|
2857
|
+
}
|
|
2858
|
+
if (str) arr.push(str);
|
|
2859
|
+
return arr;
|
|
2860
|
+
},
|
|
2861
|
+
_addOutput: function(line) {
|
|
2862
|
+
if (this.truncate) {
|
|
2863
|
+
line = line.replace(/^(?:\r\n|\r|\n)/, "");
|
|
2864
|
+
this.truncate = false;
|
|
2865
|
+
}
|
|
2866
|
+
if (!line) return line;
|
|
2867
|
+
line = line.replace(/\\/g, "\\\\");
|
|
2868
|
+
line = line.replace(/\n/g, "\\n");
|
|
2869
|
+
line = line.replace(/\r/g, "\\r");
|
|
2870
|
+
line = line.replace(/"/g, "\\\"");
|
|
2871
|
+
this.source += " ; __append(\"" + line + "\")\n";
|
|
2872
|
+
},
|
|
2873
|
+
scanLine: function(line) {
|
|
2874
|
+
let self = this;
|
|
2875
|
+
let d = this.opts.delimiter;
|
|
2876
|
+
let o = this.opts.openDelimiter;
|
|
2877
|
+
let c = this.opts.closeDelimiter;
|
|
2878
|
+
let newLineCount = 0;
|
|
2879
|
+
newLineCount = line.split("\n").length - 1;
|
|
2880
|
+
switch (line) {
|
|
2881
|
+
case o + d:
|
|
2882
|
+
case o + d + "_":
|
|
2883
|
+
this.mode = Template.modes.EVAL;
|
|
2884
|
+
break;
|
|
2885
|
+
case o + d + "=":
|
|
2886
|
+
this.mode = Template.modes.ESCAPED;
|
|
2887
|
+
break;
|
|
2888
|
+
case o + d + "-":
|
|
2889
|
+
this.mode = Template.modes.RAW;
|
|
2890
|
+
break;
|
|
2891
|
+
case o + d + "#":
|
|
2892
|
+
this.mode = Template.modes.COMMENT;
|
|
2893
|
+
break;
|
|
2894
|
+
case o + d + d:
|
|
2895
|
+
this.mode = Template.modes.LITERAL;
|
|
2896
|
+
this.source += " ; __append(\"" + line.replace(o + d + d, o + d) + "\")\n";
|
|
2897
|
+
break;
|
|
2898
|
+
case d + d + c:
|
|
2899
|
+
this.mode = Template.modes.LITERAL;
|
|
2900
|
+
this.source += " ; __append(\"" + line.replace(d + d + c, d + c) + "\")\n";
|
|
2901
|
+
break;
|
|
2902
|
+
case d + c:
|
|
2903
|
+
case "-" + d + c:
|
|
2904
|
+
case "_" + d + c:
|
|
2905
|
+
if (this.mode == Template.modes.LITERAL) this._addOutput(line);
|
|
2906
|
+
this.mode = null;
|
|
2907
|
+
this.truncate = line.indexOf("-") === 0 || line.indexOf("_") === 0;
|
|
2908
|
+
break;
|
|
2909
|
+
default: if (this.mode) {
|
|
2910
|
+
switch (this.mode) {
|
|
2911
|
+
case Template.modes.EVAL:
|
|
2912
|
+
case Template.modes.ESCAPED:
|
|
2913
|
+
case Template.modes.RAW: if (line.lastIndexOf("//") > line.lastIndexOf("\n")) line += "\n";
|
|
2914
|
+
}
|
|
2915
|
+
switch (this.mode) {
|
|
2916
|
+
case Template.modes.EVAL:
|
|
2917
|
+
this.source += " ; " + line + "\n";
|
|
2918
|
+
break;
|
|
2919
|
+
case Template.modes.ESCAPED:
|
|
2920
|
+
this.source += " ; __append(escapeFn(" + stripSemi(line) + "))\n";
|
|
2921
|
+
break;
|
|
2922
|
+
case Template.modes.RAW:
|
|
2923
|
+
this.source += " ; __append(" + stripSemi(line) + ")\n";
|
|
2924
|
+
break;
|
|
2925
|
+
case Template.modes.COMMENT: break;
|
|
2926
|
+
case Template.modes.LITERAL:
|
|
2927
|
+
this._addOutput(line);
|
|
2928
|
+
break;
|
|
2929
|
+
}
|
|
2930
|
+
} else this._addOutput(line);
|
|
2931
|
+
}
|
|
2932
|
+
if (self.opts.compileDebug && newLineCount) {
|
|
2933
|
+
this.currentLine += newLineCount;
|
|
2934
|
+
this.source += " ; __line = " + this.currentLine + "\n";
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
2937
|
+
};
|
|
2938
|
+
/**
|
|
2939
|
+
* Escape characters reserved in XML.
|
|
2940
|
+
*
|
|
2941
|
+
* This is simply an export of {@link module:utils.escapeXML}.
|
|
2942
|
+
*
|
|
2943
|
+
* If `markup` is `undefined` or `null`, the empty string is returned.
|
|
2944
|
+
*
|
|
2945
|
+
* @param {String} markup Input string
|
|
2946
|
+
* @return {String} Escaped string
|
|
2947
|
+
* @public
|
|
2948
|
+
* @func
|
|
2949
|
+
* */
|
|
2950
|
+
ejs.escapeXML = utils.escapeXML;
|
|
2951
|
+
/**
|
|
2952
|
+
* Express.js support.
|
|
2953
|
+
*
|
|
2954
|
+
* This is an alias for {@link module:ejs.renderFile}, in order to support
|
|
2955
|
+
* Express.js out-of-the-box.
|
|
2956
|
+
*
|
|
2957
|
+
* @func
|
|
2958
|
+
*/
|
|
2959
|
+
ejs.__express = ejs.renderFile;
|
|
2960
|
+
/* istanbul ignore if */
|
|
2961
|
+
if (typeof window != "undefined") window.ejs = ejs;
|
|
2962
|
+
if (typeof module != "undefined") module.exports = ejs;
|
|
2963
|
+
|
|
2964
|
+
//#endregion
|
|
2965
|
+
//#region src/constant/index.ts
|
|
2966
|
+
const templateArr = [{
|
|
2967
|
+
name: "template-vue",
|
|
2968
|
+
display: "Vue",
|
|
2969
|
+
color: import_picocolors.default.blue,
|
|
2970
|
+
templateUI: [
|
|
2971
|
+
{
|
|
2972
|
+
name: "elementUI",
|
|
2973
|
+
display: "ElementUI",
|
|
2974
|
+
color: import_picocolors.default.cyan
|
|
2975
|
+
},
|
|
2976
|
+
{
|
|
2977
|
+
name: "vant",
|
|
2978
|
+
display: "Vant",
|
|
2979
|
+
color: import_picocolors.default.blue
|
|
2980
|
+
},
|
|
2981
|
+
{
|
|
2982
|
+
name: "tDesign",
|
|
2983
|
+
display: "TDesign",
|
|
2984
|
+
color: import_picocolors.default.green
|
|
2985
|
+
}
|
|
2986
|
+
]
|
|
2987
|
+
}, {
|
|
2988
|
+
name: "template-electron",
|
|
2989
|
+
display: "Electron",
|
|
2990
|
+
color: import_picocolors.default.yellow
|
|
2991
|
+
}];
|
|
2992
|
+
const templateUI = [
|
|
2993
|
+
{
|
|
2994
|
+
name: "",
|
|
2995
|
+
display: "NoUI",
|
|
2996
|
+
color: import_picocolors.default.cyan
|
|
2997
|
+
},
|
|
2998
|
+
{
|
|
2999
|
+
name: "element-ui",
|
|
3000
|
+
display: "ElementUI",
|
|
3001
|
+
color: import_picocolors.default.blue
|
|
3002
|
+
},
|
|
3003
|
+
{
|
|
3004
|
+
name: "vant",
|
|
3005
|
+
display: "Vant",
|
|
3006
|
+
color: import_picocolors.default.green
|
|
3007
|
+
},
|
|
3008
|
+
{
|
|
3009
|
+
name: "t-design",
|
|
3010
|
+
display: "TDesign",
|
|
3011
|
+
color: import_picocolors.default.yellow
|
|
3012
|
+
}
|
|
3013
|
+
];
|
|
3014
|
+
const templatePlugins = [
|
|
3015
|
+
{
|
|
3016
|
+
name: "",
|
|
3017
|
+
display: "No",
|
|
3018
|
+
color: import_picocolors.default.cyan
|
|
3019
|
+
},
|
|
3020
|
+
{
|
|
3021
|
+
name: "css",
|
|
3022
|
+
display: "css",
|
|
3023
|
+
color: import_picocolors.default.blue
|
|
3024
|
+
},
|
|
3025
|
+
{
|
|
3026
|
+
name: "visualizer",
|
|
3027
|
+
display: "visualizer",
|
|
3028
|
+
color: import_picocolors.default.yellow
|
|
3029
|
+
},
|
|
3030
|
+
{
|
|
3031
|
+
name: "vite-compression",
|
|
3032
|
+
display: "vite-compression",
|
|
3033
|
+
color: import_picocolors.default.cyan
|
|
3034
|
+
}
|
|
3035
|
+
];
|
|
3036
|
+
|
|
3037
|
+
//#endregion
|
|
3038
|
+
//#region src/index.ts
|
|
3039
|
+
const args = (0, import_lib.default)(process.argv.slice(2), {
|
|
3040
|
+
boolean: [
|
|
3041
|
+
"hep",
|
|
3042
|
+
"immediate",
|
|
3043
|
+
"overwrite",
|
|
3044
|
+
"interative"
|
|
3045
|
+
],
|
|
3046
|
+
alias: {
|
|
3047
|
+
h: "help",
|
|
3048
|
+
i: "immediate"
|
|
3049
|
+
}
|
|
3050
|
+
});
|
|
3051
|
+
const cwd = process.cwd();
|
|
3052
|
+
const helpMessage = `\
|
|
3053
|
+
Usage: create-vite [OPTION]... [DIRECTORY]
|
|
3054
|
+
`;
|
|
3055
|
+
const templateNames = templateArr.map((t) => t.name);
|
|
3056
|
+
async function init() {
|
|
3057
|
+
const argTargetDir = args._[0] ? formatTargetDir(args._[0]) : void 0;
|
|
3058
|
+
const argtemplate = args.template;
|
|
3059
|
+
const arghelp = args.help;
|
|
3060
|
+
const argImmediate = args.immediate;
|
|
3061
|
+
const argOverwrite = args.overwrite;
|
|
3062
|
+
const defaultTargetDir = "mux-project";
|
|
3063
|
+
if (arghelp) {
|
|
3064
|
+
console.log(helpMessage);
|
|
3065
|
+
return;
|
|
3066
|
+
}
|
|
3067
|
+
const interactive = args.interative ?? process.stdin.isTTY;
|
|
3068
|
+
const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent);
|
|
3069
|
+
const cancel = () => Pt("操作禁止");
|
|
3070
|
+
let targetDir = argTargetDir;
|
|
3071
|
+
if (!targetDir) if (interactive) {
|
|
3072
|
+
const projectName = await Qt({
|
|
3073
|
+
message: "项目名:",
|
|
3074
|
+
defaultValue: defaultTargetDir,
|
|
3075
|
+
placeholder: defaultTargetDir,
|
|
3076
|
+
validate: (value) => {
|
|
3077
|
+
return !value || formatTargetDir(value).length > 0 ? void 0 : "不合法的项目名";
|
|
3078
|
+
}
|
|
3079
|
+
});
|
|
3080
|
+
if (Ct$1(projectName)) return cancel();
|
|
3081
|
+
targetDir = formatTargetDir(projectName);
|
|
3082
|
+
} else targetDir = defaultTargetDir;
|
|
3083
|
+
if (fs.existsSync(targetDir) && !isEmpty(targetDir)) {
|
|
3084
|
+
let overwrite = argOverwrite ? "yes" : void 0;
|
|
3085
|
+
if (!overwrite) if (interactive) {
|
|
3086
|
+
const res = await qt({
|
|
3087
|
+
message: (targetDir === "." ? "当前目录" : `目标目录 "${targetDir}"`) + ` 不为空. 请选择如何处理:`,
|
|
3088
|
+
options: [
|
|
3089
|
+
{
|
|
3090
|
+
label: "中止操作",
|
|
3091
|
+
value: "no"
|
|
3092
|
+
},
|
|
3093
|
+
{
|
|
3094
|
+
label: "移除所有存在文件,并继续",
|
|
3095
|
+
value: "yes"
|
|
3096
|
+
},
|
|
3097
|
+
{
|
|
3098
|
+
label: "忽略所有文件并继续",
|
|
3099
|
+
value: "ignore"
|
|
3100
|
+
}
|
|
3101
|
+
]
|
|
3102
|
+
});
|
|
3103
|
+
if (Ct$1(res)) return cancel();
|
|
3104
|
+
overwrite = res;
|
|
3105
|
+
} else overwrite = "no";
|
|
3106
|
+
switch (overwrite) {
|
|
3107
|
+
case "yes":
|
|
3108
|
+
emptyDir(targetDir);
|
|
3109
|
+
break;
|
|
3110
|
+
case "no":
|
|
3111
|
+
cancel();
|
|
3112
|
+
return;
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3115
|
+
let packageName = path.basename(path.resolve(targetDir));
|
|
3116
|
+
if (!isValidPackageName(packageName)) if (interactive) {
|
|
3117
|
+
const packageNameResult = await Qt({
|
|
3118
|
+
message: "Package name:",
|
|
3119
|
+
defaultValue: toValidPackageName(packageName),
|
|
3120
|
+
placeholder: toValidPackageName(packageName),
|
|
3121
|
+
validate(dir) {
|
|
3122
|
+
if (dir && !isValidPackageName(dir)) return "不合法的 package.json 名";
|
|
3123
|
+
}
|
|
3124
|
+
});
|
|
3125
|
+
if (Ct$1(packageNameResult)) return cancel();
|
|
3126
|
+
packageName = packageNameResult;
|
|
3127
|
+
} else packageName = toValidPackageName(packageName);
|
|
3128
|
+
let template = argtemplate;
|
|
3129
|
+
let hasInvalidArgTemplate = false;
|
|
3130
|
+
if (argtemplate && !templateNames.includes(argtemplate)) {
|
|
3131
|
+
template = void 0;
|
|
3132
|
+
hasInvalidArgTemplate = true;
|
|
3133
|
+
}
|
|
3134
|
+
if (!template) if (interactive) {
|
|
3135
|
+
const framework = await qt({
|
|
3136
|
+
message: hasInvalidArgTemplate ? `"${argtemplate}" 不是一个合法的模板. 请在下面选择一个: ` : "选择一个模板:",
|
|
3137
|
+
options: templateArr.map((framework) => {
|
|
3138
|
+
const frameworkColor = framework.color;
|
|
3139
|
+
return {
|
|
3140
|
+
label: frameworkColor(framework.display || framework.name),
|
|
3141
|
+
value: framework.name
|
|
3142
|
+
};
|
|
3143
|
+
})
|
|
3144
|
+
});
|
|
3145
|
+
if (Ct$1(framework)) return cancel();
|
|
3146
|
+
template = framework;
|
|
3147
|
+
} else template = "template-vue";
|
|
3148
|
+
const pkgManager = pkgInfo ? pkgInfo.name : "npm";
|
|
3149
|
+
const root = path.join(cwd, targetDir);
|
|
3150
|
+
fs.mkdirSync(root, { recursive: true });
|
|
3151
|
+
R.step(`脚手架项目在 ${root}...`);
|
|
3152
|
+
const templateDir = path.resolve(fileURLToPath(import.meta.url), "../..", `template/${template}`);
|
|
3153
|
+
const callbacks = [];
|
|
3154
|
+
renderTemplate(templateDir, targetDir, callbacks);
|
|
3155
|
+
if (template === "template-vue") {
|
|
3156
|
+
const currentUI = [];
|
|
3157
|
+
if (currentUI.length === 0) {
|
|
3158
|
+
const currentUITemplate = await qt({
|
|
3159
|
+
message: "选择一个组件库:",
|
|
3160
|
+
options: templateUI.map((ui) => {
|
|
3161
|
+
const frameworkColor = ui.color;
|
|
3162
|
+
return {
|
|
3163
|
+
label: frameworkColor(ui.display || ui.name),
|
|
3164
|
+
value: ui.name
|
|
3165
|
+
};
|
|
3166
|
+
}),
|
|
3167
|
+
initialValue: ""
|
|
3168
|
+
});
|
|
3169
|
+
if (currentUITemplate) currentUI.push(currentUITemplate);
|
|
3170
|
+
}
|
|
3171
|
+
const templateRoot = fileURLToPath(new URL("../template", import.meta.url));
|
|
3172
|
+
const render = function render(templateName) {
|
|
3173
|
+
renderTemplate(path.resolve(templateRoot, templateName), root, callbacks);
|
|
3174
|
+
};
|
|
3175
|
+
if (currentUI.length) render(`template-ui/${currentUI[0]}`);
|
|
3176
|
+
const currentTemplatePlugins = [];
|
|
3177
|
+
if (currentTemplatePlugins.length === 0) {
|
|
3178
|
+
const cssPluginTemplate = await Lt({
|
|
3179
|
+
message: "选择0个或者多个插件",
|
|
3180
|
+
options: templatePlugins.map((plugin) => {
|
|
3181
|
+
const frameworkColor = plugin.color;
|
|
3182
|
+
return {
|
|
3183
|
+
label: frameworkColor(plugin.display || plugin.name),
|
|
3184
|
+
value: plugin.name
|
|
3185
|
+
};
|
|
3186
|
+
}),
|
|
3187
|
+
required: false
|
|
3188
|
+
});
|
|
3189
|
+
if (cssPluginTemplate) currentTemplatePlugins.push(...cssPluginTemplate);
|
|
3190
|
+
}
|
|
3191
|
+
if (currentTemplatePlugins.length) for (const key of currentTemplatePlugins) render(`template-plugins/${key}`);
|
|
3192
|
+
}
|
|
3193
|
+
const dataStore = {};
|
|
3194
|
+
for (const cb of callbacks) await cb(dataStore);
|
|
3195
|
+
console.log(Object.keys(dataStore));
|
|
3196
|
+
if (Object.keys(dataStore)) preOrderDirectoryTraverse(root, () => {}, (filepath) => {
|
|
3197
|
+
if (filepath.endsWith(".ejs")) {
|
|
3198
|
+
const template = fs.readFileSync(filepath, "utf-8");
|
|
3199
|
+
const dest = filepath.replace(/\.ejs$/, "");
|
|
3200
|
+
const content = ejs.render(template, dataStore[dest]);
|
|
3201
|
+
fs.writeFileSync(dest, content);
|
|
3202
|
+
fs.unlinkSync(filepath);
|
|
3203
|
+
}
|
|
3204
|
+
});
|
|
3205
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(targetDir, `package.json`), "utf-8"));
|
|
3206
|
+
pkg.name = packageName;
|
|
3207
|
+
const write = (file, content) => {
|
|
3208
|
+
const targetPath = path.join(root, renameFiles[file] ?? file);
|
|
3209
|
+
if (content) fs.writeFileSync(targetPath, content);
|
|
3210
|
+
else copy(path.join(templateDir, file), targetPath);
|
|
3211
|
+
};
|
|
3212
|
+
write("package.json", JSON.stringify(pkg, null, 2) + "\n");
|
|
3213
|
+
if (argImmediate) console.log("开始安装请等候 ....");
|
|
3214
|
+
else {
|
|
3215
|
+
let doneMessage = "";
|
|
3216
|
+
const cdProjectName = path.relative(cwd, root);
|
|
3217
|
+
doneMessage += `Done. Now run:\n`;
|
|
3218
|
+
if (root !== cwd) doneMessage += `\n cd ${cdProjectName.includes(" ") ? `"${cdProjectName}"` : cdProjectName}`;
|
|
3219
|
+
doneMessage += `\n ${getInstallCommand(pkgManager).join(" ")}`;
|
|
3220
|
+
doneMessage += `\n ${getRunCommand(pkgManager, "dev").join(" ")}`;
|
|
3221
|
+
Wt(doneMessage);
|
|
3222
|
+
}
|
|
3223
|
+
}
|
|
3224
|
+
init().catch((e) => {
|
|
3225
|
+
console.log(import_picocolors.default.bgBlack(e));
|
|
3226
|
+
process.exit(1);
|
|
3227
|
+
});
|
|
3228
|
+
|
|
3229
|
+
//#endregion
|
|
3230
|
+
export { };
|