create-better-schemic 0.1.0-alpha.1

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