zapdev 0.4.0 → 0.6.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/README.md +22 -18
- package/dist/cli.js +2786 -0
- package/dist/index.js +4 -3714
- package/package.json +13 -14
package/dist/index.js
CHANGED
|
@@ -1,3714 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
function __accessProp(key) {
|
|
9
|
-
return this[key];
|
|
10
|
-
}
|
|
11
|
-
var __toESMCache_node;
|
|
12
|
-
var __toESMCache_esm;
|
|
13
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
14
|
-
var canCache = mod != null && typeof mod === "object";
|
|
15
|
-
if (canCache) {
|
|
16
|
-
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
17
|
-
var cached = cache.get(mod);
|
|
18
|
-
if (cached)
|
|
19
|
-
return cached;
|
|
20
|
-
}
|
|
21
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
22
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
23
|
-
for (let key of __getOwnPropNames(mod))
|
|
24
|
-
if (!__hasOwnProp.call(to, key))
|
|
25
|
-
__defProp(to, key, {
|
|
26
|
-
get: __accessProp.bind(mod, key),
|
|
27
|
-
enumerable: true
|
|
28
|
-
});
|
|
29
|
-
if (canCache)
|
|
30
|
-
cache.set(mod, to);
|
|
31
|
-
return to;
|
|
32
|
-
};
|
|
33
|
-
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
34
|
-
|
|
35
|
-
// node_modules/sisteransi/src/index.js
|
|
36
|
-
var require_src = __commonJS((exports, module) => {
|
|
37
|
-
var ESC2 = "\x1B";
|
|
38
|
-
var CSI2 = `${ESC2}[`;
|
|
39
|
-
var beep = "\x07";
|
|
40
|
-
var cursor = {
|
|
41
|
-
to(x, y) {
|
|
42
|
-
if (!y)
|
|
43
|
-
return `${CSI2}${x + 1}G`;
|
|
44
|
-
return `${CSI2}${y + 1};${x + 1}H`;
|
|
45
|
-
},
|
|
46
|
-
move(x, y) {
|
|
47
|
-
let ret = "";
|
|
48
|
-
if (x < 0)
|
|
49
|
-
ret += `${CSI2}${-x}D`;
|
|
50
|
-
else if (x > 0)
|
|
51
|
-
ret += `${CSI2}${x}C`;
|
|
52
|
-
if (y < 0)
|
|
53
|
-
ret += `${CSI2}${-y}A`;
|
|
54
|
-
else if (y > 0)
|
|
55
|
-
ret += `${CSI2}${y}B`;
|
|
56
|
-
return ret;
|
|
57
|
-
},
|
|
58
|
-
up: (count = 1) => `${CSI2}${count}A`,
|
|
59
|
-
down: (count = 1) => `${CSI2}${count}B`,
|
|
60
|
-
forward: (count = 1) => `${CSI2}${count}C`,
|
|
61
|
-
backward: (count = 1) => `${CSI2}${count}D`,
|
|
62
|
-
nextLine: (count = 1) => `${CSI2}E`.repeat(count),
|
|
63
|
-
prevLine: (count = 1) => `${CSI2}F`.repeat(count),
|
|
64
|
-
left: `${CSI2}G`,
|
|
65
|
-
hide: `${CSI2}?25l`,
|
|
66
|
-
show: `${CSI2}?25h`,
|
|
67
|
-
save: `${ESC2}7`,
|
|
68
|
-
restore: `${ESC2}8`
|
|
69
|
-
};
|
|
70
|
-
var scroll = {
|
|
71
|
-
up: (count = 1) => `${CSI2}S`.repeat(count),
|
|
72
|
-
down: (count = 1) => `${CSI2}T`.repeat(count)
|
|
73
|
-
};
|
|
74
|
-
var erase = {
|
|
75
|
-
screen: `${CSI2}2J`,
|
|
76
|
-
up: (count = 1) => `${CSI2}1J`.repeat(count),
|
|
77
|
-
down: (count = 1) => `${CSI2}J`.repeat(count),
|
|
78
|
-
line: `${CSI2}2K`,
|
|
79
|
-
lineEnd: `${CSI2}K`,
|
|
80
|
-
lineStart: `${CSI2}1K`,
|
|
81
|
-
lines(count) {
|
|
82
|
-
let clear = "";
|
|
83
|
-
for (let i = 0;i < count; i++)
|
|
84
|
-
clear += this.line + (i < count - 1 ? cursor.up() : "");
|
|
85
|
-
if (count)
|
|
86
|
-
clear += cursor.left;
|
|
87
|
-
return clear;
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
module.exports = { cursor, scroll, erase, beep };
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// node_modules/@clack/core/dist/index.mjs
|
|
94
|
-
import { styleText } from "util";
|
|
95
|
-
import { stdout, stdin } from "process";
|
|
96
|
-
import * as l from "readline";
|
|
97
|
-
import l__default from "readline";
|
|
98
|
-
|
|
99
|
-
// node_modules/fast-string-truncated-width/dist/utils.js
|
|
100
|
-
var getCodePointsLength = (() => {
|
|
101
|
-
const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
|
102
|
-
return (input) => {
|
|
103
|
-
let surrogatePairsNr = 0;
|
|
104
|
-
SURROGATE_PAIR_RE.lastIndex = 0;
|
|
105
|
-
while (SURROGATE_PAIR_RE.test(input)) {
|
|
106
|
-
surrogatePairsNr += 1;
|
|
107
|
-
}
|
|
108
|
-
return input.length - surrogatePairsNr;
|
|
109
|
-
};
|
|
110
|
-
})();
|
|
111
|
-
var isFullWidth = (x) => {
|
|
112
|
-
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
113
|
-
};
|
|
114
|
-
var isWideNotCJKTNotEmoji = (x) => {
|
|
115
|
-
return x === 8987 || x === 9001 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12771 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 19903 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
// node_modules/fast-string-truncated-width/dist/index.js
|
|
119
|
-
var ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
|
|
120
|
-
var CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
121
|
-
var CJKT_WIDE_RE = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu;
|
|
122
|
-
var TAB_RE = /\t{1,1000}/y;
|
|
123
|
-
var EMOJI_RE = /[\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?))*/yu;
|
|
124
|
-
var LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
125
|
-
var MODIFIER_RE = /\p{M}+/gu;
|
|
126
|
-
var NO_TRUNCATION = { limit: Infinity, ellipsis: "" };
|
|
127
|
-
var getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
|
|
128
|
-
const LIMIT = truncationOptions.limit ?? Infinity;
|
|
129
|
-
const ELLIPSIS = truncationOptions.ellipsis ?? "";
|
|
130
|
-
const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION, widthOptions).width : 0);
|
|
131
|
-
const ANSI_WIDTH = 0;
|
|
132
|
-
const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
|
|
133
|
-
const TAB_WIDTH = widthOptions.tabWidth ?? 8;
|
|
134
|
-
const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
|
|
135
|
-
const FULL_WIDTH_WIDTH = 2;
|
|
136
|
-
const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
|
|
137
|
-
const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
|
|
138
|
-
const PARSE_BLOCKS = [
|
|
139
|
-
[LATIN_RE, REGULAR_WIDTH],
|
|
140
|
-
[ANSI_RE, ANSI_WIDTH],
|
|
141
|
-
[CONTROL_RE, CONTROL_WIDTH],
|
|
142
|
-
[TAB_RE, TAB_WIDTH],
|
|
143
|
-
[EMOJI_RE, EMOJI_WIDTH],
|
|
144
|
-
[CJKT_WIDE_RE, WIDE_WIDTH]
|
|
145
|
-
];
|
|
146
|
-
let indexPrev = 0;
|
|
147
|
-
let index = 0;
|
|
148
|
-
let length = input.length;
|
|
149
|
-
let lengthExtra = 0;
|
|
150
|
-
let truncationEnabled = false;
|
|
151
|
-
let truncationIndex = length;
|
|
152
|
-
let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
|
|
153
|
-
let unmatchedStart = 0;
|
|
154
|
-
let unmatchedEnd = 0;
|
|
155
|
-
let width = 0;
|
|
156
|
-
let widthExtra = 0;
|
|
157
|
-
outer:
|
|
158
|
-
while (true) {
|
|
159
|
-
if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
|
|
160
|
-
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
|
|
161
|
-
lengthExtra = 0;
|
|
162
|
-
for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
|
|
163
|
-
const codePoint = char.codePointAt(0) || 0;
|
|
164
|
-
if (isFullWidth(codePoint)) {
|
|
165
|
-
widthExtra = FULL_WIDTH_WIDTH;
|
|
166
|
-
} else if (isWideNotCJKTNotEmoji(codePoint)) {
|
|
167
|
-
widthExtra = WIDE_WIDTH;
|
|
168
|
-
} else {
|
|
169
|
-
widthExtra = REGULAR_WIDTH;
|
|
170
|
-
}
|
|
171
|
-
if (width + widthExtra > truncationLimit) {
|
|
172
|
-
truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
|
|
173
|
-
}
|
|
174
|
-
if (width + widthExtra > LIMIT) {
|
|
175
|
-
truncationEnabled = true;
|
|
176
|
-
break outer;
|
|
177
|
-
}
|
|
178
|
-
lengthExtra += char.length;
|
|
179
|
-
width += widthExtra;
|
|
180
|
-
}
|
|
181
|
-
unmatchedStart = unmatchedEnd = 0;
|
|
182
|
-
}
|
|
183
|
-
if (index >= length) {
|
|
184
|
-
break outer;
|
|
185
|
-
}
|
|
186
|
-
for (let i = 0, l = PARSE_BLOCKS.length;i < l; i++) {
|
|
187
|
-
const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
|
|
188
|
-
BLOCK_RE.lastIndex = index;
|
|
189
|
-
if (BLOCK_RE.test(input)) {
|
|
190
|
-
lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
|
|
191
|
-
widthExtra = lengthExtra * BLOCK_WIDTH;
|
|
192
|
-
if (width + widthExtra > truncationLimit) {
|
|
193
|
-
truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
|
|
194
|
-
}
|
|
195
|
-
if (width + widthExtra > LIMIT) {
|
|
196
|
-
truncationEnabled = true;
|
|
197
|
-
break outer;
|
|
198
|
-
}
|
|
199
|
-
width += widthExtra;
|
|
200
|
-
unmatchedStart = indexPrev;
|
|
201
|
-
unmatchedEnd = index;
|
|
202
|
-
index = indexPrev = BLOCK_RE.lastIndex;
|
|
203
|
-
continue outer;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
index += 1;
|
|
207
|
-
}
|
|
208
|
-
return {
|
|
209
|
-
width: truncationEnabled ? truncationLimit : width,
|
|
210
|
-
index: truncationEnabled ? truncationIndex : length,
|
|
211
|
-
truncated: truncationEnabled,
|
|
212
|
-
ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
|
|
213
|
-
};
|
|
214
|
-
};
|
|
215
|
-
var dist_default = getStringTruncatedWidth;
|
|
216
|
-
|
|
217
|
-
// node_modules/fast-string-width/dist/index.js
|
|
218
|
-
var NO_TRUNCATION2 = {
|
|
219
|
-
limit: Infinity,
|
|
220
|
-
ellipsis: "",
|
|
221
|
-
ellipsisWidth: 0
|
|
222
|
-
};
|
|
223
|
-
var fastStringWidth = (input, options = {}) => {
|
|
224
|
-
return dist_default(input, NO_TRUNCATION2, options).width;
|
|
225
|
-
};
|
|
226
|
-
var dist_default2 = fastStringWidth;
|
|
227
|
-
|
|
228
|
-
// node_modules/fast-wrap-ansi/lib/main.js
|
|
229
|
-
var ESC = "\x1B";
|
|
230
|
-
var CSI = "\x9B";
|
|
231
|
-
var END_CODE = 39;
|
|
232
|
-
var ANSI_ESCAPE_BELL = "\x07";
|
|
233
|
-
var ANSI_CSI = "[";
|
|
234
|
-
var ANSI_OSC = "]";
|
|
235
|
-
var ANSI_SGR_TERMINATOR = "m";
|
|
236
|
-
var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
237
|
-
var GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
|
|
238
|
-
var getClosingCode = (openingCode) => {
|
|
239
|
-
if (openingCode >= 30 && openingCode <= 37)
|
|
240
|
-
return 39;
|
|
241
|
-
if (openingCode >= 90 && openingCode <= 97)
|
|
242
|
-
return 39;
|
|
243
|
-
if (openingCode >= 40 && openingCode <= 47)
|
|
244
|
-
return 49;
|
|
245
|
-
if (openingCode >= 100 && openingCode <= 107)
|
|
246
|
-
return 49;
|
|
247
|
-
if (openingCode === 1 || openingCode === 2)
|
|
248
|
-
return 22;
|
|
249
|
-
if (openingCode === 3)
|
|
250
|
-
return 23;
|
|
251
|
-
if (openingCode === 4)
|
|
252
|
-
return 24;
|
|
253
|
-
if (openingCode === 7)
|
|
254
|
-
return 27;
|
|
255
|
-
if (openingCode === 8)
|
|
256
|
-
return 28;
|
|
257
|
-
if (openingCode === 9)
|
|
258
|
-
return 29;
|
|
259
|
-
if (openingCode === 0)
|
|
260
|
-
return 0;
|
|
261
|
-
return;
|
|
262
|
-
};
|
|
263
|
-
var wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
264
|
-
var wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
|
|
265
|
-
var wrapWord = (rows, word, columns) => {
|
|
266
|
-
const characters = word[Symbol.iterator]();
|
|
267
|
-
let isInsideEscape = false;
|
|
268
|
-
let isInsideLinkEscape = false;
|
|
269
|
-
let lastRow = rows.at(-1);
|
|
270
|
-
let visible = lastRow === undefined ? 0 : dist_default2(lastRow);
|
|
271
|
-
let currentCharacter = characters.next();
|
|
272
|
-
let nextCharacter = characters.next();
|
|
273
|
-
let rawCharacterIndex = 0;
|
|
274
|
-
while (!currentCharacter.done) {
|
|
275
|
-
const character = currentCharacter.value;
|
|
276
|
-
const characterLength = dist_default2(character);
|
|
277
|
-
if (visible + characterLength <= columns) {
|
|
278
|
-
rows[rows.length - 1] += character;
|
|
279
|
-
} else {
|
|
280
|
-
rows.push(character);
|
|
281
|
-
visible = 0;
|
|
282
|
-
}
|
|
283
|
-
if (character === ESC || character === CSI) {
|
|
284
|
-
isInsideEscape = true;
|
|
285
|
-
isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
|
|
286
|
-
}
|
|
287
|
-
if (isInsideEscape) {
|
|
288
|
-
if (isInsideLinkEscape) {
|
|
289
|
-
if (character === ANSI_ESCAPE_BELL) {
|
|
290
|
-
isInsideEscape = false;
|
|
291
|
-
isInsideLinkEscape = false;
|
|
292
|
-
}
|
|
293
|
-
} else if (character === ANSI_SGR_TERMINATOR) {
|
|
294
|
-
isInsideEscape = false;
|
|
295
|
-
}
|
|
296
|
-
} else {
|
|
297
|
-
visible += characterLength;
|
|
298
|
-
if (visible === columns && !nextCharacter.done) {
|
|
299
|
-
rows.push("");
|
|
300
|
-
visible = 0;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
currentCharacter = nextCharacter;
|
|
304
|
-
nextCharacter = characters.next();
|
|
305
|
-
rawCharacterIndex += character.length;
|
|
306
|
-
}
|
|
307
|
-
lastRow = rows.at(-1);
|
|
308
|
-
if (!visible && lastRow !== undefined && lastRow.length && rows.length > 1) {
|
|
309
|
-
rows[rows.length - 2] += rows.pop();
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
var stringVisibleTrimSpacesRight = (string) => {
|
|
313
|
-
const words = string.split(" ");
|
|
314
|
-
let last = words.length;
|
|
315
|
-
while (last) {
|
|
316
|
-
if (dist_default2(words[last - 1])) {
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
last--;
|
|
320
|
-
}
|
|
321
|
-
if (last === words.length) {
|
|
322
|
-
return string;
|
|
323
|
-
}
|
|
324
|
-
return words.slice(0, last).join(" ") + words.slice(last).join("");
|
|
325
|
-
};
|
|
326
|
-
var exec = (string, columns, options = {}) => {
|
|
327
|
-
if (options.trim !== false && string.trim() === "") {
|
|
328
|
-
return "";
|
|
329
|
-
}
|
|
330
|
-
let returnValue = "";
|
|
331
|
-
let escapeCode;
|
|
332
|
-
let escapeUrl;
|
|
333
|
-
const words = string.split(" ");
|
|
334
|
-
let rows = [""];
|
|
335
|
-
let rowLength = 0;
|
|
336
|
-
for (let index = 0;index < words.length; index++) {
|
|
337
|
-
const word = words[index];
|
|
338
|
-
if (options.trim !== false) {
|
|
339
|
-
const row = rows.at(-1) ?? "";
|
|
340
|
-
const trimmed = row.trimStart();
|
|
341
|
-
if (row.length !== trimmed.length) {
|
|
342
|
-
rows[rows.length - 1] = trimmed;
|
|
343
|
-
rowLength = dist_default2(trimmed);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
if (index !== 0) {
|
|
347
|
-
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
348
|
-
rows.push("");
|
|
349
|
-
rowLength = 0;
|
|
350
|
-
}
|
|
351
|
-
if (rowLength || options.trim === false) {
|
|
352
|
-
rows[rows.length - 1] += " ";
|
|
353
|
-
rowLength++;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
const wordLength = dist_default2(word);
|
|
357
|
-
if (options.hard && wordLength > columns) {
|
|
358
|
-
const remainingColumns = columns - rowLength;
|
|
359
|
-
const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
|
|
360
|
-
const breaksStartingNextLine = Math.floor((wordLength - 1) / columns);
|
|
361
|
-
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
362
|
-
rows.push("");
|
|
363
|
-
}
|
|
364
|
-
wrapWord(rows, word, columns);
|
|
365
|
-
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
366
|
-
continue;
|
|
367
|
-
}
|
|
368
|
-
if (rowLength + wordLength > columns && rowLength && wordLength) {
|
|
369
|
-
if (options.wordWrap === false && rowLength < columns) {
|
|
370
|
-
wrapWord(rows, word, columns);
|
|
371
|
-
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
372
|
-
continue;
|
|
373
|
-
}
|
|
374
|
-
rows.push("");
|
|
375
|
-
rowLength = 0;
|
|
376
|
-
}
|
|
377
|
-
if (rowLength + wordLength > columns && options.wordWrap === false) {
|
|
378
|
-
wrapWord(rows, word, columns);
|
|
379
|
-
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
380
|
-
continue;
|
|
381
|
-
}
|
|
382
|
-
rows[rows.length - 1] += word;
|
|
383
|
-
rowLength += wordLength;
|
|
384
|
-
}
|
|
385
|
-
if (options.trim !== false) {
|
|
386
|
-
rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
387
|
-
}
|
|
388
|
-
const preString = rows.join(`
|
|
389
|
-
`);
|
|
390
|
-
let inSurrogate = false;
|
|
391
|
-
for (let i = 0;i < preString.length; i++) {
|
|
392
|
-
const character = preString[i];
|
|
393
|
-
returnValue += character;
|
|
394
|
-
if (!inSurrogate) {
|
|
395
|
-
inSurrogate = character >= "\uD800" && character <= "\uDBFF";
|
|
396
|
-
if (inSurrogate) {
|
|
397
|
-
continue;
|
|
398
|
-
}
|
|
399
|
-
} else {
|
|
400
|
-
inSurrogate = false;
|
|
401
|
-
}
|
|
402
|
-
if (character === ESC || character === CSI) {
|
|
403
|
-
GROUP_REGEX.lastIndex = i + 1;
|
|
404
|
-
const groupsResult = GROUP_REGEX.exec(preString);
|
|
405
|
-
const groups = groupsResult?.groups;
|
|
406
|
-
if (groups?.code !== undefined) {
|
|
407
|
-
const code = Number.parseFloat(groups.code);
|
|
408
|
-
escapeCode = code === END_CODE ? undefined : code;
|
|
409
|
-
} else if (groups?.uri !== undefined) {
|
|
410
|
-
escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
if (preString[i + 1] === `
|
|
414
|
-
`) {
|
|
415
|
-
if (escapeUrl) {
|
|
416
|
-
returnValue += wrapAnsiHyperlink("");
|
|
417
|
-
}
|
|
418
|
-
const closingCode = escapeCode ? getClosingCode(escapeCode) : undefined;
|
|
419
|
-
if (escapeCode && closingCode) {
|
|
420
|
-
returnValue += wrapAnsiCode(closingCode);
|
|
421
|
-
}
|
|
422
|
-
} else if (character === `
|
|
423
|
-
`) {
|
|
424
|
-
if (escapeCode && getClosingCode(escapeCode)) {
|
|
425
|
-
returnValue += wrapAnsiCode(escapeCode);
|
|
426
|
-
}
|
|
427
|
-
if (escapeUrl) {
|
|
428
|
-
returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
return returnValue;
|
|
433
|
-
};
|
|
434
|
-
var CRLF_OR_LF = /\r?\n/;
|
|
435
|
-
function wrapAnsi(string, columns, options) {
|
|
436
|
-
return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join(`
|
|
437
|
-
`);
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
// node_modules/@clack/core/dist/index.mjs
|
|
441
|
-
var import_sisteransi = __toESM(require_src(), 1);
|
|
442
|
-
import { ReadStream } from "tty";
|
|
443
|
-
function findCursor(s, o, l2) {
|
|
444
|
-
if (!l2.some((r) => !r.disabled))
|
|
445
|
-
return s;
|
|
446
|
-
const t = s + o, n = Math.max(l2.length - 1, 0), e = t < 0 ? n : t > n ? 0 : t;
|
|
447
|
-
return l2[e].disabled ? findCursor(e, o < 0 ? -1 : 1, l2) : e;
|
|
448
|
-
}
|
|
449
|
-
function findTextCursor(s, o, l2, i) {
|
|
450
|
-
const t = i.split(`
|
|
451
|
-
`);
|
|
452
|
-
let n = 0, e = s;
|
|
453
|
-
for (const r of t) {
|
|
454
|
-
if (e <= r.length)
|
|
455
|
-
break;
|
|
456
|
-
e -= r.length + 1, n++;
|
|
457
|
-
}
|
|
458
|
-
for (n = Math.max(0, Math.min(t.length - 1, n + l2)), e = Math.min(e, t[n].length) + o;e < 0 && n > 0; )
|
|
459
|
-
n--, e += t[n].length + 1;
|
|
460
|
-
for (;e > t[n].length && n < t.length - 1; )
|
|
461
|
-
e -= t[n].length + 1, n++;
|
|
462
|
-
e = Math.max(0, Math.min(t[n].length, e));
|
|
463
|
-
let h = 0;
|
|
464
|
-
for (let r = 0;r < n; r++)
|
|
465
|
-
h += t[r].length + 1;
|
|
466
|
-
return h + e;
|
|
467
|
-
}
|
|
468
|
-
var a$2 = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
469
|
-
var t = [
|
|
470
|
-
"January",
|
|
471
|
-
"February",
|
|
472
|
-
"March",
|
|
473
|
-
"April",
|
|
474
|
-
"May",
|
|
475
|
-
"June",
|
|
476
|
-
"July",
|
|
477
|
-
"August",
|
|
478
|
-
"September",
|
|
479
|
-
"October",
|
|
480
|
-
"November",
|
|
481
|
-
"December"
|
|
482
|
-
];
|
|
483
|
-
var settings = {
|
|
484
|
-
actions: new Set(a$2),
|
|
485
|
-
aliases: /* @__PURE__ */ new Map([
|
|
486
|
-
["k", "up"],
|
|
487
|
-
["j", "down"],
|
|
488
|
-
["h", "left"],
|
|
489
|
-
["l", "right"],
|
|
490
|
-
["\x03", "cancel"],
|
|
491
|
-
["escape", "cancel"]
|
|
492
|
-
]),
|
|
493
|
-
messages: {
|
|
494
|
-
cancel: "Canceled",
|
|
495
|
-
error: "Something went wrong"
|
|
496
|
-
},
|
|
497
|
-
withGuide: true,
|
|
498
|
-
date: {
|
|
499
|
-
monthNames: [...t],
|
|
500
|
-
messages: {
|
|
501
|
-
required: "Please enter a valid date",
|
|
502
|
-
invalidMonth: "There are only 12 months in a year",
|
|
503
|
-
invalidDay: (n, e) => `There are only ${n} days in ${e}`,
|
|
504
|
-
afterMin: (n) => `Date must be on or after ${n.toISOString().slice(0, 10)}`,
|
|
505
|
-
beforeMax: (n) => `Date must be on or before ${n.toISOString().slice(0, 10)}`
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
|
-
function isActionKey(n, e) {
|
|
510
|
-
if (typeof n == "string")
|
|
511
|
-
return settings.aliases.get(n) === e;
|
|
512
|
-
for (const s of n)
|
|
513
|
-
if (s !== undefined && isActionKey(s, e))
|
|
514
|
-
return true;
|
|
515
|
-
return false;
|
|
516
|
-
}
|
|
517
|
-
function diffLines(i, s) {
|
|
518
|
-
if (i === s)
|
|
519
|
-
return;
|
|
520
|
-
const e = i.split(`
|
|
521
|
-
`), t2 = s.split(`
|
|
522
|
-
`), r = Math.max(e.length, t2.length), f = [];
|
|
523
|
-
for (let n = 0;n < r; n++)
|
|
524
|
-
e[n] !== t2[n] && f.push(n);
|
|
525
|
-
return {
|
|
526
|
-
lines: f,
|
|
527
|
-
numLinesBefore: e.length,
|
|
528
|
-
numLinesAfter: t2.length,
|
|
529
|
-
numLines: r
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
var R = globalThis.process.platform.startsWith("win");
|
|
533
|
-
var CANCEL_SYMBOL = Symbol("clack:cancel");
|
|
534
|
-
function isCancel(e) {
|
|
535
|
-
return e === CANCEL_SYMBOL;
|
|
536
|
-
}
|
|
537
|
-
function setRawMode(e, r) {
|
|
538
|
-
const o = e;
|
|
539
|
-
o.isTTY && o.setRawMode(r);
|
|
540
|
-
}
|
|
541
|
-
function block({
|
|
542
|
-
input: e = stdin,
|
|
543
|
-
output: r = stdout,
|
|
544
|
-
overwrite: o = true,
|
|
545
|
-
hideCursor: t2 = true
|
|
546
|
-
} = {}) {
|
|
547
|
-
const s = l.createInterface({
|
|
548
|
-
input: e,
|
|
549
|
-
output: r,
|
|
550
|
-
prompt: "",
|
|
551
|
-
tabSize: 1
|
|
552
|
-
});
|
|
553
|
-
l.emitKeypressEvents(e, s), e instanceof ReadStream && e.isTTY && e.setRawMode(true);
|
|
554
|
-
const n = (f, { name: a, sequence: p }) => {
|
|
555
|
-
const c = String(f);
|
|
556
|
-
if (isActionKey([c, a, p], "cancel")) {
|
|
557
|
-
t2 && r.write(import_sisteransi.cursor.show), process.exit(0);
|
|
558
|
-
return;
|
|
559
|
-
}
|
|
560
|
-
if (!o)
|
|
561
|
-
return;
|
|
562
|
-
const i = a === "return" ? 0 : -1, m = a === "return" ? -1 : 0;
|
|
563
|
-
l.moveCursor(r, i, m, () => {
|
|
564
|
-
l.clearLine(r, 1, () => {
|
|
565
|
-
e.once("keypress", n);
|
|
566
|
-
});
|
|
567
|
-
});
|
|
568
|
-
};
|
|
569
|
-
return t2 && r.write(import_sisteransi.cursor.hide), e.once("keypress", n), () => {
|
|
570
|
-
e.off("keypress", n), t2 && r.write(import_sisteransi.cursor.show), e instanceof ReadStream && e.isTTY && !R && e.setRawMode(false), s.terminal = false, s.close();
|
|
571
|
-
};
|
|
572
|
-
}
|
|
573
|
-
var getColumns = (e) => ("columns" in e) && typeof e.columns == "number" ? e.columns : 80;
|
|
574
|
-
var getRows = (e) => ("rows" in e) && typeof e.rows == "number" ? e.rows : 20;
|
|
575
|
-
function wrapTextWithPrefix(e, r, o, t2 = o, s = o, n) {
|
|
576
|
-
const f = getColumns(e ?? stdout);
|
|
577
|
-
return wrapAnsi(r, f - o.length, {
|
|
578
|
-
hard: true,
|
|
579
|
-
trim: false
|
|
580
|
-
}).split(`
|
|
581
|
-
`).map((c, i, m) => {
|
|
582
|
-
const d = n ? n(c, i) : c;
|
|
583
|
-
return i === 0 ? `${t2}${d}` : i === m.length - 1 ? `${s}${d}` : `${o}${d}`;
|
|
584
|
-
}).join(`
|
|
585
|
-
`);
|
|
586
|
-
}
|
|
587
|
-
function runValidation(e, n) {
|
|
588
|
-
if ("~standard" in e) {
|
|
589
|
-
const a = e["~standard"].validate(n);
|
|
590
|
-
if (a instanceof Promise)
|
|
591
|
-
throw new TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");
|
|
592
|
-
return a.issues?.at(0)?.message;
|
|
593
|
-
}
|
|
594
|
-
return e(n);
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
class V {
|
|
598
|
-
input;
|
|
599
|
-
output;
|
|
600
|
-
_abortSignal;
|
|
601
|
-
rl;
|
|
602
|
-
opts;
|
|
603
|
-
_render;
|
|
604
|
-
_track = false;
|
|
605
|
-
_prevFrame = "";
|
|
606
|
-
_subscribers = /* @__PURE__ */ new Map;
|
|
607
|
-
_cursor = 0;
|
|
608
|
-
state = "initial";
|
|
609
|
-
error = "";
|
|
610
|
-
value;
|
|
611
|
-
userInput = "";
|
|
612
|
-
constructor(t2, e = true) {
|
|
613
|
-
const { input: i = stdin, output: n = stdout, render: s, signal: r, ...o } = t2;
|
|
614
|
-
this.opts = o, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = s.bind(this), this._track = e, this._abortSignal = r, this.input = i, this.output = n;
|
|
615
|
-
}
|
|
616
|
-
unsubscribe() {
|
|
617
|
-
this._subscribers.clear();
|
|
618
|
-
}
|
|
619
|
-
setSubscriber(t2, e) {
|
|
620
|
-
const i = this._subscribers.get(t2) ?? [];
|
|
621
|
-
i.push(e), this._subscribers.set(t2, i);
|
|
622
|
-
}
|
|
623
|
-
on(t2, e) {
|
|
624
|
-
this.setSubscriber(t2, { cb: e });
|
|
625
|
-
}
|
|
626
|
-
once(t2, e) {
|
|
627
|
-
this.setSubscriber(t2, { cb: e, once: true });
|
|
628
|
-
}
|
|
629
|
-
emit(t2, ...e) {
|
|
630
|
-
const i = this._subscribers.get(t2) ?? [], n = [];
|
|
631
|
-
for (const s of i)
|
|
632
|
-
s.cb(...e), s.once && n.push(() => i.splice(i.indexOf(s), 1));
|
|
633
|
-
for (const s of n)
|
|
634
|
-
s();
|
|
635
|
-
}
|
|
636
|
-
prompt() {
|
|
637
|
-
return new Promise((t2) => {
|
|
638
|
-
if (this._abortSignal) {
|
|
639
|
-
if (this._abortSignal.aborted)
|
|
640
|
-
return this.state = "cancel", this.close(), t2(CANCEL_SYMBOL);
|
|
641
|
-
this._abortSignal.addEventListener("abort", () => {
|
|
642
|
-
this.state = "cancel", this.close();
|
|
643
|
-
}, { once: true });
|
|
644
|
-
}
|
|
645
|
-
this.rl = l__default.createInterface({
|
|
646
|
-
input: this.input,
|
|
647
|
-
tabSize: 2,
|
|
648
|
-
prompt: "",
|
|
649
|
-
escapeCodeTimeout: 50,
|
|
650
|
-
terminal: true
|
|
651
|
-
}), this.rl.prompt(), this.opts.initialUserInput !== undefined && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), setRawMode(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
|
|
652
|
-
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(this.value);
|
|
653
|
-
}), this.once("cancel", () => {
|
|
654
|
-
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(CANCEL_SYMBOL);
|
|
655
|
-
});
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
_isActionKey(t2, e) {
|
|
659
|
-
return t2 === "\t";
|
|
660
|
-
}
|
|
661
|
-
_shouldSubmit(t2, e) {
|
|
662
|
-
return true;
|
|
663
|
-
}
|
|
664
|
-
_setValue(t2) {
|
|
665
|
-
this.value = t2, this.emit("value", this.value);
|
|
666
|
-
}
|
|
667
|
-
_setUserInput(t2, e) {
|
|
668
|
-
this.userInput = t2 ?? "", this.emit("userInput", this.userInput), e && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
|
|
669
|
-
}
|
|
670
|
-
_clearUserInput() {
|
|
671
|
-
this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
|
|
672
|
-
}
|
|
673
|
-
onKeypress(t2, e) {
|
|
674
|
-
if (this._track && e.name !== "return" && (e.name && this._isActionKey(t2, e) && this.rl?.write(null, { ctrl: true, name: "h" }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), e?.name && (!this._track && settings.aliases.has(e.name) && this.emit("cursor", settings.aliases.get(e.name)), settings.actions.has(e.name) && this.emit("cursor", e.name)), t2 && (t2.toLowerCase() === "y" || t2.toLowerCase() === "n") && this.emit("confirm", t2.toLowerCase() === "y"), this.emit("key", t2, e), e?.name === "return" && this._shouldSubmit(t2, e)) {
|
|
675
|
-
if (this.opts.validate) {
|
|
676
|
-
const i = runValidation(this.opts.validate, this.value);
|
|
677
|
-
i && (this.error = i instanceof Error ? i.message : i, this.state = "error", this.rl?.write(this.userInput));
|
|
678
|
-
}
|
|
679
|
-
this.state !== "error" && (this.state = "submit");
|
|
680
|
-
}
|
|
681
|
-
isActionKey([t2, e?.name, e?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
682
|
-
}
|
|
683
|
-
close() {
|
|
684
|
-
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
685
|
-
`), setRawMode(this.input, false), this.rl?.close(), this.rl = undefined, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
686
|
-
}
|
|
687
|
-
restoreCursor() {
|
|
688
|
-
const t2 = wrapAnsi(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
|
|
689
|
-
`).length - 1;
|
|
690
|
-
this.output.write(import_sisteransi.cursor.move(-999, t2 * -1));
|
|
691
|
-
}
|
|
692
|
-
render() {
|
|
693
|
-
const t2 = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
|
|
694
|
-
hard: true,
|
|
695
|
-
trim: false
|
|
696
|
-
});
|
|
697
|
-
if (t2 !== this._prevFrame) {
|
|
698
|
-
if (this.state === "initial")
|
|
699
|
-
this.output.write(import_sisteransi.cursor.hide);
|
|
700
|
-
else {
|
|
701
|
-
const e = diffLines(this._prevFrame, t2), i = getRows(this.output);
|
|
702
|
-
if (this.restoreCursor(), e) {
|
|
703
|
-
const n = Math.max(0, e.numLinesAfter - i), s = Math.max(0, e.numLinesBefore - i);
|
|
704
|
-
let r = e.lines.find((o) => o >= n);
|
|
705
|
-
if (r === undefined) {
|
|
706
|
-
this._prevFrame = t2;
|
|
707
|
-
return;
|
|
708
|
-
}
|
|
709
|
-
if (e.lines.length === 1) {
|
|
710
|
-
this.output.write(import_sisteransi.cursor.move(0, r - s)), this.output.write(import_sisteransi.erase.lines(1));
|
|
711
|
-
const o = t2.split(`
|
|
712
|
-
`);
|
|
713
|
-
this.output.write(o[r]), this._prevFrame = t2, this.output.write(import_sisteransi.cursor.move(0, o.length - r - 1));
|
|
714
|
-
return;
|
|
715
|
-
} else if (e.lines.length > 1) {
|
|
716
|
-
if (n < s)
|
|
717
|
-
r = n;
|
|
718
|
-
else {
|
|
719
|
-
const h = r - s;
|
|
720
|
-
h > 0 && this.output.write(import_sisteransi.cursor.move(0, h));
|
|
721
|
-
}
|
|
722
|
-
this.output.write(import_sisteransi.erase.down());
|
|
723
|
-
const f = t2.split(`
|
|
724
|
-
`).slice(r);
|
|
725
|
-
this.output.write(f.join(`
|
|
726
|
-
`)), this._prevFrame = t2;
|
|
727
|
-
return;
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
this.output.write(import_sisteransi.erase.down());
|
|
731
|
-
}
|
|
732
|
-
this.output.write(t2), this.state === "initial" && (this.state = "active"), this._prevFrame = t2;
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
function p$1(l2, e) {
|
|
737
|
-
if (l2 === undefined || e.length === 0)
|
|
738
|
-
return 0;
|
|
739
|
-
const i = e.findIndex((s) => s.value === l2);
|
|
740
|
-
return i !== -1 ? i : 0;
|
|
741
|
-
}
|
|
742
|
-
function g(l2, e) {
|
|
743
|
-
return (e.label ?? String(e.value)).toLowerCase().includes(l2.toLowerCase());
|
|
744
|
-
}
|
|
745
|
-
function m(l2, e) {
|
|
746
|
-
if (e)
|
|
747
|
-
return l2 ? e : e[0];
|
|
748
|
-
}
|
|
749
|
-
var T$1 = class T extends V {
|
|
750
|
-
filteredOptions;
|
|
751
|
-
multiple;
|
|
752
|
-
isNavigating = false;
|
|
753
|
-
selectedValues = [];
|
|
754
|
-
focusedValue;
|
|
755
|
-
#e = 0;
|
|
756
|
-
#s = "";
|
|
757
|
-
#t;
|
|
758
|
-
#i;
|
|
759
|
-
#n;
|
|
760
|
-
get cursor() {
|
|
761
|
-
return this.#e;
|
|
762
|
-
}
|
|
763
|
-
get userInputWithCursor() {
|
|
764
|
-
if (!this.userInput)
|
|
765
|
-
return styleText(["inverse", "hidden"], "_");
|
|
766
|
-
if (this._cursor >= this.userInput.length)
|
|
767
|
-
return `${this.userInput}\u2588`;
|
|
768
|
-
const e = this.userInput.slice(0, this._cursor), [t2, ...i] = this.userInput.slice(this._cursor);
|
|
769
|
-
return `${e}${styleText("inverse", t2)}${i.join("")}`;
|
|
770
|
-
}
|
|
771
|
-
get options() {
|
|
772
|
-
return typeof this.#i == "function" ? this.#i() : this.#i;
|
|
773
|
-
}
|
|
774
|
-
constructor(e) {
|
|
775
|
-
super(e), this.#i = e.options, this.#n = e.placeholder;
|
|
776
|
-
const t2 = this.options;
|
|
777
|
-
this.filteredOptions = [...t2], this.multiple = e.multiple === true, this.#t = typeof e.options == "function" ? e.filter : e.filter ?? g;
|
|
778
|
-
let i;
|
|
779
|
-
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)
|
|
780
|
-
for (const s of i) {
|
|
781
|
-
const n = t2.findIndex((o) => o.value === s);
|
|
782
|
-
n !== -1 && (this.toggleSelected(s), this.#e = n);
|
|
783
|
-
}
|
|
784
|
-
this.focusedValue = this.options[this.#e]?.value, this.on("key", (s, n) => this.#l(s, n)), this.on("userInput", (s) => this.#u(s));
|
|
785
|
-
}
|
|
786
|
-
_isActionKey(e, t2) {
|
|
787
|
-
return e === "\t" || this.multiple && this.isNavigating && t2.name === "space" && e !== undefined && e !== "";
|
|
788
|
-
}
|
|
789
|
-
#l(e, t2) {
|
|
790
|
-
const i = t2.name === "up", s = t2.name === "down", n = t2.name === "return", o = this.userInput === "" || this.userInput === "\t", u = this.#n, h = this.options, f = u !== undefined && u !== "" && h.some((r) => !r.disabled && (this.#t ? this.#t(u, r) : true));
|
|
791
|
-
if (t2.name === "tab" && o && f) {
|
|
792
|
-
this.userInput === "\t" && this._clearUserInput(), this._setUserInput(u, true), this.isNavigating = false;
|
|
793
|
-
return;
|
|
794
|
-
}
|
|
795
|
-
i || s ? (this.#e = findCursor(this.#e, i ? -1 : 1, this.filteredOptions), this.focusedValue = this.filteredOptions[this.#e]?.value, this.multiple || (this.selectedValues = [this.focusedValue]), this.isNavigating = true) : n ? this.value = m(this.multiple, this.selectedValues) : this.multiple ? this.focusedValue !== undefined && (t2.name === "tab" || this.isNavigating && t2.name === "space") ? this.toggleSelected(this.focusedValue) : this.isNavigating = false : (this.focusedValue && (this.selectedValues = [this.focusedValue]), this.isNavigating = false);
|
|
796
|
-
}
|
|
797
|
-
deselectAll() {
|
|
798
|
-
this.selectedValues = [];
|
|
799
|
-
}
|
|
800
|
-
toggleSelected(e) {
|
|
801
|
-
this.filteredOptions.length !== 0 && (this.multiple ? this.selectedValues.includes(e) ? this.selectedValues = this.selectedValues.filter((t2) => t2 !== e) : this.selectedValues = [...this.selectedValues, e] : this.selectedValues = [e]);
|
|
802
|
-
}
|
|
803
|
-
#u(e) {
|
|
804
|
-
if (e !== this.#s) {
|
|
805
|
-
this.#s = e;
|
|
806
|
-
const t2 = this.options;
|
|
807
|
-
e && this.#t ? this.filteredOptions = t2.filter((n) => this.#t?.(e, n)) : this.filteredOptions = [...t2];
|
|
808
|
-
const i = p$1(this.focusedValue, this.filteredOptions);
|
|
809
|
-
this.#e = findCursor(i, 0, this.filteredOptions);
|
|
810
|
-
const s = this.filteredOptions[this.#e];
|
|
811
|
-
s && !s.disabled ? this.focusedValue = s.value : this.focusedValue = undefined, this.multiple || (this.focusedValue !== undefined ? this.toggleSelected(this.focusedValue) : this.deselectAll());
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
};
|
|
815
|
-
|
|
816
|
-
class r extends V {
|
|
817
|
-
get cursor() {
|
|
818
|
-
return this.value ? 0 : 1;
|
|
819
|
-
}
|
|
820
|
-
get _value() {
|
|
821
|
-
return this.cursor === 0;
|
|
822
|
-
}
|
|
823
|
-
constructor(t2) {
|
|
824
|
-
super(t2, false), this.value = !!t2.initialValue, this.on("userInput", () => {
|
|
825
|
-
this.value = this._value;
|
|
826
|
-
}), this.on("confirm", (i) => {
|
|
827
|
-
this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = i, this.state = "submit", this.close();
|
|
828
|
-
}), this.on("cursor", () => {
|
|
829
|
-
this.value = !this.value;
|
|
830
|
-
});
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
var _ = {
|
|
834
|
-
Y: { type: "year", len: 4 },
|
|
835
|
-
M: { type: "month", len: 2 },
|
|
836
|
-
D: { type: "day", len: 2 }
|
|
837
|
-
};
|
|
838
|
-
function M(r2) {
|
|
839
|
-
return [...r2].map((t2) => _[t2]);
|
|
840
|
-
}
|
|
841
|
-
function P(r2) {
|
|
842
|
-
const i = new Intl.DateTimeFormat(r2, {
|
|
843
|
-
year: "numeric",
|
|
844
|
-
month: "2-digit",
|
|
845
|
-
day: "2-digit"
|
|
846
|
-
}).formatToParts(new Date(2000, 0, 15)), s = [];
|
|
847
|
-
let n = "/";
|
|
848
|
-
for (const e of i)
|
|
849
|
-
e.type === "literal" ? n = e.value.trim() || e.value : (e.type === "year" || e.type === "month" || e.type === "day") && s.push({ type: e.type, len: e.type === "year" ? 4 : 2 });
|
|
850
|
-
return { segments: s, separator: n };
|
|
851
|
-
}
|
|
852
|
-
function p(r2) {
|
|
853
|
-
return Number.parseInt((r2 || "0").replace(/_/g, "0"), 10) || 0;
|
|
854
|
-
}
|
|
855
|
-
function f(r2) {
|
|
856
|
-
return {
|
|
857
|
-
year: p(r2.year),
|
|
858
|
-
month: p(r2.month),
|
|
859
|
-
day: p(r2.day)
|
|
860
|
-
};
|
|
861
|
-
}
|
|
862
|
-
function c(r2, t2) {
|
|
863
|
-
return new Date(r2 || 2001, t2 || 1, 0).getDate();
|
|
864
|
-
}
|
|
865
|
-
function b(r2) {
|
|
866
|
-
const { year: t2, month: i, day: s } = f(r2);
|
|
867
|
-
if (!t2 || t2 < 0 || t2 > 9999 || !i || i < 1 || i > 12 || !s || s < 1)
|
|
868
|
-
return;
|
|
869
|
-
const n = new Date(Date.UTC(t2, i - 1, s));
|
|
870
|
-
if (!(n.getUTCFullYear() !== t2 || n.getUTCMonth() !== i - 1 || n.getUTCDate() !== s))
|
|
871
|
-
return { year: t2, month: i, day: s };
|
|
872
|
-
}
|
|
873
|
-
function C(r2) {
|
|
874
|
-
const t2 = b(r2);
|
|
875
|
-
return t2 ? new Date(Date.UTC(t2.year, t2.month - 1, t2.day)) : undefined;
|
|
876
|
-
}
|
|
877
|
-
function T2(r2, t2, i, s) {
|
|
878
|
-
const n = i ? {
|
|
879
|
-
year: i.getUTCFullYear(),
|
|
880
|
-
month: i.getUTCMonth() + 1,
|
|
881
|
-
day: i.getUTCDate()
|
|
882
|
-
} : null, e = s ? {
|
|
883
|
-
year: s.getUTCFullYear(),
|
|
884
|
-
month: s.getUTCMonth() + 1,
|
|
885
|
-
day: s.getUTCDate()
|
|
886
|
-
} : null;
|
|
887
|
-
return r2 === "year" ? { min: n?.year ?? 1, max: e?.year ?? 9999 } : r2 === "month" ? {
|
|
888
|
-
min: n && t2.year === n.year ? n.month : 1,
|
|
889
|
-
max: e && t2.year === e.year ? e.month : 12
|
|
890
|
-
} : {
|
|
891
|
-
min: n && t2.year === n.year && t2.month === n.month ? n.day : 1,
|
|
892
|
-
max: e && t2.year === e.year && t2.month === e.month ? e.day : c(t2.year, t2.month)
|
|
893
|
-
};
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
class U extends V {
|
|
897
|
-
#i;
|
|
898
|
-
#o;
|
|
899
|
-
#t;
|
|
900
|
-
#h;
|
|
901
|
-
#u;
|
|
902
|
-
#e = { segmentIndex: 0, positionInSegment: 0 };
|
|
903
|
-
#n = true;
|
|
904
|
-
#s = null;
|
|
905
|
-
inlineError = "";
|
|
906
|
-
get segmentCursor() {
|
|
907
|
-
return { ...this.#e };
|
|
908
|
-
}
|
|
909
|
-
get segmentValues() {
|
|
910
|
-
return { ...this.#t };
|
|
911
|
-
}
|
|
912
|
-
get segments() {
|
|
913
|
-
return this.#i;
|
|
914
|
-
}
|
|
915
|
-
get separator() {
|
|
916
|
-
return this.#o;
|
|
917
|
-
}
|
|
918
|
-
get formattedValue() {
|
|
919
|
-
return this.#l(this.#t);
|
|
920
|
-
}
|
|
921
|
-
#l(t2) {
|
|
922
|
-
return this.#i.map((i) => t2[i.type]).join(this.#o);
|
|
923
|
-
}
|
|
924
|
-
#r() {
|
|
925
|
-
this._setUserInput(this.#l(this.#t)), this._setValue(C(this.#t) ?? undefined);
|
|
926
|
-
}
|
|
927
|
-
constructor(t2) {
|
|
928
|
-
const i = t2.format ? { segments: M(t2.format), separator: t2.separator ?? "/" } : P(t2.locale), s = t2.separator ?? i.separator, n = t2.format ? M(t2.format) : i.segments, e = t2.initialValue ?? t2.defaultValue, m2 = e ? {
|
|
929
|
-
year: String(e.getUTCFullYear()).padStart(4, "0"),
|
|
930
|
-
month: String(e.getUTCMonth() + 1).padStart(2, "0"),
|
|
931
|
-
day: String(e.getUTCDate()).padStart(2, "0")
|
|
932
|
-
} : { year: "____", month: "__", day: "__" }, o = n.map((a) => m2[a.type]).join(s);
|
|
933
|
-
super({ ...t2, initialUserInput: o }, false), this.#i = n, this.#o = s, this.#t = m2, this.#h = t2.minDate, this.#u = t2.maxDate, this.#r(), this.on("cursor", (a) => this.#f(a)), this.on("key", (a, u) => this.#y(a, u)), this.on("finalize", () => this.#p(t2));
|
|
934
|
-
}
|
|
935
|
-
#a() {
|
|
936
|
-
const t2 = Math.max(0, Math.min(this.#e.segmentIndex, this.#i.length - 1)), i = this.#i[t2];
|
|
937
|
-
if (i)
|
|
938
|
-
return this.#e.positionInSegment = Math.max(0, Math.min(this.#e.positionInSegment, i.len - 1)), { segment: i, index: t2 };
|
|
939
|
-
}
|
|
940
|
-
#m(t2) {
|
|
941
|
-
this.inlineError = "", this.#s = null;
|
|
942
|
-
const i = this.#a();
|
|
943
|
-
i && (this.#e.segmentIndex = Math.max(0, Math.min(this.#i.length - 1, i.index + t2)), this.#e.positionInSegment = 0, this.#n = true);
|
|
944
|
-
}
|
|
945
|
-
#d(t2) {
|
|
946
|
-
const i = this.#a();
|
|
947
|
-
if (!i)
|
|
948
|
-
return;
|
|
949
|
-
const { segment: s } = i, n = this.#t[s.type], e = !n || n.replace(/_/g, "") === "", m2 = Number.parseInt((n || "0").replace(/_/g, "0"), 10) || 0, o = T2(s.type, f(this.#t), this.#h, this.#u);
|
|
950
|
-
let a;
|
|
951
|
-
e ? a = t2 === 1 ? o.min : o.max : a = Math.max(Math.min(o.max, m2 + t2), o.min), this.#t = {
|
|
952
|
-
...this.#t,
|
|
953
|
-
[s.type]: a.toString().padStart(s.len, "0")
|
|
954
|
-
}, this.#n = true, this.#s = null, this.#r();
|
|
955
|
-
}
|
|
956
|
-
#f(t2) {
|
|
957
|
-
if (t2)
|
|
958
|
-
switch (t2) {
|
|
959
|
-
case "right":
|
|
960
|
-
return this.#m(1);
|
|
961
|
-
case "left":
|
|
962
|
-
return this.#m(-1);
|
|
963
|
-
case "up":
|
|
964
|
-
return this.#d(1);
|
|
965
|
-
case "down":
|
|
966
|
-
return this.#d(-1);
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
#y(t2, i) {
|
|
970
|
-
if (i?.name === "backspace" || i?.sequence === "\x7F" || i?.sequence === "\b" || t2 === "\x7F" || t2 === "\b") {
|
|
971
|
-
this.inlineError = "";
|
|
972
|
-
const n = this.#a();
|
|
973
|
-
if (!n)
|
|
974
|
-
return;
|
|
975
|
-
if (!this.#t[n.segment.type].replace(/_/g, "")) {
|
|
976
|
-
this.#m(-1);
|
|
977
|
-
return;
|
|
978
|
-
}
|
|
979
|
-
this.#t[n.segment.type] = "_".repeat(n.segment.len), this.#n = true, this.#e.positionInSegment = 0, this.#r();
|
|
980
|
-
return;
|
|
981
|
-
}
|
|
982
|
-
if (i?.name === "tab") {
|
|
983
|
-
this.inlineError = "";
|
|
984
|
-
const n = this.#a();
|
|
985
|
-
if (!n)
|
|
986
|
-
return;
|
|
987
|
-
const e = i.shift ? -1 : 1, m2 = n.index + e;
|
|
988
|
-
m2 >= 0 && m2 < this.#i.length && (this.#e.segmentIndex = m2, this.#e.positionInSegment = 0, this.#n = true);
|
|
989
|
-
return;
|
|
990
|
-
}
|
|
991
|
-
if (t2 && /^[0-9]$/.test(t2)) {
|
|
992
|
-
const n = this.#a();
|
|
993
|
-
if (!n)
|
|
994
|
-
return;
|
|
995
|
-
const { segment: e } = n, m2 = !this.#t[e.type].replace(/_/g, "");
|
|
996
|
-
if (this.#n && this.#s !== null && !m2) {
|
|
997
|
-
const h = this.#s + t2, d = { ...this.#t, [e.type]: h }, g2 = this.#g(d, e);
|
|
998
|
-
if (g2) {
|
|
999
|
-
this.inlineError = g2, this.#s = null, this.#n = false;
|
|
1000
|
-
return;
|
|
1001
|
-
}
|
|
1002
|
-
this.inlineError = "", this.#t[e.type] = h, this.#s = null, this.#n = false, this.#r(), n.index < this.#i.length - 1 && (this.#e.segmentIndex = n.index + 1, this.#e.positionInSegment = 0, this.#n = true);
|
|
1003
|
-
return;
|
|
1004
|
-
}
|
|
1005
|
-
this.#n && !m2 && (this.#t[e.type] = "_".repeat(e.len), this.#e.positionInSegment = 0), this.#n = false, this.#s = null;
|
|
1006
|
-
const o = this.#t[e.type], a = o.indexOf("_"), u = a >= 0 ? a : Math.min(this.#e.positionInSegment, e.len - 1);
|
|
1007
|
-
if (u < 0 || u >= e.len)
|
|
1008
|
-
return;
|
|
1009
|
-
let l2 = o.slice(0, u) + t2 + o.slice(u + 1), D = false;
|
|
1010
|
-
if (u === 0 && o === "__" && (e.type === "month" || e.type === "day")) {
|
|
1011
|
-
const h = Number.parseInt(t2, 10);
|
|
1012
|
-
l2 = `0${t2}`, D = h <= (e.type === "month" ? 1 : 2);
|
|
1013
|
-
}
|
|
1014
|
-
if (e.type === "year" && (l2 = (o.replace(/_/g, "") + t2).padStart(e.len, "_")), !l2.includes("_")) {
|
|
1015
|
-
const h = { ...this.#t, [e.type]: l2 }, d = this.#g(h, e);
|
|
1016
|
-
if (d) {
|
|
1017
|
-
this.inlineError = d;
|
|
1018
|
-
return;
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
this.inlineError = "", this.#t[e.type] = l2;
|
|
1022
|
-
const y = l2.includes("_") ? undefined : b(this.#t);
|
|
1023
|
-
if (y) {
|
|
1024
|
-
const { year: h, month: d } = y, g2 = c(h, d);
|
|
1025
|
-
this.#t = {
|
|
1026
|
-
year: String(Math.max(0, Math.min(9999, h))).padStart(4, "0"),
|
|
1027
|
-
month: String(Math.max(1, Math.min(12, d))).padStart(2, "0"),
|
|
1028
|
-
day: String(Math.max(1, Math.min(g2, y.day))).padStart(2, "0")
|
|
1029
|
-
};
|
|
1030
|
-
}
|
|
1031
|
-
this.#r();
|
|
1032
|
-
const S = l2.indexOf("_");
|
|
1033
|
-
D ? (this.#n = true, this.#s = t2) : S >= 0 ? this.#e.positionInSegment = S : a >= 0 && n.index < this.#i.length - 1 ? (this.#e.segmentIndex = n.index + 1, this.#e.positionInSegment = 0, this.#n = true) : this.#e.positionInSegment = Math.min(u + 1, e.len - 1);
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
#g(t2, i) {
|
|
1037
|
-
const { month: s, day: n } = f(t2);
|
|
1038
|
-
if (i.type === "month" && (s < 0 || s > 12))
|
|
1039
|
-
return settings.date.messages.invalidMonth;
|
|
1040
|
-
if (i.type === "day" && (n < 0 || n > 31))
|
|
1041
|
-
return settings.date.messages.invalidDay(31, "any month");
|
|
1042
|
-
}
|
|
1043
|
-
#p(t2) {
|
|
1044
|
-
const { year: i, month: s, day: n } = f(this.#t);
|
|
1045
|
-
if (i && s && n) {
|
|
1046
|
-
const e = c(i, s);
|
|
1047
|
-
this.#t = {
|
|
1048
|
-
...this.#t,
|
|
1049
|
-
day: String(Math.min(n, e)).padStart(2, "0")
|
|
1050
|
-
};
|
|
1051
|
-
}
|
|
1052
|
-
this.value = C(this.#t) ?? t2.defaultValue ?? undefined;
|
|
1053
|
-
}
|
|
1054
|
-
}
|
|
1055
|
-
var u$1 = class u extends V {
|
|
1056
|
-
options;
|
|
1057
|
-
cursor = 0;
|
|
1058
|
-
#t;
|
|
1059
|
-
getGroupItems(t2) {
|
|
1060
|
-
return this.options.filter((r2) => r2.group === t2);
|
|
1061
|
-
}
|
|
1062
|
-
isGroupSelected(t2) {
|
|
1063
|
-
const r2 = this.getGroupItems(t2), e = this.value;
|
|
1064
|
-
return e === undefined ? false : r2.every((s) => e.includes(s.value));
|
|
1065
|
-
}
|
|
1066
|
-
toggleValue() {
|
|
1067
|
-
const t2 = this.options[this.cursor];
|
|
1068
|
-
if (this.value === undefined && (this.value = []), t2.group === true) {
|
|
1069
|
-
const r2 = t2.value, e = this.getGroupItems(r2);
|
|
1070
|
-
this.isGroupSelected(r2) ? this.value = this.value.filter((s) => e.findIndex((i) => i.value === s) === -1) : this.value = [...this.value, ...e.map((s) => s.value)], this.value = Array.from(new Set(this.value));
|
|
1071
|
-
} else {
|
|
1072
|
-
const r2 = this.value.includes(t2.value);
|
|
1073
|
-
this.value = r2 ? this.value.filter((e) => e !== t2.value) : [...this.value, t2.value];
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
constructor(t2) {
|
|
1077
|
-
super(t2, false);
|
|
1078
|
-
const { options: r2 } = t2;
|
|
1079
|
-
this.#t = t2.selectableGroups !== false, this.options = Object.entries(r2).flatMap(([e, s]) => [
|
|
1080
|
-
{ value: e, group: true, label: e },
|
|
1081
|
-
...s.map((i) => ({ ...i, group: e }))
|
|
1082
|
-
]), this.value = [...t2.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: e }) => e === t2.cursorAt), this.#t ? 0 : 1), this.on("cursor", (e) => {
|
|
1083
|
-
switch (e) {
|
|
1084
|
-
case "left":
|
|
1085
|
-
case "up": {
|
|
1086
|
-
this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
|
|
1087
|
-
const s = this.options[this.cursor]?.group === true;
|
|
1088
|
-
!this.#t && s && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
|
|
1089
|
-
break;
|
|
1090
|
-
}
|
|
1091
|
-
case "down":
|
|
1092
|
-
case "right": {
|
|
1093
|
-
this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
|
|
1094
|
-
const s = this.options[this.cursor]?.group === true;
|
|
1095
|
-
!this.#t && s && (this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1);
|
|
1096
|
-
break;
|
|
1097
|
-
}
|
|
1098
|
-
case "space":
|
|
1099
|
-
this.toggleValue();
|
|
1100
|
-
break;
|
|
1101
|
-
}
|
|
1102
|
-
});
|
|
1103
|
-
}
|
|
1104
|
-
};
|
|
1105
|
-
var o$1 = /* @__PURE__ */ new Set(["up", "down", "left", "right"]);
|
|
1106
|
-
|
|
1107
|
-
class h extends V {
|
|
1108
|
-
#t = false;
|
|
1109
|
-
#s;
|
|
1110
|
-
focused = "editor";
|
|
1111
|
-
get userInputWithCursor() {
|
|
1112
|
-
if (this.state === "submit")
|
|
1113
|
-
return this.userInput;
|
|
1114
|
-
const t2 = this.userInput;
|
|
1115
|
-
if (this.cursor >= t2.length)
|
|
1116
|
-
return `${t2}\u2588`;
|
|
1117
|
-
const s = t2.slice(0, this.cursor), r2 = t2[this.cursor], i = t2.slice(this.cursor + 1);
|
|
1118
|
-
return r2 === `
|
|
1119
|
-
` ? `${s}\u2588
|
|
1120
|
-
${i}` : `${s}${styleText("inverse", r2)}${i}`;
|
|
1121
|
-
}
|
|
1122
|
-
get cursor() {
|
|
1123
|
-
return this._cursor;
|
|
1124
|
-
}
|
|
1125
|
-
#r(t2) {
|
|
1126
|
-
if (this.userInput.length === 0) {
|
|
1127
|
-
this._setUserInput(t2);
|
|
1128
|
-
return;
|
|
1129
|
-
}
|
|
1130
|
-
this._setUserInput(this.userInput.slice(0, this.cursor) + t2 + this.userInput.slice(this.cursor));
|
|
1131
|
-
}
|
|
1132
|
-
#i(t2) {
|
|
1133
|
-
const s = this.value ?? "";
|
|
1134
|
-
switch (t2) {
|
|
1135
|
-
case "up":
|
|
1136
|
-
this._cursor = findTextCursor(this._cursor, 0, -1, s);
|
|
1137
|
-
return;
|
|
1138
|
-
case "down":
|
|
1139
|
-
this._cursor = findTextCursor(this._cursor, 0, 1, s);
|
|
1140
|
-
return;
|
|
1141
|
-
case "left":
|
|
1142
|
-
this._cursor = findTextCursor(this._cursor, -1, 0, s);
|
|
1143
|
-
return;
|
|
1144
|
-
case "right":
|
|
1145
|
-
this._cursor = findTextCursor(this._cursor, 1, 0, s);
|
|
1146
|
-
return;
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
_shouldSubmit(t2, s) {
|
|
1150
|
-
if (this.#s)
|
|
1151
|
-
return this.focused === "submit" ? true : (this.#r(`
|
|
1152
|
-
`), this._cursor++, false);
|
|
1153
|
-
const r2 = this.#t;
|
|
1154
|
-
return this.#t = true, r2 && this.cursor === this.userInput.length ? (this.userInput[this.cursor - 1] === `
|
|
1155
|
-
` && (this._setUserInput(this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)), this._cursor--), true) : (this.#r(`
|
|
1156
|
-
`), this._cursor++, false);
|
|
1157
|
-
}
|
|
1158
|
-
constructor(t2) {
|
|
1159
|
-
const s = t2.initialUserInput ?? t2.initialValue;
|
|
1160
|
-
super({
|
|
1161
|
-
...t2,
|
|
1162
|
-
initialUserInput: s
|
|
1163
|
-
}, false), s !== undefined && (this._cursor = s.length), this.#s = t2.showSubmit ?? false, this.on("key", (r2, i) => {
|
|
1164
|
-
if (i?.name && o$1.has(i.name)) {
|
|
1165
|
-
this.#t = false, this.#i(i.name);
|
|
1166
|
-
return;
|
|
1167
|
-
}
|
|
1168
|
-
if (r2 === "\t" && this.#s) {
|
|
1169
|
-
this.focused = this.focused === "editor" ? "submit" : "editor";
|
|
1170
|
-
return;
|
|
1171
|
-
}
|
|
1172
|
-
if (i?.name !== "return") {
|
|
1173
|
-
if (this.#t = false, i?.name === "backspace" && this.cursor > 0) {
|
|
1174
|
-
this._setUserInput(this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)), this._cursor--;
|
|
1175
|
-
return;
|
|
1176
|
-
}
|
|
1177
|
-
if (i?.name === "delete" && this.cursor < this.userInput.length) {
|
|
1178
|
-
this._setUserInput(this.userInput.slice(0, this.cursor) + this.userInput.slice(this.cursor + 1));
|
|
1179
|
-
return;
|
|
1180
|
-
}
|
|
1181
|
-
r2 && (this.#s && this.focused === "submit" && (this.focused = "editor"), this.#r(r2 ?? ""), this._cursor++);
|
|
1182
|
-
}
|
|
1183
|
-
}), this.on("userInput", (r2) => {
|
|
1184
|
-
this._setValue(r2);
|
|
1185
|
-
}), this.on("finalize", () => {
|
|
1186
|
-
this.value || (this.value = t2.defaultValue), this.value === undefined && (this.value = "");
|
|
1187
|
-
});
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1190
|
-
var a$1 = class a extends V {
|
|
1191
|
-
options;
|
|
1192
|
-
cursor = 0;
|
|
1193
|
-
get _value() {
|
|
1194
|
-
return this.options[this.cursor].value;
|
|
1195
|
-
}
|
|
1196
|
-
get _enabledOptions() {
|
|
1197
|
-
return this.options.filter((e) => e.disabled !== true);
|
|
1198
|
-
}
|
|
1199
|
-
toggleAll() {
|
|
1200
|
-
const e = this._enabledOptions, i = this.value !== undefined && this.value.length === e.length;
|
|
1201
|
-
this.value = i ? [] : e.map((t2) => t2.value);
|
|
1202
|
-
}
|
|
1203
|
-
toggleInvert() {
|
|
1204
|
-
const e = this.value;
|
|
1205
|
-
if (!e)
|
|
1206
|
-
return;
|
|
1207
|
-
const i = this._enabledOptions.filter((t2) => !e.includes(t2.value));
|
|
1208
|
-
this.value = i.map((t2) => t2.value);
|
|
1209
|
-
}
|
|
1210
|
-
toggleValue() {
|
|
1211
|
-
this.value === undefined && (this.value = []);
|
|
1212
|
-
const e = this.value.includes(this._value);
|
|
1213
|
-
this.value = e ? this.value.filter((i) => i !== this._value) : [...this.value, this._value];
|
|
1214
|
-
}
|
|
1215
|
-
constructor(e) {
|
|
1216
|
-
super(e, false), this.options = e.options, this.value = [...e.initialValues ?? []];
|
|
1217
|
-
const i = Math.max(this.options.findIndex(({ value: t2 }) => t2 === e.cursorAt), 0);
|
|
1218
|
-
this.cursor = this.options[i].disabled ? findCursor(i, 1, this.options) : i, this.on("key", (t2, l2) => {
|
|
1219
|
-
l2.name === "a" && this.toggleAll(), l2.name === "i" && this.toggleInvert();
|
|
1220
|
-
}), this.on("cursor", (t2) => {
|
|
1221
|
-
switch (t2) {
|
|
1222
|
-
case "left":
|
|
1223
|
-
case "up":
|
|
1224
|
-
this.cursor = findCursor(this.cursor, -1, this.options);
|
|
1225
|
-
break;
|
|
1226
|
-
case "down":
|
|
1227
|
-
case "right":
|
|
1228
|
-
this.cursor = findCursor(this.cursor, 1, this.options);
|
|
1229
|
-
break;
|
|
1230
|
-
case "space":
|
|
1231
|
-
this.toggleValue();
|
|
1232
|
-
break;
|
|
1233
|
-
}
|
|
1234
|
-
});
|
|
1235
|
-
}
|
|
1236
|
-
};
|
|
1237
|
-
class a2 extends V {
|
|
1238
|
-
options;
|
|
1239
|
-
cursor = 0;
|
|
1240
|
-
get _selectedValue() {
|
|
1241
|
-
return this.options[this.cursor];
|
|
1242
|
-
}
|
|
1243
|
-
changeValue() {
|
|
1244
|
-
this.value = this._selectedValue.value;
|
|
1245
|
-
}
|
|
1246
|
-
constructor(t2) {
|
|
1247
|
-
super(t2, false), this.options = t2.options;
|
|
1248
|
-
const i = this.options.findIndex(({ value: s }) => s === t2.initialValue), e = i === -1 ? 0 : i;
|
|
1249
|
-
this.cursor = this.options[e].disabled ? findCursor(e, 1, this.options) : e, this.changeValue(), this.on("cursor", (s) => {
|
|
1250
|
-
switch (s) {
|
|
1251
|
-
case "left":
|
|
1252
|
-
case "up":
|
|
1253
|
-
this.cursor = findCursor(this.cursor, -1, this.options);
|
|
1254
|
-
break;
|
|
1255
|
-
case "down":
|
|
1256
|
-
case "right":
|
|
1257
|
-
this.cursor = findCursor(this.cursor, 1, this.options);
|
|
1258
|
-
break;
|
|
1259
|
-
}
|
|
1260
|
-
this.changeValue();
|
|
1261
|
-
});
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
class n extends V {
|
|
1265
|
-
get userInputWithCursor() {
|
|
1266
|
-
if (this.state === "submit")
|
|
1267
|
-
return this.userInput;
|
|
1268
|
-
const t2 = this.userInput;
|
|
1269
|
-
if (this.cursor >= t2.length)
|
|
1270
|
-
return `${this.userInput}\u2588`;
|
|
1271
|
-
const e = t2.slice(0, this.cursor), [s, ...r2] = t2.slice(this.cursor);
|
|
1272
|
-
return `${e}${styleText("inverse", s)}${r2.join("")}`;
|
|
1273
|
-
}
|
|
1274
|
-
get cursor() {
|
|
1275
|
-
return this._cursor;
|
|
1276
|
-
}
|
|
1277
|
-
constructor(t2) {
|
|
1278
|
-
super({
|
|
1279
|
-
...t2,
|
|
1280
|
-
initialUserInput: t2.initialUserInput ?? t2.initialValue
|
|
1281
|
-
}), this.on("userInput", (e) => {
|
|
1282
|
-
this._setValue(e);
|
|
1283
|
-
}), this.on("finalize", () => {
|
|
1284
|
-
this.value || (this.value = t2.defaultValue), this.value === undefined && (this.value = "");
|
|
1285
|
-
});
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
// node_modules/@clack/prompts/dist/index.mjs
|
|
1290
|
-
import { styleText as styleText2, stripVTControlCharacters } from "util";
|
|
1291
|
-
import process$1 from "process";
|
|
1292
|
-
var import_sisteransi2 = __toESM(require_src(), 1);
|
|
1293
|
-
function isUnicodeSupported() {
|
|
1294
|
-
if (process$1.platform !== "win32") {
|
|
1295
|
-
return process$1.env.TERM !== "linux";
|
|
1296
|
-
}
|
|
1297
|
-
return Boolean(process$1.env.CI) || Boolean(process$1.env.WT_SESSION) || Boolean(process$1.env.TERMINUS_SUBLIME) || process$1.env.ConEmuTask === "{cmd::Cmder}" || process$1.env.TERM_PROGRAM === "Terminus-Sublime" || process$1.env.TERM_PROGRAM === "vscode" || process$1.env.TERM === "xterm-256color" || process$1.env.TERM === "alacritty" || process$1.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
1298
|
-
}
|
|
1299
|
-
var unicode = isUnicodeSupported();
|
|
1300
|
-
var isCI = () => process.env.CI === "true";
|
|
1301
|
-
var unicodeOr = (o2, e) => unicode ? o2 : e;
|
|
1302
|
-
var S_STEP_ACTIVE = unicodeOr("\u25C6", "*");
|
|
1303
|
-
var S_STEP_CANCEL = unicodeOr("\u25A0", "x");
|
|
1304
|
-
var S_STEP_ERROR = unicodeOr("\u25B2", "x");
|
|
1305
|
-
var S_STEP_SUBMIT = unicodeOr("\u25C7", "o");
|
|
1306
|
-
var S_BAR_START = unicodeOr("\u250C", "T");
|
|
1307
|
-
var S_BAR = unicodeOr("\u2502", "|");
|
|
1308
|
-
var S_BAR_END = unicodeOr("\u2514", "\u2014");
|
|
1309
|
-
var S_BAR_START_RIGHT = unicodeOr("\u2510", "T");
|
|
1310
|
-
var S_BAR_END_RIGHT = unicodeOr("\u2518", "\u2014");
|
|
1311
|
-
var S_RADIO_ACTIVE = unicodeOr("\u25CF", ">");
|
|
1312
|
-
var S_RADIO_INACTIVE = unicodeOr("\u25CB", " ");
|
|
1313
|
-
var S_CHECKBOX_ACTIVE = unicodeOr("\u25FB", "[\u2022]");
|
|
1314
|
-
var S_CHECKBOX_SELECTED = unicodeOr("\u25FC", "[+]");
|
|
1315
|
-
var S_CHECKBOX_INACTIVE = unicodeOr("\u25FB", "[ ]");
|
|
1316
|
-
var S_PASSWORD_MASK = unicodeOr("\u25AA", "\u2022");
|
|
1317
|
-
var S_BAR_H = unicodeOr("\u2500", "-");
|
|
1318
|
-
var S_CORNER_TOP_RIGHT = unicodeOr("\u256E", "+");
|
|
1319
|
-
var S_CONNECT_LEFT = unicodeOr("\u251C", "+");
|
|
1320
|
-
var S_CORNER_BOTTOM_RIGHT = unicodeOr("\u256F", "+");
|
|
1321
|
-
var S_CORNER_BOTTOM_LEFT = unicodeOr("\u2570", "+");
|
|
1322
|
-
var S_CORNER_TOP_LEFT = unicodeOr("\u256D", "+");
|
|
1323
|
-
var S_INFO = unicodeOr("\u25CF", "\u2022");
|
|
1324
|
-
var S_SUCCESS = unicodeOr("\u25C6", "*");
|
|
1325
|
-
var S_WARN = unicodeOr("\u25B2", "!");
|
|
1326
|
-
var S_ERROR = unicodeOr("\u25A0", "x");
|
|
1327
|
-
var symbol = (o2) => {
|
|
1328
|
-
switch (o2) {
|
|
1329
|
-
case "initial":
|
|
1330
|
-
case "active":
|
|
1331
|
-
return styleText2("cyan", S_STEP_ACTIVE);
|
|
1332
|
-
case "cancel":
|
|
1333
|
-
return styleText2("red", S_STEP_CANCEL);
|
|
1334
|
-
case "error":
|
|
1335
|
-
return styleText2("yellow", S_STEP_ERROR);
|
|
1336
|
-
case "submit":
|
|
1337
|
-
return styleText2("green", S_STEP_SUBMIT);
|
|
1338
|
-
}
|
|
1339
|
-
};
|
|
1340
|
-
var symbolBar = (o2) => {
|
|
1341
|
-
switch (o2) {
|
|
1342
|
-
case "initial":
|
|
1343
|
-
case "active":
|
|
1344
|
-
return styleText2("cyan", S_BAR);
|
|
1345
|
-
case "cancel":
|
|
1346
|
-
return styleText2("red", S_BAR);
|
|
1347
|
-
case "error":
|
|
1348
|
-
return styleText2("yellow", S_BAR);
|
|
1349
|
-
case "submit":
|
|
1350
|
-
return styleText2("green", S_BAR);
|
|
1351
|
-
}
|
|
1352
|
-
};
|
|
1353
|
-
function formatInstructionFooter(o2, e) {
|
|
1354
|
-
const r2 = [`${e ? `${styleText2("cyan", S_BAR)} ` : ""}${o2.join(" \u2022 ")}`];
|
|
1355
|
-
return e && r2.push(styleText2("cyan", S_BAR_END)), r2;
|
|
1356
|
-
}
|
|
1357
|
-
var E$1 = (l2, o2, g2, c2, h2, O = false) => {
|
|
1358
|
-
let r2 = o2, w = 0;
|
|
1359
|
-
if (O)
|
|
1360
|
-
for (let i = c2 - 1;i >= g2 && (r2 -= l2[i].length, w++, !(r2 <= h2)); i--)
|
|
1361
|
-
;
|
|
1362
|
-
else
|
|
1363
|
-
for (let i = g2;i < c2 && (r2 -= l2[i].length, w++, !(r2 <= h2)); i++)
|
|
1364
|
-
;
|
|
1365
|
-
return { lineCount: r2, removals: w };
|
|
1366
|
-
};
|
|
1367
|
-
var limitOptions = ({
|
|
1368
|
-
cursor: l2,
|
|
1369
|
-
options: o2,
|
|
1370
|
-
style: g2,
|
|
1371
|
-
output: c2 = process.stdout,
|
|
1372
|
-
maxItems: h2 = Number.POSITIVE_INFINITY,
|
|
1373
|
-
columnPadding: O = 0,
|
|
1374
|
-
rowPadding: r2 = 4
|
|
1375
|
-
}) => {
|
|
1376
|
-
const i = getColumns(c2) - O, I = getRows(c2), C2 = styleText2("dim", "..."), x = Math.max(I - r2, 0), m2 = Math.max(Math.min(h2, x), 5);
|
|
1377
|
-
let p2 = 0;
|
|
1378
|
-
l2 >= m2 - 3 && (p2 = Math.max(Math.min(l2 - m2 + 3, o2.length - m2), 0));
|
|
1379
|
-
let f2 = m2 < o2.length && p2 > 0, u3 = m2 < o2.length && p2 + m2 < o2.length;
|
|
1380
|
-
const W = Math.min(p2 + m2, o2.length), e = [];
|
|
1381
|
-
let d = 0;
|
|
1382
|
-
f2 && d++, u3 && d++;
|
|
1383
|
-
const v = p2 + (f2 ? 1 : 0), P2 = W - (u3 ? 1 : 0);
|
|
1384
|
-
for (let t2 = v;t2 < P2; t2++) {
|
|
1385
|
-
const n2 = wrapAnsi(g2(o2[t2], t2 === l2), i, {
|
|
1386
|
-
hard: true,
|
|
1387
|
-
trim: false
|
|
1388
|
-
}).split(`
|
|
1389
|
-
`);
|
|
1390
|
-
e.push(n2), d += n2.length;
|
|
1391
|
-
}
|
|
1392
|
-
if (d > x) {
|
|
1393
|
-
let t2 = 0, n2 = 0, s = d;
|
|
1394
|
-
const M2 = l2 - v;
|
|
1395
|
-
let a3 = x;
|
|
1396
|
-
const T3 = () => E$1(e, s, 0, M2, a3), L = () => E$1(e, s, M2 + 1, e.length, a3, true);
|
|
1397
|
-
f2 ? ({ lineCount: s, removals: t2 } = T3(), s > a3 && (u3 || (a3 -= 1), { lineCount: s, removals: n2 } = L())) : (u3 || (a3 -= 1), { lineCount: s, removals: n2 } = L(), s > a3 && (a3 -= 1, { lineCount: s, removals: t2 } = T3())), t2 > 0 && (f2 = true, e.splice(0, t2)), n2 > 0 && (u3 = true, e.splice(e.length - n2, n2));
|
|
1398
|
-
}
|
|
1399
|
-
const b2 = [];
|
|
1400
|
-
f2 && b2.push(C2);
|
|
1401
|
-
for (const t2 of e)
|
|
1402
|
-
for (const n2 of t2)
|
|
1403
|
-
b2.push(n2);
|
|
1404
|
-
return u3 && b2.push(C2), b2;
|
|
1405
|
-
};
|
|
1406
|
-
var confirm = (i) => {
|
|
1407
|
-
const a3 = i.active ?? "Yes", s = i.inactive ?? "No";
|
|
1408
|
-
return new r({
|
|
1409
|
-
active: a3,
|
|
1410
|
-
inactive: s,
|
|
1411
|
-
signal: i.signal,
|
|
1412
|
-
input: i.input,
|
|
1413
|
-
output: i.output,
|
|
1414
|
-
initialValue: i.initialValue ?? true,
|
|
1415
|
-
render() {
|
|
1416
|
-
const e = i.withGuide ?? settings.withGuide, u3 = `${symbol(this.state)} `, l2 = e ? `${styleText2("gray", S_BAR)} ` : "", f2 = wrapTextWithPrefix(i.output, i.message, l2, u3), o2 = `${e ? `${styleText2("gray", S_BAR)}
|
|
1417
|
-
` : ""}${f2}
|
|
1418
|
-
`, c2 = this.value ? a3 : s;
|
|
1419
|
-
switch (this.state) {
|
|
1420
|
-
case "submit": {
|
|
1421
|
-
const r2 = e ? `${styleText2("gray", S_BAR)} ` : "";
|
|
1422
|
-
return `${o2}${r2}${styleText2("dim", c2)}`;
|
|
1423
|
-
}
|
|
1424
|
-
case "cancel": {
|
|
1425
|
-
const r2 = e ? `${styleText2("gray", S_BAR)} ` : "";
|
|
1426
|
-
return `${o2}${r2}${styleText2(["strikethrough", "dim"], c2)}${e ? `
|
|
1427
|
-
${styleText2("gray", S_BAR)}` : ""}`;
|
|
1428
|
-
}
|
|
1429
|
-
default: {
|
|
1430
|
-
const r2 = e ? `${styleText2("cyan", S_BAR)} ` : "", g2 = e ? styleText2("cyan", S_BAR_END) : "";
|
|
1431
|
-
return `${o2}${r2}${this.value ? `${styleText2("green", S_RADIO_ACTIVE)} ${a3}` : `${styleText2("dim", S_RADIO_INACTIVE)} ${styleText2("dim", a3)}`}${i.vertical ? e ? `
|
|
1432
|
-
${styleText2("cyan", S_BAR)} ` : `
|
|
1433
|
-
` : ` ${styleText2("dim", "/")} `}${this.value ? `${styleText2("dim", S_RADIO_INACTIVE)} ${styleText2("dim", s)}` : `${styleText2("green", S_RADIO_ACTIVE)} ${s}`}
|
|
1434
|
-
${g2}
|
|
1435
|
-
`;
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
}).prompt();
|
|
1440
|
-
};
|
|
1441
|
-
var MULTISELECT_INSTRUCTIONS = [
|
|
1442
|
-
`${styleText2("dim", "\u2191/\u2193")} to navigate`,
|
|
1443
|
-
`${styleText2("dim", "Space:")} select`,
|
|
1444
|
-
`${styleText2("dim", "Enter:")} confirm`
|
|
1445
|
-
];
|
|
1446
|
-
var m2 = (n2, o2) => n2.split(`
|
|
1447
|
-
`).map((d) => o2(d)).join(`
|
|
1448
|
-
`);
|
|
1449
|
-
var multiselect = (n2) => {
|
|
1450
|
-
const o2 = (t2, a3) => {
|
|
1451
|
-
const r2 = t2.label ?? String(t2.value);
|
|
1452
|
-
return a3 === "disabled" ? `${styleText2("gray", S_CHECKBOX_INACTIVE)} ${m2(r2, (l2) => styleText2(["strikethrough", "gray"], l2))}${t2.hint ? ` ${styleText2("dim", `(${t2.hint ?? "disabled"})`)}` : ""}` : a3 === "active" ? `${styleText2("cyan", S_CHECKBOX_ACTIVE)} ${r2}${t2.hint ? ` ${styleText2("dim", `(${t2.hint})`)}` : ""}` : a3 === "selected" ? `${styleText2("green", S_CHECKBOX_SELECTED)} ${m2(r2, (l2) => styleText2("dim", l2))}${t2.hint ? ` ${styleText2("dim", `(${t2.hint})`)}` : ""}` : a3 === "cancelled" ? `${m2(r2, (l2) => styleText2(["strikethrough", "dim"], l2))}` : a3 === "active-selected" ? `${styleText2("green", S_CHECKBOX_SELECTED)} ${r2}${t2.hint ? ` ${styleText2("dim", `(${t2.hint})`)}` : ""}` : a3 === "submitted" ? `${m2(r2, (l2) => styleText2("dim", l2))}` : `${styleText2("dim", S_CHECKBOX_INACTIVE)} ${m2(r2, (l2) => styleText2("dim", l2))}`;
|
|
1453
|
-
}, d = n2.required ?? true;
|
|
1454
|
-
return new a$1({
|
|
1455
|
-
options: n2.options,
|
|
1456
|
-
signal: n2.signal,
|
|
1457
|
-
input: n2.input,
|
|
1458
|
-
output: n2.output,
|
|
1459
|
-
initialValues: n2.initialValues,
|
|
1460
|
-
required: d,
|
|
1461
|
-
cursorAt: n2.cursorAt,
|
|
1462
|
-
validate(t2) {
|
|
1463
|
-
if (d && (t2 === undefined || t2.length === 0))
|
|
1464
|
-
return `Please select at least one option.
|
|
1465
|
-
${styleText2("reset", styleText2("dim", `Press ${styleText2(["gray", "bgWhite", "inverse"], " space ")} to select, ${styleText2("gray", styleText2("bgWhite", styleText2("inverse", " enter ")))} to submit`))}`;
|
|
1466
|
-
},
|
|
1467
|
-
render() {
|
|
1468
|
-
const t2 = n2.withGuide ?? settings.withGuide, a3 = wrapTextWithPrefix(n2.output, n2.message, t2 ? `${symbolBar(this.state)} ` : "", `${symbol(this.state)} `), r2 = `${t2 ? `${styleText2("gray", S_BAR)}
|
|
1469
|
-
` : ""}${a3}
|
|
1470
|
-
`, l2 = this.value ?? [], p2 = (i, u3) => {
|
|
1471
|
-
if (i.disabled)
|
|
1472
|
-
return o2(i, "disabled");
|
|
1473
|
-
const s = l2.includes(i.value);
|
|
1474
|
-
return u3 && s ? o2(i, "active-selected") : s ? o2(i, "selected") : o2(i, u3 ? "active" : "inactive");
|
|
1475
|
-
};
|
|
1476
|
-
switch (this.state) {
|
|
1477
|
-
case "submit": {
|
|
1478
|
-
const i = this.options.filter(({ value: s }) => l2.includes(s)).map((s) => o2(s, "submitted")).join(styleText2("dim", ", ")) || styleText2("dim", "none"), u3 = wrapTextWithPrefix(n2.output, i, t2 ? `${styleText2("gray", S_BAR)} ` : "");
|
|
1479
|
-
return `${r2}${u3}`;
|
|
1480
|
-
}
|
|
1481
|
-
case "cancel": {
|
|
1482
|
-
const i = this.options.filter(({ value: s }) => l2.includes(s)).map((s) => o2(s, "cancelled")).join(styleText2("dim", ", "));
|
|
1483
|
-
if (i.trim() === "")
|
|
1484
|
-
return `${r2}${styleText2("gray", S_BAR)}`;
|
|
1485
|
-
const u3 = wrapTextWithPrefix(n2.output, i, t2 ? `${styleText2("gray", S_BAR)} ` : "");
|
|
1486
|
-
return `${r2}${u3}${t2 ? `
|
|
1487
|
-
${styleText2("gray", S_BAR)}` : ""}`;
|
|
1488
|
-
}
|
|
1489
|
-
case "error": {
|
|
1490
|
-
const i = t2 ? `${styleText2("yellow", S_BAR)} ` : "", u3 = this.error.split(`
|
|
1491
|
-
`).map(($, x) => x === 0 ? `${t2 ? `${styleText2("yellow", S_BAR_END)} ` : ""}${styleText2("yellow", $)}` : ` ${$}`).join(`
|
|
1492
|
-
`), s = r2.split(`
|
|
1493
|
-
`).length, g2 = u3.split(`
|
|
1494
|
-
`).length + 1;
|
|
1495
|
-
return `${r2}${i}${limitOptions({
|
|
1496
|
-
output: n2.output,
|
|
1497
|
-
options: this.options,
|
|
1498
|
-
cursor: this.cursor,
|
|
1499
|
-
maxItems: n2.maxItems,
|
|
1500
|
-
columnPadding: i.length,
|
|
1501
|
-
rowPadding: s + g2,
|
|
1502
|
-
style: p2
|
|
1503
|
-
}).join(`
|
|
1504
|
-
${i}`)}
|
|
1505
|
-
${u3}
|
|
1506
|
-
`;
|
|
1507
|
-
}
|
|
1508
|
-
default: {
|
|
1509
|
-
const i = t2 ? `${styleText2("cyan", S_BAR)} ` : "", u3 = r2.split(`
|
|
1510
|
-
`).length, s = formatInstructionFooter(MULTISELECT_INSTRUCTIONS, t2), g2 = s.join(`
|
|
1511
|
-
`), $ = s.length + 1;
|
|
1512
|
-
return `${r2}${i}${limitOptions({
|
|
1513
|
-
output: n2.output,
|
|
1514
|
-
options: this.options,
|
|
1515
|
-
cursor: this.cursor,
|
|
1516
|
-
maxItems: n2.maxItems,
|
|
1517
|
-
columnPadding: i.length,
|
|
1518
|
-
rowPadding: u3 + $,
|
|
1519
|
-
style: p2
|
|
1520
|
-
}).join(`
|
|
1521
|
-
${i}`)}
|
|
1522
|
-
${g2}
|
|
1523
|
-
`;
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
}).prompt();
|
|
1528
|
-
};
|
|
1529
|
-
var log = {
|
|
1530
|
-
message: (s = [], {
|
|
1531
|
-
symbol: e = styleText2("gray", S_BAR),
|
|
1532
|
-
secondarySymbol: r2 = styleText2("gray", S_BAR),
|
|
1533
|
-
output: m3 = process.stdout,
|
|
1534
|
-
spacing: l2 = 1,
|
|
1535
|
-
withGuide: c2
|
|
1536
|
-
} = {}) => {
|
|
1537
|
-
const t2 = [], o2 = c2 ?? settings.withGuide, f2 = o2 ? r2 : "", O = o2 ? `${e} ` : "", u3 = o2 ? `${r2} ` : "";
|
|
1538
|
-
for (let i = 0;i < l2; i++)
|
|
1539
|
-
t2.push(f2);
|
|
1540
|
-
const g2 = Array.isArray(s) ? s : s.split(`
|
|
1541
|
-
`);
|
|
1542
|
-
if (g2.length > 0) {
|
|
1543
|
-
const [i, ...y] = g2;
|
|
1544
|
-
i.length > 0 ? t2.push(`${O}${i}`) : t2.push(o2 ? e : "");
|
|
1545
|
-
for (const p2 of y)
|
|
1546
|
-
p2.length > 0 ? t2.push(`${u3}${p2}`) : t2.push(o2 ? r2 : "");
|
|
1547
|
-
}
|
|
1548
|
-
m3.write(`${t2.join(`
|
|
1549
|
-
`)}
|
|
1550
|
-
`);
|
|
1551
|
-
},
|
|
1552
|
-
info: (s, e) => {
|
|
1553
|
-
log.message(s, { ...e, symbol: styleText2("blue", S_INFO) });
|
|
1554
|
-
},
|
|
1555
|
-
success: (s, e) => {
|
|
1556
|
-
log.message(s, { ...e, symbol: styleText2("green", S_SUCCESS) });
|
|
1557
|
-
},
|
|
1558
|
-
step: (s, e) => {
|
|
1559
|
-
log.message(s, { ...e, symbol: styleText2("green", S_STEP_SUBMIT) });
|
|
1560
|
-
},
|
|
1561
|
-
warn: (s, e) => {
|
|
1562
|
-
log.message(s, { ...e, symbol: styleText2("yellow", S_WARN) });
|
|
1563
|
-
},
|
|
1564
|
-
warning: (s, e) => {
|
|
1565
|
-
log.warn(s, e);
|
|
1566
|
-
},
|
|
1567
|
-
error: (s, e) => {
|
|
1568
|
-
log.message(s, { ...e, symbol: styleText2("red", S_ERROR) });
|
|
1569
|
-
}
|
|
1570
|
-
};
|
|
1571
|
-
var cancel = (o2 = "", t2) => {
|
|
1572
|
-
const i = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR_END)} ` : "";
|
|
1573
|
-
i.write(`${e}${styleText2("red", o2)}
|
|
1574
|
-
|
|
1575
|
-
`);
|
|
1576
|
-
};
|
|
1577
|
-
var intro = (o2 = "", t2) => {
|
|
1578
|
-
const i = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR_START)} ` : "";
|
|
1579
|
-
i.write(`${e}${o2}
|
|
1580
|
-
`);
|
|
1581
|
-
};
|
|
1582
|
-
var outro = (o2 = "", t2) => {
|
|
1583
|
-
const i = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR)}
|
|
1584
|
-
${styleText2("gray", S_BAR_END)} ` : "";
|
|
1585
|
-
i.write(`${e}${o2}
|
|
1586
|
-
|
|
1587
|
-
`);
|
|
1588
|
-
};
|
|
1589
|
-
var W = (l2) => styleText2("magenta", l2);
|
|
1590
|
-
var spinner = ({
|
|
1591
|
-
indicator: l2 = "dots",
|
|
1592
|
-
onCancel: h2,
|
|
1593
|
-
output: n2 = process.stdout,
|
|
1594
|
-
cancelMessage: G,
|
|
1595
|
-
errorMessage: O,
|
|
1596
|
-
frames: E = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"],
|
|
1597
|
-
delay: F = unicode ? 80 : 120,
|
|
1598
|
-
signal: m3,
|
|
1599
|
-
...I
|
|
1600
|
-
} = {}) => {
|
|
1601
|
-
const u3 = isCI();
|
|
1602
|
-
let M2, T3, d = false, S = false, s = "", p2, w = performance.now();
|
|
1603
|
-
const x = getColumns(n2), k = I?.styleFrame ?? W, g2 = (e) => {
|
|
1604
|
-
const r2 = e > 1 ? O ?? settings.messages.error : G ?? settings.messages.cancel;
|
|
1605
|
-
S = e === 1, d && (a3(r2, e), S && typeof h2 == "function" && h2());
|
|
1606
|
-
}, f2 = () => g2(2), i = () => g2(1), A = () => {
|
|
1607
|
-
process.on("uncaughtExceptionMonitor", f2), process.on("unhandledRejection", f2), process.on("SIGINT", i), process.on("SIGTERM", i), process.on("exit", g2), m3 && m3.addEventListener("abort", i);
|
|
1608
|
-
}, H = () => {
|
|
1609
|
-
process.removeListener("uncaughtExceptionMonitor", f2), process.removeListener("unhandledRejection", f2), process.removeListener("SIGINT", i), process.removeListener("SIGTERM", i), process.removeListener("exit", g2), m3 && m3.removeEventListener("abort", i);
|
|
1610
|
-
}, y = () => {
|
|
1611
|
-
if (p2 === undefined)
|
|
1612
|
-
return;
|
|
1613
|
-
u3 && n2.write(`
|
|
1614
|
-
`);
|
|
1615
|
-
const r2 = wrapAnsi(p2, x, {
|
|
1616
|
-
hard: true,
|
|
1617
|
-
trim: false
|
|
1618
|
-
}).split(`
|
|
1619
|
-
`);
|
|
1620
|
-
r2.length > 1 && n2.write(import_sisteransi2.cursor.up(r2.length - 1)), n2.write(import_sisteransi2.cursor.to(0)), n2.write(import_sisteransi2.erase.down());
|
|
1621
|
-
}, C2 = (e) => e.replace(/\.+$/, ""), _2 = (e) => {
|
|
1622
|
-
const r2 = (performance.now() - e) / 1000, t2 = Math.floor(r2 / 60), o2 = Math.floor(r2 % 60);
|
|
1623
|
-
return t2 > 0 ? `[${t2}m ${o2}s]` : `[${o2}s]`;
|
|
1624
|
-
}, N = I.withGuide ?? settings.withGuide, P2 = (e = "") => {
|
|
1625
|
-
d = true, M2 = block({ output: n2 }), s = C2(e), w = performance.now(), N && n2.write(`${styleText2("gray", S_BAR)}
|
|
1626
|
-
`);
|
|
1627
|
-
let r2 = 0, t2 = 0;
|
|
1628
|
-
A(), T3 = setInterval(() => {
|
|
1629
|
-
if (u3 && s === p2)
|
|
1630
|
-
return;
|
|
1631
|
-
y(), p2 = s;
|
|
1632
|
-
const o2 = k(E[r2]);
|
|
1633
|
-
let v;
|
|
1634
|
-
if (u3)
|
|
1635
|
-
v = `${o2} ${s}...`;
|
|
1636
|
-
else if (l2 === "timer")
|
|
1637
|
-
v = `${o2} ${s} ${_2(w)}`;
|
|
1638
|
-
else {
|
|
1639
|
-
const B = ".".repeat(Math.floor(t2)).slice(0, 3);
|
|
1640
|
-
v = `${o2} ${s}${B}`;
|
|
1641
|
-
}
|
|
1642
|
-
const j = wrapAnsi(v, x, {
|
|
1643
|
-
hard: true,
|
|
1644
|
-
trim: false
|
|
1645
|
-
});
|
|
1646
|
-
n2.write(j), r2 = r2 + 1 < E.length ? r2 + 1 : 0, t2 = t2 < 4 ? t2 + 0.125 : 0;
|
|
1647
|
-
}, F);
|
|
1648
|
-
}, a3 = (e = "", r2 = 0, t2 = false) => {
|
|
1649
|
-
if (!d)
|
|
1650
|
-
return;
|
|
1651
|
-
d = false, clearInterval(T3), y();
|
|
1652
|
-
const o2 = r2 === 0 ? styleText2("green", S_STEP_SUBMIT) : r2 === 1 ? styleText2("red", S_STEP_CANCEL) : styleText2("red", S_STEP_ERROR);
|
|
1653
|
-
s = e ?? s, t2 || (l2 === "timer" ? n2.write(`${o2} ${s} ${_2(w)}
|
|
1654
|
-
`) : n2.write(`${o2} ${s}
|
|
1655
|
-
`)), H(), M2();
|
|
1656
|
-
};
|
|
1657
|
-
return {
|
|
1658
|
-
start: P2,
|
|
1659
|
-
stop: (e = "") => a3(e, 0),
|
|
1660
|
-
message: (e = "") => {
|
|
1661
|
-
s = C2(e ?? s);
|
|
1662
|
-
},
|
|
1663
|
-
cancel: (e = "") => a3(e, 1),
|
|
1664
|
-
error: (e = "") => a3(e, 2),
|
|
1665
|
-
clear: () => a3("", 0, true),
|
|
1666
|
-
get isCancelled() {
|
|
1667
|
-
return S;
|
|
1668
|
-
}
|
|
1669
|
-
};
|
|
1670
|
-
};
|
|
1671
|
-
var u3 = {
|
|
1672
|
-
light: unicodeOr("\u2500", "-"),
|
|
1673
|
-
heavy: unicodeOr("\u2501", "="),
|
|
1674
|
-
block: unicodeOr("\u2588", "#")
|
|
1675
|
-
};
|
|
1676
|
-
var SELECT_INSTRUCTIONS = [
|
|
1677
|
-
`${styleText2("dim", "\u2191/\u2193")} to navigate`,
|
|
1678
|
-
`${styleText2("dim", "Enter:")} confirm`
|
|
1679
|
-
];
|
|
1680
|
-
var c2 = (t2, a3) => t2.includes(`
|
|
1681
|
-
`) ? t2.split(`
|
|
1682
|
-
`).map((i) => a3(i)).join(`
|
|
1683
|
-
`) : a3(t2);
|
|
1684
|
-
var select = (t2) => {
|
|
1685
|
-
const a3 = (i, m3) => {
|
|
1686
|
-
const s = i.label ?? String(i.value);
|
|
1687
|
-
switch (m3) {
|
|
1688
|
-
case "disabled":
|
|
1689
|
-
return `${styleText2("gray", S_RADIO_INACTIVE)} ${c2(s, (n2) => styleText2("gray", n2))}${i.hint ? ` ${styleText2("dim", `(${i.hint ?? "disabled"})`)}` : ""}`;
|
|
1690
|
-
case "selected":
|
|
1691
|
-
return `${c2(s, (n2) => styleText2("dim", n2))}`;
|
|
1692
|
-
case "active":
|
|
1693
|
-
return `${styleText2("green", S_RADIO_ACTIVE)} ${s}${i.hint ? ` ${styleText2("dim", `(${i.hint})`)}` : ""}`;
|
|
1694
|
-
case "cancelled":
|
|
1695
|
-
return `${c2(s, (n2) => styleText2(["strikethrough", "dim"], n2))}`;
|
|
1696
|
-
default:
|
|
1697
|
-
return `${styleText2("dim", S_RADIO_INACTIVE)} ${c2(s, (n2) => styleText2("dim", n2))}`;
|
|
1698
|
-
}
|
|
1699
|
-
};
|
|
1700
|
-
return new a2({
|
|
1701
|
-
options: t2.options,
|
|
1702
|
-
signal: t2.signal,
|
|
1703
|
-
input: t2.input,
|
|
1704
|
-
output: t2.output,
|
|
1705
|
-
initialValue: t2.initialValue,
|
|
1706
|
-
render() {
|
|
1707
|
-
const i = t2.withGuide ?? settings.withGuide, m3 = `${symbol(this.state)} `, s = `${symbolBar(this.state)} `, n2 = wrapTextWithPrefix(t2.output, t2.message, s, m3), u4 = `${i ? `${styleText2("gray", S_BAR)}
|
|
1708
|
-
` : ""}${n2}
|
|
1709
|
-
`;
|
|
1710
|
-
switch (this.state) {
|
|
1711
|
-
case "submit": {
|
|
1712
|
-
const r2 = i ? `${styleText2("gray", S_BAR)} ` : "", o2 = wrapTextWithPrefix(t2.output, a3(this.options[this.cursor], "selected"), r2);
|
|
1713
|
-
return `${u4}${o2}`;
|
|
1714
|
-
}
|
|
1715
|
-
case "cancel": {
|
|
1716
|
-
const r2 = i ? `${styleText2("gray", S_BAR)} ` : "", o2 = wrapTextWithPrefix(t2.output, a3(this.options[this.cursor], "cancelled"), r2);
|
|
1717
|
-
return `${u4}${o2}${i ? `
|
|
1718
|
-
${styleText2("gray", S_BAR)}` : ""}`;
|
|
1719
|
-
}
|
|
1720
|
-
default: {
|
|
1721
|
-
const r2 = i ? `${styleText2("cyan", S_BAR)} ` : "", o2 = u4.split(`
|
|
1722
|
-
`).length, $ = formatInstructionFooter(SELECT_INSTRUCTIONS, i), h2 = $.join(`
|
|
1723
|
-
`), b2 = $.length + 1;
|
|
1724
|
-
return `${u4}${r2}${limitOptions({
|
|
1725
|
-
output: t2.output,
|
|
1726
|
-
cursor: this.cursor,
|
|
1727
|
-
options: this.options,
|
|
1728
|
-
maxItems: t2.maxItems,
|
|
1729
|
-
columnPadding: r2.length,
|
|
1730
|
-
rowPadding: o2 + b2,
|
|
1731
|
-
style: (p2, x) => a3(p2, p2.disabled ? "disabled" : x ? "active" : "inactive")
|
|
1732
|
-
}).join(`
|
|
1733
|
-
${r2}`)}
|
|
1734
|
-
${h2}
|
|
1735
|
-
`;
|
|
1736
|
-
}
|
|
1737
|
-
}
|
|
1738
|
-
}
|
|
1739
|
-
}).prompt();
|
|
1740
|
-
};
|
|
1741
|
-
var i = `${styleText2("gray", S_BAR)} `;
|
|
1742
|
-
var text = (t2) => new n({
|
|
1743
|
-
validate: t2.validate,
|
|
1744
|
-
placeholder: t2.placeholder,
|
|
1745
|
-
defaultValue: t2.defaultValue,
|
|
1746
|
-
initialValue: t2.initialValue,
|
|
1747
|
-
output: t2.output,
|
|
1748
|
-
signal: t2.signal,
|
|
1749
|
-
input: t2.input,
|
|
1750
|
-
render() {
|
|
1751
|
-
const i2 = t2?.withGuide ?? settings.withGuide, s = `${`${i2 ? `${styleText2("gray", S_BAR)}
|
|
1752
|
-
` : ""}${symbol(this.state)} `}${t2.message}
|
|
1753
|
-
`, c3 = t2.placeholder ? styleText2("inverse", t2.placeholder[0]) + styleText2("dim", t2.placeholder.slice(1)) : styleText2(["inverse", "hidden"], "_"), o2 = this.userInput ? this.userInputWithCursor : c3, a3 = this.value ?? "";
|
|
1754
|
-
switch (this.state) {
|
|
1755
|
-
case "error": {
|
|
1756
|
-
const n2 = this.error ? ` ${styleText2("yellow", this.error)}` : "", r2 = i2 ? `${styleText2("yellow", S_BAR)} ` : "", d = i2 ? styleText2("yellow", S_BAR_END) : "";
|
|
1757
|
-
return `${s.trim()}
|
|
1758
|
-
${r2}${o2}
|
|
1759
|
-
${d}${n2}
|
|
1760
|
-
`;
|
|
1761
|
-
}
|
|
1762
|
-
case "submit": {
|
|
1763
|
-
const n2 = a3 ? ` ${styleText2("dim", a3)}` : "", r2 = i2 ? styleText2("gray", S_BAR) : "";
|
|
1764
|
-
return `${s}${r2}${n2}`;
|
|
1765
|
-
}
|
|
1766
|
-
case "cancel": {
|
|
1767
|
-
const n2 = a3 ? ` ${styleText2(["strikethrough", "dim"], a3)}` : "", r2 = i2 ? styleText2("gray", S_BAR) : "";
|
|
1768
|
-
return `${s}${r2}${n2}${a3.trim() ? `
|
|
1769
|
-
${r2}` : ""}`;
|
|
1770
|
-
}
|
|
1771
|
-
default: {
|
|
1772
|
-
const n2 = i2 ? `${styleText2("cyan", S_BAR)} ` : "", r2 = i2 ? styleText2("cyan", S_BAR_END) : "";
|
|
1773
|
-
return `${s}${n2}${o2}
|
|
1774
|
-
${r2}
|
|
1775
|
-
`;
|
|
1776
|
-
}
|
|
1777
|
-
}
|
|
1778
|
-
}
|
|
1779
|
-
}).prompt();
|
|
1780
|
-
|
|
1781
|
-
// node_modules/citty/dist/_chunks/libs/scule.mjs
|
|
1782
|
-
var NUMBER_CHAR_RE = /\d/;
|
|
1783
|
-
var STR_SPLITTERS = [
|
|
1784
|
-
"-",
|
|
1785
|
-
"_",
|
|
1786
|
-
"/",
|
|
1787
|
-
"."
|
|
1788
|
-
];
|
|
1789
|
-
function isUppercase(char = "") {
|
|
1790
|
-
if (NUMBER_CHAR_RE.test(char))
|
|
1791
|
-
return;
|
|
1792
|
-
return char !== char.toLowerCase();
|
|
1793
|
-
}
|
|
1794
|
-
function splitByCase(str, separators) {
|
|
1795
|
-
const splitters = separators ?? STR_SPLITTERS;
|
|
1796
|
-
const parts = [];
|
|
1797
|
-
if (!str || typeof str !== "string")
|
|
1798
|
-
return parts;
|
|
1799
|
-
let buff = "";
|
|
1800
|
-
let previousUpper;
|
|
1801
|
-
let previousSplitter;
|
|
1802
|
-
for (const char of str) {
|
|
1803
|
-
const isSplitter = splitters.includes(char);
|
|
1804
|
-
if (isSplitter === true) {
|
|
1805
|
-
parts.push(buff);
|
|
1806
|
-
buff = "";
|
|
1807
|
-
previousUpper = undefined;
|
|
1808
|
-
continue;
|
|
1809
|
-
}
|
|
1810
|
-
const isUpper = isUppercase(char);
|
|
1811
|
-
if (previousSplitter === false) {
|
|
1812
|
-
if (previousUpper === false && isUpper === true) {
|
|
1813
|
-
parts.push(buff);
|
|
1814
|
-
buff = char;
|
|
1815
|
-
previousUpper = isUpper;
|
|
1816
|
-
continue;
|
|
1817
|
-
}
|
|
1818
|
-
if (previousUpper === true && isUpper === false && buff.length > 1) {
|
|
1819
|
-
const lastChar = buff.at(-1);
|
|
1820
|
-
parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
|
|
1821
|
-
buff = lastChar + char;
|
|
1822
|
-
previousUpper = isUpper;
|
|
1823
|
-
continue;
|
|
1824
|
-
}
|
|
1825
|
-
}
|
|
1826
|
-
buff += char;
|
|
1827
|
-
previousUpper = isUpper;
|
|
1828
|
-
previousSplitter = isSplitter;
|
|
1829
|
-
}
|
|
1830
|
-
parts.push(buff);
|
|
1831
|
-
return parts;
|
|
1832
|
-
}
|
|
1833
|
-
function upperFirst(str) {
|
|
1834
|
-
return str ? str[0].toUpperCase() + str.slice(1) : "";
|
|
1835
|
-
}
|
|
1836
|
-
function lowerFirst(str) {
|
|
1837
|
-
return str ? str[0].toLowerCase() + str.slice(1) : "";
|
|
1838
|
-
}
|
|
1839
|
-
function pascalCase(str, opts) {
|
|
1840
|
-
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p2) => upperFirst(opts?.normalize ? p2.toLowerCase() : p2)).join("") : "";
|
|
1841
|
-
}
|
|
1842
|
-
function camelCase(str, opts) {
|
|
1843
|
-
return lowerFirst(pascalCase(str || "", opts));
|
|
1844
|
-
}
|
|
1845
|
-
function kebabCase(str, joiner) {
|
|
1846
|
-
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p2) => p2.toLowerCase()).join(joiner ?? "-") : "";
|
|
1847
|
-
}
|
|
1848
|
-
function snakeCase(str) {
|
|
1849
|
-
return kebabCase(str || "", "_");
|
|
1850
|
-
}
|
|
1851
|
-
|
|
1852
|
-
// node_modules/citty/dist/index.mjs
|
|
1853
|
-
import { parseArgs as parseArgs$1 } from "util";
|
|
1854
|
-
function toArray(val) {
|
|
1855
|
-
if (Array.isArray(val))
|
|
1856
|
-
return val;
|
|
1857
|
-
return val === undefined ? [] : [val];
|
|
1858
|
-
}
|
|
1859
|
-
function formatLineColumns(lines, linePrefix = "") {
|
|
1860
|
-
const maxLength = [];
|
|
1861
|
-
for (const line of lines)
|
|
1862
|
-
for (const [i2, element] of line.entries())
|
|
1863
|
-
maxLength[i2] = Math.max(maxLength[i2] || 0, element.length);
|
|
1864
|
-
return lines.map((l2) => l2.map((c3, i2) => linePrefix + c3[i2 === 0 ? "padStart" : "padEnd"](maxLength[i2])).join(" ")).join(`
|
|
1865
|
-
`);
|
|
1866
|
-
}
|
|
1867
|
-
function resolveValue(input) {
|
|
1868
|
-
return typeof input === "function" ? input() : input;
|
|
1869
|
-
}
|
|
1870
|
-
var CLIError = class extends Error {
|
|
1871
|
-
code;
|
|
1872
|
-
constructor(message, code) {
|
|
1873
|
-
super(message);
|
|
1874
|
-
this.name = "CLIError";
|
|
1875
|
-
this.code = code;
|
|
1876
|
-
}
|
|
1877
|
-
};
|
|
1878
|
-
function parseRawArgs(args = [], opts = {}) {
|
|
1879
|
-
const booleans = new Set(opts.boolean || []);
|
|
1880
|
-
const strings = new Set(opts.string || []);
|
|
1881
|
-
const aliasMap = opts.alias || {};
|
|
1882
|
-
const defaults = opts.default || {};
|
|
1883
|
-
const aliasToMain = /* @__PURE__ */ new Map;
|
|
1884
|
-
const mainToAliases = /* @__PURE__ */ new Map;
|
|
1885
|
-
for (const [key, value] of Object.entries(aliasMap)) {
|
|
1886
|
-
const targets = value;
|
|
1887
|
-
for (const target of targets) {
|
|
1888
|
-
aliasToMain.set(key, target);
|
|
1889
|
-
if (!mainToAliases.has(target))
|
|
1890
|
-
mainToAliases.set(target, []);
|
|
1891
|
-
mainToAliases.get(target).push(key);
|
|
1892
|
-
aliasToMain.set(target, key);
|
|
1893
|
-
if (!mainToAliases.has(key))
|
|
1894
|
-
mainToAliases.set(key, []);
|
|
1895
|
-
mainToAliases.get(key).push(target);
|
|
1896
|
-
}
|
|
1897
|
-
}
|
|
1898
|
-
const options = {};
|
|
1899
|
-
function getType(name) {
|
|
1900
|
-
if (booleans.has(name))
|
|
1901
|
-
return "boolean";
|
|
1902
|
-
const aliases = mainToAliases.get(name) || [];
|
|
1903
|
-
for (const alias of aliases)
|
|
1904
|
-
if (booleans.has(alias))
|
|
1905
|
-
return "boolean";
|
|
1906
|
-
return "string";
|
|
1907
|
-
}
|
|
1908
|
-
function isStringType(name) {
|
|
1909
|
-
if (strings.has(name))
|
|
1910
|
-
return true;
|
|
1911
|
-
const aliases = mainToAliases.get(name) || [];
|
|
1912
|
-
for (const alias of aliases)
|
|
1913
|
-
if (strings.has(alias))
|
|
1914
|
-
return true;
|
|
1915
|
-
return false;
|
|
1916
|
-
}
|
|
1917
|
-
const allOptions = new Set([
|
|
1918
|
-
...booleans,
|
|
1919
|
-
...strings,
|
|
1920
|
-
...Object.keys(aliasMap),
|
|
1921
|
-
...Object.values(aliasMap).flat(),
|
|
1922
|
-
...Object.keys(defaults)
|
|
1923
|
-
]);
|
|
1924
|
-
for (const name of allOptions)
|
|
1925
|
-
if (!options[name])
|
|
1926
|
-
options[name] = {
|
|
1927
|
-
type: getType(name),
|
|
1928
|
-
default: defaults[name]
|
|
1929
|
-
};
|
|
1930
|
-
for (const [alias, main] of aliasToMain.entries())
|
|
1931
|
-
if (alias.length === 1 && options[main] && !options[main].short)
|
|
1932
|
-
options[main].short = alias;
|
|
1933
|
-
const processedArgs = [];
|
|
1934
|
-
const negatedFlags = {};
|
|
1935
|
-
for (let i2 = 0;i2 < args.length; i2++) {
|
|
1936
|
-
const arg = args[i2];
|
|
1937
|
-
if (arg === "--") {
|
|
1938
|
-
processedArgs.push(...args.slice(i2));
|
|
1939
|
-
break;
|
|
1940
|
-
}
|
|
1941
|
-
if (arg.startsWith("--no-")) {
|
|
1942
|
-
const flagName = arg.slice(5);
|
|
1943
|
-
negatedFlags[flagName] = true;
|
|
1944
|
-
continue;
|
|
1945
|
-
}
|
|
1946
|
-
processedArgs.push(arg);
|
|
1947
|
-
}
|
|
1948
|
-
let parsed;
|
|
1949
|
-
try {
|
|
1950
|
-
parsed = parseArgs$1({
|
|
1951
|
-
args: processedArgs,
|
|
1952
|
-
options: Object.keys(options).length > 0 ? options : undefined,
|
|
1953
|
-
allowPositionals: true,
|
|
1954
|
-
strict: false
|
|
1955
|
-
});
|
|
1956
|
-
} catch {
|
|
1957
|
-
parsed = {
|
|
1958
|
-
values: {},
|
|
1959
|
-
positionals: processedArgs
|
|
1960
|
-
};
|
|
1961
|
-
}
|
|
1962
|
-
const out = { _: [] };
|
|
1963
|
-
out._ = parsed.positionals;
|
|
1964
|
-
for (const [key, value] of Object.entries(parsed.values)) {
|
|
1965
|
-
let coerced = value;
|
|
1966
|
-
if (getType(key) === "boolean" && typeof value === "string")
|
|
1967
|
-
coerced = value !== "false";
|
|
1968
|
-
else if (isStringType(key) && typeof value === "boolean")
|
|
1969
|
-
coerced = "";
|
|
1970
|
-
out[key] = coerced;
|
|
1971
|
-
}
|
|
1972
|
-
for (const [name] of Object.entries(negatedFlags)) {
|
|
1973
|
-
out[name] = false;
|
|
1974
|
-
const mainName = aliasToMain.get(name);
|
|
1975
|
-
if (mainName)
|
|
1976
|
-
out[mainName] = false;
|
|
1977
|
-
const aliases = mainToAliases.get(name);
|
|
1978
|
-
if (aliases)
|
|
1979
|
-
for (const alias of aliases)
|
|
1980
|
-
out[alias] = false;
|
|
1981
|
-
}
|
|
1982
|
-
for (const [alias, main] of aliasToMain.entries()) {
|
|
1983
|
-
if (out[alias] !== undefined && out[main] === undefined)
|
|
1984
|
-
out[main] = out[alias];
|
|
1985
|
-
if (out[main] !== undefined && out[alias] === undefined)
|
|
1986
|
-
out[alias] = out[main];
|
|
1987
|
-
if (out[alias] !== out[main] && defaults[main] === out[main])
|
|
1988
|
-
out[main] = out[alias];
|
|
1989
|
-
}
|
|
1990
|
-
return out;
|
|
1991
|
-
}
|
|
1992
|
-
var noColor = /* @__PURE__ */ (() => {
|
|
1993
|
-
const env = globalThis.process?.env ?? {};
|
|
1994
|
-
return env.NO_COLOR === "1" || env.TERM === "dumb" || env.TEST || env.CI;
|
|
1995
|
-
})();
|
|
1996
|
-
var _c = (c3, r2 = 39) => (t2) => noColor ? t2 : `\x1B[${c3}m${t2}\x1B[${r2}m`;
|
|
1997
|
-
var bold = /* @__PURE__ */ _c(1, 22);
|
|
1998
|
-
var cyan = /* @__PURE__ */ _c(36);
|
|
1999
|
-
var gray = /* @__PURE__ */ _c(90);
|
|
2000
|
-
var underline = /* @__PURE__ */ _c(4, 24);
|
|
2001
|
-
function parseArgs(rawArgs, argsDef) {
|
|
2002
|
-
const parseOptions = {
|
|
2003
|
-
boolean: [],
|
|
2004
|
-
string: [],
|
|
2005
|
-
alias: {},
|
|
2006
|
-
default: {}
|
|
2007
|
-
};
|
|
2008
|
-
const args = resolveArgs(argsDef);
|
|
2009
|
-
for (const arg of args) {
|
|
2010
|
-
if (arg.type === "positional")
|
|
2011
|
-
continue;
|
|
2012
|
-
if (arg.type === "string" || arg.type === "enum")
|
|
2013
|
-
parseOptions.string.push(arg.name);
|
|
2014
|
-
else if (arg.type === "boolean")
|
|
2015
|
-
parseOptions.boolean.push(arg.name);
|
|
2016
|
-
if (arg.default !== undefined)
|
|
2017
|
-
parseOptions.default[arg.name] = arg.default;
|
|
2018
|
-
if (arg.alias)
|
|
2019
|
-
parseOptions.alias[arg.name] = arg.alias;
|
|
2020
|
-
const camelName = camelCase(arg.name);
|
|
2021
|
-
const kebabName = kebabCase(arg.name);
|
|
2022
|
-
if (camelName !== arg.name || kebabName !== arg.name) {
|
|
2023
|
-
const existingAliases = toArray(parseOptions.alias[arg.name] || []);
|
|
2024
|
-
if (camelName !== arg.name && !existingAliases.includes(camelName))
|
|
2025
|
-
existingAliases.push(camelName);
|
|
2026
|
-
if (kebabName !== arg.name && !existingAliases.includes(kebabName))
|
|
2027
|
-
existingAliases.push(kebabName);
|
|
2028
|
-
if (existingAliases.length > 0)
|
|
2029
|
-
parseOptions.alias[arg.name] = existingAliases;
|
|
2030
|
-
}
|
|
2031
|
-
}
|
|
2032
|
-
const parsed = parseRawArgs(rawArgs, parseOptions);
|
|
2033
|
-
const [...positionalArguments] = parsed._;
|
|
2034
|
-
const parsedArgsProxy = new Proxy(parsed, { get(target, prop) {
|
|
2035
|
-
return target[prop] ?? target[camelCase(prop)] ?? target[kebabCase(prop)];
|
|
2036
|
-
} });
|
|
2037
|
-
for (const [, arg] of args.entries())
|
|
2038
|
-
if (arg.type === "positional") {
|
|
2039
|
-
const nextPositionalArgument = positionalArguments.shift();
|
|
2040
|
-
if (nextPositionalArgument !== undefined)
|
|
2041
|
-
parsedArgsProxy[arg.name] = nextPositionalArgument;
|
|
2042
|
-
else if (arg.default === undefined && arg.required !== false)
|
|
2043
|
-
throw new CLIError(`Missing required positional argument: ${arg.name.toUpperCase()}`, "EARG");
|
|
2044
|
-
else
|
|
2045
|
-
parsedArgsProxy[arg.name] = arg.default;
|
|
2046
|
-
} else if (arg.type === "enum") {
|
|
2047
|
-
const argument = parsedArgsProxy[arg.name];
|
|
2048
|
-
const options = arg.options || [];
|
|
2049
|
-
if (argument !== undefined && options.length > 0 && !options.includes(argument))
|
|
2050
|
-
throw new CLIError(`Invalid value for argument: ${cyan(`--${arg.name}`)} (${cyan(argument)}). Expected one of: ${options.map((o2) => cyan(o2)).join(", ")}.`, "EARG");
|
|
2051
|
-
} else if (arg.required && parsedArgsProxy[arg.name] === undefined)
|
|
2052
|
-
throw new CLIError(`Missing required argument: --${arg.name}`, "EARG");
|
|
2053
|
-
return parsedArgsProxy;
|
|
2054
|
-
}
|
|
2055
|
-
function resolveArgs(argsDef) {
|
|
2056
|
-
const args = [];
|
|
2057
|
-
for (const [name, argDef] of Object.entries(argsDef || {}))
|
|
2058
|
-
args.push({
|
|
2059
|
-
...argDef,
|
|
2060
|
-
name,
|
|
2061
|
-
alias: toArray(argDef.alias)
|
|
2062
|
-
});
|
|
2063
|
-
return args;
|
|
2064
|
-
}
|
|
2065
|
-
async function resolvePlugins(plugins) {
|
|
2066
|
-
return Promise.all(plugins.map((p2) => resolveValue(p2)));
|
|
2067
|
-
}
|
|
2068
|
-
function defineCommand(def) {
|
|
2069
|
-
return def;
|
|
2070
|
-
}
|
|
2071
|
-
async function runCommand(cmd, opts) {
|
|
2072
|
-
const cmdArgs = await resolveValue(cmd.args || {});
|
|
2073
|
-
const parsedArgs = parseArgs(opts.rawArgs, cmdArgs);
|
|
2074
|
-
const context = {
|
|
2075
|
-
rawArgs: opts.rawArgs,
|
|
2076
|
-
args: parsedArgs,
|
|
2077
|
-
data: opts.data,
|
|
2078
|
-
cmd
|
|
2079
|
-
};
|
|
2080
|
-
const plugins = await resolvePlugins(cmd.plugins ?? []);
|
|
2081
|
-
let result;
|
|
2082
|
-
let runError;
|
|
2083
|
-
try {
|
|
2084
|
-
for (const plugin of plugins)
|
|
2085
|
-
await plugin.setup?.(context);
|
|
2086
|
-
if (typeof cmd.setup === "function")
|
|
2087
|
-
await cmd.setup(context);
|
|
2088
|
-
const subCommands = await resolveValue(cmd.subCommands);
|
|
2089
|
-
if (subCommands && Object.keys(subCommands).length > 0) {
|
|
2090
|
-
const subCommandArgIndex = findSubCommandIndex(opts.rawArgs, cmdArgs);
|
|
2091
|
-
const explicitName = opts.rawArgs[subCommandArgIndex];
|
|
2092
|
-
if (explicitName) {
|
|
2093
|
-
const subCommand = await _findSubCommand(subCommands, explicitName);
|
|
2094
|
-
if (!subCommand)
|
|
2095
|
-
throw new CLIError(`Unknown command ${cyan(explicitName)}`, "E_UNKNOWN_COMMAND");
|
|
2096
|
-
await runCommand(subCommand, { rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1) });
|
|
2097
|
-
} else {
|
|
2098
|
-
const defaultSubCommand = await resolveValue(cmd.default);
|
|
2099
|
-
if (defaultSubCommand) {
|
|
2100
|
-
if (cmd.run)
|
|
2101
|
-
throw new CLIError(`Cannot specify both 'run' and 'default' on the same command.`, "E_DEFAULT_CONFLICT");
|
|
2102
|
-
const subCommand = await _findSubCommand(subCommands, defaultSubCommand);
|
|
2103
|
-
if (!subCommand)
|
|
2104
|
-
throw new CLIError(`Default sub command ${cyan(defaultSubCommand)} not found in subCommands.`, "E_UNKNOWN_COMMAND");
|
|
2105
|
-
await runCommand(subCommand, { rawArgs: opts.rawArgs });
|
|
2106
|
-
} else if (!cmd.run)
|
|
2107
|
-
throw new CLIError(`No command specified.`, "E_NO_COMMAND");
|
|
2108
|
-
}
|
|
2109
|
-
}
|
|
2110
|
-
if (typeof cmd.run === "function")
|
|
2111
|
-
result = await cmd.run(context);
|
|
2112
|
-
} catch (error) {
|
|
2113
|
-
runError = error;
|
|
2114
|
-
}
|
|
2115
|
-
const cleanupErrors = [];
|
|
2116
|
-
if (typeof cmd.cleanup === "function")
|
|
2117
|
-
try {
|
|
2118
|
-
await cmd.cleanup(context);
|
|
2119
|
-
} catch (error) {
|
|
2120
|
-
cleanupErrors.push(error);
|
|
2121
|
-
}
|
|
2122
|
-
for (const plugin of [...plugins].reverse())
|
|
2123
|
-
try {
|
|
2124
|
-
await plugin.cleanup?.(context);
|
|
2125
|
-
} catch (error) {
|
|
2126
|
-
cleanupErrors.push(error);
|
|
2127
|
-
}
|
|
2128
|
-
if (runError)
|
|
2129
|
-
throw runError;
|
|
2130
|
-
if (cleanupErrors.length === 1)
|
|
2131
|
-
throw cleanupErrors[0];
|
|
2132
|
-
if (cleanupErrors.length > 1)
|
|
2133
|
-
throw new Error("Multiple cleanup errors", { cause: cleanupErrors });
|
|
2134
|
-
return { result };
|
|
2135
|
-
}
|
|
2136
|
-
async function resolveSubCommand(cmd, rawArgs, parent) {
|
|
2137
|
-
const subCommands = await resolveValue(cmd.subCommands);
|
|
2138
|
-
if (subCommands && Object.keys(subCommands).length > 0) {
|
|
2139
|
-
const subCommandArgIndex = findSubCommandIndex(rawArgs, await resolveValue(cmd.args || {}));
|
|
2140
|
-
const subCommandName = rawArgs[subCommandArgIndex];
|
|
2141
|
-
const subCommand = await _findSubCommand(subCommands, subCommandName);
|
|
2142
|
-
if (subCommand)
|
|
2143
|
-
return resolveSubCommand(subCommand, rawArgs.slice(subCommandArgIndex + 1), cmd);
|
|
2144
|
-
}
|
|
2145
|
-
return [cmd, parent];
|
|
2146
|
-
}
|
|
2147
|
-
async function _findSubCommand(subCommands, name) {
|
|
2148
|
-
if (name in subCommands)
|
|
2149
|
-
return resolveValue(subCommands[name]);
|
|
2150
|
-
for (const sub of Object.values(subCommands)) {
|
|
2151
|
-
const resolved = await resolveValue(sub);
|
|
2152
|
-
const meta = await resolveValue(resolved?.meta);
|
|
2153
|
-
if (meta?.alias) {
|
|
2154
|
-
if (toArray(meta.alias).includes(name))
|
|
2155
|
-
return resolved;
|
|
2156
|
-
}
|
|
2157
|
-
}
|
|
2158
|
-
}
|
|
2159
|
-
function findSubCommandIndex(rawArgs, argsDef) {
|
|
2160
|
-
for (let i2 = 0;i2 < rawArgs.length; i2++) {
|
|
2161
|
-
const arg = rawArgs[i2];
|
|
2162
|
-
if (arg === "--")
|
|
2163
|
-
return -1;
|
|
2164
|
-
if (arg.startsWith("-")) {
|
|
2165
|
-
if (!arg.includes("=") && _isValueFlag(arg, argsDef))
|
|
2166
|
-
i2++;
|
|
2167
|
-
continue;
|
|
2168
|
-
}
|
|
2169
|
-
return i2;
|
|
2170
|
-
}
|
|
2171
|
-
return -1;
|
|
2172
|
-
}
|
|
2173
|
-
function _isValueFlag(flag, argsDef) {
|
|
2174
|
-
const name = flag.replace(/^-{1,2}/, "");
|
|
2175
|
-
const normalized = camelCase(name);
|
|
2176
|
-
for (const [key, def] of Object.entries(argsDef)) {
|
|
2177
|
-
if (def.type !== "string" && def.type !== "enum")
|
|
2178
|
-
continue;
|
|
2179
|
-
if (normalized === camelCase(key))
|
|
2180
|
-
return true;
|
|
2181
|
-
if ((Array.isArray(def.alias) ? def.alias : def.alias ? [def.alias] : []).includes(name))
|
|
2182
|
-
return true;
|
|
2183
|
-
}
|
|
2184
|
-
return false;
|
|
2185
|
-
}
|
|
2186
|
-
async function showUsage(cmd, parent) {
|
|
2187
|
-
try {
|
|
2188
|
-
console.log(await renderUsage(cmd, parent) + `
|
|
2189
|
-
`);
|
|
2190
|
-
} catch (error) {
|
|
2191
|
-
console.error(error);
|
|
2192
|
-
}
|
|
2193
|
-
}
|
|
2194
|
-
var negativePrefixRe = /^no[-A-Z]/;
|
|
2195
|
-
async function renderUsage(cmd, parent) {
|
|
2196
|
-
const cmdMeta = await resolveValue(cmd.meta || {});
|
|
2197
|
-
const cmdArgs = resolveArgs(await resolveValue(cmd.args || {}));
|
|
2198
|
-
const parentMeta = await resolveValue(parent?.meta || {});
|
|
2199
|
-
const commandName = `${parentMeta.name ? `${parentMeta.name} ` : ""}` + (cmdMeta.name || process.argv[1]);
|
|
2200
|
-
const argLines = [];
|
|
2201
|
-
const posLines = [];
|
|
2202
|
-
const commandsLines = [];
|
|
2203
|
-
const usageLine = [];
|
|
2204
|
-
for (const arg of cmdArgs)
|
|
2205
|
-
if (arg.type === "positional") {
|
|
2206
|
-
const name = arg.name.toUpperCase();
|
|
2207
|
-
const isRequired = arg.required !== false && arg.default === undefined;
|
|
2208
|
-
posLines.push([cyan(name + renderValueHint(arg)), renderDescription(arg, isRequired)]);
|
|
2209
|
-
usageLine.push(isRequired ? `<${name}>` : `[${name}]`);
|
|
2210
|
-
} else {
|
|
2211
|
-
const isRequired = arg.required === true && arg.default === undefined;
|
|
2212
|
-
const argStr = [...(arg.alias || []).map((a3) => `-${a3}`), `--${arg.name}`].join(", ") + renderValueHint(arg);
|
|
2213
|
-
argLines.push([cyan(argStr), renderDescription(arg, isRequired)]);
|
|
2214
|
-
if (arg.type === "boolean" && (arg.default === true || arg.negativeDescription) && !negativePrefixRe.test(arg.name)) {
|
|
2215
|
-
const negativeArgStr = [...(arg.alias || []).map((a3) => `--no-${a3}`), `--no-${arg.name}`].join(", ");
|
|
2216
|
-
argLines.push([cyan(negativeArgStr), [arg.negativeDescription, isRequired ? gray("(Required)") : ""].filter(Boolean).join(" ")]);
|
|
2217
|
-
}
|
|
2218
|
-
if (isRequired)
|
|
2219
|
-
usageLine.push(`--${arg.name}` + renderValueHint(arg));
|
|
2220
|
-
}
|
|
2221
|
-
if (cmd.subCommands) {
|
|
2222
|
-
const commandNames = [];
|
|
2223
|
-
const subCommands = await resolveValue(cmd.subCommands);
|
|
2224
|
-
for (const [name, sub] of Object.entries(subCommands)) {
|
|
2225
|
-
const meta = await resolveValue((await resolveValue(sub))?.meta);
|
|
2226
|
-
if (meta?.hidden)
|
|
2227
|
-
continue;
|
|
2228
|
-
const aliases = toArray(meta?.alias);
|
|
2229
|
-
const label = [name, ...aliases].join(", ");
|
|
2230
|
-
commandsLines.push([cyan(label), meta?.description || ""]);
|
|
2231
|
-
commandNames.push(name, ...aliases);
|
|
2232
|
-
}
|
|
2233
|
-
usageLine.push(commandNames.join("|"));
|
|
2234
|
-
}
|
|
2235
|
-
const usageLines = [];
|
|
2236
|
-
const version = cmdMeta.version || parentMeta.version;
|
|
2237
|
-
usageLines.push(gray(`${cmdMeta.description} (${commandName + (version ? ` v${version}` : "")})`), "");
|
|
2238
|
-
const hasOptions = argLines.length > 0 || posLines.length > 0;
|
|
2239
|
-
usageLines.push(`${underline(bold("USAGE"))} ${cyan(`${commandName}${hasOptions ? " [OPTIONS]" : ""} ${usageLine.join(" ")}`)}`, "");
|
|
2240
|
-
if (posLines.length > 0) {
|
|
2241
|
-
usageLines.push(underline(bold("ARGUMENTS")), "");
|
|
2242
|
-
usageLines.push(formatLineColumns(posLines, " "));
|
|
2243
|
-
usageLines.push("");
|
|
2244
|
-
}
|
|
2245
|
-
if (argLines.length > 0) {
|
|
2246
|
-
usageLines.push(underline(bold("OPTIONS")), "");
|
|
2247
|
-
usageLines.push(formatLineColumns(argLines, " "));
|
|
2248
|
-
usageLines.push("");
|
|
2249
|
-
}
|
|
2250
|
-
if (commandsLines.length > 0) {
|
|
2251
|
-
usageLines.push(underline(bold("COMMANDS")), "");
|
|
2252
|
-
usageLines.push(formatLineColumns(commandsLines, " "));
|
|
2253
|
-
usageLines.push("", `Use ${cyan(`${commandName} <command> --help`)} for more information about a command.`);
|
|
2254
|
-
}
|
|
2255
|
-
return usageLines.filter((l2) => typeof l2 === "string").join(`
|
|
2256
|
-
`);
|
|
2257
|
-
}
|
|
2258
|
-
function renderValueHint(arg) {
|
|
2259
|
-
const valueHint = arg.valueHint ? `=<${arg.valueHint}>` : "";
|
|
2260
|
-
const fallbackValueHint = valueHint || `=<${snakeCase(arg.name)}>`;
|
|
2261
|
-
if (!arg.type || arg.type === "positional" || arg.type === "boolean")
|
|
2262
|
-
return valueHint;
|
|
2263
|
-
if (arg.type === "enum" && arg.options?.length)
|
|
2264
|
-
return `=<${arg.options.join("|")}>`;
|
|
2265
|
-
return fallbackValueHint;
|
|
2266
|
-
}
|
|
2267
|
-
function renderDescription(arg, required) {
|
|
2268
|
-
const requiredHint = required ? gray("(Required)") : "";
|
|
2269
|
-
const defaultHint = arg.default === undefined ? "" : gray(`(Default: ${arg.default})`);
|
|
2270
|
-
return [
|
|
2271
|
-
arg.description,
|
|
2272
|
-
requiredHint,
|
|
2273
|
-
defaultHint
|
|
2274
|
-
].filter(Boolean).join(" ");
|
|
2275
|
-
}
|
|
2276
|
-
async function runMain(cmd, opts = {}) {
|
|
2277
|
-
const rawArgs = opts.rawArgs || process.argv.slice(2);
|
|
2278
|
-
const showUsage$1 = opts.showUsage || showUsage;
|
|
2279
|
-
try {
|
|
2280
|
-
const builtinFlags = await _resolveBuiltinFlags(cmd);
|
|
2281
|
-
if (builtinFlags.help.length > 0 && rawArgs.some((arg) => builtinFlags.help.includes(arg))) {
|
|
2282
|
-
await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
|
|
2283
|
-
process.exit(0);
|
|
2284
|
-
} else if (rawArgs.length === 1 && builtinFlags.version.includes(rawArgs[0])) {
|
|
2285
|
-
const meta = typeof cmd.meta === "function" ? await cmd.meta() : await cmd.meta;
|
|
2286
|
-
if (!meta?.version)
|
|
2287
|
-
throw new CLIError("No version specified", "E_NO_VERSION");
|
|
2288
|
-
console.log(meta.version);
|
|
2289
|
-
} else
|
|
2290
|
-
await runCommand(cmd, { rawArgs });
|
|
2291
|
-
} catch (error) {
|
|
2292
|
-
if (error instanceof CLIError) {
|
|
2293
|
-
await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
|
|
2294
|
-
console.error(error.message);
|
|
2295
|
-
} else
|
|
2296
|
-
console.error(error, `
|
|
2297
|
-
`);
|
|
2298
|
-
process.exit(1);
|
|
2299
|
-
}
|
|
2300
|
-
}
|
|
2301
|
-
async function _resolveBuiltinFlags(cmd) {
|
|
2302
|
-
const argsDef = await resolveValue(cmd.args || {});
|
|
2303
|
-
const userNames = /* @__PURE__ */ new Set;
|
|
2304
|
-
const userAliases = /* @__PURE__ */ new Set;
|
|
2305
|
-
for (const [name, def] of Object.entries(argsDef)) {
|
|
2306
|
-
userNames.add(name);
|
|
2307
|
-
for (const alias of toArray(def.alias))
|
|
2308
|
-
userAliases.add(alias);
|
|
2309
|
-
}
|
|
2310
|
-
return {
|
|
2311
|
-
help: _getBuiltinFlags("help", "h", userNames, userAliases),
|
|
2312
|
-
version: _getBuiltinFlags("version", "v", userNames, userAliases)
|
|
2313
|
-
};
|
|
2314
|
-
}
|
|
2315
|
-
function _getBuiltinFlags(long, short, userNames, userAliases) {
|
|
2316
|
-
if (userNames.has(long) || userAliases.has(long))
|
|
2317
|
-
return [];
|
|
2318
|
-
if (userNames.has(short) || userAliases.has(short))
|
|
2319
|
-
return [`--${long}`];
|
|
2320
|
-
return [`--${long}`, `-${short}`];
|
|
2321
|
-
}
|
|
2322
|
-
|
|
2323
|
-
// src/lib/branches.ts
|
|
2324
|
-
function parseDefaultBranch(originHead) {
|
|
2325
|
-
const trimmed = originHead.trim();
|
|
2326
|
-
if (!trimmed)
|
|
2327
|
-
return null;
|
|
2328
|
-
return trimmed.replace(/^origin\//, "");
|
|
2329
|
-
}
|
|
2330
|
-
function parseBranches(raw) {
|
|
2331
|
-
return raw.split(`
|
|
2332
|
-
`).map((branch) => branch.trim()).filter(Boolean);
|
|
2333
|
-
}
|
|
2334
|
-
function deletableBranches(all, protectedBranches) {
|
|
2335
|
-
const kept = new Set(protectedBranches.filter(Boolean));
|
|
2336
|
-
return all.filter((branch) => !kept.has(branch));
|
|
2337
|
-
}
|
|
2338
|
-
|
|
2339
|
-
// src/lib/errors.ts
|
|
2340
|
-
function errorMessage(error) {
|
|
2341
|
-
return error instanceof Error ? error.message : String(error);
|
|
2342
|
-
}
|
|
2343
|
-
|
|
2344
|
-
// src/lib/git.ts
|
|
2345
|
-
import { readdir } from "fs/promises";
|
|
2346
|
-
import { join } from "path";
|
|
2347
|
-
var {$ } = globalThis.Bun;
|
|
2348
|
-
var UPSTREAM_REF = "@{upstream}";
|
|
2349
|
-
var BRANCH_FORMAT = "%(refname:short)";
|
|
2350
|
-
async function stageAll() {
|
|
2351
|
-
await $`git add -A`.quiet();
|
|
2352
|
-
}
|
|
2353
|
-
async function getStagedDiff() {
|
|
2354
|
-
return await $`git diff --cached`.quiet().text();
|
|
2355
|
-
}
|
|
2356
|
-
async function commit(message) {
|
|
2357
|
-
await $`git commit -m ${message}`.quiet();
|
|
2358
|
-
}
|
|
2359
|
-
async function currentBranch() {
|
|
2360
|
-
return (await $`git symbolic-ref --short HEAD`.quiet().text()).trim();
|
|
2361
|
-
}
|
|
2362
|
-
async function hasUpstream() {
|
|
2363
|
-
const result = await $`git rev-parse --abbrev-ref --symbolic-full-name ${UPSTREAM_REF}`.nothrow().quiet();
|
|
2364
|
-
return result.exitCode === 0;
|
|
2365
|
-
}
|
|
2366
|
-
async function push() {
|
|
2367
|
-
await $`git push`.quiet();
|
|
2368
|
-
}
|
|
2369
|
-
async function pushSetUpstream(branch) {
|
|
2370
|
-
await $`git push -u origin ${branch}`.quiet();
|
|
2371
|
-
}
|
|
2372
|
-
async function findGitRepos(start) {
|
|
2373
|
-
const repos = [];
|
|
2374
|
-
await collectRepos(start, repos);
|
|
2375
|
-
return repos.sort();
|
|
2376
|
-
}
|
|
2377
|
-
async function collectRepos(dir, repos) {
|
|
2378
|
-
const entries = await readdir(dir, { withFileTypes: true }).catch(() => null);
|
|
2379
|
-
if (!entries)
|
|
2380
|
-
return;
|
|
2381
|
-
if (entries.some((entry) => entry.name === ".git")) {
|
|
2382
|
-
repos.push(dir);
|
|
2383
|
-
return;
|
|
2384
|
-
}
|
|
2385
|
-
const subdirs = entries.filter((entry) => entry.isDirectory() && entry.name !== "node_modules");
|
|
2386
|
-
await Promise.all(subdirs.map((entry) => collectRepos(join(dir, entry.name), repos)));
|
|
2387
|
-
}
|
|
2388
|
-
async function fetchPrune(repo) {
|
|
2389
|
-
await $`git fetch --prune`.cwd(repo).quiet();
|
|
2390
|
-
}
|
|
2391
|
-
async function defaultBranch(repo) {
|
|
2392
|
-
const result = await $`git symbolic-ref --quiet --short refs/remotes/origin/HEAD`.cwd(repo).nothrow().quiet();
|
|
2393
|
-
return result.exitCode === 0 ? parseDefaultBranch(result.text()) : null;
|
|
2394
|
-
}
|
|
2395
|
-
async function currentBranchAt(repo) {
|
|
2396
|
-
const result = await $`git symbolic-ref --quiet --short HEAD`.cwd(repo).nothrow().quiet();
|
|
2397
|
-
return result.exitCode === 0 ? result.text().trim() : null;
|
|
2398
|
-
}
|
|
2399
|
-
async function localBranches(repo) {
|
|
2400
|
-
return parseBranches(await $`git branch --format=${BRANCH_FORMAT}`.cwd(repo).quiet().text());
|
|
2401
|
-
}
|
|
2402
|
-
async function switchBranch(repo, branch) {
|
|
2403
|
-
await $`git switch ${branch}`.cwd(repo).quiet();
|
|
2404
|
-
}
|
|
2405
|
-
async function deleteBranch(repo, branch) {
|
|
2406
|
-
await $`git branch -D ${branch}`.cwd(repo).quiet();
|
|
2407
|
-
}
|
|
2408
|
-
async function pull(repo) {
|
|
2409
|
-
await $`git pull`.cwd(repo).quiet();
|
|
2410
|
-
}
|
|
2411
|
-
|
|
2412
|
-
// src/commands/cleanup.ts
|
|
2413
|
-
var cleanupCommand = defineCommand({
|
|
2414
|
-
meta: {
|
|
2415
|
-
name: "cleanup",
|
|
2416
|
-
description: "Prune every git repo under a path, then delete stale local branches."
|
|
2417
|
-
},
|
|
2418
|
-
args: {
|
|
2419
|
-
path: {
|
|
2420
|
-
type: "positional",
|
|
2421
|
-
required: false,
|
|
2422
|
-
default: ".",
|
|
2423
|
-
description: "Directory to scan for git repos (recursively)."
|
|
2424
|
-
},
|
|
2425
|
-
stay: {
|
|
2426
|
-
type: "boolean",
|
|
2427
|
-
alias: "s",
|
|
2428
|
-
description: "Stay on the current branch instead of switching to the default."
|
|
2429
|
-
},
|
|
2430
|
-
pull: {
|
|
2431
|
-
type: "boolean",
|
|
2432
|
-
alias: "p",
|
|
2433
|
-
description: "Pull the checked-out branch after cleanup without asking."
|
|
2434
|
-
},
|
|
2435
|
-
yes: {
|
|
2436
|
-
type: "boolean",
|
|
2437
|
-
alias: "y",
|
|
2438
|
-
description: "Non-interactive: switch to default and delete every other local branch."
|
|
2439
|
-
}
|
|
2440
|
-
},
|
|
2441
|
-
async run({ args }) {
|
|
2442
|
-
const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY) && !args.yes;
|
|
2443
|
-
const options = { stay: Boolean(args.stay), pull: Boolean(args.pull) };
|
|
2444
|
-
const path = args.path || ".";
|
|
2445
|
-
if (interactive)
|
|
2446
|
-
intro("zapdev cleanup");
|
|
2447
|
-
const repos = await findGitRepos(path);
|
|
2448
|
-
if (repos.length === 0) {
|
|
2449
|
-
log.warn(`No git repository found under ${path}.`);
|
|
2450
|
-
if (interactive)
|
|
2451
|
-
outro("Nothing to do.");
|
|
2452
|
-
return;
|
|
2453
|
-
}
|
|
2454
|
-
for (const repo of repos) {
|
|
2455
|
-
const cancelled = await cleanupRepo(repo, options, interactive);
|
|
2456
|
-
if (cancelled) {
|
|
2457
|
-
cancel("Cancelled.");
|
|
2458
|
-
return;
|
|
2459
|
-
}
|
|
2460
|
-
}
|
|
2461
|
-
if (interactive)
|
|
2462
|
-
outro(`Done (${repos.length} repo${repos.length > 1 ? "s" : ""}).`);
|
|
2463
|
-
}
|
|
2464
|
-
});
|
|
2465
|
-
async function cleanupRepo(repo, options, interactive) {
|
|
2466
|
-
log.step(`Cleaning ${repo}`);
|
|
2467
|
-
const fetchLoader = interactive ? spinner() : undefined;
|
|
2468
|
-
fetchLoader?.start("Fetching + pruning\u2026");
|
|
2469
|
-
try {
|
|
2470
|
-
await fetchPrune(repo);
|
|
2471
|
-
fetchLoader?.stop("Fetched + pruned");
|
|
2472
|
-
} catch (error) {
|
|
2473
|
-
fetchLoader?.error("Fetch failed");
|
|
2474
|
-
log.warn(` Fetch failed, continuing: ${errorMessage(error)}`);
|
|
2475
|
-
}
|
|
2476
|
-
const base = await defaultBranch(repo);
|
|
2477
|
-
if (!base) {
|
|
2478
|
-
log.warn(" Skipped: no origin/HEAD.");
|
|
2479
|
-
return false;
|
|
2480
|
-
}
|
|
2481
|
-
const current = await currentBranchAt(repo);
|
|
2482
|
-
let endBranch = base;
|
|
2483
|
-
if (current && current !== base) {
|
|
2484
|
-
if (options.stay) {
|
|
2485
|
-
endBranch = current;
|
|
2486
|
-
} else if (interactive) {
|
|
2487
|
-
const choice = await select({
|
|
2488
|
-
message: "After cleanup, be on:",
|
|
2489
|
-
initialValue: base,
|
|
2490
|
-
options: [
|
|
2491
|
-
{ value: base, label: `Switch to ${base}` },
|
|
2492
|
-
{ value: current, label: `Stay on ${current} (keep it)` }
|
|
2493
|
-
]
|
|
2494
|
-
});
|
|
2495
|
-
if (isCancel(choice))
|
|
2496
|
-
return true;
|
|
2497
|
-
endBranch = choice;
|
|
2498
|
-
}
|
|
2499
|
-
}
|
|
2500
|
-
if (current !== endBranch) {
|
|
2501
|
-
try {
|
|
2502
|
-
await switchBranch(repo, endBranch);
|
|
2503
|
-
} catch (error) {
|
|
2504
|
-
log.error(` Could not switch to ${endBranch}: ${errorMessage(error)}`);
|
|
2505
|
-
return false;
|
|
2506
|
-
}
|
|
2507
|
-
}
|
|
2508
|
-
const candidates = deletableBranches(await localBranches(repo), [base, endBranch]);
|
|
2509
|
-
if (candidates.length === 0) {
|
|
2510
|
-
log.info(" No branch to delete.");
|
|
2511
|
-
} else {
|
|
2512
|
-
let toDelete = candidates;
|
|
2513
|
-
if (interactive) {
|
|
2514
|
-
const selected = await multiselect({
|
|
2515
|
-
message: "Branches to delete",
|
|
2516
|
-
options: candidates.map((branch) => ({ value: branch, label: branch })),
|
|
2517
|
-
required: false
|
|
2518
|
-
});
|
|
2519
|
-
if (isCancel(selected))
|
|
2520
|
-
return true;
|
|
2521
|
-
toDelete = selected;
|
|
2522
|
-
}
|
|
2523
|
-
let deleted = 0;
|
|
2524
|
-
for (const branch of toDelete) {
|
|
2525
|
-
try {
|
|
2526
|
-
await deleteBranch(repo, branch);
|
|
2527
|
-
deleted += 1;
|
|
2528
|
-
} catch (error) {
|
|
2529
|
-
log.error(` Could not delete ${branch}: ${errorMessage(error)}`);
|
|
2530
|
-
}
|
|
2531
|
-
}
|
|
2532
|
-
if (deleted > 0)
|
|
2533
|
-
log.success(` Deleted ${deleted} branch${deleted > 1 ? "es" : ""}.`);
|
|
2534
|
-
}
|
|
2535
|
-
let shouldPull = options.pull;
|
|
2536
|
-
if (!shouldPull && interactive) {
|
|
2537
|
-
const answer = await confirm({ message: `Pull ${endBranch}?`, initialValue: false });
|
|
2538
|
-
if (isCancel(answer))
|
|
2539
|
-
return true;
|
|
2540
|
-
shouldPull = answer;
|
|
2541
|
-
}
|
|
2542
|
-
if (shouldPull) {
|
|
2543
|
-
const pullLoader = interactive ? spinner() : undefined;
|
|
2544
|
-
pullLoader?.start(`Pulling ${endBranch}\u2026`);
|
|
2545
|
-
try {
|
|
2546
|
-
await pull(repo);
|
|
2547
|
-
pullLoader?.stop(`\u2713 Pulled ${endBranch}`);
|
|
2548
|
-
} catch (error) {
|
|
2549
|
-
pullLoader?.error("Pull failed");
|
|
2550
|
-
log.error(` Pull failed: ${errorMessage(error)}`);
|
|
2551
|
-
}
|
|
2552
|
-
}
|
|
2553
|
-
return false;
|
|
2554
|
-
}
|
|
2555
|
-
|
|
2556
|
-
// src/lib/config.ts
|
|
2557
|
-
var DEFAULT_OLLAMA_URL = "http://localhost:11434";
|
|
2558
|
-
var DEFAULT_MODEL = "deepseek-v4-flash:cloud";
|
|
2559
|
-
function resolveConfig(env = process.env, overrides = {}) {
|
|
2560
|
-
return {
|
|
2561
|
-
ollamaUrl: overrides.ollamaUrl ?? env.OLLAMA_URL ?? DEFAULT_OLLAMA_URL,
|
|
2562
|
-
model: overrides.model ?? env.OLLAMA_MODEL ?? DEFAULT_MODEL
|
|
2563
|
-
};
|
|
2564
|
-
}
|
|
2565
|
-
|
|
2566
|
-
// node_modules/ollama/dist/index.mjs
|
|
2567
|
-
import fs, { promises } from "fs";
|
|
2568
|
-
import { resolve } from "path";
|
|
2569
|
-
|
|
2570
|
-
// node_modules/whatwg-fetch/fetch.js
|
|
2571
|
-
var g2 = typeof globalThis !== "undefined" && globalThis || typeof self !== "undefined" && self || typeof global !== "undefined" && global || {};
|
|
2572
|
-
var support = {
|
|
2573
|
-
searchParams: "URLSearchParams" in g2,
|
|
2574
|
-
iterable: "Symbol" in g2 && "iterator" in Symbol,
|
|
2575
|
-
blob: "FileReader" in g2 && "Blob" in g2 && function() {
|
|
2576
|
-
try {
|
|
2577
|
-
new Blob;
|
|
2578
|
-
return true;
|
|
2579
|
-
} catch (e) {
|
|
2580
|
-
return false;
|
|
2581
|
-
}
|
|
2582
|
-
}(),
|
|
2583
|
-
formData: "FormData" in g2,
|
|
2584
|
-
arrayBuffer: "ArrayBuffer" in g2
|
|
2585
|
-
};
|
|
2586
|
-
function isDataView(obj) {
|
|
2587
|
-
return obj && DataView.prototype.isPrototypeOf(obj);
|
|
2588
|
-
}
|
|
2589
|
-
if (support.arrayBuffer) {
|
|
2590
|
-
viewClasses = [
|
|
2591
|
-
"[object Int8Array]",
|
|
2592
|
-
"[object Uint8Array]",
|
|
2593
|
-
"[object Uint8ClampedArray]",
|
|
2594
|
-
"[object Int16Array]",
|
|
2595
|
-
"[object Uint16Array]",
|
|
2596
|
-
"[object Int32Array]",
|
|
2597
|
-
"[object Uint32Array]",
|
|
2598
|
-
"[object Float32Array]",
|
|
2599
|
-
"[object Float64Array]"
|
|
2600
|
-
];
|
|
2601
|
-
isArrayBufferView = ArrayBuffer.isView || function(obj) {
|
|
2602
|
-
return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1;
|
|
2603
|
-
};
|
|
2604
|
-
}
|
|
2605
|
-
var viewClasses;
|
|
2606
|
-
var isArrayBufferView;
|
|
2607
|
-
function normalizeName(name) {
|
|
2608
|
-
if (typeof name !== "string") {
|
|
2609
|
-
name = String(name);
|
|
2610
|
-
}
|
|
2611
|
-
if (/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(name) || name === "") {
|
|
2612
|
-
throw new TypeError('Invalid character in header field name: "' + name + '"');
|
|
2613
|
-
}
|
|
2614
|
-
return name.toLowerCase();
|
|
2615
|
-
}
|
|
2616
|
-
function normalizeValue(value) {
|
|
2617
|
-
if (typeof value !== "string") {
|
|
2618
|
-
value = String(value);
|
|
2619
|
-
}
|
|
2620
|
-
return value;
|
|
2621
|
-
}
|
|
2622
|
-
function iteratorFor(items) {
|
|
2623
|
-
var iterator = {
|
|
2624
|
-
next: function() {
|
|
2625
|
-
var value = items.shift();
|
|
2626
|
-
return { done: value === undefined, value };
|
|
2627
|
-
}
|
|
2628
|
-
};
|
|
2629
|
-
if (support.iterable) {
|
|
2630
|
-
iterator[Symbol.iterator] = function() {
|
|
2631
|
-
return iterator;
|
|
2632
|
-
};
|
|
2633
|
-
}
|
|
2634
|
-
return iterator;
|
|
2635
|
-
}
|
|
2636
|
-
function Headers2(headers) {
|
|
2637
|
-
this.map = {};
|
|
2638
|
-
if (headers instanceof Headers2) {
|
|
2639
|
-
headers.forEach(function(value, name) {
|
|
2640
|
-
this.append(name, value);
|
|
2641
|
-
}, this);
|
|
2642
|
-
} else if (Array.isArray(headers)) {
|
|
2643
|
-
headers.forEach(function(header) {
|
|
2644
|
-
if (header.length != 2) {
|
|
2645
|
-
throw new TypeError("Headers constructor: expected name/value pair to be length 2, found" + header.length);
|
|
2646
|
-
}
|
|
2647
|
-
this.append(header[0], header[1]);
|
|
2648
|
-
}, this);
|
|
2649
|
-
} else if (headers) {
|
|
2650
|
-
Object.getOwnPropertyNames(headers).forEach(function(name) {
|
|
2651
|
-
this.append(name, headers[name]);
|
|
2652
|
-
}, this);
|
|
2653
|
-
}
|
|
2654
|
-
}
|
|
2655
|
-
Headers2.prototype.append = function(name, value) {
|
|
2656
|
-
name = normalizeName(name);
|
|
2657
|
-
value = normalizeValue(value);
|
|
2658
|
-
var oldValue = this.map[name];
|
|
2659
|
-
this.map[name] = oldValue ? oldValue + ", " + value : value;
|
|
2660
|
-
};
|
|
2661
|
-
Headers2.prototype["delete"] = function(name) {
|
|
2662
|
-
delete this.map[normalizeName(name)];
|
|
2663
|
-
};
|
|
2664
|
-
Headers2.prototype.get = function(name) {
|
|
2665
|
-
name = normalizeName(name);
|
|
2666
|
-
return this.has(name) ? this.map[name] : null;
|
|
2667
|
-
};
|
|
2668
|
-
Headers2.prototype.has = function(name) {
|
|
2669
|
-
return this.map.hasOwnProperty(normalizeName(name));
|
|
2670
|
-
};
|
|
2671
|
-
Headers2.prototype.set = function(name, value) {
|
|
2672
|
-
this.map[normalizeName(name)] = normalizeValue(value);
|
|
2673
|
-
};
|
|
2674
|
-
Headers2.prototype.forEach = function(callback, thisArg) {
|
|
2675
|
-
for (var name in this.map) {
|
|
2676
|
-
if (this.map.hasOwnProperty(name)) {
|
|
2677
|
-
callback.call(thisArg, this.map[name], name, this);
|
|
2678
|
-
}
|
|
2679
|
-
}
|
|
2680
|
-
};
|
|
2681
|
-
Headers2.prototype.keys = function() {
|
|
2682
|
-
var items = [];
|
|
2683
|
-
this.forEach(function(value, name) {
|
|
2684
|
-
items.push(name);
|
|
2685
|
-
});
|
|
2686
|
-
return iteratorFor(items);
|
|
2687
|
-
};
|
|
2688
|
-
Headers2.prototype.values = function() {
|
|
2689
|
-
var items = [];
|
|
2690
|
-
this.forEach(function(value) {
|
|
2691
|
-
items.push(value);
|
|
2692
|
-
});
|
|
2693
|
-
return iteratorFor(items);
|
|
2694
|
-
};
|
|
2695
|
-
Headers2.prototype.entries = function() {
|
|
2696
|
-
var items = [];
|
|
2697
|
-
this.forEach(function(value, name) {
|
|
2698
|
-
items.push([name, value]);
|
|
2699
|
-
});
|
|
2700
|
-
return iteratorFor(items);
|
|
2701
|
-
};
|
|
2702
|
-
if (support.iterable) {
|
|
2703
|
-
Headers2.prototype[Symbol.iterator] = Headers2.prototype.entries;
|
|
2704
|
-
}
|
|
2705
|
-
function consumed(body) {
|
|
2706
|
-
if (body._noBody)
|
|
2707
|
-
return;
|
|
2708
|
-
if (body.bodyUsed) {
|
|
2709
|
-
return Promise.reject(new TypeError("Already read"));
|
|
2710
|
-
}
|
|
2711
|
-
body.bodyUsed = true;
|
|
2712
|
-
}
|
|
2713
|
-
function fileReaderReady(reader) {
|
|
2714
|
-
return new Promise(function(resolve, reject) {
|
|
2715
|
-
reader.onload = function() {
|
|
2716
|
-
resolve(reader.result);
|
|
2717
|
-
};
|
|
2718
|
-
reader.onerror = function() {
|
|
2719
|
-
reject(reader.error);
|
|
2720
|
-
};
|
|
2721
|
-
});
|
|
2722
|
-
}
|
|
2723
|
-
function readBlobAsArrayBuffer(blob) {
|
|
2724
|
-
var reader = new FileReader;
|
|
2725
|
-
var promise = fileReaderReady(reader);
|
|
2726
|
-
reader.readAsArrayBuffer(blob);
|
|
2727
|
-
return promise;
|
|
2728
|
-
}
|
|
2729
|
-
function readBlobAsText(blob) {
|
|
2730
|
-
var reader = new FileReader;
|
|
2731
|
-
var promise = fileReaderReady(reader);
|
|
2732
|
-
var match = /charset=([A-Za-z0-9_-]+)/.exec(blob.type);
|
|
2733
|
-
var encoding = match ? match[1] : "utf-8";
|
|
2734
|
-
reader.readAsText(blob, encoding);
|
|
2735
|
-
return promise;
|
|
2736
|
-
}
|
|
2737
|
-
function readArrayBufferAsText(buf) {
|
|
2738
|
-
var view = new Uint8Array(buf);
|
|
2739
|
-
var chars = new Array(view.length);
|
|
2740
|
-
for (var i2 = 0;i2 < view.length; i2++) {
|
|
2741
|
-
chars[i2] = String.fromCharCode(view[i2]);
|
|
2742
|
-
}
|
|
2743
|
-
return chars.join("");
|
|
2744
|
-
}
|
|
2745
|
-
function bufferClone(buf) {
|
|
2746
|
-
if (buf.slice) {
|
|
2747
|
-
return buf.slice(0);
|
|
2748
|
-
} else {
|
|
2749
|
-
var view = new Uint8Array(buf.byteLength);
|
|
2750
|
-
view.set(new Uint8Array(buf));
|
|
2751
|
-
return view.buffer;
|
|
2752
|
-
}
|
|
2753
|
-
}
|
|
2754
|
-
function Body() {
|
|
2755
|
-
this.bodyUsed = false;
|
|
2756
|
-
this._initBody = function(body) {
|
|
2757
|
-
this.bodyUsed = this.bodyUsed;
|
|
2758
|
-
this._bodyInit = body;
|
|
2759
|
-
if (!body) {
|
|
2760
|
-
this._noBody = true;
|
|
2761
|
-
this._bodyText = "";
|
|
2762
|
-
} else if (typeof body === "string") {
|
|
2763
|
-
this._bodyText = body;
|
|
2764
|
-
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
|
|
2765
|
-
this._bodyBlob = body;
|
|
2766
|
-
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
|
|
2767
|
-
this._bodyFormData = body;
|
|
2768
|
-
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
|
|
2769
|
-
this._bodyText = body.toString();
|
|
2770
|
-
} else if (support.arrayBuffer && support.blob && isDataView(body)) {
|
|
2771
|
-
this._bodyArrayBuffer = bufferClone(body.buffer);
|
|
2772
|
-
this._bodyInit = new Blob([this._bodyArrayBuffer]);
|
|
2773
|
-
} else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
|
|
2774
|
-
this._bodyArrayBuffer = bufferClone(body);
|
|
2775
|
-
} else {
|
|
2776
|
-
this._bodyText = body = Object.prototype.toString.call(body);
|
|
2777
|
-
}
|
|
2778
|
-
if (!this.headers.get("content-type")) {
|
|
2779
|
-
if (typeof body === "string") {
|
|
2780
|
-
this.headers.set("content-type", "text/plain;charset=UTF-8");
|
|
2781
|
-
} else if (this._bodyBlob && this._bodyBlob.type) {
|
|
2782
|
-
this.headers.set("content-type", this._bodyBlob.type);
|
|
2783
|
-
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
|
|
2784
|
-
this.headers.set("content-type", "application/x-www-form-urlencoded;charset=UTF-8");
|
|
2785
|
-
}
|
|
2786
|
-
}
|
|
2787
|
-
};
|
|
2788
|
-
if (support.blob) {
|
|
2789
|
-
this.blob = function() {
|
|
2790
|
-
var rejected = consumed(this);
|
|
2791
|
-
if (rejected) {
|
|
2792
|
-
return rejected;
|
|
2793
|
-
}
|
|
2794
|
-
if (this._bodyBlob) {
|
|
2795
|
-
return Promise.resolve(this._bodyBlob);
|
|
2796
|
-
} else if (this._bodyArrayBuffer) {
|
|
2797
|
-
return Promise.resolve(new Blob([this._bodyArrayBuffer]));
|
|
2798
|
-
} else if (this._bodyFormData) {
|
|
2799
|
-
throw new Error("could not read FormData body as blob");
|
|
2800
|
-
} else {
|
|
2801
|
-
return Promise.resolve(new Blob([this._bodyText]));
|
|
2802
|
-
}
|
|
2803
|
-
};
|
|
2804
|
-
}
|
|
2805
|
-
this.arrayBuffer = function() {
|
|
2806
|
-
if (this._bodyArrayBuffer) {
|
|
2807
|
-
var isConsumed = consumed(this);
|
|
2808
|
-
if (isConsumed) {
|
|
2809
|
-
return isConsumed;
|
|
2810
|
-
} else if (ArrayBuffer.isView(this._bodyArrayBuffer)) {
|
|
2811
|
-
return Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset, this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength));
|
|
2812
|
-
} else {
|
|
2813
|
-
return Promise.resolve(this._bodyArrayBuffer);
|
|
2814
|
-
}
|
|
2815
|
-
} else if (support.blob) {
|
|
2816
|
-
return this.blob().then(readBlobAsArrayBuffer);
|
|
2817
|
-
} else {
|
|
2818
|
-
throw new Error("could not read as ArrayBuffer");
|
|
2819
|
-
}
|
|
2820
|
-
};
|
|
2821
|
-
this.text = function() {
|
|
2822
|
-
var rejected = consumed(this);
|
|
2823
|
-
if (rejected) {
|
|
2824
|
-
return rejected;
|
|
2825
|
-
}
|
|
2826
|
-
if (this._bodyBlob) {
|
|
2827
|
-
return readBlobAsText(this._bodyBlob);
|
|
2828
|
-
} else if (this._bodyArrayBuffer) {
|
|
2829
|
-
return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer));
|
|
2830
|
-
} else if (this._bodyFormData) {
|
|
2831
|
-
throw new Error("could not read FormData body as text");
|
|
2832
|
-
} else {
|
|
2833
|
-
return Promise.resolve(this._bodyText);
|
|
2834
|
-
}
|
|
2835
|
-
};
|
|
2836
|
-
if (support.formData) {
|
|
2837
|
-
this.formData = function() {
|
|
2838
|
-
return this.text().then(decode);
|
|
2839
|
-
};
|
|
2840
|
-
}
|
|
2841
|
-
this.json = function() {
|
|
2842
|
-
return this.text().then(JSON.parse);
|
|
2843
|
-
};
|
|
2844
|
-
return this;
|
|
2845
|
-
}
|
|
2846
|
-
var methods = ["CONNECT", "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "TRACE"];
|
|
2847
|
-
function normalizeMethod(method) {
|
|
2848
|
-
var upcased = method.toUpperCase();
|
|
2849
|
-
return methods.indexOf(upcased) > -1 ? upcased : method;
|
|
2850
|
-
}
|
|
2851
|
-
function Request(input, options) {
|
|
2852
|
-
if (!(this instanceof Request)) {
|
|
2853
|
-
throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');
|
|
2854
|
-
}
|
|
2855
|
-
options = options || {};
|
|
2856
|
-
var body = options.body;
|
|
2857
|
-
if (input instanceof Request) {
|
|
2858
|
-
if (input.bodyUsed) {
|
|
2859
|
-
throw new TypeError("Already read");
|
|
2860
|
-
}
|
|
2861
|
-
this.url = input.url;
|
|
2862
|
-
this.credentials = input.credentials;
|
|
2863
|
-
if (!options.headers) {
|
|
2864
|
-
this.headers = new Headers2(input.headers);
|
|
2865
|
-
}
|
|
2866
|
-
this.method = input.method;
|
|
2867
|
-
this.mode = input.mode;
|
|
2868
|
-
this.signal = input.signal;
|
|
2869
|
-
if (!body && input._bodyInit != null) {
|
|
2870
|
-
body = input._bodyInit;
|
|
2871
|
-
input.bodyUsed = true;
|
|
2872
|
-
}
|
|
2873
|
-
} else {
|
|
2874
|
-
this.url = String(input);
|
|
2875
|
-
}
|
|
2876
|
-
this.credentials = options.credentials || this.credentials || "same-origin";
|
|
2877
|
-
if (options.headers || !this.headers) {
|
|
2878
|
-
this.headers = new Headers2(options.headers);
|
|
2879
|
-
}
|
|
2880
|
-
this.method = normalizeMethod(options.method || this.method || "GET");
|
|
2881
|
-
this.mode = options.mode || this.mode || null;
|
|
2882
|
-
this.signal = options.signal || this.signal || function() {
|
|
2883
|
-
if ("AbortController" in g2) {
|
|
2884
|
-
var ctrl = new AbortController;
|
|
2885
|
-
return ctrl.signal;
|
|
2886
|
-
}
|
|
2887
|
-
}();
|
|
2888
|
-
this.referrer = null;
|
|
2889
|
-
if ((this.method === "GET" || this.method === "HEAD") && body) {
|
|
2890
|
-
throw new TypeError("Body not allowed for GET or HEAD requests");
|
|
2891
|
-
}
|
|
2892
|
-
this._initBody(body);
|
|
2893
|
-
if (this.method === "GET" || this.method === "HEAD") {
|
|
2894
|
-
if (options.cache === "no-store" || options.cache === "no-cache") {
|
|
2895
|
-
var reParamSearch = /([?&])_=[^&]*/;
|
|
2896
|
-
if (reParamSearch.test(this.url)) {
|
|
2897
|
-
this.url = this.url.replace(reParamSearch, "$1_=" + new Date().getTime());
|
|
2898
|
-
} else {
|
|
2899
|
-
var reQueryString = /\?/;
|
|
2900
|
-
this.url += (reQueryString.test(this.url) ? "&" : "?") + "_=" + new Date().getTime();
|
|
2901
|
-
}
|
|
2902
|
-
}
|
|
2903
|
-
}
|
|
2904
|
-
}
|
|
2905
|
-
Request.prototype.clone = function() {
|
|
2906
|
-
return new Request(this, { body: this._bodyInit });
|
|
2907
|
-
};
|
|
2908
|
-
function decode(body) {
|
|
2909
|
-
var form = new FormData;
|
|
2910
|
-
body.trim().split("&").forEach(function(bytes) {
|
|
2911
|
-
if (bytes) {
|
|
2912
|
-
var split = bytes.split("=");
|
|
2913
|
-
var name = split.shift().replace(/\+/g, " ");
|
|
2914
|
-
var value = split.join("=").replace(/\+/g, " ");
|
|
2915
|
-
form.append(decodeURIComponent(name), decodeURIComponent(value));
|
|
2916
|
-
}
|
|
2917
|
-
});
|
|
2918
|
-
return form;
|
|
2919
|
-
}
|
|
2920
|
-
function parseHeaders(rawHeaders) {
|
|
2921
|
-
var headers = new Headers2;
|
|
2922
|
-
var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, " ");
|
|
2923
|
-
preProcessedHeaders.split("\r").map(function(header) {
|
|
2924
|
-
return header.indexOf(`
|
|
2925
|
-
`) === 0 ? header.substr(1, header.length) : header;
|
|
2926
|
-
}).forEach(function(line) {
|
|
2927
|
-
var parts = line.split(":");
|
|
2928
|
-
var key = parts.shift().trim();
|
|
2929
|
-
if (key) {
|
|
2930
|
-
var value = parts.join(":").trim();
|
|
2931
|
-
try {
|
|
2932
|
-
headers.append(key, value);
|
|
2933
|
-
} catch (error) {
|
|
2934
|
-
console.warn("Response " + error.message);
|
|
2935
|
-
}
|
|
2936
|
-
}
|
|
2937
|
-
});
|
|
2938
|
-
return headers;
|
|
2939
|
-
}
|
|
2940
|
-
Body.call(Request.prototype);
|
|
2941
|
-
function Response(bodyInit, options) {
|
|
2942
|
-
if (!(this instanceof Response)) {
|
|
2943
|
-
throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');
|
|
2944
|
-
}
|
|
2945
|
-
if (!options) {
|
|
2946
|
-
options = {};
|
|
2947
|
-
}
|
|
2948
|
-
this.type = "default";
|
|
2949
|
-
this.status = options.status === undefined ? 200 : options.status;
|
|
2950
|
-
if (this.status < 200 || this.status > 599) {
|
|
2951
|
-
throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");
|
|
2952
|
-
}
|
|
2953
|
-
this.ok = this.status >= 200 && this.status < 300;
|
|
2954
|
-
this.statusText = options.statusText === undefined ? "" : "" + options.statusText;
|
|
2955
|
-
this.headers = new Headers2(options.headers);
|
|
2956
|
-
this.url = options.url || "";
|
|
2957
|
-
this._initBody(bodyInit);
|
|
2958
|
-
}
|
|
2959
|
-
Body.call(Response.prototype);
|
|
2960
|
-
Response.prototype.clone = function() {
|
|
2961
|
-
return new Response(this._bodyInit, {
|
|
2962
|
-
status: this.status,
|
|
2963
|
-
statusText: this.statusText,
|
|
2964
|
-
headers: new Headers2(this.headers),
|
|
2965
|
-
url: this.url
|
|
2966
|
-
});
|
|
2967
|
-
};
|
|
2968
|
-
Response.error = function() {
|
|
2969
|
-
var response = new Response(null, { status: 200, statusText: "" });
|
|
2970
|
-
response.ok = false;
|
|
2971
|
-
response.status = 0;
|
|
2972
|
-
response.type = "error";
|
|
2973
|
-
return response;
|
|
2974
|
-
};
|
|
2975
|
-
var redirectStatuses = [301, 302, 303, 307, 308];
|
|
2976
|
-
Response.redirect = function(url, status) {
|
|
2977
|
-
if (redirectStatuses.indexOf(status) === -1) {
|
|
2978
|
-
throw new RangeError("Invalid status code");
|
|
2979
|
-
}
|
|
2980
|
-
return new Response(null, { status, headers: { location: url } });
|
|
2981
|
-
};
|
|
2982
|
-
var DOMException = g2.DOMException;
|
|
2983
|
-
try {
|
|
2984
|
-
new DOMException;
|
|
2985
|
-
} catch (err) {
|
|
2986
|
-
DOMException = function(message, name) {
|
|
2987
|
-
this.message = message;
|
|
2988
|
-
this.name = name;
|
|
2989
|
-
var error = Error(message);
|
|
2990
|
-
this.stack = error.stack;
|
|
2991
|
-
};
|
|
2992
|
-
DOMException.prototype = Object.create(Error.prototype);
|
|
2993
|
-
DOMException.prototype.constructor = DOMException;
|
|
2994
|
-
}
|
|
2995
|
-
function fetch2(input, init) {
|
|
2996
|
-
return new Promise(function(resolve, reject) {
|
|
2997
|
-
var request = new Request(input, init);
|
|
2998
|
-
if (request.signal && request.signal.aborted) {
|
|
2999
|
-
return reject(new DOMException("Aborted", "AbortError"));
|
|
3000
|
-
}
|
|
3001
|
-
var xhr = new XMLHttpRequest;
|
|
3002
|
-
function abortXhr() {
|
|
3003
|
-
xhr.abort();
|
|
3004
|
-
}
|
|
3005
|
-
xhr.onload = function() {
|
|
3006
|
-
var options = {
|
|
3007
|
-
statusText: xhr.statusText,
|
|
3008
|
-
headers: parseHeaders(xhr.getAllResponseHeaders() || "")
|
|
3009
|
-
};
|
|
3010
|
-
if (request.url.indexOf("file://") === 0 && (xhr.status < 200 || xhr.status > 599)) {
|
|
3011
|
-
options.status = 200;
|
|
3012
|
-
} else {
|
|
3013
|
-
options.status = xhr.status;
|
|
3014
|
-
}
|
|
3015
|
-
options.url = "responseURL" in xhr ? xhr.responseURL : options.headers.get("X-Request-URL");
|
|
3016
|
-
var body = "response" in xhr ? xhr.response : xhr.responseText;
|
|
3017
|
-
setTimeout(function() {
|
|
3018
|
-
resolve(new Response(body, options));
|
|
3019
|
-
}, 0);
|
|
3020
|
-
};
|
|
3021
|
-
xhr.onerror = function() {
|
|
3022
|
-
setTimeout(function() {
|
|
3023
|
-
reject(new TypeError("Network request failed"));
|
|
3024
|
-
}, 0);
|
|
3025
|
-
};
|
|
3026
|
-
xhr.ontimeout = function() {
|
|
3027
|
-
setTimeout(function() {
|
|
3028
|
-
reject(new TypeError("Network request timed out"));
|
|
3029
|
-
}, 0);
|
|
3030
|
-
};
|
|
3031
|
-
xhr.onabort = function() {
|
|
3032
|
-
setTimeout(function() {
|
|
3033
|
-
reject(new DOMException("Aborted", "AbortError"));
|
|
3034
|
-
}, 0);
|
|
3035
|
-
};
|
|
3036
|
-
function fixUrl(url) {
|
|
3037
|
-
try {
|
|
3038
|
-
return url === "" && g2.location.href ? g2.location.href : url;
|
|
3039
|
-
} catch (e) {
|
|
3040
|
-
return url;
|
|
3041
|
-
}
|
|
3042
|
-
}
|
|
3043
|
-
xhr.open(request.method, fixUrl(request.url), true);
|
|
3044
|
-
if (request.credentials === "include") {
|
|
3045
|
-
xhr.withCredentials = true;
|
|
3046
|
-
} else if (request.credentials === "omit") {
|
|
3047
|
-
xhr.withCredentials = false;
|
|
3048
|
-
}
|
|
3049
|
-
if ("responseType" in xhr) {
|
|
3050
|
-
if (support.blob) {
|
|
3051
|
-
xhr.responseType = "blob";
|
|
3052
|
-
} else if (support.arrayBuffer) {
|
|
3053
|
-
xhr.responseType = "arraybuffer";
|
|
3054
|
-
}
|
|
3055
|
-
}
|
|
3056
|
-
if (init && typeof init.headers === "object" && !(init.headers instanceof Headers2 || g2.Headers && init.headers instanceof g2.Headers)) {
|
|
3057
|
-
var names = [];
|
|
3058
|
-
Object.getOwnPropertyNames(init.headers).forEach(function(name) {
|
|
3059
|
-
names.push(normalizeName(name));
|
|
3060
|
-
xhr.setRequestHeader(name, normalizeValue(init.headers[name]));
|
|
3061
|
-
});
|
|
3062
|
-
request.headers.forEach(function(value, name) {
|
|
3063
|
-
if (names.indexOf(name) === -1) {
|
|
3064
|
-
xhr.setRequestHeader(name, value);
|
|
3065
|
-
}
|
|
3066
|
-
});
|
|
3067
|
-
} else {
|
|
3068
|
-
request.headers.forEach(function(value, name) {
|
|
3069
|
-
xhr.setRequestHeader(name, value);
|
|
3070
|
-
});
|
|
3071
|
-
}
|
|
3072
|
-
if (request.signal) {
|
|
3073
|
-
request.signal.addEventListener("abort", abortXhr);
|
|
3074
|
-
xhr.onreadystatechange = function() {
|
|
3075
|
-
if (xhr.readyState === 4) {
|
|
3076
|
-
request.signal.removeEventListener("abort", abortXhr);
|
|
3077
|
-
}
|
|
3078
|
-
};
|
|
3079
|
-
}
|
|
3080
|
-
xhr.send(typeof request._bodyInit === "undefined" ? null : request._bodyInit);
|
|
3081
|
-
});
|
|
3082
|
-
}
|
|
3083
|
-
fetch2.polyfill = true;
|
|
3084
|
-
if (!g2.fetch) {
|
|
3085
|
-
g2.fetch = fetch2;
|
|
3086
|
-
g2.Headers = Headers2;
|
|
3087
|
-
g2.Request = Request;
|
|
3088
|
-
g2.Response = Response;
|
|
3089
|
-
}
|
|
3090
|
-
|
|
3091
|
-
// node_modules/ollama/dist/browser.mjs
|
|
3092
|
-
var defaultPort = "11434";
|
|
3093
|
-
var defaultHost = `http://127.0.0.1:${defaultPort}`;
|
|
3094
|
-
var version = "0.6.3";
|
|
3095
|
-
var __defProp$1 = Object.defineProperty;
|
|
3096
|
-
var __defNormalProp$1 = (obj, key, value) => (key in obj) ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3097
|
-
var __publicField$1 = (obj, key, value) => {
|
|
3098
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3099
|
-
return value;
|
|
3100
|
-
};
|
|
3101
|
-
|
|
3102
|
-
class ResponseError extends Error {
|
|
3103
|
-
constructor(error, status_code) {
|
|
3104
|
-
super(error);
|
|
3105
|
-
this.error = error;
|
|
3106
|
-
this.status_code = status_code;
|
|
3107
|
-
this.name = "ResponseError";
|
|
3108
|
-
if (Error.captureStackTrace) {
|
|
3109
|
-
Error.captureStackTrace(this, ResponseError);
|
|
3110
|
-
}
|
|
3111
|
-
}
|
|
3112
|
-
}
|
|
3113
|
-
|
|
3114
|
-
class AbortableAsyncIterator {
|
|
3115
|
-
constructor(abortController, itr, doneCallback) {
|
|
3116
|
-
__publicField$1(this, "abortController");
|
|
3117
|
-
__publicField$1(this, "itr");
|
|
3118
|
-
__publicField$1(this, "doneCallback");
|
|
3119
|
-
this.abortController = abortController;
|
|
3120
|
-
this.itr = itr;
|
|
3121
|
-
this.doneCallback = doneCallback;
|
|
3122
|
-
}
|
|
3123
|
-
abort() {
|
|
3124
|
-
this.abortController.abort();
|
|
3125
|
-
}
|
|
3126
|
-
async* [Symbol.asyncIterator]() {
|
|
3127
|
-
for await (const message of this.itr) {
|
|
3128
|
-
if ("error" in message) {
|
|
3129
|
-
throw new Error(message.error);
|
|
3130
|
-
}
|
|
3131
|
-
yield message;
|
|
3132
|
-
if (message.done || message.status === "success") {
|
|
3133
|
-
this.doneCallback();
|
|
3134
|
-
return;
|
|
3135
|
-
}
|
|
3136
|
-
}
|
|
3137
|
-
throw new Error("Did not receive done or success response in stream.");
|
|
3138
|
-
}
|
|
3139
|
-
}
|
|
3140
|
-
var checkOk = async (response) => {
|
|
3141
|
-
if (response.ok) {
|
|
3142
|
-
return;
|
|
3143
|
-
}
|
|
3144
|
-
let message = `Error ${response.status}: ${response.statusText}`;
|
|
3145
|
-
let errorData = null;
|
|
3146
|
-
if (response.headers.get("content-type")?.includes("application/json")) {
|
|
3147
|
-
try {
|
|
3148
|
-
errorData = await response.json();
|
|
3149
|
-
message = errorData.error || message;
|
|
3150
|
-
} catch (error) {
|
|
3151
|
-
console.log("Failed to parse error response as JSON");
|
|
3152
|
-
}
|
|
3153
|
-
} else {
|
|
3154
|
-
try {
|
|
3155
|
-
console.log("Getting text from response");
|
|
3156
|
-
const textResponse = await response.text();
|
|
3157
|
-
message = textResponse || message;
|
|
3158
|
-
} catch (error) {
|
|
3159
|
-
console.log("Failed to get text from error response");
|
|
3160
|
-
}
|
|
3161
|
-
}
|
|
3162
|
-
throw new ResponseError(message, response.status);
|
|
3163
|
-
};
|
|
3164
|
-
function getPlatform() {
|
|
3165
|
-
if (typeof window !== "undefined" && window.navigator) {
|
|
3166
|
-
const nav = navigator;
|
|
3167
|
-
if ("userAgentData" in nav && nav.userAgentData?.platform) {
|
|
3168
|
-
return `${nav.userAgentData.platform.toLowerCase()} Browser/${navigator.userAgent};`;
|
|
3169
|
-
}
|
|
3170
|
-
if (navigator.platform) {
|
|
3171
|
-
return `${navigator.platform.toLowerCase()} Browser/${navigator.userAgent};`;
|
|
3172
|
-
}
|
|
3173
|
-
return `unknown Browser/${navigator.userAgent};`;
|
|
3174
|
-
} else if (typeof process !== "undefined") {
|
|
3175
|
-
return `${process.arch} ${process.platform} Node.js/${process.version}`;
|
|
3176
|
-
}
|
|
3177
|
-
return "";
|
|
3178
|
-
}
|
|
3179
|
-
function normalizeHeaders(headers) {
|
|
3180
|
-
if (headers instanceof Headers) {
|
|
3181
|
-
const obj = {};
|
|
3182
|
-
headers.forEach((value, key) => {
|
|
3183
|
-
obj[key] = value;
|
|
3184
|
-
});
|
|
3185
|
-
return obj;
|
|
3186
|
-
} else if (Array.isArray(headers)) {
|
|
3187
|
-
return Object.fromEntries(headers);
|
|
3188
|
-
} else {
|
|
3189
|
-
return headers || {};
|
|
3190
|
-
}
|
|
3191
|
-
}
|
|
3192
|
-
var readEnvVar = (obj, key) => {
|
|
3193
|
-
return obj[key];
|
|
3194
|
-
};
|
|
3195
|
-
var fetchWithHeaders = async (fetch3, url, options = {}) => {
|
|
3196
|
-
const defaultHeaders = {
|
|
3197
|
-
"Content-Type": "application/json",
|
|
3198
|
-
Accept: "application/json",
|
|
3199
|
-
"User-Agent": `ollama-js/${version} (${getPlatform()})`
|
|
3200
|
-
};
|
|
3201
|
-
options.headers = normalizeHeaders(options.headers);
|
|
3202
|
-
try {
|
|
3203
|
-
const parsed = new URL(url);
|
|
3204
|
-
if (parsed.protocol === "https:" && parsed.hostname === "ollama.com") {
|
|
3205
|
-
const apiKey = typeof process === "object" && process !== null && typeof process.env === "object" && process.env !== null ? readEnvVar(process.env, "OLLAMA_API_KEY") : undefined;
|
|
3206
|
-
const authorization = options.headers["authorization"] || options.headers["Authorization"];
|
|
3207
|
-
if (!authorization && apiKey) {
|
|
3208
|
-
options.headers["Authorization"] = `Bearer ${apiKey}`;
|
|
3209
|
-
}
|
|
3210
|
-
}
|
|
3211
|
-
} catch (error) {
|
|
3212
|
-
console.error("error parsing url", error);
|
|
3213
|
-
}
|
|
3214
|
-
const customHeaders = Object.fromEntries(Object.entries(options.headers).filter(([key]) => !Object.keys(defaultHeaders).some((defaultKey) => defaultKey.toLowerCase() === key.toLowerCase())));
|
|
3215
|
-
options.headers = {
|
|
3216
|
-
...defaultHeaders,
|
|
3217
|
-
...customHeaders
|
|
3218
|
-
};
|
|
3219
|
-
return fetch3(url, options);
|
|
3220
|
-
};
|
|
3221
|
-
var get = async (fetch3, host, options) => {
|
|
3222
|
-
const response = await fetchWithHeaders(fetch3, host, {
|
|
3223
|
-
headers: options?.headers
|
|
3224
|
-
});
|
|
3225
|
-
await checkOk(response);
|
|
3226
|
-
return response;
|
|
3227
|
-
};
|
|
3228
|
-
var post = async (fetch3, host, data, options) => {
|
|
3229
|
-
const isRecord = (input) => {
|
|
3230
|
-
return input !== null && typeof input === "object" && !Array.isArray(input);
|
|
3231
|
-
};
|
|
3232
|
-
const formattedData = isRecord(data) ? JSON.stringify(data) : data;
|
|
3233
|
-
const response = await fetchWithHeaders(fetch3, host, {
|
|
3234
|
-
method: "POST",
|
|
3235
|
-
body: formattedData,
|
|
3236
|
-
signal: options?.signal,
|
|
3237
|
-
headers: options?.headers
|
|
3238
|
-
});
|
|
3239
|
-
await checkOk(response);
|
|
3240
|
-
return response;
|
|
3241
|
-
};
|
|
3242
|
-
var del = async (fetch3, host, data, options) => {
|
|
3243
|
-
const response = await fetchWithHeaders(fetch3, host, {
|
|
3244
|
-
method: "DELETE",
|
|
3245
|
-
body: JSON.stringify(data),
|
|
3246
|
-
headers: options?.headers
|
|
3247
|
-
});
|
|
3248
|
-
await checkOk(response);
|
|
3249
|
-
return response;
|
|
3250
|
-
};
|
|
3251
|
-
var parseJSON = async function* (itr) {
|
|
3252
|
-
const decoder = new TextDecoder("utf-8");
|
|
3253
|
-
let buffer = "";
|
|
3254
|
-
const reader = itr.getReader();
|
|
3255
|
-
while (true) {
|
|
3256
|
-
const { done, value: chunk } = await reader.read();
|
|
3257
|
-
if (done) {
|
|
3258
|
-
break;
|
|
3259
|
-
}
|
|
3260
|
-
buffer += decoder.decode(chunk, { stream: true });
|
|
3261
|
-
const parts = buffer.split(`
|
|
3262
|
-
`);
|
|
3263
|
-
buffer = parts.pop() ?? "";
|
|
3264
|
-
for (const part of parts) {
|
|
3265
|
-
try {
|
|
3266
|
-
yield JSON.parse(part);
|
|
3267
|
-
} catch (error) {
|
|
3268
|
-
console.warn("invalid json: ", part);
|
|
3269
|
-
}
|
|
3270
|
-
}
|
|
3271
|
-
}
|
|
3272
|
-
buffer += decoder.decode();
|
|
3273
|
-
for (const part of buffer.split(`
|
|
3274
|
-
`).filter((p2) => p2 !== "")) {
|
|
3275
|
-
try {
|
|
3276
|
-
yield JSON.parse(part);
|
|
3277
|
-
} catch (error) {
|
|
3278
|
-
console.warn("invalid json: ", part);
|
|
3279
|
-
}
|
|
3280
|
-
}
|
|
3281
|
-
};
|
|
3282
|
-
var formatHost = (host) => {
|
|
3283
|
-
if (!host) {
|
|
3284
|
-
return defaultHost;
|
|
3285
|
-
}
|
|
3286
|
-
let isExplicitProtocol = host.includes("://");
|
|
3287
|
-
if (host.startsWith(":")) {
|
|
3288
|
-
host = `http://127.0.0.1${host}`;
|
|
3289
|
-
isExplicitProtocol = true;
|
|
3290
|
-
}
|
|
3291
|
-
if (!isExplicitProtocol) {
|
|
3292
|
-
host = `http://${host}`;
|
|
3293
|
-
}
|
|
3294
|
-
const url = new URL(host);
|
|
3295
|
-
let port = url.port;
|
|
3296
|
-
if (!port) {
|
|
3297
|
-
if (!isExplicitProtocol) {
|
|
3298
|
-
port = defaultPort;
|
|
3299
|
-
} else {
|
|
3300
|
-
port = url.protocol === "https:" ? "443" : "80";
|
|
3301
|
-
}
|
|
3302
|
-
}
|
|
3303
|
-
let auth = "";
|
|
3304
|
-
if (url.username) {
|
|
3305
|
-
auth = url.username;
|
|
3306
|
-
if (url.password) {
|
|
3307
|
-
auth += `:${url.password}`;
|
|
3308
|
-
}
|
|
3309
|
-
auth += "@";
|
|
3310
|
-
}
|
|
3311
|
-
let formattedHost = `${url.protocol}//${auth}${url.hostname}:${port}${url.pathname}`;
|
|
3312
|
-
if (formattedHost.endsWith("/")) {
|
|
3313
|
-
formattedHost = formattedHost.slice(0, -1);
|
|
3314
|
-
}
|
|
3315
|
-
return formattedHost;
|
|
3316
|
-
};
|
|
3317
|
-
var __defProp2 = Object.defineProperty;
|
|
3318
|
-
var __defNormalProp = (obj, key, value) => (key in obj) ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3319
|
-
var __publicField = (obj, key, value) => {
|
|
3320
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3321
|
-
return value;
|
|
3322
|
-
};
|
|
3323
|
-
var Ollama$1 = class Ollama {
|
|
3324
|
-
constructor(config) {
|
|
3325
|
-
__publicField(this, "config");
|
|
3326
|
-
__publicField(this, "fetch");
|
|
3327
|
-
__publicField(this, "ongoingStreamedRequests", []);
|
|
3328
|
-
this.config = {
|
|
3329
|
-
host: "",
|
|
3330
|
-
headers: config?.headers
|
|
3331
|
-
};
|
|
3332
|
-
if (!config?.proxy) {
|
|
3333
|
-
this.config.host = formatHost(config?.host ?? defaultHost);
|
|
3334
|
-
}
|
|
3335
|
-
this.fetch = config?.fetch ?? fetch;
|
|
3336
|
-
}
|
|
3337
|
-
abort() {
|
|
3338
|
-
for (const request of this.ongoingStreamedRequests) {
|
|
3339
|
-
request.abort();
|
|
3340
|
-
}
|
|
3341
|
-
this.ongoingStreamedRequests.length = 0;
|
|
3342
|
-
}
|
|
3343
|
-
async processStreamableRequest(endpoint, request) {
|
|
3344
|
-
request.stream = request.stream ?? false;
|
|
3345
|
-
const host = `${this.config.host}/api/${endpoint}`;
|
|
3346
|
-
if (request.stream) {
|
|
3347
|
-
const abortController = new AbortController;
|
|
3348
|
-
const response2 = await post(this.fetch, host, request, {
|
|
3349
|
-
signal: abortController.signal,
|
|
3350
|
-
headers: this.config.headers
|
|
3351
|
-
});
|
|
3352
|
-
if (!response2.body) {
|
|
3353
|
-
throw new Error("Missing body");
|
|
3354
|
-
}
|
|
3355
|
-
const itr = parseJSON(response2.body);
|
|
3356
|
-
const abortableAsyncIterator = new AbortableAsyncIterator(abortController, itr, () => {
|
|
3357
|
-
const i2 = this.ongoingStreamedRequests.indexOf(abortableAsyncIterator);
|
|
3358
|
-
if (i2 > -1) {
|
|
3359
|
-
this.ongoingStreamedRequests.splice(i2, 1);
|
|
3360
|
-
}
|
|
3361
|
-
});
|
|
3362
|
-
this.ongoingStreamedRequests.push(abortableAsyncIterator);
|
|
3363
|
-
return abortableAsyncIterator;
|
|
3364
|
-
}
|
|
3365
|
-
const response = await post(this.fetch, host, request, {
|
|
3366
|
-
headers: this.config.headers
|
|
3367
|
-
});
|
|
3368
|
-
return await response.json();
|
|
3369
|
-
}
|
|
3370
|
-
async encodeImage(image) {
|
|
3371
|
-
if (typeof image !== "string") {
|
|
3372
|
-
const uint8Array = new Uint8Array(image);
|
|
3373
|
-
let byteString = "";
|
|
3374
|
-
const len = uint8Array.byteLength;
|
|
3375
|
-
for (let i2 = 0;i2 < len; i2++) {
|
|
3376
|
-
byteString += String.fromCharCode(uint8Array[i2]);
|
|
3377
|
-
}
|
|
3378
|
-
return btoa(byteString);
|
|
3379
|
-
}
|
|
3380
|
-
return image;
|
|
3381
|
-
}
|
|
3382
|
-
async generate(request) {
|
|
3383
|
-
if (request.images) {
|
|
3384
|
-
request.images = await Promise.all(request.images.map(this.encodeImage.bind(this)));
|
|
3385
|
-
}
|
|
3386
|
-
return this.processStreamableRequest("generate", request);
|
|
3387
|
-
}
|
|
3388
|
-
async chat(request) {
|
|
3389
|
-
if (request.messages) {
|
|
3390
|
-
for (const message of request.messages) {
|
|
3391
|
-
if (message.images) {
|
|
3392
|
-
message.images = await Promise.all(message.images.map(this.encodeImage.bind(this)));
|
|
3393
|
-
}
|
|
3394
|
-
}
|
|
3395
|
-
}
|
|
3396
|
-
return this.processStreamableRequest("chat", request);
|
|
3397
|
-
}
|
|
3398
|
-
async create(request) {
|
|
3399
|
-
return this.processStreamableRequest("create", {
|
|
3400
|
-
...request
|
|
3401
|
-
});
|
|
3402
|
-
}
|
|
3403
|
-
async pull(request) {
|
|
3404
|
-
return this.processStreamableRequest("pull", {
|
|
3405
|
-
name: request.model,
|
|
3406
|
-
stream: request.stream,
|
|
3407
|
-
insecure: request.insecure
|
|
3408
|
-
});
|
|
3409
|
-
}
|
|
3410
|
-
async push(request) {
|
|
3411
|
-
return this.processStreamableRequest("push", {
|
|
3412
|
-
name: request.model,
|
|
3413
|
-
stream: request.stream,
|
|
3414
|
-
insecure: request.insecure
|
|
3415
|
-
});
|
|
3416
|
-
}
|
|
3417
|
-
async delete(request) {
|
|
3418
|
-
await del(this.fetch, `${this.config.host}/api/delete`, { name: request.model }, { headers: this.config.headers });
|
|
3419
|
-
return { status: "success" };
|
|
3420
|
-
}
|
|
3421
|
-
async copy(request) {
|
|
3422
|
-
await post(this.fetch, `${this.config.host}/api/copy`, { ...request }, {
|
|
3423
|
-
headers: this.config.headers
|
|
3424
|
-
});
|
|
3425
|
-
return { status: "success" };
|
|
3426
|
-
}
|
|
3427
|
-
async list() {
|
|
3428
|
-
const response = await get(this.fetch, `${this.config.host}/api/tags`, {
|
|
3429
|
-
headers: this.config.headers
|
|
3430
|
-
});
|
|
3431
|
-
return await response.json();
|
|
3432
|
-
}
|
|
3433
|
-
async show(request) {
|
|
3434
|
-
const response = await post(this.fetch, `${this.config.host}/api/show`, {
|
|
3435
|
-
...request
|
|
3436
|
-
}, {
|
|
3437
|
-
headers: this.config.headers
|
|
3438
|
-
});
|
|
3439
|
-
return await response.json();
|
|
3440
|
-
}
|
|
3441
|
-
async embed(request) {
|
|
3442
|
-
const response = await post(this.fetch, `${this.config.host}/api/embed`, {
|
|
3443
|
-
...request
|
|
3444
|
-
}, {
|
|
3445
|
-
headers: this.config.headers
|
|
3446
|
-
});
|
|
3447
|
-
return await response.json();
|
|
3448
|
-
}
|
|
3449
|
-
async embeddings(request) {
|
|
3450
|
-
const response = await post(this.fetch, `${this.config.host}/api/embeddings`, {
|
|
3451
|
-
...request
|
|
3452
|
-
}, {
|
|
3453
|
-
headers: this.config.headers
|
|
3454
|
-
});
|
|
3455
|
-
return await response.json();
|
|
3456
|
-
}
|
|
3457
|
-
async ps() {
|
|
3458
|
-
const response = await get(this.fetch, `${this.config.host}/api/ps`, {
|
|
3459
|
-
headers: this.config.headers
|
|
3460
|
-
});
|
|
3461
|
-
return await response.json();
|
|
3462
|
-
}
|
|
3463
|
-
async version() {
|
|
3464
|
-
const response = await get(this.fetch, `${this.config.host}/api/version`, {
|
|
3465
|
-
headers: this.config.headers
|
|
3466
|
-
});
|
|
3467
|
-
return await response.json();
|
|
3468
|
-
}
|
|
3469
|
-
async webSearch(request) {
|
|
3470
|
-
if (!request.query || request.query.length === 0) {
|
|
3471
|
-
throw new Error("Query is required");
|
|
3472
|
-
}
|
|
3473
|
-
const response = await post(this.fetch, `https://ollama.com/api/web_search`, { ...request }, {
|
|
3474
|
-
headers: this.config.headers
|
|
3475
|
-
});
|
|
3476
|
-
return await response.json();
|
|
3477
|
-
}
|
|
3478
|
-
async webFetch(request) {
|
|
3479
|
-
if (!request.url || request.url.length === 0) {
|
|
3480
|
-
throw new Error("URL is required");
|
|
3481
|
-
}
|
|
3482
|
-
const response = await post(this.fetch, `https://ollama.com/api/web_fetch`, { ...request }, { headers: this.config.headers });
|
|
3483
|
-
return await response.json();
|
|
3484
|
-
}
|
|
3485
|
-
};
|
|
3486
|
-
var browser = new Ollama$1;
|
|
3487
|
-
|
|
3488
|
-
// node_modules/ollama/dist/index.mjs
|
|
3489
|
-
class Ollama2 extends Ollama$1 {
|
|
3490
|
-
async encodeImage(image) {
|
|
3491
|
-
if (typeof image !== "string") {
|
|
3492
|
-
return Buffer.from(image).toString("base64");
|
|
3493
|
-
}
|
|
3494
|
-
try {
|
|
3495
|
-
if (fs.existsSync(image)) {
|
|
3496
|
-
const fileBuffer = await promises.readFile(resolve(image));
|
|
3497
|
-
return Buffer.from(fileBuffer).toString("base64");
|
|
3498
|
-
}
|
|
3499
|
-
} catch {}
|
|
3500
|
-
return image;
|
|
3501
|
-
}
|
|
3502
|
-
async fileExists(path) {
|
|
3503
|
-
try {
|
|
3504
|
-
await promises.access(path);
|
|
3505
|
-
return true;
|
|
3506
|
-
} catch {
|
|
3507
|
-
return false;
|
|
3508
|
-
}
|
|
3509
|
-
}
|
|
3510
|
-
async create(request) {
|
|
3511
|
-
if (request.from && await this.fileExists(resolve(request.from))) {
|
|
3512
|
-
throw Error("Creating with a local path is not currently supported from ollama-js");
|
|
3513
|
-
}
|
|
3514
|
-
if (request.stream) {
|
|
3515
|
-
return super.create(request);
|
|
3516
|
-
} else {
|
|
3517
|
-
return super.create(request);
|
|
3518
|
-
}
|
|
3519
|
-
}
|
|
3520
|
-
}
|
|
3521
|
-
var index = new Ollama2;
|
|
3522
|
-
|
|
3523
|
-
// src/lib/commit-message.ts
|
|
3524
|
-
var COMMIT_SYSTEM_PROMPT = [
|
|
3525
|
-
"Generate ONE commit message in Conventional Commits format.",
|
|
3526
|
-
'A single line: "type(scope): description", imperative, English, \u226472 chars.',
|
|
3527
|
-
"Reply ONLY with the message, no backticks, no quotes, no explanation."
|
|
3528
|
-
].join(`
|
|
3529
|
-
`);
|
|
3530
|
-
var MAX_DIFF_CHARS = 12000;
|
|
3531
|
-
function truncateDiff(diff, max = MAX_DIFF_CHARS) {
|
|
3532
|
-
return diff.length > max ? diff.slice(0, max) : diff;
|
|
3533
|
-
}
|
|
3534
|
-
function sanitizeCommitMessage(raw) {
|
|
3535
|
-
const firstLine = raw.split(`
|
|
3536
|
-
`, 1)[0] ?? "";
|
|
3537
|
-
return firstLine.replace(/[`"]/g, "").trim();
|
|
3538
|
-
}
|
|
3539
|
-
|
|
3540
|
-
// src/lib/ollama.ts
|
|
3541
|
-
var REQUEST_TIMEOUT_MS = 25000;
|
|
3542
|
-
var fetchWithTimeout = Object.assign((input, init) => fetch(input, { ...init, signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) }), { preconnect: fetch.preconnect });
|
|
3543
|
-
async function generateCommitMessage(diff, config) {
|
|
3544
|
-
const client = new Ollama2({ host: config.ollamaUrl, fetch: fetchWithTimeout });
|
|
3545
|
-
const response = await client.chat({
|
|
3546
|
-
model: config.model,
|
|
3547
|
-
stream: false,
|
|
3548
|
-
keep_alive: "30m",
|
|
3549
|
-
options: { temperature: 0.2 },
|
|
3550
|
-
messages: [
|
|
3551
|
-
{ role: "system", content: COMMIT_SYSTEM_PROMPT },
|
|
3552
|
-
{ role: "user", content: truncateDiff(diff) }
|
|
3553
|
-
]
|
|
3554
|
-
});
|
|
3555
|
-
return sanitizeCommitMessage(response.message.content);
|
|
3556
|
-
}
|
|
3557
|
-
|
|
3558
|
-
// src/commands/commit.ts
|
|
3559
|
-
var commitCommand = defineCommand({
|
|
3560
|
-
meta: {
|
|
3561
|
-
name: "commit",
|
|
3562
|
-
description: "Stage all changes and commit with an LLM-generated Conventional Commits message."
|
|
3563
|
-
},
|
|
3564
|
-
args: {
|
|
3565
|
-
model: {
|
|
3566
|
-
type: "string",
|
|
3567
|
-
alias: "m",
|
|
3568
|
-
description: "Override the Ollama model (defaults to $OLLAMA_MODEL)."
|
|
3569
|
-
},
|
|
3570
|
-
push: {
|
|
3571
|
-
type: "boolean",
|
|
3572
|
-
alias: "p",
|
|
3573
|
-
description: "Push after committing without asking."
|
|
3574
|
-
},
|
|
3575
|
-
yes: {
|
|
3576
|
-
type: "boolean",
|
|
3577
|
-
alias: "y",
|
|
3578
|
-
description: "Skip prompts and commit directly."
|
|
3579
|
-
}
|
|
3580
|
-
},
|
|
3581
|
-
async run({ args }) {
|
|
3582
|
-
const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
3583
|
-
const config = resolveConfig(process.env, args.model ? { model: args.model } : {});
|
|
3584
|
-
if (interactive)
|
|
3585
|
-
intro("zapdev commit");
|
|
3586
|
-
await stageAll();
|
|
3587
|
-
const diff = await getStagedDiff();
|
|
3588
|
-
if (!diff.trim()) {
|
|
3589
|
-
log.warn("Nothing to commit.");
|
|
3590
|
-
if (interactive)
|
|
3591
|
-
outro("Nothing to do.");
|
|
3592
|
-
return;
|
|
3593
|
-
}
|
|
3594
|
-
const loader = interactive ? spinner() : undefined;
|
|
3595
|
-
loader?.start("Generating commit message\u2026");
|
|
3596
|
-
let message;
|
|
3597
|
-
try {
|
|
3598
|
-
message = await generateCommitMessage(diff, config);
|
|
3599
|
-
} catch (error) {
|
|
3600
|
-
loader?.error("Generation failed");
|
|
3601
|
-
log.error(`Generation failed (machine unreachable?): ${errorMessage(error)}`);
|
|
3602
|
-
process.exitCode = 1;
|
|
3603
|
-
return;
|
|
3604
|
-
}
|
|
3605
|
-
if (!message) {
|
|
3606
|
-
loader?.error("Generation failed");
|
|
3607
|
-
log.error("Generation failed: the model returned an empty message.");
|
|
3608
|
-
process.exitCode = 1;
|
|
3609
|
-
return;
|
|
3610
|
-
}
|
|
3611
|
-
if (loader)
|
|
3612
|
-
loader.stop(message);
|
|
3613
|
-
else
|
|
3614
|
-
log.message(message);
|
|
3615
|
-
let finalMessage = message;
|
|
3616
|
-
if (interactive && !args.yes) {
|
|
3617
|
-
const action = await select({
|
|
3618
|
-
message: "Action",
|
|
3619
|
-
initialValue: "commit",
|
|
3620
|
-
options: [
|
|
3621
|
-
{ value: "commit", label: "Commit" },
|
|
3622
|
-
{ value: "edit", label: "Edit message" },
|
|
3623
|
-
{ value: "cancel", label: "Cancel" }
|
|
3624
|
-
]
|
|
3625
|
-
});
|
|
3626
|
-
if (isCancel(action) || action === "cancel") {
|
|
3627
|
-
cancel("Cancelled (changes left staged).");
|
|
3628
|
-
return;
|
|
3629
|
-
}
|
|
3630
|
-
if (action === "edit") {
|
|
3631
|
-
const edited = await text({ message: "Edit message", initialValue: message });
|
|
3632
|
-
if (isCancel(edited)) {
|
|
3633
|
-
cancel("Cancelled (changes left staged).");
|
|
3634
|
-
return;
|
|
3635
|
-
}
|
|
3636
|
-
finalMessage = edited.trim();
|
|
3637
|
-
if (!finalMessage) {
|
|
3638
|
-
cancel("Empty message, cancelled.");
|
|
3639
|
-
return;
|
|
3640
|
-
}
|
|
3641
|
-
}
|
|
3642
|
-
}
|
|
3643
|
-
await commit(finalMessage);
|
|
3644
|
-
if (interactive)
|
|
3645
|
-
log.success(`Committed: ${finalMessage}`);
|
|
3646
|
-
let shouldPush = Boolean(args.push);
|
|
3647
|
-
if (!shouldPush && interactive && !args.yes) {
|
|
3648
|
-
const answer = await confirm({ message: "Push?", initialValue: false });
|
|
3649
|
-
if (isCancel(answer)) {
|
|
3650
|
-
if (interactive)
|
|
3651
|
-
outro("Committed. Not pushed.");
|
|
3652
|
-
return;
|
|
3653
|
-
}
|
|
3654
|
-
shouldPush = answer;
|
|
3655
|
-
}
|
|
3656
|
-
if (shouldPush) {
|
|
3657
|
-
const pushLoader = interactive ? spinner() : undefined;
|
|
3658
|
-
pushLoader?.start("Pushing\u2026");
|
|
3659
|
-
try {
|
|
3660
|
-
if (await hasUpstream())
|
|
3661
|
-
await push();
|
|
3662
|
-
else
|
|
3663
|
-
await pushSetUpstream(await currentBranch());
|
|
3664
|
-
pushLoader?.stop("\u2713 Pushed");
|
|
3665
|
-
} catch (error) {
|
|
3666
|
-
pushLoader?.error("Push failed");
|
|
3667
|
-
log.error(`Push failed: ${errorMessage(error)}`);
|
|
3668
|
-
process.exitCode = 1;
|
|
3669
|
-
return;
|
|
3670
|
-
}
|
|
3671
|
-
}
|
|
3672
|
-
if (interactive)
|
|
3673
|
-
outro("Done.");
|
|
3674
|
-
}
|
|
3675
|
-
});
|
|
3676
|
-
|
|
3677
|
-
// src/index.ts
|
|
3678
|
-
var commands = {
|
|
3679
|
-
commit: commitCommand,
|
|
3680
|
-
cleanup: cleanupCommand
|
|
3681
|
-
};
|
|
3682
|
-
var MENU = {
|
|
3683
|
-
commit: "Stage all changes and commit with an AI-generated message",
|
|
3684
|
-
cleanup: "Prune repos and delete stale local branches"
|
|
3685
|
-
};
|
|
3686
|
-
var menuOptions = Object.keys(MENU).map((value) => ({
|
|
3687
|
-
value,
|
|
3688
|
-
label: value,
|
|
3689
|
-
hint: MENU[value]
|
|
3690
|
-
}));
|
|
3691
|
-
var main = defineCommand({
|
|
3692
|
-
meta: {
|
|
3693
|
-
name: "zapdev",
|
|
3694
|
-
version: "0.1.0",
|
|
3695
|
-
description: "Fast, precise git chores from your terminal."
|
|
3696
|
-
},
|
|
3697
|
-
subCommands: commands,
|
|
3698
|
-
async run({ args, cmd }) {
|
|
3699
|
-
const selected = args._[0];
|
|
3700
|
-
if (selected && selected in commands)
|
|
3701
|
-
return;
|
|
3702
|
-
if (!(process.stdin.isTTY && process.stdout.isTTY)) {
|
|
3703
|
-
await showUsage(cmd);
|
|
3704
|
-
return;
|
|
3705
|
-
}
|
|
3706
|
-
const choice = await select({ message: "Which command?", options: menuOptions });
|
|
3707
|
-
if (isCancel(choice)) {
|
|
3708
|
-
cancel("Cancelled.");
|
|
3709
|
-
return;
|
|
3710
|
-
}
|
|
3711
|
-
await runCommand(commands[choice], { rawArgs: [] });
|
|
3712
|
-
}
|
|
3713
|
-
});
|
|
3714
|
-
await runMain(main);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import nodeModule from "node:module";
|
|
3
|
+
nodeModule.enableCompileCache?.();
|
|
4
|
+
await import("./cli.js");
|