create-better-schemic 0.1.0-alpha.1 → 0.1.0-alpha.10
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/lib/index.js +609 -679
- package/package.json +4 -6
- package/src/index.ts +3 -3
package/lib/index.js
CHANGED
|
@@ -1,105 +1,115 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
|
|
9
|
-
return
|
|
10
|
-
}
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
12
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
20
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
+
const to = isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
if (mod && typeof mod === "object" || typeof mod === "function") {
|
|
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
|
+
});
|
|
16
29
|
}
|
|
30
|
+
if (canCache)
|
|
31
|
+
cache.set(mod, to);
|
|
17
32
|
return to;
|
|
18
33
|
};
|
|
19
|
-
var
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
34
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
27
35
|
|
|
28
36
|
// ../../node_modules/.bun/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
|
|
29
|
-
var require_src = __commonJS({
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
37
|
+
var require_src = __commonJS(function(exports, module) {
|
|
38
|
+
var ESC = "\x1B";
|
|
39
|
+
var CSI = `${ESC}[`;
|
|
40
|
+
var beep = "\x07";
|
|
41
|
+
var cursor = {
|
|
42
|
+
to(x, y) {
|
|
43
|
+
if (!y)
|
|
44
|
+
return `${CSI}${x + 1}G`;
|
|
45
|
+
return `${CSI}${y + 1};${x + 1}H`;
|
|
46
|
+
},
|
|
47
|
+
move(x, y) {
|
|
48
|
+
let ret = "";
|
|
49
|
+
if (x < 0)
|
|
50
|
+
ret += `${CSI}${-x}D`;
|
|
51
|
+
else if (x > 0)
|
|
52
|
+
ret += `${CSI}${x}C`;
|
|
53
|
+
if (y < 0)
|
|
54
|
+
ret += `${CSI}${-y}A`;
|
|
55
|
+
else if (y > 0)
|
|
56
|
+
ret += `${CSI}${y}B`;
|
|
57
|
+
return ret;
|
|
58
|
+
},
|
|
59
|
+
up: (count = 1) => `${CSI}${count}A`,
|
|
60
|
+
down: (count = 1) => `${CSI}${count}B`,
|
|
61
|
+
forward: (count = 1) => `${CSI}${count}C`,
|
|
62
|
+
backward: (count = 1) => `${CSI}${count}D`,
|
|
63
|
+
nextLine: (count = 1) => `${CSI}E`.repeat(count),
|
|
64
|
+
prevLine: (count = 1) => `${CSI}F`.repeat(count),
|
|
65
|
+
left: `${CSI}G`,
|
|
66
|
+
hide: `${CSI}?25l`,
|
|
67
|
+
show: `${CSI}?25h`,
|
|
68
|
+
save: `${ESC}7`,
|
|
69
|
+
restore: `${ESC}8`
|
|
70
|
+
};
|
|
71
|
+
var scroll = {
|
|
72
|
+
up: (count = 1) => `${CSI}S`.repeat(count),
|
|
73
|
+
down: (count = 1) => `${CSI}T`.repeat(count)
|
|
74
|
+
};
|
|
75
|
+
var erase = {
|
|
76
|
+
screen: `${CSI}2J`,
|
|
77
|
+
up: (count = 1) => `${CSI}1J`.repeat(count),
|
|
78
|
+
down: (count = 1) => `${CSI}J`.repeat(count),
|
|
79
|
+
line: `${CSI}2K`,
|
|
80
|
+
lineEnd: `${CSI}K`,
|
|
81
|
+
lineStart: `${CSI}1K`,
|
|
82
|
+
lines(count) {
|
|
83
|
+
let clear = "";
|
|
84
|
+
for (let i = 0;i < count; i++)
|
|
85
|
+
clear += this.line + (i < count - 1 ? cursor.up() : "");
|
|
86
|
+
if (count)
|
|
87
|
+
clear += cursor.left;
|
|
88
|
+
return clear;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
module.exports = { cursor, scroll, erase, beep };
|
|
82
92
|
});
|
|
83
93
|
|
|
84
94
|
// src/index.ts
|
|
85
|
-
import { spawnSync } from "child_process";
|
|
95
|
+
import { spawnSync } from "node:child_process";
|
|
86
96
|
import {
|
|
87
|
-
existsSync
|
|
97
|
+
existsSync,
|
|
88
98
|
mkdirSync,
|
|
89
|
-
readdirSync
|
|
99
|
+
readdirSync,
|
|
90
100
|
readFileSync,
|
|
91
101
|
writeFileSync
|
|
92
|
-
} from "fs";
|
|
93
|
-
import { basename, join
|
|
102
|
+
} from "node:fs";
|
|
103
|
+
import { basename, join, resolve } from "node:path";
|
|
94
104
|
|
|
95
105
|
// ../../node_modules/.bun/@clack+core@1.5.1/node_modules/@clack/core/dist/index.mjs
|
|
96
|
-
import { styleText } from "util";
|
|
97
|
-
import { stdout, stdin } from "process";
|
|
98
|
-
import * as l from "readline";
|
|
99
|
-
import l__default from "readline";
|
|
106
|
+
import { styleText } from "node:util";
|
|
107
|
+
import { stdout, stdin } from "node:process";
|
|
108
|
+
import * as l from "node:readline";
|
|
109
|
+
import l__default from "node:readline";
|
|
100
110
|
|
|
101
111
|
// ../../node_modules/.bun/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/utils.js
|
|
102
|
-
var getCodePointsLength =
|
|
112
|
+
var getCodePointsLength = (() => {
|
|
103
113
|
const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
|
104
114
|
return (input) => {
|
|
105
115
|
let surrogatePairsNr = 0;
|
|
@@ -122,9 +132,9 @@ var ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf
|
|
|
122
132
|
var CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
123
133
|
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;
|
|
124
134
|
var TAB_RE = /\t{1,1000}/y;
|
|
125
|
-
var EMOJI_RE =
|
|
135
|
+
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;
|
|
126
136
|
var LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
127
|
-
var MODIFIER_RE =
|
|
137
|
+
var MODIFIER_RE = /\p{M}+/gu;
|
|
128
138
|
var NO_TRUNCATION = { limit: Infinity, ellipsis: "" };
|
|
129
139
|
var getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
|
|
130
140
|
const LIMIT = truncationOptions.limit ?? Infinity;
|
|
@@ -156,56 +166,57 @@ var getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {})
|
|
|
156
166
|
let unmatchedEnd = 0;
|
|
157
167
|
let width = 0;
|
|
158
168
|
let widthExtra = 0;
|
|
159
|
-
outer:
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
169
|
+
outer:
|
|
170
|
+
while (true) {
|
|
171
|
+
if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
|
|
172
|
+
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
|
|
173
|
+
lengthExtra = 0;
|
|
174
|
+
for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
|
|
175
|
+
const codePoint = char.codePointAt(0) || 0;
|
|
176
|
+
if (isFullWidth(codePoint)) {
|
|
177
|
+
widthExtra = FULL_WIDTH_WIDTH;
|
|
178
|
+
} else if (isWideNotCJKTNotEmoji(codePoint)) {
|
|
179
|
+
widthExtra = WIDE_WIDTH;
|
|
180
|
+
} else {
|
|
181
|
+
widthExtra = REGULAR_WIDTH;
|
|
182
|
+
}
|
|
183
|
+
if (width + widthExtra > truncationLimit) {
|
|
184
|
+
truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
|
|
185
|
+
}
|
|
186
|
+
if (width + widthExtra > LIMIT) {
|
|
187
|
+
truncationEnabled = true;
|
|
188
|
+
break outer;
|
|
189
|
+
}
|
|
190
|
+
lengthExtra += char.length;
|
|
191
|
+
width += widthExtra;
|
|
178
192
|
}
|
|
179
|
-
|
|
180
|
-
width += widthExtra;
|
|
193
|
+
unmatchedStart = unmatchedEnd = 0;
|
|
181
194
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
195
|
+
if (index >= length) {
|
|
196
|
+
break outer;
|
|
197
|
+
}
|
|
198
|
+
for (let i = 0, l = PARSE_BLOCKS.length;i < l; i++) {
|
|
199
|
+
const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
|
|
200
|
+
BLOCK_RE.lastIndex = index;
|
|
201
|
+
if (BLOCK_RE.test(input)) {
|
|
202
|
+
lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
|
|
203
|
+
widthExtra = lengthExtra * BLOCK_WIDTH;
|
|
204
|
+
if (width + widthExtra > truncationLimit) {
|
|
205
|
+
truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
|
|
206
|
+
}
|
|
207
|
+
if (width + widthExtra > LIMIT) {
|
|
208
|
+
truncationEnabled = true;
|
|
209
|
+
break outer;
|
|
210
|
+
}
|
|
211
|
+
width += widthExtra;
|
|
212
|
+
unmatchedStart = indexPrev;
|
|
213
|
+
unmatchedEnd = index;
|
|
214
|
+
index = indexPrev = BLOCK_RE.lastIndex;
|
|
215
|
+
continue outer;
|
|
199
216
|
}
|
|
200
|
-
width += widthExtra;
|
|
201
|
-
unmatchedStart = indexPrev;
|
|
202
|
-
unmatchedEnd = index;
|
|
203
|
-
index = indexPrev = BLOCK_RE.lastIndex;
|
|
204
|
-
continue outer;
|
|
205
217
|
}
|
|
218
|
+
index += 1;
|
|
206
219
|
}
|
|
207
|
-
index += 1;
|
|
208
|
-
}
|
|
209
220
|
return {
|
|
210
221
|
width: truncationEnabled ? truncationLimit : width,
|
|
211
222
|
index: truncationEnabled ? truncationIndex : length,
|
|
@@ -228,7 +239,7 @@ var dist_default2 = fastStringWidth;
|
|
|
228
239
|
|
|
229
240
|
// ../../node_modules/.bun/fast-wrap-ansi@0.2.2/node_modules/fast-wrap-ansi/lib/main.js
|
|
230
241
|
var ESC = "\x1B";
|
|
231
|
-
var CSI = "
|
|
242
|
+
var CSI = "";
|
|
232
243
|
var END_CODE = 39;
|
|
233
244
|
var ANSI_ESCAPE_BELL = "\x07";
|
|
234
245
|
var ANSI_CSI = "[";
|
|
@@ -259,7 +270,7 @@ var getClosingCode = (openingCode) => {
|
|
|
259
270
|
return 29;
|
|
260
271
|
if (openingCode === 0)
|
|
261
272
|
return 0;
|
|
262
|
-
return
|
|
273
|
+
return;
|
|
263
274
|
};
|
|
264
275
|
var wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
265
276
|
var wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
|
|
@@ -268,7 +279,7 @@ var wrapWord = (rows, word, columns) => {
|
|
|
268
279
|
let isInsideEscape = false;
|
|
269
280
|
let isInsideLinkEscape = false;
|
|
270
281
|
let lastRow = rows.at(-1);
|
|
271
|
-
let visible = lastRow ===
|
|
282
|
+
let visible = lastRow === undefined ? 0 : dist_default2(lastRow);
|
|
272
283
|
let currentCharacter = characters.next();
|
|
273
284
|
let nextCharacter = characters.next();
|
|
274
285
|
let rawCharacterIndex = 0;
|
|
@@ -306,7 +317,7 @@ var wrapWord = (rows, word, columns) => {
|
|
|
306
317
|
rawCharacterIndex += character.length;
|
|
307
318
|
}
|
|
308
319
|
lastRow = rows.at(-1);
|
|
309
|
-
if (!visible && lastRow !==
|
|
320
|
+
if (!visible && lastRow !== undefined && lastRow.length && rows.length > 1) {
|
|
310
321
|
rows[rows.length - 2] += rows.pop();
|
|
311
322
|
}
|
|
312
323
|
};
|
|
@@ -334,7 +345,7 @@ var exec = (string, columns, options = {}) => {
|
|
|
334
345
|
const words = string.split(" ");
|
|
335
346
|
let rows = [""];
|
|
336
347
|
let rowLength = 0;
|
|
337
|
-
for (let index = 0;
|
|
348
|
+
for (let index = 0;index < words.length; index++) {
|
|
338
349
|
const word = words[index];
|
|
339
350
|
if (options.trim !== false) {
|
|
340
351
|
const row = rows.at(-1) ?? "";
|
|
@@ -386,10 +397,11 @@ var exec = (string, columns, options = {}) => {
|
|
|
386
397
|
if (options.trim !== false) {
|
|
387
398
|
rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
388
399
|
}
|
|
389
|
-
const preString = rows.join(
|
|
400
|
+
const preString = rows.join(`
|
|
401
|
+
`);
|
|
390
402
|
let inSurrogate = false;
|
|
391
|
-
for (let
|
|
392
|
-
const character = preString[
|
|
403
|
+
for (let i = 0;i < preString.length; i++) {
|
|
404
|
+
const character = preString[i];
|
|
393
405
|
returnValue += character;
|
|
394
406
|
if (!inSurrogate) {
|
|
395
407
|
inSurrogate = character >= "\uD800" && character <= "\uDBFF";
|
|
@@ -400,25 +412,27 @@ var exec = (string, columns, options = {}) => {
|
|
|
400
412
|
inSurrogate = false;
|
|
401
413
|
}
|
|
402
414
|
if (character === ESC || character === CSI) {
|
|
403
|
-
GROUP_REGEX.lastIndex =
|
|
415
|
+
GROUP_REGEX.lastIndex = i + 1;
|
|
404
416
|
const groupsResult = GROUP_REGEX.exec(preString);
|
|
405
417
|
const groups = groupsResult?.groups;
|
|
406
|
-
if (groups?.code !==
|
|
418
|
+
if (groups?.code !== undefined) {
|
|
407
419
|
const code = Number.parseFloat(groups.code);
|
|
408
|
-
escapeCode = code === END_CODE ?
|
|
409
|
-
} else if (groups?.uri !==
|
|
410
|
-
escapeUrl = groups.uri.length === 0 ?
|
|
420
|
+
escapeCode = code === END_CODE ? undefined : code;
|
|
421
|
+
} else if (groups?.uri !== undefined) {
|
|
422
|
+
escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
|
|
411
423
|
}
|
|
412
424
|
}
|
|
413
|
-
if (preString[
|
|
425
|
+
if (preString[i + 1] === `
|
|
426
|
+
`) {
|
|
414
427
|
if (escapeUrl) {
|
|
415
428
|
returnValue += wrapAnsiHyperlink("");
|
|
416
429
|
}
|
|
417
|
-
const closingCode = escapeCode ? getClosingCode(escapeCode) :
|
|
430
|
+
const closingCode = escapeCode ? getClosingCode(escapeCode) : undefined;
|
|
418
431
|
if (escapeCode && closingCode) {
|
|
419
432
|
returnValue += wrapAnsiCode(closingCode);
|
|
420
433
|
}
|
|
421
|
-
} else if (character ===
|
|
434
|
+
} else if (character === `
|
|
435
|
+
`) {
|
|
422
436
|
if (escapeCode && getClosingCode(escapeCode)) {
|
|
423
437
|
returnValue += wrapAnsiCode(escapeCode);
|
|
424
438
|
}
|
|
@@ -431,17 +445,18 @@ var exec = (string, columns, options = {}) => {
|
|
|
431
445
|
};
|
|
432
446
|
var CRLF_OR_LF = /\r?\n/;
|
|
433
447
|
function wrapAnsi(string, columns, options) {
|
|
434
|
-
return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join(
|
|
448
|
+
return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join(`
|
|
449
|
+
`);
|
|
435
450
|
}
|
|
436
451
|
|
|
437
452
|
// ../../node_modules/.bun/@clack+core@1.5.1/node_modules/@clack/core/dist/index.mjs
|
|
438
453
|
var import_sisteransi = __toESM(require_src(), 1);
|
|
439
|
-
import { ReadStream } from "tty";
|
|
440
|
-
function findCursor(s, o,
|
|
441
|
-
if (!
|
|
454
|
+
import { ReadStream } from "node:tty";
|
|
455
|
+
function findCursor(s, o, l) {
|
|
456
|
+
if (!l.some((r) => !r.disabled))
|
|
442
457
|
return s;
|
|
443
|
-
const
|
|
444
|
-
return
|
|
458
|
+
const t = s + o, n = Math.max(l.length - 1, 0), e = t < 0 ? n : t > n ? 0 : t;
|
|
459
|
+
return l[e]?.disabled ? findCursor(e, o < 0 ? -1 : 1, l) : e;
|
|
445
460
|
}
|
|
446
461
|
var a$1 = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
447
462
|
var t = [
|
|
@@ -461,13 +476,11 @@ var t = [
|
|
|
461
476
|
var settings = {
|
|
462
477
|
actions: new Set(a$1),
|
|
463
478
|
aliases: /* @__PURE__ */ new Map([
|
|
464
|
-
// vim support
|
|
465
479
|
["k", "up"],
|
|
466
480
|
["j", "down"],
|
|
467
481
|
["h", "left"],
|
|
468
482
|
["l", "right"],
|
|
469
|
-
["
|
|
470
|
-
// opinionated defaults!
|
|
483
|
+
["\x03", "cancel"],
|
|
471
484
|
["escape", "cancel"]
|
|
472
485
|
]),
|
|
473
486
|
messages: {
|
|
@@ -475,108 +488,113 @@ var settings = {
|
|
|
475
488
|
error: "Something went wrong"
|
|
476
489
|
},
|
|
477
490
|
withGuide: true,
|
|
478
|
-
accessible:
|
|
491
|
+
accessible: undefined,
|
|
479
492
|
date: {
|
|
480
493
|
monthNames: [...t],
|
|
481
494
|
messages: {
|
|
482
495
|
required: "Please enter a valid date",
|
|
483
496
|
invalidMonth: "There are only 12 months in a year",
|
|
484
|
-
invalidDay: (
|
|
485
|
-
afterMin: (
|
|
486
|
-
beforeMax: (
|
|
497
|
+
invalidDay: (n, e) => `There are only ${n} days in ${e}`,
|
|
498
|
+
afterMin: (n) => `Date must be on or after ${n.toISOString().slice(0, 10)}`,
|
|
499
|
+
beforeMax: (n) => `Date must be on or before ${n.toISOString().slice(0, 10)}`
|
|
487
500
|
}
|
|
488
501
|
}
|
|
489
502
|
};
|
|
490
|
-
function isAccessible(
|
|
491
|
-
if (
|
|
492
|
-
|
|
503
|
+
function isAccessible(n) {
|
|
504
|
+
if (n !== undefined)
|
|
505
|
+
return n;
|
|
506
|
+
if (settings.accessible !== undefined)
|
|
507
|
+
return settings.accessible;
|
|
493
508
|
const e = process.env.ACCESSIBLE;
|
|
494
|
-
return e !==
|
|
509
|
+
return e !== undefined && e !== "" && e !== "0" && e !== "false";
|
|
495
510
|
}
|
|
496
|
-
function isActionKey(
|
|
497
|
-
if (typeof
|
|
498
|
-
return settings.aliases.get(
|
|
499
|
-
for (const s of
|
|
500
|
-
if (s !==
|
|
511
|
+
function isActionKey(n, e) {
|
|
512
|
+
if (typeof n == "string")
|
|
513
|
+
return settings.aliases.get(n) === e;
|
|
514
|
+
for (const s of n)
|
|
515
|
+
if (s !== undefined && isActionKey(s, e))
|
|
501
516
|
return true;
|
|
502
517
|
return false;
|
|
503
518
|
}
|
|
504
|
-
function diffLines(
|
|
505
|
-
if (
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
`),
|
|
509
|
-
|
|
510
|
-
|
|
519
|
+
function diffLines(i, s) {
|
|
520
|
+
if (i === s)
|
|
521
|
+
return;
|
|
522
|
+
const e = i.split(`
|
|
523
|
+
`), t = s.split(`
|
|
524
|
+
`), r = Math.max(e.length, t.length), f = [];
|
|
525
|
+
for (let n = 0;n < r; n++)
|
|
526
|
+
e[n] !== t[n] && f.push(n);
|
|
511
527
|
return {
|
|
512
528
|
lines: f,
|
|
513
529
|
numLinesBefore: e.length,
|
|
514
|
-
numLinesAfter:
|
|
515
|
-
numLines:
|
|
530
|
+
numLinesAfter: t.length,
|
|
531
|
+
numLines: r
|
|
516
532
|
};
|
|
517
533
|
}
|
|
518
534
|
var R = globalThis.process.platform.startsWith("win");
|
|
519
|
-
var CANCEL_SYMBOL =
|
|
535
|
+
var CANCEL_SYMBOL = Symbol("clack:cancel");
|
|
520
536
|
function isCancel(e) {
|
|
521
537
|
return e === CANCEL_SYMBOL;
|
|
522
538
|
}
|
|
523
|
-
function setRawMode(e,
|
|
539
|
+
function setRawMode(e, r) {
|
|
524
540
|
const o = e;
|
|
525
|
-
o.isTTY && o.setRawMode(
|
|
541
|
+
o.isTTY && o.setRawMode(r);
|
|
526
542
|
}
|
|
527
543
|
function block({
|
|
528
544
|
input: e = stdin,
|
|
529
|
-
output:
|
|
545
|
+
output: r = stdout,
|
|
530
546
|
overwrite: o = true,
|
|
531
|
-
hideCursor:
|
|
547
|
+
hideCursor: n = true
|
|
532
548
|
} = {}) {
|
|
533
549
|
const s = l.createInterface({
|
|
534
550
|
input: e,
|
|
535
|
-
output:
|
|
551
|
+
output: r,
|
|
536
552
|
prompt: "",
|
|
537
553
|
tabSize: 1
|
|
538
554
|
});
|
|
539
555
|
l.emitKeypressEvents(e, s), e instanceof ReadStream && e.isTTY && e.setRawMode(true);
|
|
540
|
-
const
|
|
541
|
-
const
|
|
542
|
-
if (isActionKey([
|
|
543
|
-
|
|
556
|
+
const t = (f, { name: a, sequence: w }) => {
|
|
557
|
+
const c = String(f);
|
|
558
|
+
if (isActionKey([c, a, w], "cancel")) {
|
|
559
|
+
n && r.write(import_sisteransi.cursor.show), process.exit(0);
|
|
544
560
|
return;
|
|
545
561
|
}
|
|
546
|
-
if (!o)
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
562
|
+
if (!o)
|
|
563
|
+
return;
|
|
564
|
+
const i = a === "return" ? 0 : -1, m = a === "return" ? -1 : 0;
|
|
565
|
+
l.moveCursor(r, i, m, () => {
|
|
566
|
+
l.clearLine(r, 1, () => {
|
|
567
|
+
e.once("keypress", t);
|
|
551
568
|
});
|
|
552
569
|
});
|
|
553
570
|
};
|
|
554
|
-
return
|
|
555
|
-
e.off("keypress",
|
|
571
|
+
return n && r.write(import_sisteransi.cursor.hide), e.once("keypress", t), () => {
|
|
572
|
+
e.off("keypress", t), n && r.write(import_sisteransi.cursor.show), e instanceof ReadStream && e.isTTY && !R && e.setRawMode(false), s.terminal = false, s.close();
|
|
556
573
|
};
|
|
557
574
|
}
|
|
558
|
-
var getColumns = (e) => "columns" in e && typeof e.columns == "number" ? e.columns : 80;
|
|
559
|
-
var getRows = (e) => "rows" in e && typeof e.rows == "number" ? e.rows : 20;
|
|
560
|
-
function wrapTextWithPrefix(e,
|
|
575
|
+
var getColumns = (e) => ("columns" in e) && typeof e.columns == "number" ? e.columns : 80;
|
|
576
|
+
var getRows = (e) => ("rows" in e) && typeof e.rows == "number" ? e.rows : 20;
|
|
577
|
+
function wrapTextWithPrefix(e, r, o, n = o, s = o, t) {
|
|
561
578
|
const f = getColumns(e ?? stdout);
|
|
562
|
-
return wrapAnsi(
|
|
579
|
+
return wrapAnsi(r, f - o.length, {
|
|
563
580
|
hard: true,
|
|
564
581
|
trim: false
|
|
565
582
|
}).split(`
|
|
566
|
-
`).map((
|
|
567
|
-
const d =
|
|
568
|
-
return
|
|
583
|
+
`).map((c, i, m) => {
|
|
584
|
+
const d = t ? t(c, i) : c;
|
|
585
|
+
return i === 0 ? `${n}${d}` : i === m.length - 1 ? `${s}${d}` : `${o}${d}`;
|
|
569
586
|
}).join(`
|
|
570
587
|
`);
|
|
571
588
|
}
|
|
572
|
-
function runValidation(e,
|
|
589
|
+
function runValidation(e, a) {
|
|
573
590
|
if ("~standard" in e) {
|
|
574
|
-
const
|
|
575
|
-
return
|
|
591
|
+
const n = e["~standard"].validate(a);
|
|
592
|
+
return n instanceof Promise ? n.then((r) => r.issues?.at(0)?.message) : n.issues?.at(0)?.message;
|
|
576
593
|
}
|
|
577
|
-
return e(
|
|
594
|
+
return e(a);
|
|
578
595
|
}
|
|
579
|
-
|
|
596
|
+
|
|
597
|
+
class y {
|
|
580
598
|
input;
|
|
581
599
|
output;
|
|
582
600
|
_abortSignal;
|
|
@@ -585,78 +603,47 @@ var y = class {
|
|
|
585
603
|
_render;
|
|
586
604
|
_track = false;
|
|
587
605
|
_prevFrame = "";
|
|
588
|
-
_subscribers = /* @__PURE__ */ new Map
|
|
606
|
+
_subscribers = /* @__PURE__ */ new Map;
|
|
589
607
|
_cursor = 0;
|
|
590
608
|
state = "initial";
|
|
591
609
|
error = "";
|
|
592
610
|
value;
|
|
593
611
|
userInput = "";
|
|
594
|
-
/**
|
|
595
|
-
* Whether accessible (static, screen-reader friendly) output is enabled for
|
|
596
|
-
* this prompt, resolved from the `accessible` option, the global setting,
|
|
597
|
-
* and the `ACCESSIBLE` env var.
|
|
598
|
-
*/
|
|
599
612
|
get accessible() {
|
|
600
613
|
return isAccessible(this.opts.accessible);
|
|
601
614
|
}
|
|
602
|
-
constructor(
|
|
603
|
-
const { input:
|
|
604
|
-
this.opts = o, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render =
|
|
615
|
+
constructor(t, e = true) {
|
|
616
|
+
const { input: i = stdin, output: s = stdout, render: r, signal: n, ...o } = t;
|
|
617
|
+
this.opts = o, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = r.bind(this), this._track = e, this._abortSignal = n, this.input = i, this.output = s;
|
|
605
618
|
}
|
|
606
|
-
/**
|
|
607
|
-
* Unsubscribe all listeners
|
|
608
|
-
*/
|
|
609
619
|
unsubscribe() {
|
|
610
620
|
this._subscribers.clear();
|
|
611
621
|
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
*/
|
|
616
|
-
setSubscriber(t2, e) {
|
|
617
|
-
const i2 = this._subscribers.get(t2) ?? [];
|
|
618
|
-
i2.push(e), this._subscribers.set(t2, i2);
|
|
622
|
+
setSubscriber(t, e) {
|
|
623
|
+
const i = this._subscribers.get(t) ?? [];
|
|
624
|
+
i.push(e), this._subscribers.set(t, i);
|
|
619
625
|
}
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
* @param event - The event name
|
|
623
|
-
* @param cb - The callback
|
|
624
|
-
*/
|
|
625
|
-
on(t2, e) {
|
|
626
|
-
this.setSubscriber(t2, { cb: e });
|
|
626
|
+
on(t, e) {
|
|
627
|
+
this.setSubscriber(t, { cb: e });
|
|
627
628
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
* @param event - The event name
|
|
631
|
-
* @param cb - The callback
|
|
632
|
-
*/
|
|
633
|
-
once(t2, e) {
|
|
634
|
-
this.setSubscriber(t2, { cb: e, once: true });
|
|
629
|
+
once(t, e) {
|
|
630
|
+
this.setSubscriber(t, { cb: e, once: true });
|
|
635
631
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
const i2 = this._subscribers.get(t2) ?? [], s = [];
|
|
643
|
-
for (const r2 of i2)
|
|
644
|
-
r2.cb(...e), r2.once && s.push(() => i2.splice(i2.indexOf(r2), 1));
|
|
645
|
-
for (const r2 of s)
|
|
646
|
-
r2();
|
|
632
|
+
emit(t, ...e) {
|
|
633
|
+
const i = this._subscribers.get(t) ?? [], s = [];
|
|
634
|
+
for (const r of i)
|
|
635
|
+
r.cb(...e), r.once && s.push(() => i.splice(i.indexOf(r), 1));
|
|
636
|
+
for (const r of s)
|
|
637
|
+
r();
|
|
647
638
|
}
|
|
648
639
|
prompt() {
|
|
649
|
-
return new Promise((
|
|
640
|
+
return new Promise((t) => {
|
|
650
641
|
if (this._abortSignal) {
|
|
651
642
|
if (this._abortSignal.aborted)
|
|
652
|
-
return this.state = "cancel", this.close(),
|
|
653
|
-
this._abortSignal.addEventListener(
|
|
654
|
-
"
|
|
655
|
-
|
|
656
|
-
this.state = "cancel", this.close();
|
|
657
|
-
},
|
|
658
|
-
{ once: true }
|
|
659
|
-
);
|
|
643
|
+
return this.state = "cancel", this.close(), t(CANCEL_SYMBOL);
|
|
644
|
+
this._abortSignal.addEventListener("abort", () => {
|
|
645
|
+
this.state = "cancel", this.close();
|
|
646
|
+
}, { once: true });
|
|
660
647
|
}
|
|
661
648
|
this.rl = l__default.createInterface({
|
|
662
649
|
input: this.input,
|
|
@@ -664,111 +651,111 @@ var y = class {
|
|
|
664
651
|
prompt: "",
|
|
665
652
|
escapeCodeTimeout: 50,
|
|
666
653
|
terminal: true
|
|
667
|
-
}), this.rl.prompt(), this.opts.initialUserInput !==
|
|
668
|
-
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false),
|
|
654
|
+
}), 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", () => {
|
|
655
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(this.value);
|
|
669
656
|
}), this.once("cancel", () => {
|
|
670
|
-
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false),
|
|
657
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(CANCEL_SYMBOL);
|
|
671
658
|
});
|
|
672
659
|
});
|
|
673
660
|
}
|
|
674
|
-
_isActionKey(
|
|
675
|
-
return
|
|
661
|
+
_isActionKey(t, e) {
|
|
662
|
+
return t === "\t";
|
|
676
663
|
}
|
|
677
|
-
_shouldSubmit(
|
|
664
|
+
_shouldSubmit(t, e) {
|
|
678
665
|
return true;
|
|
679
666
|
}
|
|
680
|
-
_setValue(
|
|
681
|
-
this.value =
|
|
667
|
+
_setValue(t) {
|
|
668
|
+
this.value = t, this.emit("value", this.value);
|
|
682
669
|
}
|
|
683
|
-
_setUserInput(
|
|
684
|
-
this.userInput =
|
|
670
|
+
_setUserInput(t, e) {
|
|
671
|
+
this.userInput = t ?? "", this.emit("userInput", this.userInput), e && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
|
|
685
672
|
}
|
|
686
673
|
_clearUserInput() {
|
|
687
674
|
this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
|
|
688
675
|
}
|
|
689
|
-
async onKeypress(
|
|
676
|
+
async onKeypress(t, e) {
|
|
690
677
|
if (this.state !== "validating") {
|
|
691
|
-
if (this._track && e.name !== "return" && (e.name && this._isActionKey(
|
|
678
|
+
if (this._track && e.name !== "return" && (e.name && this._isActionKey(t, 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)), t && (t.toLowerCase() === "y" || t.toLowerCase() === "n") && this.emit("confirm", t.toLowerCase() === "y"), this.emit("key", t, e), e?.name === "return" && this._shouldSubmit(t, e)) {
|
|
692
679
|
if (this.opts.validate) {
|
|
693
|
-
const
|
|
680
|
+
const i = runValidation(this.opts.validate, this.value);
|
|
694
681
|
let s;
|
|
695
|
-
|
|
682
|
+
i instanceof Promise ? (this.state = "validating", this.render(), s = await i) : s = i, s && (this.error = s instanceof Error ? s.message : s, this.state = "error", this.rl?.write(this.userInput));
|
|
696
683
|
}
|
|
697
684
|
this.state !== "error" && (this.state = "submit");
|
|
698
685
|
}
|
|
699
|
-
isActionKey([
|
|
686
|
+
isActionKey([t, 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();
|
|
700
687
|
}
|
|
701
688
|
}
|
|
702
689
|
close() {
|
|
703
690
|
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
704
|
-
`), setRawMode(this.input, false), this.rl?.close(), this.rl =
|
|
691
|
+
`), setRawMode(this.input, false), this.rl?.close(), this.rl = undefined, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
705
692
|
}
|
|
706
693
|
restoreCursor() {
|
|
707
|
-
const
|
|
694
|
+
const t = wrapAnsi(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
|
|
708
695
|
`).length - 1;
|
|
709
|
-
this.output.write(import_sisteransi.cursor.move(-999,
|
|
696
|
+
this.output.write(import_sisteransi.cursor.move(-999, t * -1));
|
|
710
697
|
}
|
|
711
698
|
render() {
|
|
712
|
-
const
|
|
699
|
+
const t = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
|
|
713
700
|
hard: true,
|
|
714
701
|
trim: false
|
|
715
702
|
});
|
|
716
|
-
if (
|
|
703
|
+
if (t !== this._prevFrame) {
|
|
717
704
|
if (this.state === "initial")
|
|
718
705
|
this.output.write(import_sisteransi.cursor.hide);
|
|
719
706
|
else {
|
|
720
|
-
const e = diffLines(this._prevFrame,
|
|
707
|
+
const e = diffLines(this._prevFrame, t), i = getRows(this.output);
|
|
721
708
|
if (this.restoreCursor(), e) {
|
|
722
|
-
const s = Math.max(0, e.numLinesAfter -
|
|
723
|
-
let
|
|
724
|
-
if (
|
|
725
|
-
this._prevFrame =
|
|
709
|
+
const s = Math.max(0, e.numLinesAfter - i), r = Math.max(0, e.numLinesBefore - i);
|
|
710
|
+
let n = e.lines.find((o) => o >= s);
|
|
711
|
+
if (n === undefined) {
|
|
712
|
+
this._prevFrame = t;
|
|
726
713
|
return;
|
|
727
714
|
}
|
|
728
715
|
if (e.lines.length === 1) {
|
|
729
|
-
this.output.write(import_sisteransi.cursor.move(0,
|
|
730
|
-
const o =
|
|
716
|
+
this.output.write(import_sisteransi.cursor.move(0, n - r)), this.output.write(import_sisteransi.erase.lines(1));
|
|
717
|
+
const o = t.split(`
|
|
731
718
|
`);
|
|
732
|
-
this.output.write(o[
|
|
719
|
+
this.output.write(o[n]), this._prevFrame = t, this.output.write(import_sisteransi.cursor.move(0, o.length - n - 1));
|
|
733
720
|
return;
|
|
734
721
|
} else if (e.lines.length > 1) {
|
|
735
|
-
if (s <
|
|
736
|
-
|
|
722
|
+
if (s < r)
|
|
723
|
+
n = s;
|
|
737
724
|
else {
|
|
738
|
-
const
|
|
739
|
-
|
|
725
|
+
const h = n - r;
|
|
726
|
+
h > 0 && this.output.write(import_sisteransi.cursor.move(0, h));
|
|
740
727
|
}
|
|
741
728
|
this.output.write(import_sisteransi.erase.down());
|
|
742
|
-
const f =
|
|
743
|
-
`).slice(
|
|
729
|
+
const f = t.split(`
|
|
730
|
+
`).slice(n);
|
|
744
731
|
this.output.write(f.join(`
|
|
745
|
-
`)), this._prevFrame =
|
|
732
|
+
`)), this._prevFrame = t;
|
|
746
733
|
return;
|
|
747
734
|
}
|
|
748
735
|
}
|
|
749
736
|
this.output.write(import_sisteransi.erase.down());
|
|
750
737
|
}
|
|
751
|
-
this.output.write(
|
|
738
|
+
this.output.write(t), this.state === "initial" && (this.state = "active"), this._prevFrame = t;
|
|
752
739
|
}
|
|
753
740
|
}
|
|
754
|
-
}
|
|
755
|
-
|
|
741
|
+
}
|
|
742
|
+
class r extends y {
|
|
756
743
|
get cursor() {
|
|
757
744
|
return this.value ? 0 : 1;
|
|
758
745
|
}
|
|
759
746
|
get _value() {
|
|
760
747
|
return this.cursor === 0;
|
|
761
748
|
}
|
|
762
|
-
constructor(
|
|
763
|
-
super(
|
|
749
|
+
constructor(t) {
|
|
750
|
+
super(t, false), this.value = !!t.initialValue, this.on("userInput", () => {
|
|
764
751
|
this.value = this._value;
|
|
765
|
-
}), this.on("confirm", (
|
|
766
|
-
this.output.write(import_sisteransi.cursor.move(0, -1)), this.value =
|
|
752
|
+
}), this.on("confirm", (i) => {
|
|
753
|
+
this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = i, this.state = "submit", this.close();
|
|
767
754
|
}), this.on("cursor", () => {
|
|
768
755
|
this.value = !this.value;
|
|
769
756
|
});
|
|
770
757
|
}
|
|
771
|
-
}
|
|
758
|
+
}
|
|
772
759
|
var n$1 = class n extends y {
|
|
773
760
|
options;
|
|
774
761
|
cursor = 0;
|
|
@@ -777,12 +764,12 @@ var n$1 = class n extends y {
|
|
|
777
764
|
}
|
|
778
765
|
changeValue() {
|
|
779
766
|
const e = this._selectedValue;
|
|
780
|
-
this.value = e ===
|
|
767
|
+
this.value = e === undefined ? undefined : e.value;
|
|
781
768
|
}
|
|
782
769
|
constructor(e) {
|
|
783
770
|
super(e, false), this.options = e.options;
|
|
784
|
-
const o = this.options.findIndex(({ value: s }) => s === e.initialValue),
|
|
785
|
-
this.cursor = this.options[
|
|
771
|
+
const o = this.options.findIndex(({ value: s }) => s === e.initialValue), t = o === -1 ? 0 : o;
|
|
772
|
+
this.cursor = this.options[t]?.disabled ? findCursor(t, 1, this.options) : t, this.changeValue(), this.on("cursor", (s) => {
|
|
786
773
|
switch (s) {
|
|
787
774
|
case "left":
|
|
788
775
|
case "up":
|
|
@@ -797,37 +784,35 @@ var n$1 = class n extends y {
|
|
|
797
784
|
});
|
|
798
785
|
}
|
|
799
786
|
};
|
|
800
|
-
|
|
787
|
+
class n extends y {
|
|
801
788
|
get userInputWithCursor() {
|
|
802
789
|
if (this.state === "submit")
|
|
803
790
|
return this.userInput;
|
|
804
|
-
const
|
|
805
|
-
if (this.cursor >=
|
|
806
|
-
return `${this.userInput}
|
|
807
|
-
const
|
|
808
|
-
return `${
|
|
791
|
+
const t = this.userInput;
|
|
792
|
+
if (this.cursor >= t.length)
|
|
793
|
+
return `${this.userInput}█`;
|
|
794
|
+
const r = t.slice(0, this.cursor), s = t.slice(this.cursor, this.cursor + 1), e = t.slice(this.cursor + 1);
|
|
795
|
+
return `${r}${styleText("inverse", s)}${e}`;
|
|
809
796
|
}
|
|
810
797
|
get cursor() {
|
|
811
798
|
return this._cursor;
|
|
812
799
|
}
|
|
813
|
-
constructor(
|
|
800
|
+
constructor(t) {
|
|
814
801
|
super({
|
|
815
|
-
...
|
|
816
|
-
initialUserInput:
|
|
817
|
-
}), this.on("userInput", (
|
|
818
|
-
this._setValue(
|
|
802
|
+
...t,
|
|
803
|
+
initialUserInput: t.initialUserInput ?? t.initialValue
|
|
804
|
+
}), this.on("userInput", (r) => {
|
|
805
|
+
this._setValue(r);
|
|
819
806
|
}), this.on("finalize", () => {
|
|
820
|
-
this.value || (this.value =
|
|
807
|
+
this.value || (this.value = t.defaultValue), this.value === undefined && (this.value = "");
|
|
821
808
|
});
|
|
822
809
|
}
|
|
823
|
-
}
|
|
810
|
+
}
|
|
824
811
|
|
|
825
812
|
// ../../node_modules/.bun/@clack+prompts@1.8.1/node_modules/@clack/prompts/dist/index.mjs
|
|
826
|
-
import { styleText as styleText2, stripVTControlCharacters } from "util";
|
|
827
|
-
import process$1 from "process";
|
|
813
|
+
import { styleText as styleText2, stripVTControlCharacters } from "node:util";
|
|
814
|
+
import process$1 from "node:process";
|
|
828
815
|
var import_sisteransi2 = __toESM(require_src(), 1);
|
|
829
|
-
import { existsSync, lstatSync, readdirSync } from "fs";
|
|
830
|
-
import { dirname, join } from "path";
|
|
831
816
|
function isUnicodeSupported() {
|
|
832
817
|
if (process$1.platform !== "win32") {
|
|
833
818
|
return process$1.env.TERM !== "linux";
|
|
@@ -837,31 +822,31 @@ function isUnicodeSupported() {
|
|
|
837
822
|
var unicode = isUnicodeSupported();
|
|
838
823
|
var isCI = () => process.env.CI === "true";
|
|
839
824
|
var unicodeOr = (o, e) => unicode ? o : e;
|
|
840
|
-
var S_STEP_ACTIVE = unicodeOr("
|
|
841
|
-
var S_STEP_CANCEL = unicodeOr("
|
|
842
|
-
var S_STEP_ERROR = unicodeOr("
|
|
843
|
-
var S_STEP_SUBMIT = unicodeOr("
|
|
844
|
-
var S_BAR_START = unicodeOr("
|
|
845
|
-
var S_BAR = unicodeOr("
|
|
846
|
-
var S_BAR_END = unicodeOr("
|
|
847
|
-
var S_BAR_START_RIGHT = unicodeOr("
|
|
848
|
-
var S_BAR_END_RIGHT = unicodeOr("
|
|
849
|
-
var S_RADIO_ACTIVE = unicodeOr("
|
|
850
|
-
var S_RADIO_INACTIVE = unicodeOr("
|
|
851
|
-
var S_CHECKBOX_ACTIVE = unicodeOr("
|
|
852
|
-
var S_CHECKBOX_SELECTED = unicodeOr("
|
|
853
|
-
var S_CHECKBOX_INACTIVE = unicodeOr("
|
|
854
|
-
var S_PASSWORD_MASK = unicodeOr("
|
|
855
|
-
var S_BAR_H = unicodeOr("
|
|
856
|
-
var S_CORNER_TOP_RIGHT = unicodeOr("
|
|
857
|
-
var S_CONNECT_LEFT = unicodeOr("
|
|
858
|
-
var S_CORNER_BOTTOM_RIGHT = unicodeOr("
|
|
859
|
-
var S_CORNER_BOTTOM_LEFT = unicodeOr("
|
|
860
|
-
var S_CORNER_TOP_LEFT = unicodeOr("
|
|
861
|
-
var S_INFO = unicodeOr("
|
|
862
|
-
var S_SUCCESS = unicodeOr("
|
|
863
|
-
var S_WARN = unicodeOr("
|
|
864
|
-
var S_ERROR = unicodeOr("
|
|
825
|
+
var S_STEP_ACTIVE = unicodeOr("◆", "*");
|
|
826
|
+
var S_STEP_CANCEL = unicodeOr("■", "x");
|
|
827
|
+
var S_STEP_ERROR = unicodeOr("▲", "x");
|
|
828
|
+
var S_STEP_SUBMIT = unicodeOr("◇", "o");
|
|
829
|
+
var S_BAR_START = unicodeOr("┌", "T");
|
|
830
|
+
var S_BAR = unicodeOr("│", "|");
|
|
831
|
+
var S_BAR_END = unicodeOr("└", "—");
|
|
832
|
+
var S_BAR_START_RIGHT = unicodeOr("┐", "T");
|
|
833
|
+
var S_BAR_END_RIGHT = unicodeOr("┘", "—");
|
|
834
|
+
var S_RADIO_ACTIVE = unicodeOr("●", ">");
|
|
835
|
+
var S_RADIO_INACTIVE = unicodeOr("○", " ");
|
|
836
|
+
var S_CHECKBOX_ACTIVE = unicodeOr("◻", "[•]");
|
|
837
|
+
var S_CHECKBOX_SELECTED = unicodeOr("◼", "[+]");
|
|
838
|
+
var S_CHECKBOX_INACTIVE = unicodeOr("◻", "[ ]");
|
|
839
|
+
var S_PASSWORD_MASK = unicodeOr("▪", "•");
|
|
840
|
+
var S_BAR_H = unicodeOr("─", "-");
|
|
841
|
+
var S_CORNER_TOP_RIGHT = unicodeOr("╮", "+");
|
|
842
|
+
var S_CONNECT_LEFT = unicodeOr("├", "+");
|
|
843
|
+
var S_CORNER_BOTTOM_RIGHT = unicodeOr("╯", "+");
|
|
844
|
+
var S_CORNER_BOTTOM_LEFT = unicodeOr("╰", "+");
|
|
845
|
+
var S_CORNER_TOP_LEFT = unicodeOr("╭", "+");
|
|
846
|
+
var S_INFO = unicodeOr("●", "•");
|
|
847
|
+
var S_SUCCESS = unicodeOr("◆", "*");
|
|
848
|
+
var S_WARN = unicodeOr("▲", "!");
|
|
849
|
+
var S_ERROR = unicodeOr("■", "x");
|
|
865
850
|
var symbol = (o) => {
|
|
866
851
|
switch (o) {
|
|
867
852
|
case "initial":
|
|
@@ -891,106 +876,90 @@ var symbolBar = (o) => {
|
|
|
891
876
|
}
|
|
892
877
|
};
|
|
893
878
|
function formatInstructionFooter(o, e) {
|
|
894
|
-
const
|
|
895
|
-
return e &&
|
|
879
|
+
const r = [`${e ? `${styleText2("cyan", S_BAR)} ` : ""}${o.join(" • ")}`];
|
|
880
|
+
return e && r.push(styleText2("cyan", S_BAR_END)), r;
|
|
896
881
|
}
|
|
897
|
-
var I = (
|
|
898
|
-
let
|
|
899
|
-
if (
|
|
900
|
-
for (let
|
|
901
|
-
const m =
|
|
902
|
-
if (m && (
|
|
882
|
+
var I = (l, e, w, p, b, C = false) => {
|
|
883
|
+
let r = e, O = 0;
|
|
884
|
+
if (C)
|
|
885
|
+
for (let i = p - 1;i >= w; i--) {
|
|
886
|
+
const m = l[i];
|
|
887
|
+
if (m && (r -= m.length), O++, r <= b)
|
|
888
|
+
break;
|
|
903
889
|
}
|
|
904
890
|
else
|
|
905
|
-
for (let
|
|
906
|
-
const m =
|
|
907
|
-
if (m && (
|
|
891
|
+
for (let i = w;i < p; i++) {
|
|
892
|
+
const m = l[i];
|
|
893
|
+
if (m && (r -= m.length), O++, r <= b)
|
|
894
|
+
break;
|
|
908
895
|
}
|
|
909
|
-
return { lineCount:
|
|
896
|
+
return { lineCount: r, removals: O };
|
|
910
897
|
};
|
|
911
898
|
var limitOptions = ({
|
|
912
|
-
cursor:
|
|
899
|
+
cursor: l,
|
|
913
900
|
options: e,
|
|
914
901
|
style: w,
|
|
915
902
|
output: p = process.stdout,
|
|
916
903
|
maxItems: b = Number.POSITIVE_INFINITY,
|
|
917
|
-
columnPadding:
|
|
918
|
-
rowPadding:
|
|
904
|
+
columnPadding: C = 0,
|
|
905
|
+
rowPadding: r = 4
|
|
919
906
|
}) => {
|
|
920
|
-
const
|
|
907
|
+
const i = getColumns(p) - C, m = getRows(p), M = styleText2("dim", "..."), v = Math.max(m - r, 0), a = Math.max(Math.min(b, v), 5);
|
|
921
908
|
let f = 0;
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
));
|
|
926
|
-
let d = a2 < e.length && f > 0, c2 = a2 < e.length && f + a2 < e.length;
|
|
927
|
-
const W2 = Math.min(
|
|
928
|
-
f + a2,
|
|
929
|
-
e.length
|
|
930
|
-
), s = [];
|
|
909
|
+
l >= a - 3 && (f = Math.max(Math.min(l - a + 3, e.length - a), 0));
|
|
910
|
+
let d = a < e.length && f > 0, c = a < e.length && f + a < e.length;
|
|
911
|
+
const W = Math.min(f + a, e.length), s = [];
|
|
931
912
|
let g = 0;
|
|
932
|
-
d && g++,
|
|
933
|
-
const T = f + (d ? 1 : 0),
|
|
934
|
-
for (let
|
|
935
|
-
const
|
|
913
|
+
d && g++, c && g++;
|
|
914
|
+
const T = f + (d ? 1 : 0), y = W - (c ? 1 : 0);
|
|
915
|
+
for (let t = T;t < y; t++) {
|
|
916
|
+
const n = e[t], o = n ? w(n, t === l) : "", h = wrapAnsi(o, i, {
|
|
936
917
|
hard: true,
|
|
937
918
|
trim: false
|
|
938
919
|
}).split(`
|
|
939
920
|
`);
|
|
940
|
-
s.push(
|
|
921
|
+
s.push(h), g += h.length;
|
|
941
922
|
}
|
|
942
923
|
if (g > v) {
|
|
943
|
-
let
|
|
944
|
-
const
|
|
945
|
-
let
|
|
946
|
-
const L = () => I(s, o, 0,
|
|
947
|
-
|
|
948
|
-
o,
|
|
949
|
-
h2 + 1,
|
|
950
|
-
s.length,
|
|
951
|
-
u3,
|
|
952
|
-
true
|
|
953
|
-
);
|
|
954
|
-
d ? ({ lineCount: o, removals: t2 } = L(), o > u3 && (c2 || (u3 -= 1), { lineCount: o, removals: n3 } = E())) : (c2 || (u3 -= 1), { lineCount: o, removals: n3 } = E(), o > u3 && (u3 -= 1, { lineCount: o, removals: t2 } = L())), t2 > 0 && (d = true, s.splice(0, t2)), n3 > 0 && (c2 = true, s.splice(s.length - n3, n3));
|
|
924
|
+
let t = 0, n = 0, o = g;
|
|
925
|
+
const h = l - T;
|
|
926
|
+
let u = v;
|
|
927
|
+
const L = () => I(s, o, 0, h, u), E = () => I(s, o, h + 1, s.length, u, true);
|
|
928
|
+
d ? ({ lineCount: o, removals: t } = L(), o > u && (c || (u -= 1), { lineCount: o, removals: n } = E())) : (c || (u -= 1), { lineCount: o, removals: n } = E(), o > u && (u -= 1, { lineCount: o, removals: t } = L())), t > 0 && (d = true, s.splice(0, t)), n > 0 && (c = true, s.splice(s.length - n, n));
|
|
955
929
|
}
|
|
956
930
|
const x = [];
|
|
957
931
|
d && x.push(M);
|
|
958
|
-
for (const
|
|
959
|
-
for (const
|
|
960
|
-
x.push(
|
|
961
|
-
return
|
|
932
|
+
for (const t of s)
|
|
933
|
+
for (const n of t)
|
|
934
|
+
x.push(n);
|
|
935
|
+
return c && x.push(M), x;
|
|
962
936
|
};
|
|
963
937
|
var confirm = (e) => {
|
|
964
|
-
const
|
|
938
|
+
const a = e.active ?? "Yes", o = e.inactive ?? "No";
|
|
965
939
|
return new r({
|
|
966
|
-
active:
|
|
940
|
+
active: a,
|
|
967
941
|
inactive: o,
|
|
968
942
|
signal: e.signal,
|
|
969
943
|
input: e.input,
|
|
970
944
|
output: e.output,
|
|
971
945
|
initialValue: e.initialValue ?? true,
|
|
972
946
|
render() {
|
|
973
|
-
const
|
|
974
|
-
e.output,
|
|
975
|
-
e.message,
|
|
976
|
-
l2,
|
|
977
|
-
u3
|
|
978
|
-
), s = `${i2 ? `${styleText2("gray", S_BAR)}
|
|
947
|
+
const i = e.withGuide ?? settings.withGuide, u = `${symbol(this.state)} `, l = i ? `${styleText2("gray", S_BAR)} ` : "", f = wrapTextWithPrefix(e.output, e.message, l, u), s = `${i ? `${styleText2("gray", S_BAR)}
|
|
979
948
|
` : ""}${f}
|
|
980
|
-
`,
|
|
949
|
+
`, c = this.value ? a : o;
|
|
981
950
|
switch (this.state) {
|
|
982
951
|
case "submit": {
|
|
983
|
-
const
|
|
984
|
-
return `${s}${
|
|
952
|
+
const r = i ? `${styleText2("gray", S_BAR)} ` : "";
|
|
953
|
+
return `${s}${r}${styleText2("dim", c)}`;
|
|
985
954
|
}
|
|
986
955
|
case "cancel": {
|
|
987
|
-
const
|
|
988
|
-
return `${s}${
|
|
956
|
+
const r = i ? `${styleText2("gray", S_BAR)} ` : "";
|
|
957
|
+
return `${s}${r}${styleText2(["strikethrough", "dim"], c)}${i ? `
|
|
989
958
|
${styleText2("gray", S_BAR)}` : ""}`;
|
|
990
959
|
}
|
|
991
960
|
default: {
|
|
992
|
-
const
|
|
993
|
-
return `${s}${
|
|
961
|
+
const r = i ? `${styleText2("cyan", S_BAR)} ` : "", g = i ? styleText2("cyan", S_BAR_END) : "";
|
|
962
|
+
return `${s}${r}${this.value ? `${styleText2("green", S_RADIO_ACTIVE)} ${a}` : `${styleText2("dim", S_RADIO_INACTIVE)} ${styleText2("dim", a)}`}${e.vertical ? i ? `
|
|
994
963
|
${styleText2("cyan", S_BAR)} ` : `
|
|
995
964
|
` : ` ${styleText2("dim", "/")} `}${this.value ? `${styleText2("dim", S_RADIO_INACTIVE)} ${styleText2("dim", o)}` : `${styleText2("green", S_RADIO_ACTIVE)} ${o}`}
|
|
996
965
|
${g}
|
|
@@ -1001,30 +970,30 @@ ${g}
|
|
|
1001
970
|
}).prompt();
|
|
1002
971
|
};
|
|
1003
972
|
var MULTISELECT_INSTRUCTIONS = [
|
|
1004
|
-
`${styleText2("dim", "
|
|
973
|
+
`${styleText2("dim", "↑/↓")} to navigate`,
|
|
1005
974
|
`${styleText2("dim", "Space:")} select`,
|
|
1006
975
|
`${styleText2("dim", "Enter:")} confirm`
|
|
1007
976
|
];
|
|
1008
977
|
var log = {
|
|
1009
978
|
message: (s = [], {
|
|
1010
979
|
symbol: e = styleText2("gray", S_BAR),
|
|
1011
|
-
secondarySymbol:
|
|
980
|
+
secondarySymbol: r = styleText2("gray", S_BAR),
|
|
1012
981
|
output: m = process.stdout,
|
|
1013
|
-
spacing:
|
|
1014
|
-
withGuide:
|
|
982
|
+
spacing: l = 1,
|
|
983
|
+
withGuide: c
|
|
1015
984
|
} = {}) => {
|
|
1016
|
-
const
|
|
1017
|
-
for (let
|
|
1018
|
-
|
|
985
|
+
const t = [], o = c ?? settings.withGuide, f = o ? r : "", O = o ? `${e} ` : "", u = o ? `${r} ` : "";
|
|
986
|
+
for (let i = 0;i < l; i++)
|
|
987
|
+
t.push(f);
|
|
1019
988
|
const g = Array.isArray(s) ? s : s.split(`
|
|
1020
989
|
`);
|
|
1021
990
|
if (g.length > 0) {
|
|
1022
|
-
const [
|
|
1023
|
-
|
|
1024
|
-
for (const p of
|
|
1025
|
-
p.length > 0 ?
|
|
991
|
+
const [i, ...y] = g;
|
|
992
|
+
i.length > 0 ? t.push(`${O}${i}`) : t.push(o ? e : "");
|
|
993
|
+
for (const p of y)
|
|
994
|
+
p.length > 0 ? t.push(`${u}${p}`) : t.push(o ? r : "");
|
|
1026
995
|
}
|
|
1027
|
-
m.write(`${
|
|
996
|
+
m.write(`${t.join(`
|
|
1028
997
|
`)}
|
|
1029
998
|
`);
|
|
1030
999
|
},
|
|
@@ -1040,7 +1009,6 @@ var log = {
|
|
|
1040
1009
|
warn: (s, e) => {
|
|
1041
1010
|
log.message(s, { ...e, symbol: styleText2("yellow", S_WARN) });
|
|
1042
1011
|
},
|
|
1043
|
-
/** alias for `log.warn()`. */
|
|
1044
1012
|
warning: (s, e) => {
|
|
1045
1013
|
log.warn(s, e);
|
|
1046
1014
|
},
|
|
@@ -1048,214 +1016,193 @@ var log = {
|
|
|
1048
1016
|
log.message(s, { ...e, symbol: styleText2("red", S_ERROR) });
|
|
1049
1017
|
}
|
|
1050
1018
|
};
|
|
1051
|
-
var cancel = (o = "",
|
|
1052
|
-
const
|
|
1053
|
-
|
|
1019
|
+
var cancel = (o = "", t) => {
|
|
1020
|
+
const i = t?.output ?? process.stdout, e = t?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR_END)} ` : "";
|
|
1021
|
+
i.write(`${e}${styleText2("red", o)}
|
|
1054
1022
|
|
|
1055
1023
|
`);
|
|
1056
1024
|
};
|
|
1057
|
-
var intro = (o = "",
|
|
1058
|
-
const
|
|
1059
|
-
|
|
1025
|
+
var intro = (o = "", t) => {
|
|
1026
|
+
const i = t?.output ?? process.stdout, e = t?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR_START)} ` : "";
|
|
1027
|
+
i.write(`${e}${o}
|
|
1060
1028
|
`);
|
|
1061
1029
|
};
|
|
1062
|
-
var outro = (o = "",
|
|
1063
|
-
const
|
|
1030
|
+
var outro = (o = "", t) => {
|
|
1031
|
+
const i = t?.output ?? process.stdout, e = t?.withGuide ?? settings.withGuide ? `${styleText2("gray", S_BAR)}
|
|
1064
1032
|
${styleText2("gray", S_BAR_END)} ` : "";
|
|
1065
|
-
|
|
1033
|
+
i.write(`${e}${o}
|
|
1066
1034
|
|
|
1067
1035
|
`);
|
|
1068
1036
|
};
|
|
1069
1037
|
var W$1 = (o) => o;
|
|
1070
1038
|
var C = (o, e, s) => {
|
|
1071
|
-
const
|
|
1039
|
+
const a = {
|
|
1072
1040
|
hard: true,
|
|
1073
1041
|
trim: false
|
|
1074
|
-
},
|
|
1075
|
-
`),
|
|
1076
|
-
return wrapAnsi(o, g,
|
|
1042
|
+
}, i = wrapAnsi(o, e, a).split(`
|
|
1043
|
+
`), c = i.reduce((n, t) => Math.max(dist_default2(t), n), 0), u = i.map(s).reduce((n, t) => Math.max(dist_default2(t), n), 0), g = e - (u - c);
|
|
1044
|
+
return wrapAnsi(o, g, a);
|
|
1077
1045
|
};
|
|
1078
1046
|
var note = (o = "", e = "", s) => {
|
|
1079
|
-
const
|
|
1080
|
-
`).map(
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
)
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
`)
|
|
1090
|
-
` : "", l$1 = i2 ? S_CONNECT_LEFT : S_CORNER_BOTTOM_LEFT;
|
|
1091
|
-
a2.write(
|
|
1092
|
-
`${T}${styleText2("green", S_STEP_SUBMIT)} ${styleText2("reset", e)} ${styleText2(
|
|
1093
|
-
"gray",
|
|
1094
|
-
S_BAR_H.repeat(Math.max(t2 - n3 - 1, 1)) + S_CORNER_TOP_RIGHT
|
|
1095
|
-
)}
|
|
1096
|
-
${h2}
|
|
1097
|
-
${styleText2("gray", l$1 + S_BAR_H.repeat(t2 + 2) + S_CORNER_BOTTOM_RIGHT)}
|
|
1098
|
-
`
|
|
1099
|
-
);
|
|
1047
|
+
const a = s?.output ?? process$1.stdout, i = s?.withGuide ?? settings.withGuide, c = s?.format ?? W$1, g = ["", ...C(o, getColumns(a) - 6, c).split(`
|
|
1048
|
+
`).map(c), ""], n = dist_default2(e), t = Math.max(g.reduce((m, F) => {
|
|
1049
|
+
const O = dist_default2(F);
|
|
1050
|
+
return O > m ? O : m;
|
|
1051
|
+
}, 0), n) + 2, h = g.map((m) => `${styleText2("gray", S_BAR)} ${m}${" ".repeat(t - dist_default2(m))}${styleText2("gray", S_BAR)}`).join(`
|
|
1052
|
+
`), T = i ? `${styleText2("gray", S_BAR)}
|
|
1053
|
+
` : "", l$1 = i ? S_CONNECT_LEFT : S_CORNER_BOTTOM_LEFT;
|
|
1054
|
+
a.write(`${T}${styleText2("green", S_STEP_SUBMIT)} ${styleText2("reset", e)} ${styleText2("gray", S_BAR_H.repeat(Math.max(t - n - 1, 1)) + S_CORNER_TOP_RIGHT)}
|
|
1055
|
+
${h}
|
|
1056
|
+
${styleText2("gray", l$1 + S_BAR_H.repeat(t + 2) + S_CORNER_BOTTOM_RIGHT)}
|
|
1057
|
+
`);
|
|
1100
1058
|
};
|
|
1101
|
-
var W = (
|
|
1059
|
+
var W = (l) => styleText2("magenta", l);
|
|
1102
1060
|
var spinner = ({
|
|
1103
|
-
indicator:
|
|
1104
|
-
onCancel:
|
|
1105
|
-
output:
|
|
1061
|
+
indicator: l = "dots",
|
|
1062
|
+
onCancel: h,
|
|
1063
|
+
output: n = process.stdout,
|
|
1106
1064
|
cancelMessage: G,
|
|
1107
1065
|
errorMessage: O,
|
|
1108
|
-
frames: E = unicode ? ["
|
|
1066
|
+
frames: E = unicode ? ["◒", "◐", "◓", "◑"] : ["•", "o", "O", "0"],
|
|
1109
1067
|
delay: F = unicode ? 80 : 120,
|
|
1110
1068
|
signal: m,
|
|
1111
|
-
...
|
|
1069
|
+
...I
|
|
1112
1070
|
} = {}) => {
|
|
1113
|
-
const
|
|
1071
|
+
const u = isCI();
|
|
1114
1072
|
let M, T, d = false, S = false, s = "", p, w = performance.now();
|
|
1115
|
-
const x = getColumns(
|
|
1116
|
-
const
|
|
1117
|
-
S = e === 1, d && (
|
|
1118
|
-
}, f = () => g(2),
|
|
1119
|
-
process.on("uncaughtExceptionMonitor", f), process.on("unhandledRejection", f), process.on("SIGINT",
|
|
1073
|
+
const x = getColumns(n), k = I?.styleFrame ?? W, g = (e) => {
|
|
1074
|
+
const r = e > 1 ? O ?? settings.messages.error : G ?? settings.messages.cancel;
|
|
1075
|
+
S = e === 1, d && (a(r, e), S && typeof h == "function" && h());
|
|
1076
|
+
}, f = () => g(2), i = () => g(1), A = () => {
|
|
1077
|
+
process.on("uncaughtExceptionMonitor", f), process.on("unhandledRejection", f), process.on("SIGINT", i), process.on("SIGTERM", i), process.on("exit", g), m && m.addEventListener("abort", i);
|
|
1120
1078
|
}, H = () => {
|
|
1121
|
-
process.removeListener("uncaughtExceptionMonitor", f), process.removeListener("unhandledRejection", f), process.removeListener("SIGINT",
|
|
1122
|
-
},
|
|
1123
|
-
if (p ===
|
|
1124
|
-
|
|
1079
|
+
process.removeListener("uncaughtExceptionMonitor", f), process.removeListener("unhandledRejection", f), process.removeListener("SIGINT", i), process.removeListener("SIGTERM", i), process.removeListener("exit", g), m && m.removeEventListener("abort", i);
|
|
1080
|
+
}, y = () => {
|
|
1081
|
+
if (p === undefined)
|
|
1082
|
+
return;
|
|
1083
|
+
u && n.write(`
|
|
1125
1084
|
`);
|
|
1126
|
-
const
|
|
1085
|
+
const r = wrapAnsi(p, x, {
|
|
1127
1086
|
hard: true,
|
|
1128
1087
|
trim: false
|
|
1129
1088
|
}).split(`
|
|
1130
1089
|
`);
|
|
1131
|
-
|
|
1132
|
-
},
|
|
1133
|
-
const
|
|
1134
|
-
return
|
|
1135
|
-
}, N =
|
|
1136
|
-
d = true, M = block({ output:
|
|
1090
|
+
r.length > 1 && n.write(import_sisteransi2.cursor.up(r.length - 1)), n.write(import_sisteransi2.cursor.to(0)), n.write(import_sisteransi2.erase.down());
|
|
1091
|
+
}, C = (e) => e.replace(/\.+$/, ""), _ = (e) => {
|
|
1092
|
+
const r = (performance.now() - e) / 1000, t = Math.floor(r / 60), o = Math.floor(r % 60);
|
|
1093
|
+
return t > 0 ? `[${t}m ${o}s]` : `[${o}s]`;
|
|
1094
|
+
}, N = I.withGuide ?? settings.withGuide, P = (e = "") => {
|
|
1095
|
+
d = true, M = block({ output: n }), s = C(e), w = performance.now(), N && n.write(`${styleText2("gray", S_BAR)}
|
|
1137
1096
|
`);
|
|
1138
|
-
let
|
|
1097
|
+
let r = 0, t = 0;
|
|
1139
1098
|
A(), T = setInterval(() => {
|
|
1140
|
-
if (
|
|
1099
|
+
if (u && s === p)
|
|
1141
1100
|
return;
|
|
1142
|
-
|
|
1143
|
-
const o = k(E[
|
|
1101
|
+
y(), p = s;
|
|
1102
|
+
const o = k(E[r]);
|
|
1144
1103
|
let v;
|
|
1145
|
-
if (
|
|
1104
|
+
if (u)
|
|
1146
1105
|
v = `${o} ${s}...`;
|
|
1147
|
-
else if (
|
|
1106
|
+
else if (l === "timer")
|
|
1148
1107
|
v = `${o} ${s} ${_(w)}`;
|
|
1149
1108
|
else {
|
|
1150
|
-
const B = ".".repeat(Math.floor(
|
|
1109
|
+
const B = ".".repeat(Math.floor(t)).slice(0, 3);
|
|
1151
1110
|
v = `${o} ${s}${B}`;
|
|
1152
1111
|
}
|
|
1153
1112
|
const j = wrapAnsi(v, x, {
|
|
1154
1113
|
hard: true,
|
|
1155
1114
|
trim: false
|
|
1156
1115
|
});
|
|
1157
|
-
|
|
1116
|
+
n.write(j), r = r + 1 < E.length ? r + 1 : 0, t = t < 4 ? t + 0.125 : 0;
|
|
1158
1117
|
}, F);
|
|
1159
|
-
},
|
|
1160
|
-
if (!d)
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1118
|
+
}, a = (e = "", r = 0, t = false) => {
|
|
1119
|
+
if (!d)
|
|
1120
|
+
return;
|
|
1121
|
+
d = false, clearInterval(T), y();
|
|
1122
|
+
const o = r === 0 ? styleText2("green", S_STEP_SUBMIT) : r === 1 ? styleText2("red", S_STEP_CANCEL) : styleText2("red", S_STEP_ERROR);
|
|
1123
|
+
s = e ?? s, t || (l === "timer" ? n.write(`${o} ${s} ${_(w)}
|
|
1124
|
+
`) : n.write(`${o} ${s}
|
|
1165
1125
|
`)), H(), M();
|
|
1166
1126
|
};
|
|
1167
1127
|
return {
|
|
1168
1128
|
start: P,
|
|
1169
|
-
stop: (e = "") =>
|
|
1129
|
+
stop: (e = "") => a(e, 0),
|
|
1170
1130
|
message: (e = "") => {
|
|
1171
|
-
s =
|
|
1131
|
+
s = C(e ?? s);
|
|
1172
1132
|
},
|
|
1173
|
-
cancel: (e = "") =>
|
|
1174
|
-
error: (e = "") =>
|
|
1175
|
-
clear: () =>
|
|
1133
|
+
cancel: (e = "") => a(e, 1),
|
|
1134
|
+
error: (e = "") => a(e, 2),
|
|
1135
|
+
clear: () => a("", 0, true),
|
|
1176
1136
|
get isCancelled() {
|
|
1177
1137
|
return S;
|
|
1178
1138
|
}
|
|
1179
1139
|
};
|
|
1180
1140
|
};
|
|
1181
1141
|
var u2 = {
|
|
1182
|
-
light: unicodeOr("
|
|
1183
|
-
heavy: unicodeOr("
|
|
1184
|
-
block: unicodeOr("
|
|
1142
|
+
light: unicodeOr("─", "-"),
|
|
1143
|
+
heavy: unicodeOr("━", "="),
|
|
1144
|
+
block: unicodeOr("█", "#")
|
|
1185
1145
|
};
|
|
1186
1146
|
var SELECT_INSTRUCTIONS = [
|
|
1187
|
-
`${styleText2("dim", "
|
|
1147
|
+
`${styleText2("dim", "↑/↓")} to navigate`,
|
|
1188
1148
|
`${styleText2("dim", "Enter:")} confirm`
|
|
1189
1149
|
];
|
|
1190
|
-
var c = (
|
|
1191
|
-
`) ?
|
|
1150
|
+
var c = (t, o) => t.includes(`
|
|
1151
|
+
`) ? t.split(`
|
|
1192
1152
|
`).map((d) => o(d)).join(`
|
|
1193
|
-
`) : o(
|
|
1194
|
-
var select = (
|
|
1195
|
-
const o = (
|
|
1196
|
-
if (
|
|
1153
|
+
`) : o(t);
|
|
1154
|
+
var select = (t) => {
|
|
1155
|
+
const o = (n, m) => {
|
|
1156
|
+
if (n === undefined)
|
|
1197
1157
|
return "";
|
|
1198
|
-
const s =
|
|
1158
|
+
const s = n.label ?? String(n.value);
|
|
1199
1159
|
switch (m) {
|
|
1200
1160
|
case "disabled":
|
|
1201
|
-
return `${styleText2("gray", S_RADIO_INACTIVE)} ${c(s, (
|
|
1161
|
+
return `${styleText2("gray", S_RADIO_INACTIVE)} ${c(s, (i) => styleText2("gray", i))}${n.hint ? ` ${styleText2("dim", `(${n.hint ?? "disabled"})`)}` : ""}`;
|
|
1202
1162
|
case "selected":
|
|
1203
|
-
return `${c(s, (
|
|
1163
|
+
return `${c(s, (i) => styleText2("dim", i))}`;
|
|
1204
1164
|
case "active":
|
|
1205
|
-
return `${styleText2("green", S_RADIO_ACTIVE)} ${s}${
|
|
1165
|
+
return `${styleText2("green", S_RADIO_ACTIVE)} ${s}${n.hint ? ` ${styleText2("dim", `(${n.hint})`)}` : ""}`;
|
|
1206
1166
|
case "cancelled":
|
|
1207
|
-
return `${c(s, (
|
|
1167
|
+
return `${c(s, (i) => styleText2(["strikethrough", "dim"], i))}`;
|
|
1208
1168
|
default:
|
|
1209
|
-
return `${styleText2("dim", S_RADIO_INACTIVE)} ${c(s, (
|
|
1169
|
+
return `${styleText2("dim", S_RADIO_INACTIVE)} ${c(s, (i) => styleText2("dim", i))}`;
|
|
1210
1170
|
}
|
|
1211
|
-
}, d =
|
|
1171
|
+
}, d = t.showInstructions ?? true;
|
|
1212
1172
|
return new n$1({
|
|
1213
|
-
options:
|
|
1214
|
-
signal:
|
|
1215
|
-
input:
|
|
1216
|
-
output:
|
|
1217
|
-
initialValue:
|
|
1173
|
+
options: t.options,
|
|
1174
|
+
signal: t.signal,
|
|
1175
|
+
input: t.input,
|
|
1176
|
+
output: t.output,
|
|
1177
|
+
initialValue: t.initialValue,
|
|
1218
1178
|
render() {
|
|
1219
|
-
const
|
|
1220
|
-
|
|
1221
|
-
t2.message,
|
|
1222
|
-
s,
|
|
1223
|
-
m
|
|
1224
|
-
), u3 = `${n3 ? `${styleText2("gray", S_BAR)}
|
|
1225
|
-
` : ""}${i2}
|
|
1179
|
+
const n = t.withGuide ?? settings.withGuide, m = `${symbol(this.state)} `, s = `${symbolBar(this.state)} `, i = wrapTextWithPrefix(t.output, t.message, s, m), u = `${n ? `${styleText2("gray", S_BAR)}
|
|
1180
|
+
` : ""}${i}
|
|
1226
1181
|
`;
|
|
1227
1182
|
switch (this.state) {
|
|
1228
1183
|
case "submit": {
|
|
1229
|
-
const
|
|
1230
|
-
|
|
1231
|
-
o(this.options[this.cursor], "selected"),
|
|
1232
|
-
r2
|
|
1233
|
-
);
|
|
1234
|
-
return `${u3}${a2}`;
|
|
1184
|
+
const r = n ? `${styleText2("gray", S_BAR)} ` : "", a = wrapTextWithPrefix(t.output, o(this.options[this.cursor], "selected"), r);
|
|
1185
|
+
return `${u}${a}`;
|
|
1235
1186
|
}
|
|
1236
1187
|
case "cancel": {
|
|
1237
|
-
const
|
|
1238
|
-
|
|
1239
|
-
o(this.options[this.cursor], "cancelled"),
|
|
1240
|
-
r2
|
|
1241
|
-
);
|
|
1242
|
-
return `${u3}${a2}${n3 ? `
|
|
1188
|
+
const r = n ? `${styleText2("gray", S_BAR)} ` : "", a = wrapTextWithPrefix(t.output, o(this.options[this.cursor], "cancelled"), r);
|
|
1189
|
+
return `${u}${a}${n ? `
|
|
1243
1190
|
${styleText2("gray", S_BAR)}` : ""}`;
|
|
1244
1191
|
}
|
|
1245
1192
|
default: {
|
|
1246
|
-
const
|
|
1247
|
-
`).length, p = d ? formatInstructionFooter(SELECT_INSTRUCTIONS,
|
|
1193
|
+
const r = n ? `${styleText2("cyan", S_BAR)} ` : "", a = u.split(`
|
|
1194
|
+
`).length, p = d ? formatInstructionFooter(SELECT_INSTRUCTIONS, n) : n ? [styleText2("cyan", S_BAR_END)] : [], f = p.join(`
|
|
1248
1195
|
`), b = p.length + 1;
|
|
1249
|
-
return `${
|
|
1250
|
-
output:
|
|
1196
|
+
return `${u}${r}${limitOptions({
|
|
1197
|
+
output: t.output,
|
|
1251
1198
|
cursor: this.cursor,
|
|
1252
1199
|
options: this.options,
|
|
1253
|
-
maxItems:
|
|
1254
|
-
columnPadding:
|
|
1255
|
-
rowPadding:
|
|
1200
|
+
maxItems: t.maxItems,
|
|
1201
|
+
columnPadding: r.length,
|
|
1202
|
+
rowPadding: a + b,
|
|
1256
1203
|
style: (g, x) => o(g, g.disabled ? "disabled" : x ? "active" : "inactive")
|
|
1257
1204
|
}).join(`
|
|
1258
|
-
${
|
|
1205
|
+
${r}`)}
|
|
1259
1206
|
${f}
|
|
1260
1207
|
`;
|
|
1261
1208
|
}
|
|
@@ -1264,56 +1211,52 @@ ${f}
|
|
|
1264
1211
|
}).prompt();
|
|
1265
1212
|
};
|
|
1266
1213
|
var i = `${styleText2("gray", S_BAR)} `;
|
|
1267
|
-
var text = (
|
|
1268
|
-
validate:
|
|
1269
|
-
placeholder:
|
|
1270
|
-
defaultValue:
|
|
1271
|
-
initialValue:
|
|
1272
|
-
output:
|
|
1273
|
-
signal:
|
|
1274
|
-
input:
|
|
1214
|
+
var text = (t) => new n({
|
|
1215
|
+
validate: t.validate,
|
|
1216
|
+
placeholder: t.placeholder,
|
|
1217
|
+
defaultValue: t.defaultValue,
|
|
1218
|
+
initialValue: t.initialValue,
|
|
1219
|
+
output: t.output,
|
|
1220
|
+
signal: t.signal,
|
|
1221
|
+
input: t.input,
|
|
1275
1222
|
render() {
|
|
1276
|
-
const
|
|
1277
|
-
` : ""}${symbol(this.state)} `}${
|
|
1278
|
-
`, d =
|
|
1279
|
-
// biome-ignore lint/style/noNonNullAssertion: guarded by placeholder.length > 0
|
|
1280
|
-
styleText2("inverse", t2.placeholder[0]) + styleText2("dim", t2.placeholder.slice(1))
|
|
1281
|
-
) : styleText2(["inverse", "hidden"], "_"), o = this.userInput ? this.userInputWithCursor : d, s = this.value ?? "";
|
|
1223
|
+
const r = t?.withGuide ?? settings.withGuide, l = `${`${r ? `${styleText2("gray", S_BAR)}
|
|
1224
|
+
` : ""}${symbol(this.state)} `}${t.message}
|
|
1225
|
+
`, d = t.placeholder && t.placeholder.length > 0 ? styleText2("inverse", t.placeholder[0]) + styleText2("dim", t.placeholder.slice(1)) : styleText2(["inverse", "hidden"], "_"), o = this.userInput ? this.userInputWithCursor : d, s = this.value ?? "";
|
|
1282
1226
|
switch (this.state) {
|
|
1283
1227
|
case "validating": {
|
|
1284
|
-
const
|
|
1285
|
-
return `${
|
|
1286
|
-
${
|
|
1228
|
+
const n = r ? `${styleText2("cyan", S_BAR)} ` : "", i = r ? styleText2("cyan", S_BAR_END) : "", c = styleText2("dim", o), $ = styleText2("dim", "Validating...");
|
|
1229
|
+
return `${l}${n}${c}
|
|
1230
|
+
${i} ${$}
|
|
1287
1231
|
`;
|
|
1288
1232
|
}
|
|
1289
1233
|
case "error": {
|
|
1290
|
-
const
|
|
1291
|
-
return `${
|
|
1292
|
-
${
|
|
1293
|
-
${
|
|
1234
|
+
const n = this.error ? ` ${styleText2("yellow", this.error)}` : "", i = r ? `${styleText2("yellow", S_BAR)} ` : "", c = r ? styleText2("yellow", S_BAR_END) : "";
|
|
1235
|
+
return `${l.trim()}
|
|
1236
|
+
${i}${o}
|
|
1237
|
+
${c}${n}
|
|
1294
1238
|
`;
|
|
1295
1239
|
}
|
|
1296
1240
|
case "submit": {
|
|
1297
|
-
const
|
|
1298
|
-
return `${
|
|
1241
|
+
const n = s ? `${r ? " " : ""}${styleText2("dim", s)}` : "", i = r ? styleText2("gray", S_BAR) : "";
|
|
1242
|
+
return `${l}${i}${n}`;
|
|
1299
1243
|
}
|
|
1300
1244
|
case "cancel": {
|
|
1301
|
-
const
|
|
1302
|
-
return `${
|
|
1303
|
-
${
|
|
1245
|
+
const n = s ? ` ${styleText2(["strikethrough", "dim"], s)}` : "", i = r ? styleText2("gray", S_BAR) : "";
|
|
1246
|
+
return `${l}${i}${n}${s.trim() ? `
|
|
1247
|
+
${i}` : ""}`;
|
|
1304
1248
|
}
|
|
1305
1249
|
default: {
|
|
1306
|
-
const
|
|
1307
|
-
return `${
|
|
1308
|
-
${
|
|
1250
|
+
const n = r ? `${styleText2("cyan", S_BAR)} ` : "", i = r ? styleText2("cyan", S_BAR_END) : "";
|
|
1251
|
+
return `${l}${n}${o}
|
|
1252
|
+
${i}
|
|
1309
1253
|
`;
|
|
1310
1254
|
}
|
|
1311
1255
|
}
|
|
1312
1256
|
}
|
|
1313
1257
|
}).prompt();
|
|
1314
|
-
|
|
1315
1258
|
// package.json
|
|
1316
|
-
var version = "0.1.0-alpha.
|
|
1259
|
+
var version = "0.1.0-alpha.10";
|
|
1317
1260
|
|
|
1318
1261
|
// src/index.ts
|
|
1319
1262
|
var RANGE = `^${version}`;
|
|
@@ -1330,22 +1273,28 @@ var DRIVER_NAMES = Object.keys(DRIVERS);
|
|
|
1330
1273
|
var PMS = ["bun", "npm", "pnpm", "yarn"];
|
|
1331
1274
|
function parseArgs(argv) {
|
|
1332
1275
|
const o = { git: true, yes: false };
|
|
1333
|
-
for (let
|
|
1334
|
-
const
|
|
1335
|
-
if (
|
|
1336
|
-
|
|
1337
|
-
else if (
|
|
1338
|
-
|
|
1339
|
-
else if (
|
|
1340
|
-
|
|
1276
|
+
for (let i = 0;i < argv.length; i++) {
|
|
1277
|
+
const a = argv[i];
|
|
1278
|
+
if (a === "-y" || a === "--yes")
|
|
1279
|
+
o.yes = true;
|
|
1280
|
+
else if (a === "--no-install")
|
|
1281
|
+
o.install = false;
|
|
1282
|
+
else if (a === "--no-git")
|
|
1283
|
+
o.git = false;
|
|
1284
|
+
else if (a === "--driver")
|
|
1285
|
+
o.driver = argv[++i];
|
|
1286
|
+
else if (a === "--pm")
|
|
1287
|
+
o.pm = argv[++i];
|
|
1288
|
+
else if (a === "-h" || a === "--help") {
|
|
1341
1289
|
printHelp();
|
|
1342
1290
|
process.exit(0);
|
|
1343
|
-
} else if (!
|
|
1291
|
+
} else if (!a.startsWith("-") && o.dir === undefined)
|
|
1292
|
+
o.dir = a;
|
|
1344
1293
|
}
|
|
1345
1294
|
return o;
|
|
1346
1295
|
}
|
|
1347
1296
|
function printHelp() {
|
|
1348
|
-
console.log(`create-better-schemic
|
|
1297
|
+
console.log(`create-better-schemic — scaffold a new Better-schemic project
|
|
1349
1298
|
|
|
1350
1299
|
Usage: create-better-schemic [directory] [options]
|
|
1351
1300
|
|
|
@@ -1359,7 +1308,9 @@ Options:
|
|
|
1359
1308
|
}
|
|
1360
1309
|
function detectPm() {
|
|
1361
1310
|
const ua = process.env.npm_config_user_agent ?? "";
|
|
1362
|
-
for (const pm of PMS)
|
|
1311
|
+
for (const pm of PMS)
|
|
1312
|
+
if (ua.startsWith(pm))
|
|
1313
|
+
return pm;
|
|
1363
1314
|
return "npm";
|
|
1364
1315
|
}
|
|
1365
1316
|
function abortIfCancel(value) {
|
|
@@ -1379,33 +1330,30 @@ function depMap(driver, pm) {
|
|
|
1379
1330
|
[d.pkg]: RANGE,
|
|
1380
1331
|
...d.deps
|
|
1381
1332
|
};
|
|
1382
|
-
if (pm === "pnpm")
|
|
1333
|
+
if (pm === "pnpm")
|
|
1334
|
+
deps["@better-schemic/core"] = RANGE;
|
|
1383
1335
|
return deps;
|
|
1384
1336
|
}
|
|
1385
|
-
var TSCONFIG = `${JSON.stringify(
|
|
1386
|
-
{
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
types: ["node"]
|
|
1398
|
-
},
|
|
1399
|
-
exclude: ["node_modules"]
|
|
1337
|
+
var TSCONFIG = `${JSON.stringify({
|
|
1338
|
+
compilerOptions: {
|
|
1339
|
+
target: "ESNext",
|
|
1340
|
+
module: "ESNext",
|
|
1341
|
+
moduleResolution: "bundler",
|
|
1342
|
+
moduleDetection: "force",
|
|
1343
|
+
strict: true,
|
|
1344
|
+
skipLibCheck: true,
|
|
1345
|
+
resolveJsonModule: true,
|
|
1346
|
+
noEmit: true,
|
|
1347
|
+
lib: ["ESNext"],
|
|
1348
|
+
types: ["node"]
|
|
1400
1349
|
},
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
)}
|
|
1350
|
+
exclude: ["node_modules"]
|
|
1351
|
+
}, null, 2)}
|
|
1404
1352
|
`;
|
|
1405
1353
|
function applyPackageJson(target, name, driver, pm) {
|
|
1406
|
-
const path =
|
|
1354
|
+
const path = join(target, "package.json");
|
|
1407
1355
|
const deps = depMap(driver, pm);
|
|
1408
|
-
if (!
|
|
1356
|
+
if (!existsSync(path)) {
|
|
1409
1357
|
const fresh = {
|
|
1410
1358
|
name,
|
|
1411
1359
|
version: "0.0.0",
|
|
@@ -1427,25 +1375,22 @@ function applyPackageJson(target, name, driver, pm) {
|
|
|
1427
1375
|
pkg.dependencies[k] = v;
|
|
1428
1376
|
added.push(k);
|
|
1429
1377
|
}
|
|
1430
|
-
pkg.dependencies = Object.fromEntries(
|
|
1431
|
-
Object.entries(pkg.dependencies).sort()
|
|
1432
|
-
);
|
|
1378
|
+
pkg.dependencies = Object.fromEntries(Object.entries(pkg.dependencies).sort());
|
|
1433
1379
|
pkg.scripts ??= {};
|
|
1434
1380
|
for (const [k, v] of Object.entries(SCRIPTS))
|
|
1435
|
-
if (!(k in pkg.scripts))
|
|
1381
|
+
if (!(k in pkg.scripts))
|
|
1382
|
+
pkg.scripts[k] = v;
|
|
1436
1383
|
writeFileSync(path, `${JSON.stringify(pkg, null, 2)}
|
|
1437
1384
|
`);
|
|
1438
|
-
return added.length ? `~ package.json (added ${added.join(", ")})` : dim("
|
|
1385
|
+
return added.length ? `~ package.json (added ${added.join(", ")})` : dim("· package.json (deps already present)");
|
|
1439
1386
|
}
|
|
1440
1387
|
function applyTsconfig(target) {
|
|
1441
|
-
const path =
|
|
1442
|
-
if (!
|
|
1388
|
+
const path = join(target, "tsconfig.json");
|
|
1389
|
+
if (!existsSync(path)) {
|
|
1443
1390
|
writeFileSync(path, TSCONFIG);
|
|
1444
1391
|
return "+ tsconfig.json";
|
|
1445
1392
|
}
|
|
1446
|
-
return dim(
|
|
1447
|
-
"\xB7 tsconfig.json (kept \u2014 needs module esnext/preserve/nodenext + resolveJsonModule for seed imports)"
|
|
1448
|
-
);
|
|
1393
|
+
return dim("· tsconfig.json (kept — needs module esnext/preserve/nodenext + resolveJsonModule for seed imports)");
|
|
1449
1394
|
}
|
|
1450
1395
|
var GITIGNORE = `node_modules/
|
|
1451
1396
|
.env
|
|
@@ -1453,18 +1398,19 @@ var GITIGNORE = `node_modules/
|
|
|
1453
1398
|
.DS_Store
|
|
1454
1399
|
`;
|
|
1455
1400
|
function writeIfAbsent(dir, file, content) {
|
|
1456
|
-
const path =
|
|
1457
|
-
if (
|
|
1401
|
+
const path = join(dir, file);
|
|
1402
|
+
if (existsSync(path))
|
|
1403
|
+
return dim(`· ${file} (exists, skipped)`);
|
|
1458
1404
|
writeFileSync(path, content);
|
|
1459
1405
|
return `+ ${file}`;
|
|
1460
1406
|
}
|
|
1461
1407
|
function run(cmd, args, cwd, capture = false) {
|
|
1462
|
-
const
|
|
1408
|
+
const r = spawnSync(cmd, args, {
|
|
1463
1409
|
cwd,
|
|
1464
1410
|
stdio: capture ? "pipe" : "inherit",
|
|
1465
1411
|
encoding: "utf8"
|
|
1466
1412
|
});
|
|
1467
|
-
return { ok:
|
|
1413
|
+
return { ok: r.status === 0, out: `${r.stdout ?? ""}${r.stderr ?? ""}` };
|
|
1468
1414
|
}
|
|
1469
1415
|
async function main() {
|
|
1470
1416
|
const opts = parseArgs(process.argv.slice(2));
|
|
@@ -1472,26 +1418,22 @@ async function main() {
|
|
|
1472
1418
|
intro(bold("create-better-schemic"));
|
|
1473
1419
|
let dir = opts.dir;
|
|
1474
1420
|
if (!dir && tty) {
|
|
1475
|
-
dir = abortIfCancel(
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
})
|
|
1481
|
-
);
|
|
1421
|
+
dir = abortIfCancel(await text({
|
|
1422
|
+
message: "Project directory",
|
|
1423
|
+
placeholder: "better-schemic-app",
|
|
1424
|
+
defaultValue: "better-schemic-app"
|
|
1425
|
+
}));
|
|
1482
1426
|
}
|
|
1483
1427
|
dir ||= "better-schemic-app";
|
|
1484
1428
|
const target = resolve(process.cwd(), dir);
|
|
1485
1429
|
const name = basename(target);
|
|
1486
1430
|
mkdirSync(target, { recursive: true });
|
|
1487
|
-
const isExisting =
|
|
1488
|
-
if (
|
|
1489
|
-
const ok = abortIfCancel(
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
})
|
|
1494
|
-
);
|
|
1431
|
+
const isExisting = existsSync(join(target, "package.json"));
|
|
1432
|
+
if (readdirSync(target).length && !isExisting && tty) {
|
|
1433
|
+
const ok = abortIfCancel(await confirm({
|
|
1434
|
+
message: `${bold(dir)} is not empty — continue?`,
|
|
1435
|
+
initialValue: false
|
|
1436
|
+
}));
|
|
1495
1437
|
if (!ok) {
|
|
1496
1438
|
cancel("Aborted.");
|
|
1497
1439
|
process.exit(1);
|
|
@@ -1499,16 +1441,14 @@ async function main() {
|
|
|
1499
1441
|
}
|
|
1500
1442
|
let driver = opts.driver;
|
|
1501
1443
|
if (!driver && tty) {
|
|
1502
|
-
driver = abortIfCancel(
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
})
|
|
1511
|
-
);
|
|
1444
|
+
driver = abortIfCancel(await select({
|
|
1445
|
+
message: "Database driver",
|
|
1446
|
+
options: DRIVER_NAMES.map((n) => ({
|
|
1447
|
+
value: n,
|
|
1448
|
+
label: DRIVERS[n].label
|
|
1449
|
+
})),
|
|
1450
|
+
initialValue: "surrealdb"
|
|
1451
|
+
}));
|
|
1512
1452
|
}
|
|
1513
1453
|
driver ||= "surrealdb";
|
|
1514
1454
|
if (!DRIVERS[driver]) {
|
|
@@ -1517,25 +1457,21 @@ async function main() {
|
|
|
1517
1457
|
}
|
|
1518
1458
|
const detected = detectPm();
|
|
1519
1459
|
let install = opts.install;
|
|
1520
|
-
if (install ===
|
|
1521
|
-
install = tty ? abortIfCancel(
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
})
|
|
1526
|
-
) : true;
|
|
1460
|
+
if (install === undefined)
|
|
1461
|
+
install = tty ? abortIfCancel(await confirm({
|
|
1462
|
+
message: "Install dependencies now?",
|
|
1463
|
+
initialValue: true
|
|
1464
|
+
})) : true;
|
|
1527
1465
|
let pm = opts.pm ?? detected;
|
|
1528
1466
|
if (install && !opts.pm && tty) {
|
|
1529
|
-
pm = abortIfCancel(
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
})
|
|
1538
|
-
);
|
|
1467
|
+
pm = abortIfCancel(await select({
|
|
1468
|
+
message: "Install with which package manager?",
|
|
1469
|
+
options: [detected, ...PMS.filter((x) => x !== detected)].map((m) => ({
|
|
1470
|
+
value: m,
|
|
1471
|
+
label: m === detected ? `${m} (detected)` : m
|
|
1472
|
+
})),
|
|
1473
|
+
initialValue: detected
|
|
1474
|
+
}));
|
|
1539
1475
|
}
|
|
1540
1476
|
const written = [
|
|
1541
1477
|
applyPackageJson(target, name, driver, pm),
|
|
@@ -1543,33 +1479,27 @@ async function main() {
|
|
|
1543
1479
|
writeIfAbsent(target, ".gitignore", GITIGNORE)
|
|
1544
1480
|
];
|
|
1545
1481
|
const header = isExisting ? `Adding Better-schemic to ${name}` : name;
|
|
1546
|
-
log.step(
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
)
|
|
1550
|
-
if (opts.git && !existsSync2(join2(target, ".git")))
|
|
1482
|
+
log.step(`${bold(header)} ${dim(`(${DRIVERS[driver].label})`)}
|
|
1483
|
+
${written.join(`
|
|
1484
|
+
`)}`);
|
|
1485
|
+
if (opts.git && !existsSync(join(target, ".git")))
|
|
1551
1486
|
run("git", ["init", "-q"], target);
|
|
1552
1487
|
if (install) {
|
|
1553
1488
|
const s = spinner();
|
|
1554
1489
|
s.start(`Installing dependencies with ${pm}`);
|
|
1555
|
-
const
|
|
1556
|
-
if (!
|
|
1490
|
+
const r = run(pm, ["install"], target, true);
|
|
1491
|
+
if (!r.ok) {
|
|
1557
1492
|
s.stop(`${pm} install failed`);
|
|
1558
|
-
log.error(
|
|
1493
|
+
log.error(r.out.trim().split(`
|
|
1494
|
+
`).slice(-8).join(`
|
|
1495
|
+
`));
|
|
1559
1496
|
outro(`Fix the install, then run ${bold("better-schemic init")}.`);
|
|
1560
1497
|
process.exit(1);
|
|
1561
1498
|
}
|
|
1562
1499
|
s.stop("Dependencies installed");
|
|
1563
1500
|
log.step("Scaffolding the schema");
|
|
1564
1501
|
const runtime = pm === "bun" ? "bun" : "node";
|
|
1565
|
-
const cliJs =
|
|
1566
|
-
target,
|
|
1567
|
-
"node_modules",
|
|
1568
|
-
"@better-schemic",
|
|
1569
|
-
"cli",
|
|
1570
|
-
"lib",
|
|
1571
|
-
"cli.js"
|
|
1572
|
-
);
|
|
1502
|
+
const cliJs = join(target, "node_modules", "@better-schemic", "cli", "lib", "cli.js");
|
|
1573
1503
|
process.env.BETTER_SCHEMIC_NO_BOOTSTRAP = "1";
|
|
1574
1504
|
process.env.SCHEMIC_NO_BOOTSTRAP = "1";
|
|
1575
1505
|
run(runtime, [cliJs, "init", "--driver", driver], target);
|