create-baresync 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +2531 -0
- package/dist/index.js +2529 -0
- package/dist/templates/app/db-helper.ts +22 -0
- package/dist/templates/app/drizzle-local-config.ts +19 -0
- package/dist/templates/app/package.json +17 -0
- package/dist/templates/app/src/lib.rs +21 -0
- package/dist/templates/app/src-tauri/Cargo.toml +19 -0
- package/dist/templates/app/src-tauri/build.rs +3 -0
- package/dist/templates/app/src-tauri/tauri.conf.json +27 -0
- package/dist/templates/app/sync-client.ts +11 -0
- package/dist/templates/root/README.md +11 -0
- package/dist/templates/root/package.json +14 -0
- package/dist/templates/root/scripts/dev.mjs +52 -0
- package/dist/templates/root/scripts/run-workspace.mjs +19 -0
- package/dist/templates/server/db/client.ts +32 -0
- package/dist/templates/server/db/v1/sync-repository.ts +140 -0
- package/dist/templates/server/drizzle-config.ts +15 -0
- package/dist/templates/server/fallback-instructions.md +10 -0
- package/dist/templates/server/package.json +17 -0
- package/dist/templates/server/src/index-elysia.ts +12 -0
- package/dist/templates/server/src/index-hono.ts +13 -0
- package/dist/templates/server/src/sync-route.ts +46 -0
- package/dist/templates/server/src/sync-routes.ts +46 -0
- package/dist/templates/server/src/v1/routes-elysia.ts +62 -0
- package/dist/templates/server/src/v1/routes-hono.ts +65 -0
- package/dist/templates/server/src/v1/routes.ts +76 -0
- package/dist/templates/server/src-db/client.ts +17 -0
- package/dist/templates/server/src-db/v1/sync-repository.ts +140 -0
- package/dist/templates/sync-contract/generate.ts +7 -0
- package/dist/templates/sync-contract/package.json +25 -0
- package/dist/templates/sync-contract/src/api-schema.ts +3 -0
- package/dist/templates/sync-contract/src/api-synced-schema.ts +20 -0
- package/dist/templates/sync-contract/src/constants.ts +4 -0
- package/dist/templates/sync-contract/src/index.ts +5 -0
- package/dist/templates/sync-contract/src/local-schema.ts +4 -0
- package/dist/templates/sync-contract/src/local-synced-schema.ts +22 -0
- package/dist/templates/sync-contract/sync.config.ts +17 -0
- package/dist/templates/sync-contract/tsconfig.json +17 -0
- package/package.json +35 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2529 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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 ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
for (let key of __getOwnPropNames(mod))
|
|
23
|
+
if (!__hasOwnProp.call(to, key))
|
|
24
|
+
__defProp(to, key, {
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
26
|
+
enumerable: true
|
|
27
|
+
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
33
|
+
|
|
34
|
+
// ../../node_modules/.bun/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
|
|
35
|
+
var require_src = __commonJS((exports, module) => {
|
|
36
|
+
var ESC2 = "\x1B";
|
|
37
|
+
var CSI2 = `${ESC2}[`;
|
|
38
|
+
var beep = "\x07";
|
|
39
|
+
var cursor = {
|
|
40
|
+
to(x, y) {
|
|
41
|
+
if (!y)
|
|
42
|
+
return `${CSI2}${x + 1}G`;
|
|
43
|
+
return `${CSI2}${y + 1};${x + 1}H`;
|
|
44
|
+
},
|
|
45
|
+
move(x, y) {
|
|
46
|
+
let ret = "";
|
|
47
|
+
if (x < 0)
|
|
48
|
+
ret += `${CSI2}${-x}D`;
|
|
49
|
+
else if (x > 0)
|
|
50
|
+
ret += `${CSI2}${x}C`;
|
|
51
|
+
if (y < 0)
|
|
52
|
+
ret += `${CSI2}${-y}A`;
|
|
53
|
+
else if (y > 0)
|
|
54
|
+
ret += `${CSI2}${y}B`;
|
|
55
|
+
return ret;
|
|
56
|
+
},
|
|
57
|
+
up: (count = 1) => `${CSI2}${count}A`,
|
|
58
|
+
down: (count = 1) => `${CSI2}${count}B`,
|
|
59
|
+
forward: (count = 1) => `${CSI2}${count}C`,
|
|
60
|
+
backward: (count = 1) => `${CSI2}${count}D`,
|
|
61
|
+
nextLine: (count = 1) => `${CSI2}E`.repeat(count),
|
|
62
|
+
prevLine: (count = 1) => `${CSI2}F`.repeat(count),
|
|
63
|
+
left: `${CSI2}G`,
|
|
64
|
+
hide: `${CSI2}?25l`,
|
|
65
|
+
show: `${CSI2}?25h`,
|
|
66
|
+
save: `${ESC2}7`,
|
|
67
|
+
restore: `${ESC2}8`
|
|
68
|
+
};
|
|
69
|
+
var scroll = {
|
|
70
|
+
up: (count = 1) => `${CSI2}S`.repeat(count),
|
|
71
|
+
down: (count = 1) => `${CSI2}T`.repeat(count)
|
|
72
|
+
};
|
|
73
|
+
var erase = {
|
|
74
|
+
screen: `${CSI2}2J`,
|
|
75
|
+
up: (count = 1) => `${CSI2}1J`.repeat(count),
|
|
76
|
+
down: (count = 1) => `${CSI2}J`.repeat(count),
|
|
77
|
+
line: `${CSI2}2K`,
|
|
78
|
+
lineEnd: `${CSI2}K`,
|
|
79
|
+
lineStart: `${CSI2}1K`,
|
|
80
|
+
lines(count) {
|
|
81
|
+
let clear = "";
|
|
82
|
+
for (let i = 0;i < count; i++)
|
|
83
|
+
clear += this.line + (i < count - 1 ? cursor.up() : "");
|
|
84
|
+
if (count)
|
|
85
|
+
clear += cursor.left;
|
|
86
|
+
return clear;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
module.exports = { cursor, scroll, erase, beep };
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// ../../node_modules/.bun/picocolors@1.1.1/node_modules/picocolors/picocolors.js
|
|
93
|
+
var require_picocolors = __commonJS((exports, module) => {
|
|
94
|
+
var p2 = process || {};
|
|
95
|
+
var argv = p2.argv || [];
|
|
96
|
+
var env = p2.env || {};
|
|
97
|
+
var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p2.platform === "win32" || (p2.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
98
|
+
var formatter = (open, close, replace = open) => (input) => {
|
|
99
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
100
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
101
|
+
};
|
|
102
|
+
var replaceClose = (string, close, replace, index) => {
|
|
103
|
+
let result = "", cursor = 0;
|
|
104
|
+
do {
|
|
105
|
+
result += string.substring(cursor, index) + replace;
|
|
106
|
+
cursor = index + close.length;
|
|
107
|
+
index = string.indexOf(close, cursor);
|
|
108
|
+
} while (~index);
|
|
109
|
+
return result + string.substring(cursor);
|
|
110
|
+
};
|
|
111
|
+
var createColors = (enabled = isColorSupported) => {
|
|
112
|
+
let f2 = enabled ? formatter : () => String;
|
|
113
|
+
return {
|
|
114
|
+
isColorSupported: enabled,
|
|
115
|
+
reset: f2("\x1B[0m", "\x1B[0m"),
|
|
116
|
+
bold: f2("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
117
|
+
dim: f2("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
118
|
+
italic: f2("\x1B[3m", "\x1B[23m"),
|
|
119
|
+
underline: f2("\x1B[4m", "\x1B[24m"),
|
|
120
|
+
inverse: f2("\x1B[7m", "\x1B[27m"),
|
|
121
|
+
hidden: f2("\x1B[8m", "\x1B[28m"),
|
|
122
|
+
strikethrough: f2("\x1B[9m", "\x1B[29m"),
|
|
123
|
+
black: f2("\x1B[30m", "\x1B[39m"),
|
|
124
|
+
red: f2("\x1B[31m", "\x1B[39m"),
|
|
125
|
+
green: f2("\x1B[32m", "\x1B[39m"),
|
|
126
|
+
yellow: f2("\x1B[33m", "\x1B[39m"),
|
|
127
|
+
blue: f2("\x1B[34m", "\x1B[39m"),
|
|
128
|
+
magenta: f2("\x1B[35m", "\x1B[39m"),
|
|
129
|
+
cyan: f2("\x1B[36m", "\x1B[39m"),
|
|
130
|
+
white: f2("\x1B[37m", "\x1B[39m"),
|
|
131
|
+
gray: f2("\x1B[90m", "\x1B[39m"),
|
|
132
|
+
bgBlack: f2("\x1B[40m", "\x1B[49m"),
|
|
133
|
+
bgRed: f2("\x1B[41m", "\x1B[49m"),
|
|
134
|
+
bgGreen: f2("\x1B[42m", "\x1B[49m"),
|
|
135
|
+
bgYellow: f2("\x1B[43m", "\x1B[49m"),
|
|
136
|
+
bgBlue: f2("\x1B[44m", "\x1B[49m"),
|
|
137
|
+
bgMagenta: f2("\x1B[45m", "\x1B[49m"),
|
|
138
|
+
bgCyan: f2("\x1B[46m", "\x1B[49m"),
|
|
139
|
+
bgWhite: f2("\x1B[47m", "\x1B[49m"),
|
|
140
|
+
blackBright: f2("\x1B[90m", "\x1B[39m"),
|
|
141
|
+
redBright: f2("\x1B[91m", "\x1B[39m"),
|
|
142
|
+
greenBright: f2("\x1B[92m", "\x1B[39m"),
|
|
143
|
+
yellowBright: f2("\x1B[93m", "\x1B[39m"),
|
|
144
|
+
blueBright: f2("\x1B[94m", "\x1B[39m"),
|
|
145
|
+
magentaBright: f2("\x1B[95m", "\x1B[39m"),
|
|
146
|
+
cyanBright: f2("\x1B[96m", "\x1B[39m"),
|
|
147
|
+
whiteBright: f2("\x1B[97m", "\x1B[39m"),
|
|
148
|
+
bgBlackBright: f2("\x1B[100m", "\x1B[49m"),
|
|
149
|
+
bgRedBright: f2("\x1B[101m", "\x1B[49m"),
|
|
150
|
+
bgGreenBright: f2("\x1B[102m", "\x1B[49m"),
|
|
151
|
+
bgYellowBright: f2("\x1B[103m", "\x1B[49m"),
|
|
152
|
+
bgBlueBright: f2("\x1B[104m", "\x1B[49m"),
|
|
153
|
+
bgMagentaBright: f2("\x1B[105m", "\x1B[49m"),
|
|
154
|
+
bgCyanBright: f2("\x1B[106m", "\x1B[49m"),
|
|
155
|
+
bgWhiteBright: f2("\x1B[107m", "\x1B[49m")
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
module.exports = createColors();
|
|
159
|
+
module.exports.createColors = createColors;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// src/package-manager.ts
|
|
163
|
+
function detectPackageManager() {
|
|
164
|
+
const userAgent = process.env.npm_config_user_agent ?? "";
|
|
165
|
+
if (userAgent.includes("bun")) {
|
|
166
|
+
return "bun";
|
|
167
|
+
}
|
|
168
|
+
if (userAgent.includes("pnpm")) {
|
|
169
|
+
return "pnpm";
|
|
170
|
+
}
|
|
171
|
+
if (userAgent.includes("yarn")) {
|
|
172
|
+
return "yarn";
|
|
173
|
+
}
|
|
174
|
+
if (userAgent.includes("npm")) {
|
|
175
|
+
return "npm";
|
|
176
|
+
}
|
|
177
|
+
if (typeof process.versions.bun === "string") {
|
|
178
|
+
return "bun";
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
// src/scaffold.ts
|
|
183
|
+
import { spawn } from "child_process";
|
|
184
|
+
import fs3 from "fs/promises";
|
|
185
|
+
import path3 from "path";
|
|
186
|
+
|
|
187
|
+
// ../../node_modules/.bun/@clack+core@1.3.1/node_modules/@clack/core/dist/index.mjs
|
|
188
|
+
import { styleText as v } from "util";
|
|
189
|
+
import { stdout as x, stdin as D } from "process";
|
|
190
|
+
import E from "readline";
|
|
191
|
+
|
|
192
|
+
// ../../node_modules/.bun/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/utils.js
|
|
193
|
+
var getCodePointsLength = (() => {
|
|
194
|
+
const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
|
195
|
+
return (input) => {
|
|
196
|
+
let surrogatePairsNr = 0;
|
|
197
|
+
SURROGATE_PAIR_RE.lastIndex = 0;
|
|
198
|
+
while (SURROGATE_PAIR_RE.test(input)) {
|
|
199
|
+
surrogatePairsNr += 1;
|
|
200
|
+
}
|
|
201
|
+
return input.length - surrogatePairsNr;
|
|
202
|
+
};
|
|
203
|
+
})();
|
|
204
|
+
var isFullWidth = (x) => {
|
|
205
|
+
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
206
|
+
};
|
|
207
|
+
var isWideNotCJKTNotEmoji = (x) => {
|
|
208
|
+
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;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// ../../node_modules/.bun/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/index.js
|
|
212
|
+
var ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
|
|
213
|
+
var CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
214
|
+
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;
|
|
215
|
+
var TAB_RE = /\t{1,1000}/y;
|
|
216
|
+
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;
|
|
217
|
+
var LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
218
|
+
var MODIFIER_RE = /\p{M}+/gu;
|
|
219
|
+
var NO_TRUNCATION = { limit: Infinity, ellipsis: "" };
|
|
220
|
+
var getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
|
|
221
|
+
const LIMIT = truncationOptions.limit ?? Infinity;
|
|
222
|
+
const ELLIPSIS = truncationOptions.ellipsis ?? "";
|
|
223
|
+
const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION, widthOptions).width : 0);
|
|
224
|
+
const ANSI_WIDTH = 0;
|
|
225
|
+
const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
|
|
226
|
+
const TAB_WIDTH = widthOptions.tabWidth ?? 8;
|
|
227
|
+
const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
|
|
228
|
+
const FULL_WIDTH_WIDTH = 2;
|
|
229
|
+
const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
|
|
230
|
+
const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
|
|
231
|
+
const PARSE_BLOCKS = [
|
|
232
|
+
[LATIN_RE, REGULAR_WIDTH],
|
|
233
|
+
[ANSI_RE, ANSI_WIDTH],
|
|
234
|
+
[CONTROL_RE, CONTROL_WIDTH],
|
|
235
|
+
[TAB_RE, TAB_WIDTH],
|
|
236
|
+
[EMOJI_RE, EMOJI_WIDTH],
|
|
237
|
+
[CJKT_WIDE_RE, WIDE_WIDTH]
|
|
238
|
+
];
|
|
239
|
+
let indexPrev = 0;
|
|
240
|
+
let index = 0;
|
|
241
|
+
let length = input.length;
|
|
242
|
+
let lengthExtra = 0;
|
|
243
|
+
let truncationEnabled = false;
|
|
244
|
+
let truncationIndex = length;
|
|
245
|
+
let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
|
|
246
|
+
let unmatchedStart = 0;
|
|
247
|
+
let unmatchedEnd = 0;
|
|
248
|
+
let width = 0;
|
|
249
|
+
let widthExtra = 0;
|
|
250
|
+
outer:
|
|
251
|
+
while (true) {
|
|
252
|
+
if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
|
|
253
|
+
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
|
|
254
|
+
lengthExtra = 0;
|
|
255
|
+
for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
|
|
256
|
+
const codePoint = char.codePointAt(0) || 0;
|
|
257
|
+
if (isFullWidth(codePoint)) {
|
|
258
|
+
widthExtra = FULL_WIDTH_WIDTH;
|
|
259
|
+
} else if (isWideNotCJKTNotEmoji(codePoint)) {
|
|
260
|
+
widthExtra = WIDE_WIDTH;
|
|
261
|
+
} else {
|
|
262
|
+
widthExtra = REGULAR_WIDTH;
|
|
263
|
+
}
|
|
264
|
+
if (width + widthExtra > truncationLimit) {
|
|
265
|
+
truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
|
|
266
|
+
}
|
|
267
|
+
if (width + widthExtra > LIMIT) {
|
|
268
|
+
truncationEnabled = true;
|
|
269
|
+
break outer;
|
|
270
|
+
}
|
|
271
|
+
lengthExtra += char.length;
|
|
272
|
+
width += widthExtra;
|
|
273
|
+
}
|
|
274
|
+
unmatchedStart = unmatchedEnd = 0;
|
|
275
|
+
}
|
|
276
|
+
if (index >= length) {
|
|
277
|
+
break outer;
|
|
278
|
+
}
|
|
279
|
+
for (let i = 0, l = PARSE_BLOCKS.length;i < l; i++) {
|
|
280
|
+
const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
|
|
281
|
+
BLOCK_RE.lastIndex = index;
|
|
282
|
+
if (BLOCK_RE.test(input)) {
|
|
283
|
+
lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
|
|
284
|
+
widthExtra = lengthExtra * BLOCK_WIDTH;
|
|
285
|
+
if (width + widthExtra > truncationLimit) {
|
|
286
|
+
truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
|
|
287
|
+
}
|
|
288
|
+
if (width + widthExtra > LIMIT) {
|
|
289
|
+
truncationEnabled = true;
|
|
290
|
+
break outer;
|
|
291
|
+
}
|
|
292
|
+
width += widthExtra;
|
|
293
|
+
unmatchedStart = indexPrev;
|
|
294
|
+
unmatchedEnd = index;
|
|
295
|
+
index = indexPrev = BLOCK_RE.lastIndex;
|
|
296
|
+
continue outer;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
index += 1;
|
|
300
|
+
}
|
|
301
|
+
return {
|
|
302
|
+
width: truncationEnabled ? truncationLimit : width,
|
|
303
|
+
index: truncationEnabled ? truncationIndex : length,
|
|
304
|
+
truncated: truncationEnabled,
|
|
305
|
+
ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
|
|
306
|
+
};
|
|
307
|
+
};
|
|
308
|
+
var dist_default = getStringTruncatedWidth;
|
|
309
|
+
|
|
310
|
+
// ../../node_modules/.bun/fast-string-width@3.0.2/node_modules/fast-string-width/dist/index.js
|
|
311
|
+
var NO_TRUNCATION2 = {
|
|
312
|
+
limit: Infinity,
|
|
313
|
+
ellipsis: "",
|
|
314
|
+
ellipsisWidth: 0
|
|
315
|
+
};
|
|
316
|
+
var fastStringWidth = (input, options = {}) => {
|
|
317
|
+
return dist_default(input, NO_TRUNCATION2, options).width;
|
|
318
|
+
};
|
|
319
|
+
var dist_default2 = fastStringWidth;
|
|
320
|
+
|
|
321
|
+
// ../../node_modules/.bun/fast-wrap-ansi@0.2.0/node_modules/fast-wrap-ansi/lib/main.js
|
|
322
|
+
var ESC = "\x1B";
|
|
323
|
+
var CSI = "\x9B";
|
|
324
|
+
var END_CODE = 39;
|
|
325
|
+
var ANSI_ESCAPE_BELL = "\x07";
|
|
326
|
+
var ANSI_CSI = "[";
|
|
327
|
+
var ANSI_OSC = "]";
|
|
328
|
+
var ANSI_SGR_TERMINATOR = "m";
|
|
329
|
+
var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
330
|
+
var GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
|
|
331
|
+
var getClosingCode = (openingCode) => {
|
|
332
|
+
if (openingCode >= 30 && openingCode <= 37)
|
|
333
|
+
return 39;
|
|
334
|
+
if (openingCode >= 90 && openingCode <= 97)
|
|
335
|
+
return 39;
|
|
336
|
+
if (openingCode >= 40 && openingCode <= 47)
|
|
337
|
+
return 49;
|
|
338
|
+
if (openingCode >= 100 && openingCode <= 107)
|
|
339
|
+
return 49;
|
|
340
|
+
if (openingCode === 1 || openingCode === 2)
|
|
341
|
+
return 22;
|
|
342
|
+
if (openingCode === 3)
|
|
343
|
+
return 23;
|
|
344
|
+
if (openingCode === 4)
|
|
345
|
+
return 24;
|
|
346
|
+
if (openingCode === 7)
|
|
347
|
+
return 27;
|
|
348
|
+
if (openingCode === 8)
|
|
349
|
+
return 28;
|
|
350
|
+
if (openingCode === 9)
|
|
351
|
+
return 29;
|
|
352
|
+
if (openingCode === 0)
|
|
353
|
+
return 0;
|
|
354
|
+
return;
|
|
355
|
+
};
|
|
356
|
+
var wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
357
|
+
var wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
|
|
358
|
+
var wrapWord = (rows, word, columns) => {
|
|
359
|
+
const characters = word[Symbol.iterator]();
|
|
360
|
+
let isInsideEscape = false;
|
|
361
|
+
let isInsideLinkEscape = false;
|
|
362
|
+
let lastRow = rows.at(-1);
|
|
363
|
+
let visible = lastRow === undefined ? 0 : dist_default2(lastRow);
|
|
364
|
+
let currentCharacter = characters.next();
|
|
365
|
+
let nextCharacter = characters.next();
|
|
366
|
+
let rawCharacterIndex = 0;
|
|
367
|
+
while (!currentCharacter.done) {
|
|
368
|
+
const character = currentCharacter.value;
|
|
369
|
+
const characterLength = dist_default2(character);
|
|
370
|
+
if (visible + characterLength <= columns) {
|
|
371
|
+
rows[rows.length - 1] += character;
|
|
372
|
+
} else {
|
|
373
|
+
rows.push(character);
|
|
374
|
+
visible = 0;
|
|
375
|
+
}
|
|
376
|
+
if (character === ESC || character === CSI) {
|
|
377
|
+
isInsideEscape = true;
|
|
378
|
+
isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
|
|
379
|
+
}
|
|
380
|
+
if (isInsideEscape) {
|
|
381
|
+
if (isInsideLinkEscape) {
|
|
382
|
+
if (character === ANSI_ESCAPE_BELL) {
|
|
383
|
+
isInsideEscape = false;
|
|
384
|
+
isInsideLinkEscape = false;
|
|
385
|
+
}
|
|
386
|
+
} else if (character === ANSI_SGR_TERMINATOR) {
|
|
387
|
+
isInsideEscape = false;
|
|
388
|
+
}
|
|
389
|
+
} else {
|
|
390
|
+
visible += characterLength;
|
|
391
|
+
if (visible === columns && !nextCharacter.done) {
|
|
392
|
+
rows.push("");
|
|
393
|
+
visible = 0;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
currentCharacter = nextCharacter;
|
|
397
|
+
nextCharacter = characters.next();
|
|
398
|
+
rawCharacterIndex += character.length;
|
|
399
|
+
}
|
|
400
|
+
lastRow = rows.at(-1);
|
|
401
|
+
if (!visible && lastRow !== undefined && lastRow.length && rows.length > 1) {
|
|
402
|
+
rows[rows.length - 2] += rows.pop();
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
var stringVisibleTrimSpacesRight = (string) => {
|
|
406
|
+
const words = string.split(" ");
|
|
407
|
+
let last = words.length;
|
|
408
|
+
while (last) {
|
|
409
|
+
if (dist_default2(words[last - 1])) {
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
last--;
|
|
413
|
+
}
|
|
414
|
+
if (last === words.length) {
|
|
415
|
+
return string;
|
|
416
|
+
}
|
|
417
|
+
return words.slice(0, last).join(" ") + words.slice(last).join("");
|
|
418
|
+
};
|
|
419
|
+
var exec = (string, columns, options = {}) => {
|
|
420
|
+
if (options.trim !== false && string.trim() === "") {
|
|
421
|
+
return "";
|
|
422
|
+
}
|
|
423
|
+
let returnValue = "";
|
|
424
|
+
let escapeCode;
|
|
425
|
+
let escapeUrl;
|
|
426
|
+
const words = string.split(" ");
|
|
427
|
+
let rows = [""];
|
|
428
|
+
let rowLength = 0;
|
|
429
|
+
for (let index = 0;index < words.length; index++) {
|
|
430
|
+
const word = words[index];
|
|
431
|
+
if (options.trim !== false) {
|
|
432
|
+
const row = rows.at(-1) ?? "";
|
|
433
|
+
const trimmed = row.trimStart();
|
|
434
|
+
if (row.length !== trimmed.length) {
|
|
435
|
+
rows[rows.length - 1] = trimmed;
|
|
436
|
+
rowLength = dist_default2(trimmed);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
if (index !== 0) {
|
|
440
|
+
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
441
|
+
rows.push("");
|
|
442
|
+
rowLength = 0;
|
|
443
|
+
}
|
|
444
|
+
if (rowLength || options.trim === false) {
|
|
445
|
+
rows[rows.length - 1] += " ";
|
|
446
|
+
rowLength++;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
const wordLength = dist_default2(word);
|
|
450
|
+
if (options.hard && wordLength > columns) {
|
|
451
|
+
const remainingColumns = columns - rowLength;
|
|
452
|
+
const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
|
|
453
|
+
const breaksStartingNextLine = Math.floor((wordLength - 1) / columns);
|
|
454
|
+
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
455
|
+
rows.push("");
|
|
456
|
+
}
|
|
457
|
+
wrapWord(rows, word, columns);
|
|
458
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
if (rowLength + wordLength > columns && rowLength && wordLength) {
|
|
462
|
+
if (options.wordWrap === false && rowLength < columns) {
|
|
463
|
+
wrapWord(rows, word, columns);
|
|
464
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
rows.push("");
|
|
468
|
+
rowLength = 0;
|
|
469
|
+
}
|
|
470
|
+
if (rowLength + wordLength > columns && options.wordWrap === false) {
|
|
471
|
+
wrapWord(rows, word, columns);
|
|
472
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
rows[rows.length - 1] += word;
|
|
476
|
+
rowLength += wordLength;
|
|
477
|
+
}
|
|
478
|
+
if (options.trim !== false) {
|
|
479
|
+
rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
480
|
+
}
|
|
481
|
+
const preString = rows.join(`
|
|
482
|
+
`);
|
|
483
|
+
let inSurrogate = false;
|
|
484
|
+
for (let i = 0;i < preString.length; i++) {
|
|
485
|
+
const character = preString[i];
|
|
486
|
+
returnValue += character;
|
|
487
|
+
if (!inSurrogate) {
|
|
488
|
+
inSurrogate = character >= "\uD800" && character <= "\uDBFF";
|
|
489
|
+
if (inSurrogate) {
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
} else {
|
|
493
|
+
inSurrogate = false;
|
|
494
|
+
}
|
|
495
|
+
if (character === ESC || character === CSI) {
|
|
496
|
+
GROUP_REGEX.lastIndex = i + 1;
|
|
497
|
+
const groupsResult = GROUP_REGEX.exec(preString);
|
|
498
|
+
const groups = groupsResult?.groups;
|
|
499
|
+
if (groups?.code !== undefined) {
|
|
500
|
+
const code = Number.parseFloat(groups.code);
|
|
501
|
+
escapeCode = code === END_CODE ? undefined : code;
|
|
502
|
+
} else if (groups?.uri !== undefined) {
|
|
503
|
+
escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
if (preString[i + 1] === `
|
|
507
|
+
`) {
|
|
508
|
+
if (escapeUrl) {
|
|
509
|
+
returnValue += wrapAnsiHyperlink("");
|
|
510
|
+
}
|
|
511
|
+
const closingCode = escapeCode ? getClosingCode(escapeCode) : undefined;
|
|
512
|
+
if (escapeCode && closingCode) {
|
|
513
|
+
returnValue += wrapAnsiCode(closingCode);
|
|
514
|
+
}
|
|
515
|
+
} else if (character === `
|
|
516
|
+
`) {
|
|
517
|
+
if (escapeCode && getClosingCode(escapeCode)) {
|
|
518
|
+
returnValue += wrapAnsiCode(escapeCode);
|
|
519
|
+
}
|
|
520
|
+
if (escapeUrl) {
|
|
521
|
+
returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return returnValue;
|
|
526
|
+
};
|
|
527
|
+
var CRLF_OR_LF = /\r?\n/;
|
|
528
|
+
function wrapAnsi(string, columns, options) {
|
|
529
|
+
return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join(`
|
|
530
|
+
`);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// ../../node_modules/.bun/@clack+core@1.3.1/node_modules/@clack/core/dist/index.mjs
|
|
534
|
+
var import_sisteransi = __toESM(require_src(), 1);
|
|
535
|
+
function f(r, t, s) {
|
|
536
|
+
if (!s.some((o) => !o.disabled))
|
|
537
|
+
return r;
|
|
538
|
+
const e = r + t, i = Math.max(s.length - 1, 0), n = e < 0 ? i : e > i ? 0 : e;
|
|
539
|
+
return s[n].disabled ? f(n, t < 0 ? -1 : 1, s) : n;
|
|
540
|
+
}
|
|
541
|
+
function I(r, t, s, e) {
|
|
542
|
+
const i = e.split(`
|
|
543
|
+
`);
|
|
544
|
+
let n = 0, o = r;
|
|
545
|
+
for (const a of i) {
|
|
546
|
+
if (o <= a.length)
|
|
547
|
+
break;
|
|
548
|
+
o -= a.length + 1, n++;
|
|
549
|
+
}
|
|
550
|
+
for (n = Math.max(0, Math.min(i.length - 1, n + s)), o = Math.min(o, i[n].length) + t;o < 0 && n > 0; )
|
|
551
|
+
n--, o += i[n].length + 1;
|
|
552
|
+
for (;o > i[n].length && n < i.length - 1; )
|
|
553
|
+
o -= i[n].length + 1, n++;
|
|
554
|
+
o = Math.max(0, Math.min(i[n].length, o));
|
|
555
|
+
let u = 0;
|
|
556
|
+
for (let a = 0;a < n; a++)
|
|
557
|
+
u += i[a].length + 1;
|
|
558
|
+
return u + o;
|
|
559
|
+
}
|
|
560
|
+
var G = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
561
|
+
var K = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
562
|
+
var h = { actions: new Set(G), aliases: new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"], ["\x03", "cancel"], ["escape", "cancel"]]), messages: { cancel: "Canceled", error: "Something went wrong" }, withGuide: true, date: { monthNames: [...K], messages: { required: "Please enter a valid date", invalidMonth: "There are only 12 months in a year", invalidDay: (r, t) => `There are only ${r} days in ${t}`, afterMin: (r) => `Date must be on or after ${r.toISOString().slice(0, 10)}`, beforeMax: (r) => `Date must be on or before ${r.toISOString().slice(0, 10)}` } } };
|
|
563
|
+
function C(r, t) {
|
|
564
|
+
if (typeof r == "string")
|
|
565
|
+
return h.aliases.get(r) === t;
|
|
566
|
+
for (const s of r)
|
|
567
|
+
if (s !== undefined && C(s, t))
|
|
568
|
+
return true;
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
571
|
+
function z(r, t) {
|
|
572
|
+
if (r === t)
|
|
573
|
+
return;
|
|
574
|
+
const s = r.split(`
|
|
575
|
+
`), e = t.split(`
|
|
576
|
+
`), i = Math.max(s.length, e.length), n = [];
|
|
577
|
+
for (let o = 0;o < i; o++)
|
|
578
|
+
s[o] !== e[o] && n.push(o);
|
|
579
|
+
return { lines: n, numLinesBefore: s.length, numLinesAfter: e.length, numLines: i };
|
|
580
|
+
}
|
|
581
|
+
var Y = globalThis.process.platform.startsWith("win");
|
|
582
|
+
var k = Symbol("clack:cancel");
|
|
583
|
+
function q(r) {
|
|
584
|
+
return r === k;
|
|
585
|
+
}
|
|
586
|
+
function w(r, t) {
|
|
587
|
+
const s = r;
|
|
588
|
+
s.isTTY && s.setRawMode(t);
|
|
589
|
+
}
|
|
590
|
+
var A = (r) => ("columns" in r) && typeof r.columns == "number" ? r.columns : 80;
|
|
591
|
+
var L = (r) => ("rows" in r) && typeof r.rows == "number" ? r.rows : 20;
|
|
592
|
+
function W(r, t, s, e = s, i = s, n) {
|
|
593
|
+
const o = A(r ?? x);
|
|
594
|
+
return wrapAnsi(t, o - s.length, { hard: true, trim: false }).split(`
|
|
595
|
+
`).map((u, a, l) => {
|
|
596
|
+
const c = n ? n(u, a) : u;
|
|
597
|
+
return a === 0 ? `${e}${c}` : a === l.length - 1 ? `${i}${c}` : `${s}${c}`;
|
|
598
|
+
}).join(`
|
|
599
|
+
`);
|
|
600
|
+
}
|
|
601
|
+
var m = class {
|
|
602
|
+
input;
|
|
603
|
+
output;
|
|
604
|
+
_abortSignal;
|
|
605
|
+
rl;
|
|
606
|
+
opts;
|
|
607
|
+
_render;
|
|
608
|
+
_track = false;
|
|
609
|
+
_prevFrame = "";
|
|
610
|
+
_subscribers = new Map;
|
|
611
|
+
_cursor = 0;
|
|
612
|
+
state = "initial";
|
|
613
|
+
error = "";
|
|
614
|
+
value;
|
|
615
|
+
userInput = "";
|
|
616
|
+
constructor(t, s = true) {
|
|
617
|
+
const { input: e = D, output: i = x, render: n, signal: o, ...u } = t;
|
|
618
|
+
this.opts = u, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = n.bind(this), this._track = s, this._abortSignal = o, this.input = e, this.output = i;
|
|
619
|
+
}
|
|
620
|
+
unsubscribe() {
|
|
621
|
+
this._subscribers.clear();
|
|
622
|
+
}
|
|
623
|
+
setSubscriber(t, s) {
|
|
624
|
+
const e = this._subscribers.get(t) ?? [];
|
|
625
|
+
e.push(s), this._subscribers.set(t, e);
|
|
626
|
+
}
|
|
627
|
+
on(t, s) {
|
|
628
|
+
this.setSubscriber(t, { cb: s });
|
|
629
|
+
}
|
|
630
|
+
once(t, s) {
|
|
631
|
+
this.setSubscriber(t, { cb: s, once: true });
|
|
632
|
+
}
|
|
633
|
+
emit(t, ...s) {
|
|
634
|
+
const e = this._subscribers.get(t) ?? [], i = [];
|
|
635
|
+
for (const n of e)
|
|
636
|
+
n.cb(...s), n.once && i.push(() => e.splice(e.indexOf(n), 1));
|
|
637
|
+
for (const n of i)
|
|
638
|
+
n();
|
|
639
|
+
}
|
|
640
|
+
prompt() {
|
|
641
|
+
return new Promise((t) => {
|
|
642
|
+
if (this._abortSignal) {
|
|
643
|
+
if (this._abortSignal.aborted)
|
|
644
|
+
return this.state = "cancel", this.close(), t(k);
|
|
645
|
+
this._abortSignal.addEventListener("abort", () => {
|
|
646
|
+
this.state = "cancel", this.close();
|
|
647
|
+
}, { once: true });
|
|
648
|
+
}
|
|
649
|
+
this.rl = E.createInterface({ input: this.input, tabSize: 2, prompt: "", escapeCodeTimeout: 50, terminal: true }), this.rl.prompt(), this.opts.initialUserInput !== undefined && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), w(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
|
|
650
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), w(this.input, false), t(this.value);
|
|
651
|
+
}), this.once("cancel", () => {
|
|
652
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), w(this.input, false), t(k);
|
|
653
|
+
});
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
_isActionKey(t, s) {
|
|
657
|
+
return t === "\t";
|
|
658
|
+
}
|
|
659
|
+
_shouldSubmit(t, s) {
|
|
660
|
+
return true;
|
|
661
|
+
}
|
|
662
|
+
_setValue(t) {
|
|
663
|
+
this.value = t, this.emit("value", this.value);
|
|
664
|
+
}
|
|
665
|
+
_setUserInput(t, s) {
|
|
666
|
+
this.userInput = t ?? "", this.emit("userInput", this.userInput), s && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
|
|
667
|
+
}
|
|
668
|
+
_clearUserInput() {
|
|
669
|
+
this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
|
|
670
|
+
}
|
|
671
|
+
onKeypress(t, s) {
|
|
672
|
+
if (this._track && s.name !== "return" && (s.name && this._isActionKey(t, s) && 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"), s?.name && (!this._track && h.aliases.has(s.name) && this.emit("cursor", h.aliases.get(s.name)), h.actions.has(s.name) && this.emit("cursor", s.name)), t && (t.toLowerCase() === "y" || t.toLowerCase() === "n") && this.emit("confirm", t.toLowerCase() === "y"), this.emit("key", t?.toLowerCase(), s), s?.name === "return" && this._shouldSubmit(t, s)) {
|
|
673
|
+
if (this.opts.validate) {
|
|
674
|
+
const e = this.opts.validate(this.value);
|
|
675
|
+
e && (this.error = e instanceof Error ? e.message : e, this.state = "error", this.rl?.write(this.userInput));
|
|
676
|
+
}
|
|
677
|
+
this.state !== "error" && (this.state = "submit");
|
|
678
|
+
}
|
|
679
|
+
C([t, s?.name, s?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
680
|
+
}
|
|
681
|
+
close() {
|
|
682
|
+
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
683
|
+
`), w(this.input, false), this.rl?.close(), this.rl = undefined, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
684
|
+
}
|
|
685
|
+
restoreCursor() {
|
|
686
|
+
const t = wrapAnsi(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
|
|
687
|
+
`).length - 1;
|
|
688
|
+
this.output.write(import_sisteransi.cursor.move(-999, t * -1));
|
|
689
|
+
}
|
|
690
|
+
render() {
|
|
691
|
+
const t = wrapAnsi(this._render(this) ?? "", process.stdout.columns, { hard: true, trim: false });
|
|
692
|
+
if (t !== this._prevFrame) {
|
|
693
|
+
if (this.state === "initial")
|
|
694
|
+
this.output.write(import_sisteransi.cursor.hide);
|
|
695
|
+
else {
|
|
696
|
+
const s = z(this._prevFrame, t), e = L(this.output);
|
|
697
|
+
if (this.restoreCursor(), s) {
|
|
698
|
+
const i = Math.max(0, s.numLinesAfter - e), n = Math.max(0, s.numLinesBefore - e);
|
|
699
|
+
let o = s.lines.find((u) => u >= i);
|
|
700
|
+
if (o === undefined) {
|
|
701
|
+
this._prevFrame = t;
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
if (s.lines.length === 1) {
|
|
705
|
+
this.output.write(import_sisteransi.cursor.move(0, o - n)), this.output.write(import_sisteransi.erase.lines(1));
|
|
706
|
+
const u = t.split(`
|
|
707
|
+
`);
|
|
708
|
+
this.output.write(u[o]), this._prevFrame = t, this.output.write(import_sisteransi.cursor.move(0, u.length - o - 1));
|
|
709
|
+
return;
|
|
710
|
+
} else if (s.lines.length > 1) {
|
|
711
|
+
if (i < n)
|
|
712
|
+
o = i;
|
|
713
|
+
else {
|
|
714
|
+
const a = o - n;
|
|
715
|
+
a > 0 && this.output.write(import_sisteransi.cursor.move(0, a));
|
|
716
|
+
}
|
|
717
|
+
this.output.write(import_sisteransi.erase.down());
|
|
718
|
+
const u = t.split(`
|
|
719
|
+
`).slice(o);
|
|
720
|
+
this.output.write(u.join(`
|
|
721
|
+
`)), this._prevFrame = t;
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
this.output.write(import_sisteransi.erase.down());
|
|
726
|
+
}
|
|
727
|
+
this.output.write(t), this.state === "initial" && (this.state = "active"), this._prevFrame = t;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
function B(r, t) {
|
|
732
|
+
if (r === undefined || t.length === 0)
|
|
733
|
+
return 0;
|
|
734
|
+
const s = t.findIndex((e) => e.value === r);
|
|
735
|
+
return s !== -1 ? s : 0;
|
|
736
|
+
}
|
|
737
|
+
function J(r, t) {
|
|
738
|
+
return (t.label ?? String(t.value)).toLowerCase().includes(r.toLowerCase());
|
|
739
|
+
}
|
|
740
|
+
function H(r, t) {
|
|
741
|
+
if (t)
|
|
742
|
+
return r ? t : t[0];
|
|
743
|
+
}
|
|
744
|
+
var Q = class extends m {
|
|
745
|
+
filteredOptions;
|
|
746
|
+
multiple;
|
|
747
|
+
isNavigating = false;
|
|
748
|
+
selectedValues = [];
|
|
749
|
+
focusedValue;
|
|
750
|
+
#s = 0;
|
|
751
|
+
#r = "";
|
|
752
|
+
#t;
|
|
753
|
+
#n;
|
|
754
|
+
#u;
|
|
755
|
+
get cursor() {
|
|
756
|
+
return this.#s;
|
|
757
|
+
}
|
|
758
|
+
get userInputWithCursor() {
|
|
759
|
+
if (!this.userInput)
|
|
760
|
+
return v(["inverse", "hidden"], "_");
|
|
761
|
+
if (this._cursor >= this.userInput.length)
|
|
762
|
+
return `${this.userInput}\u2588`;
|
|
763
|
+
const t = this.userInput.slice(0, this._cursor), [s, ...e] = this.userInput.slice(this._cursor);
|
|
764
|
+
return `${t}${v("inverse", s)}${e.join("")}`;
|
|
765
|
+
}
|
|
766
|
+
get options() {
|
|
767
|
+
return typeof this.#n == "function" ? this.#n() : this.#n;
|
|
768
|
+
}
|
|
769
|
+
constructor(t) {
|
|
770
|
+
super(t), this.#n = t.options, this.#u = t.placeholder;
|
|
771
|
+
const s = this.options;
|
|
772
|
+
this.filteredOptions = [...s], this.multiple = t.multiple === true, this.#t = typeof t.options == "function" ? t.filter : t.filter ?? J;
|
|
773
|
+
let e;
|
|
774
|
+
if (t.initialValue && Array.isArray(t.initialValue) ? this.multiple ? e = t.initialValue : e = t.initialValue.slice(0, 1) : !this.multiple && this.options.length > 0 && (e = [this.options[0].value]), e)
|
|
775
|
+
for (const i of e) {
|
|
776
|
+
const n = s.findIndex((o) => o.value === i);
|
|
777
|
+
n !== -1 && (this.toggleSelected(i), this.#s = n);
|
|
778
|
+
}
|
|
779
|
+
this.focusedValue = this.options[this.#s]?.value, this.on("key", (i, n) => this.#e(i, n)), this.on("userInput", (i) => this.#i(i));
|
|
780
|
+
}
|
|
781
|
+
_isActionKey(t, s) {
|
|
782
|
+
return t === "\t" || this.multiple && this.isNavigating && s.name === "space" && t !== undefined && t !== "";
|
|
783
|
+
}
|
|
784
|
+
#e(t, s) {
|
|
785
|
+
const e = s.name === "up", i = s.name === "down", n = s.name === "return", o = this.userInput === "" || this.userInput === "\t", u = this.#u, a = this.options, l = u !== undefined && u !== "" && a.some((c) => !c.disabled && (this.#t ? this.#t(u, c) : true));
|
|
786
|
+
if (s.name === "tab" && o && l) {
|
|
787
|
+
this.userInput === "\t" && this._clearUserInput(), this._setUserInput(u, true), this.isNavigating = false;
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
e || i ? (this.#s = f(this.#s, e ? -1 : 1, this.filteredOptions), this.focusedValue = this.filteredOptions[this.#s]?.value, this.multiple || (this.selectedValues = [this.focusedValue]), this.isNavigating = true) : n ? this.value = H(this.multiple, this.selectedValues) : this.multiple ? this.focusedValue !== undefined && (s.name === "tab" || this.isNavigating && s.name === "space") ? this.toggleSelected(this.focusedValue) : this.isNavigating = false : (this.focusedValue && (this.selectedValues = [this.focusedValue]), this.isNavigating = false);
|
|
791
|
+
}
|
|
792
|
+
deselectAll() {
|
|
793
|
+
this.selectedValues = [];
|
|
794
|
+
}
|
|
795
|
+
toggleSelected(t) {
|
|
796
|
+
this.filteredOptions.length !== 0 && (this.multiple ? this.selectedValues.includes(t) ? this.selectedValues = this.selectedValues.filter((s) => s !== t) : this.selectedValues = [...this.selectedValues, t] : this.selectedValues = [t]);
|
|
797
|
+
}
|
|
798
|
+
#i(t) {
|
|
799
|
+
if (t !== this.#r) {
|
|
800
|
+
this.#r = t;
|
|
801
|
+
const s = this.options;
|
|
802
|
+
t && this.#t ? this.filteredOptions = s.filter((n) => this.#t?.(t, n)) : this.filteredOptions = [...s];
|
|
803
|
+
const e = B(this.focusedValue, this.filteredOptions);
|
|
804
|
+
this.#s = f(e, 0, this.filteredOptions);
|
|
805
|
+
const i = this.filteredOptions[this.#s];
|
|
806
|
+
i && !i.disabled ? this.focusedValue = i.value : this.focusedValue = undefined, this.multiple || (this.focusedValue !== undefined ? this.toggleSelected(this.focusedValue) : this.deselectAll());
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
var Z = { Y: { type: "year", len: 4 }, M: { type: "month", len: 2 }, D: { type: "day", len: 2 } };
|
|
811
|
+
function P(r) {
|
|
812
|
+
return [...r].map((t) => Z[t]);
|
|
813
|
+
}
|
|
814
|
+
function tt(r) {
|
|
815
|
+
const t = new Intl.DateTimeFormat(r, { year: "numeric", month: "2-digit", day: "2-digit" }).formatToParts(new Date(2000, 0, 15)), s = [];
|
|
816
|
+
let e = "/";
|
|
817
|
+
for (const i of t)
|
|
818
|
+
i.type === "literal" ? e = i.value.trim() || i.value : (i.type === "year" || i.type === "month" || i.type === "day") && s.push({ type: i.type, len: i.type === "year" ? 4 : 2 });
|
|
819
|
+
return { segments: s, separator: e };
|
|
820
|
+
}
|
|
821
|
+
function $(r) {
|
|
822
|
+
return Number.parseInt((r || "0").replace(/_/g, "0"), 10) || 0;
|
|
823
|
+
}
|
|
824
|
+
function S(r) {
|
|
825
|
+
return { year: $(r.year), month: $(r.month), day: $(r.day) };
|
|
826
|
+
}
|
|
827
|
+
function U(r, t) {
|
|
828
|
+
return new Date(r || 2001, t || 1, 0).getDate();
|
|
829
|
+
}
|
|
830
|
+
function F(r) {
|
|
831
|
+
const { year: t, month: s, day: e } = S(r);
|
|
832
|
+
if (!t || t < 0 || t > 9999 || !s || s < 1 || s > 12 || !e || e < 1)
|
|
833
|
+
return;
|
|
834
|
+
const i = new Date(Date.UTC(t, s - 1, e));
|
|
835
|
+
if (!(i.getUTCFullYear() !== t || i.getUTCMonth() !== s - 1 || i.getUTCDate() !== e))
|
|
836
|
+
return { year: t, month: s, day: e };
|
|
837
|
+
}
|
|
838
|
+
function N(r) {
|
|
839
|
+
const t = F(r);
|
|
840
|
+
return t ? new Date(Date.UTC(t.year, t.month - 1, t.day)) : undefined;
|
|
841
|
+
}
|
|
842
|
+
function st(r, t, s, e) {
|
|
843
|
+
const i = s ? { year: s.getUTCFullYear(), month: s.getUTCMonth() + 1, day: s.getUTCDate() } : null, n = e ? { year: e.getUTCFullYear(), month: e.getUTCMonth() + 1, day: e.getUTCDate() } : null;
|
|
844
|
+
return r === "year" ? { min: i?.year ?? 1, max: n?.year ?? 9999 } : r === "month" ? { min: i && t.year === i.year ? i.month : 1, max: n && t.year === n.year ? n.month : 12 } : { min: i && t.year === i.year && t.month === i.month ? i.day : 1, max: n && t.year === n.year && t.month === n.month ? n.day : U(t.year, t.month) };
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
class et extends m {
|
|
848
|
+
#s;
|
|
849
|
+
#r;
|
|
850
|
+
#t;
|
|
851
|
+
#n;
|
|
852
|
+
#u;
|
|
853
|
+
#e = { segmentIndex: 0, positionInSegment: 0 };
|
|
854
|
+
#i = true;
|
|
855
|
+
#o = null;
|
|
856
|
+
inlineError = "";
|
|
857
|
+
get segmentCursor() {
|
|
858
|
+
return { ...this.#e };
|
|
859
|
+
}
|
|
860
|
+
get segmentValues() {
|
|
861
|
+
return { ...this.#t };
|
|
862
|
+
}
|
|
863
|
+
get segments() {
|
|
864
|
+
return this.#s;
|
|
865
|
+
}
|
|
866
|
+
get separator() {
|
|
867
|
+
return this.#r;
|
|
868
|
+
}
|
|
869
|
+
get formattedValue() {
|
|
870
|
+
return this.#c(this.#t);
|
|
871
|
+
}
|
|
872
|
+
#c(t) {
|
|
873
|
+
return this.#s.map((s) => t[s.type]).join(this.#r);
|
|
874
|
+
}
|
|
875
|
+
#a() {
|
|
876
|
+
this._setUserInput(this.#c(this.#t)), this._setValue(N(this.#t) ?? undefined);
|
|
877
|
+
}
|
|
878
|
+
constructor(t) {
|
|
879
|
+
const s = t.format ? { segments: P(t.format), separator: t.separator ?? "/" } : tt(t.locale), e = t.separator ?? s.separator, i = t.format ? P(t.format) : s.segments, n = t.initialValue ?? t.defaultValue, o = n ? { year: String(n.getUTCFullYear()).padStart(4, "0"), month: String(n.getUTCMonth() + 1).padStart(2, "0"), day: String(n.getUTCDate()).padStart(2, "0") } : { year: "____", month: "__", day: "__" }, u = i.map((a) => o[a.type]).join(e);
|
|
880
|
+
super({ ...t, initialUserInput: u }, false), this.#s = i, this.#r = e, this.#t = o, this.#n = t.minDate, this.#u = t.maxDate, this.#a(), this.on("cursor", (a) => this.#d(a)), this.on("key", (a, l) => this.#f(a, l)), this.on("finalize", () => this.#g(t));
|
|
881
|
+
}
|
|
882
|
+
#h() {
|
|
883
|
+
const t = Math.max(0, Math.min(this.#e.segmentIndex, this.#s.length - 1)), s = this.#s[t];
|
|
884
|
+
if (s)
|
|
885
|
+
return this.#e.positionInSegment = Math.max(0, Math.min(this.#e.positionInSegment, s.len - 1)), { segment: s, index: t };
|
|
886
|
+
}
|
|
887
|
+
#l(t) {
|
|
888
|
+
this.inlineError = "", this.#o = null;
|
|
889
|
+
const s = this.#h();
|
|
890
|
+
s && (this.#e.segmentIndex = Math.max(0, Math.min(this.#s.length - 1, s.index + t)), this.#e.positionInSegment = 0, this.#i = true);
|
|
891
|
+
}
|
|
892
|
+
#p(t) {
|
|
893
|
+
const s = this.#h();
|
|
894
|
+
if (!s)
|
|
895
|
+
return;
|
|
896
|
+
const { segment: e } = s, i = this.#t[e.type], n = !i || i.replace(/_/g, "") === "", o = Number.parseInt((i || "0").replace(/_/g, "0"), 10) || 0, u = st(e.type, S(this.#t), this.#n, this.#u);
|
|
897
|
+
let a;
|
|
898
|
+
n ? a = t === 1 ? u.min : u.max : a = Math.max(Math.min(u.max, o + t), u.min), this.#t = { ...this.#t, [e.type]: a.toString().padStart(e.len, "0") }, this.#i = true, this.#o = null, this.#a();
|
|
899
|
+
}
|
|
900
|
+
#d(t) {
|
|
901
|
+
if (t)
|
|
902
|
+
switch (t) {
|
|
903
|
+
case "right":
|
|
904
|
+
return this.#l(1);
|
|
905
|
+
case "left":
|
|
906
|
+
return this.#l(-1);
|
|
907
|
+
case "up":
|
|
908
|
+
return this.#p(1);
|
|
909
|
+
case "down":
|
|
910
|
+
return this.#p(-1);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
#f(t, s) {
|
|
914
|
+
if (s?.name === "backspace" || s?.sequence === "\x7F" || s?.sequence === "\b" || t === "\x7F" || t === "\b") {
|
|
915
|
+
this.inlineError = "";
|
|
916
|
+
const e = this.#h();
|
|
917
|
+
if (!e)
|
|
918
|
+
return;
|
|
919
|
+
if (!this.#t[e.segment.type].replace(/_/g, "")) {
|
|
920
|
+
this.#l(-1);
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
this.#t[e.segment.type] = "_".repeat(e.segment.len), this.#i = true, this.#e.positionInSegment = 0, this.#a();
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
if (s?.name === "tab") {
|
|
927
|
+
this.inlineError = "";
|
|
928
|
+
const e = this.#h();
|
|
929
|
+
if (!e)
|
|
930
|
+
return;
|
|
931
|
+
const i = s.shift ? -1 : 1, n = e.index + i;
|
|
932
|
+
n >= 0 && n < this.#s.length && (this.#e.segmentIndex = n, this.#e.positionInSegment = 0, this.#i = true);
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
if (t && /^[0-9]$/.test(t)) {
|
|
936
|
+
const e = this.#h();
|
|
937
|
+
if (!e)
|
|
938
|
+
return;
|
|
939
|
+
const { segment: i } = e, n = !this.#t[i.type].replace(/_/g, "");
|
|
940
|
+
if (this.#i && this.#o !== null && !n) {
|
|
941
|
+
const d = this.#o + t, g = { ...this.#t, [i.type]: d }, _ = this.#m(g, i);
|
|
942
|
+
if (_) {
|
|
943
|
+
this.inlineError = _, this.#o = null, this.#i = false;
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
this.inlineError = "", this.#t[i.type] = d, this.#o = null, this.#i = false, this.#a(), e.index < this.#s.length - 1 && (this.#e.segmentIndex = e.index + 1, this.#e.positionInSegment = 0, this.#i = true);
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
this.#i && !n && (this.#t[i.type] = "_".repeat(i.len), this.#e.positionInSegment = 0), this.#i = false, this.#o = null;
|
|
950
|
+
const o = this.#t[i.type], u = o.indexOf("_"), a = u >= 0 ? u : Math.min(this.#e.positionInSegment, i.len - 1);
|
|
951
|
+
if (a < 0 || a >= i.len)
|
|
952
|
+
return;
|
|
953
|
+
let l = o.slice(0, a) + t + o.slice(a + 1), c = false;
|
|
954
|
+
if (a === 0 && o === "__" && (i.type === "month" || i.type === "day")) {
|
|
955
|
+
const d = Number.parseInt(t, 10);
|
|
956
|
+
l = `0${t}`, c = d <= (i.type === "month" ? 1 : 2);
|
|
957
|
+
}
|
|
958
|
+
if (i.type === "year" && (l = (o.replace(/_/g, "") + t).padStart(i.len, "_")), !l.includes("_")) {
|
|
959
|
+
const d = { ...this.#t, [i.type]: l }, g = this.#m(d, i);
|
|
960
|
+
if (g) {
|
|
961
|
+
this.inlineError = g;
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
this.inlineError = "", this.#t[i.type] = l;
|
|
966
|
+
const y = l.includes("_") ? undefined : F(this.#t);
|
|
967
|
+
if (y) {
|
|
968
|
+
const { year: d, month: g } = y, _ = U(d, g);
|
|
969
|
+
this.#t = { year: String(Math.max(0, Math.min(9999, d))).padStart(4, "0"), month: String(Math.max(1, Math.min(12, g))).padStart(2, "0"), day: String(Math.max(1, Math.min(_, y.day))).padStart(2, "0") };
|
|
970
|
+
}
|
|
971
|
+
this.#a();
|
|
972
|
+
const T = l.indexOf("_");
|
|
973
|
+
c ? (this.#i = true, this.#o = t) : T >= 0 ? this.#e.positionInSegment = T : u >= 0 && e.index < this.#s.length - 1 ? (this.#e.segmentIndex = e.index + 1, this.#e.positionInSegment = 0, this.#i = true) : this.#e.positionInSegment = Math.min(a + 1, i.len - 1);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
#m(t, s) {
|
|
977
|
+
const { month: e, day: i } = S(t);
|
|
978
|
+
if (s.type === "month" && (e < 0 || e > 12))
|
|
979
|
+
return h.date.messages.invalidMonth;
|
|
980
|
+
if (s.type === "day" && (i < 0 || i > 31))
|
|
981
|
+
return h.date.messages.invalidDay(31, "any month");
|
|
982
|
+
}
|
|
983
|
+
#g(t) {
|
|
984
|
+
const { year: s, month: e, day: i } = S(this.#t);
|
|
985
|
+
if (s && e && i) {
|
|
986
|
+
const n = U(s, e);
|
|
987
|
+
this.#t = { ...this.#t, day: String(Math.min(i, n)).padStart(2, "0") };
|
|
988
|
+
}
|
|
989
|
+
this.value = N(this.#t) ?? t.defaultValue ?? undefined;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
class it extends m {
|
|
994
|
+
options;
|
|
995
|
+
cursor = 0;
|
|
996
|
+
#s;
|
|
997
|
+
getGroupItems(t) {
|
|
998
|
+
return this.options.filter((s) => s.group === t);
|
|
999
|
+
}
|
|
1000
|
+
isGroupSelected(t) {
|
|
1001
|
+
const s = this.getGroupItems(t), e = this.value;
|
|
1002
|
+
return e === undefined ? false : s.every((i) => e.includes(i.value));
|
|
1003
|
+
}
|
|
1004
|
+
toggleValue() {
|
|
1005
|
+
const t = this.options[this.cursor];
|
|
1006
|
+
if (this.value === undefined && (this.value = []), t.group === true) {
|
|
1007
|
+
const s = t.value, e = this.getGroupItems(s);
|
|
1008
|
+
this.isGroupSelected(s) ? this.value = this.value.filter((i) => e.findIndex((n) => n.value === i) === -1) : this.value = [...this.value, ...e.map((i) => i.value)], this.value = Array.from(new Set(this.value));
|
|
1009
|
+
} else {
|
|
1010
|
+
const s = this.value.includes(t.value);
|
|
1011
|
+
this.value = s ? this.value.filter((e) => e !== t.value) : [...this.value, t.value];
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
constructor(t) {
|
|
1015
|
+
super(t, false);
|
|
1016
|
+
const { options: s } = t;
|
|
1017
|
+
this.#s = t.selectableGroups !== false, this.options = Object.entries(s).flatMap(([e, i]) => [{ value: e, group: true, label: e }, ...i.map((n) => ({ ...n, group: e }))]), this.value = [...t.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: e }) => e === t.cursorAt), this.#s ? 0 : 1), this.on("cursor", (e) => {
|
|
1018
|
+
switch (e) {
|
|
1019
|
+
case "left":
|
|
1020
|
+
case "up": {
|
|
1021
|
+
this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
|
|
1022
|
+
const i = this.options[this.cursor]?.group === true;
|
|
1023
|
+
!this.#s && i && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
|
|
1024
|
+
break;
|
|
1025
|
+
}
|
|
1026
|
+
case "down":
|
|
1027
|
+
case "right": {
|
|
1028
|
+
this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
|
|
1029
|
+
const i = this.options[this.cursor]?.group === true;
|
|
1030
|
+
!this.#s && i && (this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1);
|
|
1031
|
+
break;
|
|
1032
|
+
}
|
|
1033
|
+
case "space":
|
|
1034
|
+
this.toggleValue();
|
|
1035
|
+
break;
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
class rt extends m {
|
|
1042
|
+
#s = false;
|
|
1043
|
+
#r;
|
|
1044
|
+
focused = "editor";
|
|
1045
|
+
get userInputWithCursor() {
|
|
1046
|
+
if (this.state === "submit")
|
|
1047
|
+
return this.userInput;
|
|
1048
|
+
const t = this.userInput;
|
|
1049
|
+
if (this.cursor >= t.length)
|
|
1050
|
+
return `${t}\u2588`;
|
|
1051
|
+
const s = t.slice(0, this.cursor), e = t[this.cursor], i = t.slice(this.cursor + 1);
|
|
1052
|
+
return e === `
|
|
1053
|
+
` ? `${s}\u2588
|
|
1054
|
+
${i}` : `${s}${v("inverse", e)}${i}`;
|
|
1055
|
+
}
|
|
1056
|
+
get cursor() {
|
|
1057
|
+
return this._cursor;
|
|
1058
|
+
}
|
|
1059
|
+
#t(t) {
|
|
1060
|
+
if (this.userInput.length === 0) {
|
|
1061
|
+
this._setUserInput(t);
|
|
1062
|
+
return;
|
|
1063
|
+
}
|
|
1064
|
+
this._setUserInput(this.userInput.slice(0, this.cursor) + t + this.userInput.slice(this.cursor));
|
|
1065
|
+
}
|
|
1066
|
+
#n(t) {
|
|
1067
|
+
const s = this.value ?? "";
|
|
1068
|
+
switch (t) {
|
|
1069
|
+
case "up":
|
|
1070
|
+
this._cursor = I(this._cursor, 0, -1, s);
|
|
1071
|
+
return;
|
|
1072
|
+
case "down":
|
|
1073
|
+
this._cursor = I(this._cursor, 0, 1, s);
|
|
1074
|
+
return;
|
|
1075
|
+
case "left":
|
|
1076
|
+
this._cursor = I(this._cursor, -1, 0, s);
|
|
1077
|
+
return;
|
|
1078
|
+
case "right":
|
|
1079
|
+
this._cursor = I(this._cursor, 1, 0, s);
|
|
1080
|
+
return;
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
_shouldSubmit(t, s) {
|
|
1084
|
+
if (this.#r)
|
|
1085
|
+
return this.focused === "submit" ? true : (this.#t(`
|
|
1086
|
+
`), this._cursor++, false);
|
|
1087
|
+
const e = this.#s;
|
|
1088
|
+
return this.#s = true, e ? (this.userInput[this.cursor - 1] === `
|
|
1089
|
+
` && (this._setUserInput(this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)), this._cursor--), true) : (this.#t(`
|
|
1090
|
+
`), this._cursor++, false);
|
|
1091
|
+
}
|
|
1092
|
+
constructor(t) {
|
|
1093
|
+
super(t, false), this.#r = t.showSubmit ?? false, this.on("key", (s, e) => {
|
|
1094
|
+
if (e?.name && h.actions.has(e.name)) {
|
|
1095
|
+
this.#n(e.name);
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
if (s === "\t" && this.#r) {
|
|
1099
|
+
this.focused = this.focused === "editor" ? "submit" : "editor";
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
1102
|
+
if (e?.name !== "return") {
|
|
1103
|
+
if (this.#s = false, e?.name === "backspace" && this.cursor > 0) {
|
|
1104
|
+
this._setUserInput(this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)), this._cursor--;
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
if (e?.name === "delete" && this.cursor < this.userInput.length) {
|
|
1108
|
+
this._setUserInput(this.userInput.slice(0, this.cursor) + this.userInput.slice(this.cursor + 1));
|
|
1109
|
+
return;
|
|
1110
|
+
}
|
|
1111
|
+
s && (this.#r && this.focused === "submit" && (this.focused = "editor"), this.#t(s ?? ""), this._cursor++);
|
|
1112
|
+
}
|
|
1113
|
+
}), this.on("userInput", (s) => {
|
|
1114
|
+
this._setValue(s);
|
|
1115
|
+
}), this.on("finalize", () => {
|
|
1116
|
+
this.value || (this.value = t.defaultValue), this.value === undefined && (this.value = "");
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
class ut extends m {
|
|
1121
|
+
options;
|
|
1122
|
+
cursor = 0;
|
|
1123
|
+
get _selectedValue() {
|
|
1124
|
+
return this.options[this.cursor];
|
|
1125
|
+
}
|
|
1126
|
+
changeValue() {
|
|
1127
|
+
this.value = this._selectedValue.value;
|
|
1128
|
+
}
|
|
1129
|
+
constructor(t) {
|
|
1130
|
+
super(t, false), this.options = t.options;
|
|
1131
|
+
const s = this.options.findIndex(({ value: i }) => i === t.initialValue), e = s === -1 ? 0 : s;
|
|
1132
|
+
this.cursor = this.options[e].disabled ? f(e, 1, this.options) : e, this.changeValue(), this.on("cursor", (i) => {
|
|
1133
|
+
switch (i) {
|
|
1134
|
+
case "left":
|
|
1135
|
+
case "up":
|
|
1136
|
+
this.cursor = f(this.cursor, -1, this.options);
|
|
1137
|
+
break;
|
|
1138
|
+
case "down":
|
|
1139
|
+
case "right":
|
|
1140
|
+
this.cursor = f(this.cursor, 1, this.options);
|
|
1141
|
+
break;
|
|
1142
|
+
}
|
|
1143
|
+
this.changeValue();
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
class ht extends m {
|
|
1148
|
+
get userInputWithCursor() {
|
|
1149
|
+
if (this.state === "submit")
|
|
1150
|
+
return this.userInput;
|
|
1151
|
+
const t = this.userInput;
|
|
1152
|
+
if (this.cursor >= t.length)
|
|
1153
|
+
return `${this.userInput}\u2588`;
|
|
1154
|
+
const s = t.slice(0, this.cursor), [e, ...i] = t.slice(this.cursor);
|
|
1155
|
+
return `${s}${v("inverse", e)}${i.join("")}`;
|
|
1156
|
+
}
|
|
1157
|
+
get cursor() {
|
|
1158
|
+
return this._cursor;
|
|
1159
|
+
}
|
|
1160
|
+
constructor(t) {
|
|
1161
|
+
super({ ...t, initialUserInput: t.initialUserInput ?? t.initialValue }), this.on("userInput", (s) => {
|
|
1162
|
+
this._setValue(s);
|
|
1163
|
+
}), this.on("finalize", () => {
|
|
1164
|
+
this.value || (this.value = t.defaultValue), this.value === undefined && (this.value = "");
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
// ../../node_modules/.bun/@clack+prompts@1.4.0/node_modules/@clack/prompts/dist/index.mjs
|
|
1170
|
+
import { styleText as e, stripVTControlCharacters as nt2 } from "util";
|
|
1171
|
+
import V2 from "process";
|
|
1172
|
+
var import_sisteransi2 = __toESM(require_src(), 1);
|
|
1173
|
+
function ee() {
|
|
1174
|
+
return V2.platform !== "win32" ? V2.env.TERM !== "linux" : !!V2.env.CI || !!V2.env.WT_SESSION || !!V2.env.TERMINUS_SUBLIME || V2.env.ConEmuTask === "{cmd::Cmder}" || V2.env.TERM_PROGRAM === "Terminus-Sublime" || V2.env.TERM_PROGRAM === "vscode" || V2.env.TERM === "xterm-256color" || V2.env.TERM === "alacritty" || V2.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
1175
|
+
}
|
|
1176
|
+
var tt2 = ee();
|
|
1177
|
+
var w2 = (t, i) => tt2 ? t : i;
|
|
1178
|
+
var Tt = w2("\u25C6", "*");
|
|
1179
|
+
var at2 = w2("\u25A0", "x");
|
|
1180
|
+
var ut2 = w2("\u25B2", "x");
|
|
1181
|
+
var H2 = w2("\u25C7", "o");
|
|
1182
|
+
var lt = w2("\u250C", "T");
|
|
1183
|
+
var $2 = w2("\u2502", "|");
|
|
1184
|
+
var x2 = w2("\u2514", "\u2014");
|
|
1185
|
+
var _t = w2("\u2510", "T");
|
|
1186
|
+
var xt = w2("\u2518", "\u2014");
|
|
1187
|
+
var z2 = w2("\u25CF", ">");
|
|
1188
|
+
var U2 = w2("\u25CB", " ");
|
|
1189
|
+
var et2 = w2("\u25FB", "[\u2022]");
|
|
1190
|
+
var K2 = w2("\u25FC", "[+]");
|
|
1191
|
+
var Y2 = w2("\u25FB", "[ ]");
|
|
1192
|
+
var Et = w2("\u25AA", "\u2022");
|
|
1193
|
+
var st2 = w2("\u2500", "-");
|
|
1194
|
+
var ct = w2("\u256E", "+");
|
|
1195
|
+
var Gt = w2("\u251C", "+");
|
|
1196
|
+
var $t = w2("\u256F", "+");
|
|
1197
|
+
var dt = w2("\u2570", "+");
|
|
1198
|
+
var Mt = w2("\u256D", "+");
|
|
1199
|
+
var ht2 = w2("\u25CF", "\u2022");
|
|
1200
|
+
var pt = w2("\u25C6", "*");
|
|
1201
|
+
var mt = w2("\u25B2", "!");
|
|
1202
|
+
var gt = w2("\u25A0", "x");
|
|
1203
|
+
var P2 = (t) => {
|
|
1204
|
+
switch (t) {
|
|
1205
|
+
case "initial":
|
|
1206
|
+
case "active":
|
|
1207
|
+
return e("cyan", Tt);
|
|
1208
|
+
case "cancel":
|
|
1209
|
+
return e("red", at2);
|
|
1210
|
+
case "error":
|
|
1211
|
+
return e("yellow", ut2);
|
|
1212
|
+
case "submit":
|
|
1213
|
+
return e("green", H2);
|
|
1214
|
+
}
|
|
1215
|
+
};
|
|
1216
|
+
var yt = (t) => {
|
|
1217
|
+
switch (t) {
|
|
1218
|
+
case "initial":
|
|
1219
|
+
case "active":
|
|
1220
|
+
return e("cyan", $2);
|
|
1221
|
+
case "cancel":
|
|
1222
|
+
return e("red", $2);
|
|
1223
|
+
case "error":
|
|
1224
|
+
return e("yellow", $2);
|
|
1225
|
+
case "submit":
|
|
1226
|
+
return e("green", $2);
|
|
1227
|
+
}
|
|
1228
|
+
};
|
|
1229
|
+
var Ot = (t, i, s, r, u, n = false) => {
|
|
1230
|
+
let a = i, c = 0;
|
|
1231
|
+
if (n)
|
|
1232
|
+
for (let o = r - 1;o >= s && (a -= t[o].length, c++, !(a <= u)); o--)
|
|
1233
|
+
;
|
|
1234
|
+
else
|
|
1235
|
+
for (let o = s;o < r && (a -= t[o].length, c++, !(a <= u)); o++)
|
|
1236
|
+
;
|
|
1237
|
+
return { lineCount: a, removals: c };
|
|
1238
|
+
};
|
|
1239
|
+
var F2 = ({ cursor: t, options: i, style: s, output: r = process.stdout, maxItems: u = Number.POSITIVE_INFINITY, columnPadding: n = 0, rowPadding: a = 4 }) => {
|
|
1240
|
+
const c = A(r) - n, o = L(r), l = e("dim", "..."), d = Math.max(o - a, 0), g = Math.max(Math.min(u, d), 5);
|
|
1241
|
+
let p2 = 0;
|
|
1242
|
+
t >= g - 3 && (p2 = Math.max(Math.min(t - g + 3, i.length - g), 0));
|
|
1243
|
+
let f2 = g < i.length && p2 > 0, h2 = g < i.length && p2 + g < i.length;
|
|
1244
|
+
const I2 = Math.min(p2 + g, i.length), m2 = [];
|
|
1245
|
+
let y = 0;
|
|
1246
|
+
f2 && y++, h2 && y++;
|
|
1247
|
+
const v2 = p2 + (f2 ? 1 : 0), C2 = I2 - (h2 ? 1 : 0);
|
|
1248
|
+
for (let b = v2;b < C2; b++) {
|
|
1249
|
+
const G2 = wrapAnsi(s(i[b], b === t), c, { hard: true, trim: false }).split(`
|
|
1250
|
+
`);
|
|
1251
|
+
m2.push(G2), y += G2.length;
|
|
1252
|
+
}
|
|
1253
|
+
if (y > d) {
|
|
1254
|
+
let b = 0, G2 = 0, M = y;
|
|
1255
|
+
const N2 = t - v2;
|
|
1256
|
+
let O = d;
|
|
1257
|
+
const j2 = () => Ot(m2, M, 0, N2, O), k2 = () => Ot(m2, M, N2 + 1, m2.length, O, true);
|
|
1258
|
+
f2 ? ({ lineCount: M, removals: b } = j2(), M > O && (h2 || (O -= 1), { lineCount: M, removals: G2 } = k2())) : (h2 || (O -= 1), { lineCount: M, removals: G2 } = k2(), M > O && (O -= 1, { lineCount: M, removals: b } = j2())), b > 0 && (f2 = true, m2.splice(0, b)), G2 > 0 && (h2 = true, m2.splice(m2.length - G2, G2));
|
|
1259
|
+
}
|
|
1260
|
+
const S2 = [];
|
|
1261
|
+
f2 && S2.push(l);
|
|
1262
|
+
for (const b of m2)
|
|
1263
|
+
for (const G2 of b)
|
|
1264
|
+
S2.push(G2);
|
|
1265
|
+
return h2 && S2.push(l), S2;
|
|
1266
|
+
};
|
|
1267
|
+
var R2 = { message: (t = [], { symbol: i = e("gray", $2), secondarySymbol: s = e("gray", $2), output: r = process.stdout, spacing: u = 1, withGuide: n } = {}) => {
|
|
1268
|
+
const a = [], c = n ?? h.withGuide, o = c ? s : "", l = c ? `${i} ` : "", d = c ? `${s} ` : "";
|
|
1269
|
+
for (let p2 = 0;p2 < u; p2++)
|
|
1270
|
+
a.push(o);
|
|
1271
|
+
const g = Array.isArray(t) ? t : t.split(`
|
|
1272
|
+
`);
|
|
1273
|
+
if (g.length > 0) {
|
|
1274
|
+
const [p2, ...f2] = g;
|
|
1275
|
+
p2.length > 0 ? a.push(`${l}${p2}`) : a.push(c ? i : "");
|
|
1276
|
+
for (const h2 of f2)
|
|
1277
|
+
h2.length > 0 ? a.push(`${d}${h2}`) : a.push(c ? s : "");
|
|
1278
|
+
}
|
|
1279
|
+
r.write(`${a.join(`
|
|
1280
|
+
`)}
|
|
1281
|
+
`);
|
|
1282
|
+
}, info: (t, i) => {
|
|
1283
|
+
R2.message(t, { ...i, symbol: e("blue", ht2) });
|
|
1284
|
+
}, success: (t, i) => {
|
|
1285
|
+
R2.message(t, { ...i, symbol: e("green", pt) });
|
|
1286
|
+
}, step: (t, i) => {
|
|
1287
|
+
R2.message(t, { ...i, symbol: e("green", H2) });
|
|
1288
|
+
}, warn: (t, i) => {
|
|
1289
|
+
R2.message(t, { ...i, symbol: e("yellow", mt) });
|
|
1290
|
+
}, warning: (t, i) => {
|
|
1291
|
+
R2.warn(t, i);
|
|
1292
|
+
}, error: (t, i) => {
|
|
1293
|
+
R2.message(t, { ...i, symbol: e("red", gt) });
|
|
1294
|
+
} };
|
|
1295
|
+
var me = (t = "", i) => {
|
|
1296
|
+
const s = i?.output ?? process.stdout, r = i?.withGuide ?? h.withGuide ? `${e("gray", x2)} ` : "";
|
|
1297
|
+
s.write(`${r}${e("red", t)}
|
|
1298
|
+
|
|
1299
|
+
`);
|
|
1300
|
+
};
|
|
1301
|
+
var ge = (t = "", i) => {
|
|
1302
|
+
const s = i?.output ?? process.stdout, r = i?.withGuide ?? h.withGuide ? `${e("gray", lt)} ` : "";
|
|
1303
|
+
s.write(`${r}${t}
|
|
1304
|
+
`);
|
|
1305
|
+
};
|
|
1306
|
+
var ye = (t = "", i) => {
|
|
1307
|
+
const s = i?.output ?? process.stdout, r = i?.withGuide ?? h.withGuide ? `${e("gray", $2)}
|
|
1308
|
+
${e("gray", x2)} ` : "";
|
|
1309
|
+
s.write(`${r}${t}
|
|
1310
|
+
|
|
1311
|
+
`);
|
|
1312
|
+
};
|
|
1313
|
+
var jt = { light: w2("\u2500", "-"), heavy: w2("\u2501", "="), block: w2("\u2588", "#") };
|
|
1314
|
+
var it2 = (t, i) => t.includes(`
|
|
1315
|
+
`) ? t.split(`
|
|
1316
|
+
`).map((s) => i(s)).join(`
|
|
1317
|
+
`) : i(t);
|
|
1318
|
+
var xe = (t) => {
|
|
1319
|
+
const i = (s, r) => {
|
|
1320
|
+
const u = s.label ?? String(s.value);
|
|
1321
|
+
switch (r) {
|
|
1322
|
+
case "disabled":
|
|
1323
|
+
return `${e("gray", U2)} ${it2(u, (n) => e("gray", n))}${s.hint ? ` ${e("dim", `(${s.hint ?? "disabled"})`)}` : ""}`;
|
|
1324
|
+
case "selected":
|
|
1325
|
+
return `${it2(u, (n) => e("dim", n))}`;
|
|
1326
|
+
case "active":
|
|
1327
|
+
return `${e("green", z2)} ${u}${s.hint ? ` ${e("dim", `(${s.hint})`)}` : ""}`;
|
|
1328
|
+
case "cancelled":
|
|
1329
|
+
return `${it2(u, (n) => e(["strikethrough", "dim"], n))}`;
|
|
1330
|
+
default:
|
|
1331
|
+
return `${e("dim", U2)} ${it2(u, (n) => e("dim", n))}`;
|
|
1332
|
+
}
|
|
1333
|
+
};
|
|
1334
|
+
return new ut({ options: t.options, signal: t.signal, input: t.input, output: t.output, initialValue: t.initialValue, render() {
|
|
1335
|
+
const s = t.withGuide ?? h.withGuide, r = `${P2(this.state)} `, u = `${yt(this.state)} `, n = W(t.output, t.message, u, r), a = `${s ? `${e("gray", $2)}
|
|
1336
|
+
` : ""}${n}
|
|
1337
|
+
`;
|
|
1338
|
+
switch (this.state) {
|
|
1339
|
+
case "submit": {
|
|
1340
|
+
const c = s ? `${e("gray", $2)} ` : "", o = W(t.output, i(this.options[this.cursor], "selected"), c);
|
|
1341
|
+
return `${a}${o}`;
|
|
1342
|
+
}
|
|
1343
|
+
case "cancel": {
|
|
1344
|
+
const c = s ? `${e("gray", $2)} ` : "", o = W(t.output, i(this.options[this.cursor], "cancelled"), c);
|
|
1345
|
+
return `${a}${o}${s ? `
|
|
1346
|
+
${e("gray", $2)}` : ""}`;
|
|
1347
|
+
}
|
|
1348
|
+
default: {
|
|
1349
|
+
const c = s ? `${e("cyan", $2)} ` : "", o = s ? e("cyan", x2) : "", l = a.split(`
|
|
1350
|
+
`).length, d = s ? 2 : 1;
|
|
1351
|
+
return `${a}${c}${F2({ output: t.output, cursor: this.cursor, options: this.options, maxItems: t.maxItems, columnPadding: c.length, rowPadding: l + d, style: (g, p2) => i(g, g.disabled ? "disabled" : p2 ? "active" : "inactive") }).join(`
|
|
1352
|
+
${c}`)}
|
|
1353
|
+
${o}
|
|
1354
|
+
`;
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
} }).prompt();
|
|
1358
|
+
};
|
|
1359
|
+
var Nt = `${e("gray", $2)} `;
|
|
1360
|
+
var Pe = (t) => new ht({ validate: t.validate, placeholder: t.placeholder, defaultValue: t.defaultValue, initialValue: t.initialValue, output: t.output, signal: t.signal, input: t.input, render() {
|
|
1361
|
+
const i = t?.withGuide ?? h.withGuide, s = `${`${i ? `${e("gray", $2)}
|
|
1362
|
+
` : ""}${P2(this.state)} `}${t.message}
|
|
1363
|
+
`, r = t.placeholder ? e("inverse", t.placeholder[0]) + e("dim", t.placeholder.slice(1)) : e(["inverse", "hidden"], "_"), u = this.userInput ? this.userInputWithCursor : r, n = this.value ?? "";
|
|
1364
|
+
switch (this.state) {
|
|
1365
|
+
case "error": {
|
|
1366
|
+
const a = this.error ? ` ${e("yellow", this.error)}` : "", c = i ? `${e("yellow", $2)} ` : "", o = i ? e("yellow", x2) : "";
|
|
1367
|
+
return `${s.trim()}
|
|
1368
|
+
${c}${u}
|
|
1369
|
+
${o}${a}
|
|
1370
|
+
`;
|
|
1371
|
+
}
|
|
1372
|
+
case "submit": {
|
|
1373
|
+
const a = n ? ` ${e("dim", n)}` : "", c = i ? e("gray", $2) : "";
|
|
1374
|
+
return `${s}${c}${a}`;
|
|
1375
|
+
}
|
|
1376
|
+
case "cancel": {
|
|
1377
|
+
const a = n ? ` ${e(["strikethrough", "dim"], n)}` : "", c = i ? e("gray", $2) : "";
|
|
1378
|
+
return `${s}${c}${a}${n.trim() ? `
|
|
1379
|
+
${c}` : ""}`;
|
|
1380
|
+
}
|
|
1381
|
+
default: {
|
|
1382
|
+
const a = i ? `${e("cyan", $2)} ` : "", c = i ? e("cyan", x2) : "";
|
|
1383
|
+
return `${s}${a}${u}
|
|
1384
|
+
${c}
|
|
1385
|
+
`;
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
} }).prompt();
|
|
1389
|
+
|
|
1390
|
+
// ../../node_modules/.bun/jsonrepair@3.14.0/node_modules/jsonrepair/lib/esm/utils/JSONRepairError.js
|
|
1391
|
+
class JSONRepairError extends Error {
|
|
1392
|
+
constructor(message, position) {
|
|
1393
|
+
super(`${message} at position ${position}`);
|
|
1394
|
+
this.position = position;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
// ../../node_modules/.bun/jsonrepair@3.14.0/node_modules/jsonrepair/lib/esm/utils/stringUtils.js
|
|
1399
|
+
var codeSpace = 32;
|
|
1400
|
+
var codeNewline = 10;
|
|
1401
|
+
var codeTab = 9;
|
|
1402
|
+
var codeReturn = 13;
|
|
1403
|
+
var codeNonBreakingSpace = 160;
|
|
1404
|
+
var codeMongolianVowelSeparator = 6158;
|
|
1405
|
+
var codeEnQuad = 8192;
|
|
1406
|
+
var codeZeroWidthSpace = 8203;
|
|
1407
|
+
var codeNarrowNoBreakSpace = 8239;
|
|
1408
|
+
var codeMediumMathematicalSpace = 8287;
|
|
1409
|
+
var codeIdeographicSpace = 12288;
|
|
1410
|
+
var codeZeroWidthNoBreakSpace = 65279;
|
|
1411
|
+
function isHex(char) {
|
|
1412
|
+
return /^[0-9A-Fa-f]$/.test(char);
|
|
1413
|
+
}
|
|
1414
|
+
function isDigit(char) {
|
|
1415
|
+
return char >= "0" && char <= "9";
|
|
1416
|
+
}
|
|
1417
|
+
function isValidStringCharacter(char) {
|
|
1418
|
+
return char >= " ";
|
|
1419
|
+
}
|
|
1420
|
+
function isDelimiter(char) {
|
|
1421
|
+
return `,:[]/{}()
|
|
1422
|
+
+`.includes(char);
|
|
1423
|
+
}
|
|
1424
|
+
function isFunctionNameCharStart(char) {
|
|
1425
|
+
return char >= "a" && char <= "z" || char >= "A" && char <= "Z" || char === "_" || char === "$";
|
|
1426
|
+
}
|
|
1427
|
+
function isFunctionNameChar(char) {
|
|
1428
|
+
return char >= "a" && char <= "z" || char >= "A" && char <= "Z" || char === "_" || char === "$" || char >= "0" && char <= "9";
|
|
1429
|
+
}
|
|
1430
|
+
var regexUrlStart = /^(http|https|ftp|mailto|file|data|irc):\/\/$/;
|
|
1431
|
+
var regexUrlChar = /^[A-Za-z0-9-._~:/?#@!$&'()*+;=]$/;
|
|
1432
|
+
function isUnquotedStringDelimiter(char) {
|
|
1433
|
+
return `,[]/{}
|
|
1434
|
+
+`.includes(char);
|
|
1435
|
+
}
|
|
1436
|
+
function isStartOfValue(char) {
|
|
1437
|
+
return isQuote(char) || regexStartOfValue.test(char);
|
|
1438
|
+
}
|
|
1439
|
+
var regexStartOfValue = /^[[{\w-]$/;
|
|
1440
|
+
function isControlCharacter(char) {
|
|
1441
|
+
return char === `
|
|
1442
|
+
` || char === "\r" || char === "\t" || char === "\b" || char === "\f";
|
|
1443
|
+
}
|
|
1444
|
+
function isWhitespace(text, index) {
|
|
1445
|
+
const code = text.charCodeAt(index);
|
|
1446
|
+
return code === codeSpace || code === codeNewline || code === codeTab || code === codeReturn;
|
|
1447
|
+
}
|
|
1448
|
+
function isWhitespaceExceptNewline(text, index) {
|
|
1449
|
+
const code = text.charCodeAt(index);
|
|
1450
|
+
return code === codeSpace || code === codeTab || code === codeReturn;
|
|
1451
|
+
}
|
|
1452
|
+
function isSpecialWhitespace(text, index) {
|
|
1453
|
+
const code = text.charCodeAt(index);
|
|
1454
|
+
return code === codeNonBreakingSpace || code === codeMongolianVowelSeparator || code >= codeEnQuad && code <= codeZeroWidthSpace || code === codeNarrowNoBreakSpace || code === codeMediumMathematicalSpace || code === codeIdeographicSpace || code === codeZeroWidthNoBreakSpace;
|
|
1455
|
+
}
|
|
1456
|
+
function isQuote(char) {
|
|
1457
|
+
return isDoubleQuoteLike(char) || isSingleQuoteLike(char);
|
|
1458
|
+
}
|
|
1459
|
+
function isDoubleQuoteLike(char) {
|
|
1460
|
+
return char === '"' || char === "\u201C" || char === "\u201D";
|
|
1461
|
+
}
|
|
1462
|
+
function isDoubleQuote(char) {
|
|
1463
|
+
return char === '"';
|
|
1464
|
+
}
|
|
1465
|
+
function isSingleQuoteLike(char) {
|
|
1466
|
+
return char === "'" || char === "\u2018" || char === "\u2019" || char === "`" || char === "\xB4";
|
|
1467
|
+
}
|
|
1468
|
+
function isSingleQuote(char) {
|
|
1469
|
+
return char === "'";
|
|
1470
|
+
}
|
|
1471
|
+
function stripLastOccurrence(text, textToStrip) {
|
|
1472
|
+
let stripRemainingText = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1473
|
+
const index = text.lastIndexOf(textToStrip);
|
|
1474
|
+
return index !== -1 ? text.substring(0, index) + (stripRemainingText ? "" : text.substring(index + 1)) : text;
|
|
1475
|
+
}
|
|
1476
|
+
function insertBeforeLastWhitespace(text, textToInsert) {
|
|
1477
|
+
let index = text.length;
|
|
1478
|
+
if (!isWhitespace(text, index - 1)) {
|
|
1479
|
+
return text + textToInsert;
|
|
1480
|
+
}
|
|
1481
|
+
while (isWhitespace(text, index - 1)) {
|
|
1482
|
+
index--;
|
|
1483
|
+
}
|
|
1484
|
+
return text.substring(0, index) + textToInsert + text.substring(index);
|
|
1485
|
+
}
|
|
1486
|
+
function removeAtIndex(text, start, count) {
|
|
1487
|
+
return text.substring(0, start) + text.substring(start + count);
|
|
1488
|
+
}
|
|
1489
|
+
function endsWithCommaOrNewline(text) {
|
|
1490
|
+
return /[,\n][ \t\r]*$/.test(text);
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
// ../../node_modules/.bun/jsonrepair@3.14.0/node_modules/jsonrepair/lib/esm/regular/jsonrepair.js
|
|
1494
|
+
var controlCharacters = {
|
|
1495
|
+
"\b": "\\b",
|
|
1496
|
+
"\f": "\\f",
|
|
1497
|
+
"\n": "\\n",
|
|
1498
|
+
"\r": "\\r",
|
|
1499
|
+
"\t": "\\t"
|
|
1500
|
+
};
|
|
1501
|
+
var escapeCharacters = {
|
|
1502
|
+
'"': '"',
|
|
1503
|
+
"\\": "\\",
|
|
1504
|
+
"/": "/",
|
|
1505
|
+
b: "\b",
|
|
1506
|
+
f: "\f",
|
|
1507
|
+
n: `
|
|
1508
|
+
`,
|
|
1509
|
+
r: "\r",
|
|
1510
|
+
t: "\t"
|
|
1511
|
+
};
|
|
1512
|
+
function jsonrepair(text) {
|
|
1513
|
+
let i = 0;
|
|
1514
|
+
let output = "";
|
|
1515
|
+
parseMarkdownCodeBlock(["```", "[```", "{```"]);
|
|
1516
|
+
const processed = parseValue();
|
|
1517
|
+
if (!processed) {
|
|
1518
|
+
throwUnexpectedEnd();
|
|
1519
|
+
}
|
|
1520
|
+
parseMarkdownCodeBlock(["```", "```]", "```}"]);
|
|
1521
|
+
const processedComma = parseCharacter(",");
|
|
1522
|
+
if (processedComma) {
|
|
1523
|
+
parseWhitespaceAndSkipComments();
|
|
1524
|
+
}
|
|
1525
|
+
if (isStartOfValue(text[i]) && endsWithCommaOrNewline(output)) {
|
|
1526
|
+
if (!processedComma) {
|
|
1527
|
+
output = insertBeforeLastWhitespace(output, ",");
|
|
1528
|
+
}
|
|
1529
|
+
parseNewlineDelimitedJSON();
|
|
1530
|
+
} else if (processedComma) {
|
|
1531
|
+
output = stripLastOccurrence(output, ",");
|
|
1532
|
+
}
|
|
1533
|
+
while (text[i] === "}" || text[i] === "]") {
|
|
1534
|
+
i++;
|
|
1535
|
+
parseWhitespaceAndSkipComments();
|
|
1536
|
+
}
|
|
1537
|
+
if (i >= text.length) {
|
|
1538
|
+
return output;
|
|
1539
|
+
}
|
|
1540
|
+
throwUnexpectedCharacter();
|
|
1541
|
+
function parseValue() {
|
|
1542
|
+
parseWhitespaceAndSkipComments();
|
|
1543
|
+
const processed2 = parseObject() || parseArray() || parseString() || parseNumber() || parseKeywords() || parseUnquotedString(false) || parseRegex();
|
|
1544
|
+
parseWhitespaceAndSkipComments();
|
|
1545
|
+
return processed2;
|
|
1546
|
+
}
|
|
1547
|
+
function parseWhitespaceAndSkipComments() {
|
|
1548
|
+
let skipNewline = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
1549
|
+
const start = i;
|
|
1550
|
+
let changed = parseWhitespace(skipNewline);
|
|
1551
|
+
do {
|
|
1552
|
+
changed = parseComment();
|
|
1553
|
+
if (changed) {
|
|
1554
|
+
changed = parseWhitespace(skipNewline);
|
|
1555
|
+
}
|
|
1556
|
+
} while (changed);
|
|
1557
|
+
return i > start;
|
|
1558
|
+
}
|
|
1559
|
+
function parseWhitespace(skipNewline) {
|
|
1560
|
+
const _isWhiteSpace = skipNewline ? isWhitespace : isWhitespaceExceptNewline;
|
|
1561
|
+
let whitespace = "";
|
|
1562
|
+
while (true) {
|
|
1563
|
+
if (_isWhiteSpace(text, i)) {
|
|
1564
|
+
whitespace += text[i];
|
|
1565
|
+
i++;
|
|
1566
|
+
} else if (isSpecialWhitespace(text, i)) {
|
|
1567
|
+
whitespace += " ";
|
|
1568
|
+
i++;
|
|
1569
|
+
} else {
|
|
1570
|
+
break;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
if (whitespace.length > 0) {
|
|
1574
|
+
output += whitespace;
|
|
1575
|
+
return true;
|
|
1576
|
+
}
|
|
1577
|
+
return false;
|
|
1578
|
+
}
|
|
1579
|
+
function parseComment() {
|
|
1580
|
+
if (text[i] === "/" && text[i + 1] === "*") {
|
|
1581
|
+
while (i < text.length && !atEndOfBlockComment(text, i)) {
|
|
1582
|
+
i++;
|
|
1583
|
+
}
|
|
1584
|
+
i += 2;
|
|
1585
|
+
return true;
|
|
1586
|
+
}
|
|
1587
|
+
if (text[i] === "/" && text[i + 1] === "/") {
|
|
1588
|
+
while (i < text.length && text[i] !== `
|
|
1589
|
+
`) {
|
|
1590
|
+
i++;
|
|
1591
|
+
}
|
|
1592
|
+
return true;
|
|
1593
|
+
}
|
|
1594
|
+
return false;
|
|
1595
|
+
}
|
|
1596
|
+
function parseMarkdownCodeBlock(blocks) {
|
|
1597
|
+
if (skipMarkdownCodeBlock(blocks)) {
|
|
1598
|
+
if (isFunctionNameCharStart(text[i])) {
|
|
1599
|
+
while (i < text.length && isFunctionNameChar(text[i])) {
|
|
1600
|
+
i++;
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
parseWhitespaceAndSkipComments();
|
|
1604
|
+
return true;
|
|
1605
|
+
}
|
|
1606
|
+
return false;
|
|
1607
|
+
}
|
|
1608
|
+
function skipMarkdownCodeBlock(blocks) {
|
|
1609
|
+
parseWhitespace(true);
|
|
1610
|
+
for (const block of blocks) {
|
|
1611
|
+
const end = i + block.length;
|
|
1612
|
+
if (text.slice(i, end) === block) {
|
|
1613
|
+
i = end;
|
|
1614
|
+
return true;
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
return false;
|
|
1618
|
+
}
|
|
1619
|
+
function parseCharacter(char) {
|
|
1620
|
+
if (text[i] === char) {
|
|
1621
|
+
output += text[i];
|
|
1622
|
+
i++;
|
|
1623
|
+
return true;
|
|
1624
|
+
}
|
|
1625
|
+
return false;
|
|
1626
|
+
}
|
|
1627
|
+
function skipCharacter(char) {
|
|
1628
|
+
if (text[i] === char) {
|
|
1629
|
+
i++;
|
|
1630
|
+
return true;
|
|
1631
|
+
}
|
|
1632
|
+
return false;
|
|
1633
|
+
}
|
|
1634
|
+
function skipEscapeCharacter() {
|
|
1635
|
+
return skipCharacter("\\");
|
|
1636
|
+
}
|
|
1637
|
+
function skipEllipsis() {
|
|
1638
|
+
parseWhitespaceAndSkipComments();
|
|
1639
|
+
if (text[i] === "." && text[i + 1] === "." && text[i + 2] === ".") {
|
|
1640
|
+
i += 3;
|
|
1641
|
+
parseWhitespaceAndSkipComments();
|
|
1642
|
+
skipCharacter(",");
|
|
1643
|
+
return true;
|
|
1644
|
+
}
|
|
1645
|
+
return false;
|
|
1646
|
+
}
|
|
1647
|
+
function parseObject() {
|
|
1648
|
+
if (text[i] === "{") {
|
|
1649
|
+
output += "{";
|
|
1650
|
+
i++;
|
|
1651
|
+
parseWhitespaceAndSkipComments();
|
|
1652
|
+
if (skipCharacter(",")) {
|
|
1653
|
+
parseWhitespaceAndSkipComments();
|
|
1654
|
+
}
|
|
1655
|
+
let initial = true;
|
|
1656
|
+
while (i < text.length && text[i] !== "}") {
|
|
1657
|
+
let processedComma2;
|
|
1658
|
+
if (!initial) {
|
|
1659
|
+
processedComma2 = parseCharacter(",");
|
|
1660
|
+
if (!processedComma2) {
|
|
1661
|
+
output = insertBeforeLastWhitespace(output, ",");
|
|
1662
|
+
}
|
|
1663
|
+
parseWhitespaceAndSkipComments();
|
|
1664
|
+
} else {
|
|
1665
|
+
processedComma2 = true;
|
|
1666
|
+
initial = false;
|
|
1667
|
+
}
|
|
1668
|
+
skipEllipsis();
|
|
1669
|
+
const processedKey = parseString() || parseUnquotedString(true);
|
|
1670
|
+
if (!processedKey) {
|
|
1671
|
+
if (text[i] === "}" || text[i] === "{" || text[i] === "]" || text[i] === "[" || text[i] === undefined) {
|
|
1672
|
+
output = stripLastOccurrence(output, ",");
|
|
1673
|
+
} else {
|
|
1674
|
+
throwObjectKeyExpected();
|
|
1675
|
+
}
|
|
1676
|
+
break;
|
|
1677
|
+
}
|
|
1678
|
+
parseWhitespaceAndSkipComments();
|
|
1679
|
+
const processedColon = parseCharacter(":");
|
|
1680
|
+
const truncatedText = i >= text.length;
|
|
1681
|
+
if (!processedColon) {
|
|
1682
|
+
if (isStartOfValue(text[i]) || truncatedText) {
|
|
1683
|
+
output = insertBeforeLastWhitespace(output, ":");
|
|
1684
|
+
} else {
|
|
1685
|
+
throwColonExpected();
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
const processedValue = parseValue();
|
|
1689
|
+
if (!processedValue) {
|
|
1690
|
+
if (processedColon || truncatedText) {
|
|
1691
|
+
output += "null";
|
|
1692
|
+
} else {
|
|
1693
|
+
throwColonExpected();
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
if (text[i] === "}") {
|
|
1698
|
+
output += "}";
|
|
1699
|
+
i++;
|
|
1700
|
+
} else {
|
|
1701
|
+
output = insertBeforeLastWhitespace(output, "}");
|
|
1702
|
+
}
|
|
1703
|
+
return true;
|
|
1704
|
+
}
|
|
1705
|
+
return false;
|
|
1706
|
+
}
|
|
1707
|
+
function parseArray() {
|
|
1708
|
+
if (text[i] === "[") {
|
|
1709
|
+
output += "[";
|
|
1710
|
+
i++;
|
|
1711
|
+
parseWhitespaceAndSkipComments();
|
|
1712
|
+
if (skipCharacter(",")) {
|
|
1713
|
+
parseWhitespaceAndSkipComments();
|
|
1714
|
+
}
|
|
1715
|
+
let initial = true;
|
|
1716
|
+
while (i < text.length && text[i] !== "]") {
|
|
1717
|
+
if (!initial) {
|
|
1718
|
+
const processedComma2 = parseCharacter(",");
|
|
1719
|
+
if (!processedComma2) {
|
|
1720
|
+
output = insertBeforeLastWhitespace(output, ",");
|
|
1721
|
+
}
|
|
1722
|
+
} else {
|
|
1723
|
+
initial = false;
|
|
1724
|
+
}
|
|
1725
|
+
skipEllipsis();
|
|
1726
|
+
const processedValue = parseValue();
|
|
1727
|
+
if (!processedValue) {
|
|
1728
|
+
output = stripLastOccurrence(output, ",");
|
|
1729
|
+
break;
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
if (text[i] === "]") {
|
|
1733
|
+
output += "]";
|
|
1734
|
+
i++;
|
|
1735
|
+
} else {
|
|
1736
|
+
output = insertBeforeLastWhitespace(output, "]");
|
|
1737
|
+
}
|
|
1738
|
+
return true;
|
|
1739
|
+
}
|
|
1740
|
+
return false;
|
|
1741
|
+
}
|
|
1742
|
+
function parseNewlineDelimitedJSON() {
|
|
1743
|
+
let initial = true;
|
|
1744
|
+
let processedValue = true;
|
|
1745
|
+
while (processedValue) {
|
|
1746
|
+
if (!initial) {
|
|
1747
|
+
const processedComma2 = parseCharacter(",");
|
|
1748
|
+
if (!processedComma2) {
|
|
1749
|
+
output = insertBeforeLastWhitespace(output, ",");
|
|
1750
|
+
}
|
|
1751
|
+
} else {
|
|
1752
|
+
initial = false;
|
|
1753
|
+
}
|
|
1754
|
+
processedValue = parseValue();
|
|
1755
|
+
}
|
|
1756
|
+
if (!processedValue) {
|
|
1757
|
+
output = stripLastOccurrence(output, ",");
|
|
1758
|
+
}
|
|
1759
|
+
output = `[
|
|
1760
|
+
${output}
|
|
1761
|
+
]`;
|
|
1762
|
+
}
|
|
1763
|
+
function parseString() {
|
|
1764
|
+
let stopAtDelimiter = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
1765
|
+
let stopAtIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
|
|
1766
|
+
let skipEscapeChars = text[i] === "\\";
|
|
1767
|
+
if (skipEscapeChars) {
|
|
1768
|
+
i++;
|
|
1769
|
+
skipEscapeChars = true;
|
|
1770
|
+
}
|
|
1771
|
+
if (isQuote(text[i])) {
|
|
1772
|
+
const isEndQuote = isDoubleQuote(text[i]) ? isDoubleQuote : isSingleQuote(text[i]) ? isSingleQuote : isSingleQuoteLike(text[i]) ? isSingleQuoteLike : isDoubleQuoteLike;
|
|
1773
|
+
const iBefore = i;
|
|
1774
|
+
const oBefore = output.length;
|
|
1775
|
+
let str = '"';
|
|
1776
|
+
i++;
|
|
1777
|
+
while (true) {
|
|
1778
|
+
if (i >= text.length) {
|
|
1779
|
+
const iPrev = prevNonWhitespaceIndex(i - 1);
|
|
1780
|
+
if (!stopAtDelimiter && isDelimiter(text.charAt(iPrev))) {
|
|
1781
|
+
i = iBefore;
|
|
1782
|
+
output = output.substring(0, oBefore);
|
|
1783
|
+
return parseString(true);
|
|
1784
|
+
}
|
|
1785
|
+
str = insertBeforeLastWhitespace(str, '"');
|
|
1786
|
+
output += str;
|
|
1787
|
+
return true;
|
|
1788
|
+
}
|
|
1789
|
+
if (i === stopAtIndex) {
|
|
1790
|
+
str = insertBeforeLastWhitespace(str, '"');
|
|
1791
|
+
output += str;
|
|
1792
|
+
return true;
|
|
1793
|
+
}
|
|
1794
|
+
if (isEndQuote(text[i])) {
|
|
1795
|
+
const iQuote = i;
|
|
1796
|
+
const oQuote = str.length;
|
|
1797
|
+
str += '"';
|
|
1798
|
+
i++;
|
|
1799
|
+
output += str;
|
|
1800
|
+
parseWhitespaceAndSkipComments(false);
|
|
1801
|
+
if (stopAtDelimiter || i >= text.length || isDelimiter(text[i]) || isQuote(text[i]) || isDigit(text[i])) {
|
|
1802
|
+
parseConcatenatedString();
|
|
1803
|
+
return true;
|
|
1804
|
+
}
|
|
1805
|
+
const iPrevChar = prevNonWhitespaceIndex(iQuote - 1);
|
|
1806
|
+
const prevChar = text.charAt(iPrevChar);
|
|
1807
|
+
if (prevChar === ",") {
|
|
1808
|
+
i = iBefore;
|
|
1809
|
+
output = output.substring(0, oBefore);
|
|
1810
|
+
return parseString(false, iPrevChar);
|
|
1811
|
+
}
|
|
1812
|
+
if (isDelimiter(prevChar)) {
|
|
1813
|
+
i = iBefore;
|
|
1814
|
+
output = output.substring(0, oBefore);
|
|
1815
|
+
return parseString(true);
|
|
1816
|
+
}
|
|
1817
|
+
output = output.substring(0, oBefore);
|
|
1818
|
+
i = iQuote + 1;
|
|
1819
|
+
str = `${str.substring(0, oQuote)}\\${str.substring(oQuote)}`;
|
|
1820
|
+
} else if (stopAtDelimiter && isUnquotedStringDelimiter(text[i])) {
|
|
1821
|
+
if (text[i - 1] === ":" && regexUrlStart.test(text.substring(iBefore + 1, i + 2))) {
|
|
1822
|
+
while (i < text.length && regexUrlChar.test(text[i])) {
|
|
1823
|
+
str += text[i];
|
|
1824
|
+
i++;
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
str = insertBeforeLastWhitespace(str, '"');
|
|
1828
|
+
output += str;
|
|
1829
|
+
parseConcatenatedString();
|
|
1830
|
+
return true;
|
|
1831
|
+
} else if (text[i] === "\\") {
|
|
1832
|
+
const char = text.charAt(i + 1);
|
|
1833
|
+
const escapeChar = escapeCharacters[char];
|
|
1834
|
+
if (escapeChar !== undefined) {
|
|
1835
|
+
str += text.slice(i, i + 2);
|
|
1836
|
+
i += 2;
|
|
1837
|
+
} else if (char === "u") {
|
|
1838
|
+
let j2 = 2;
|
|
1839
|
+
while (j2 < 6 && isHex(text[i + j2])) {
|
|
1840
|
+
j2++;
|
|
1841
|
+
}
|
|
1842
|
+
if (j2 === 6) {
|
|
1843
|
+
str += text.slice(i, i + 6);
|
|
1844
|
+
i += 6;
|
|
1845
|
+
} else if (i + j2 >= text.length) {
|
|
1846
|
+
i = text.length;
|
|
1847
|
+
} else {
|
|
1848
|
+
throwInvalidUnicodeCharacter();
|
|
1849
|
+
}
|
|
1850
|
+
} else if (char === `
|
|
1851
|
+
`) {
|
|
1852
|
+
str += "\\n";
|
|
1853
|
+
i += 2;
|
|
1854
|
+
} else {
|
|
1855
|
+
str += char;
|
|
1856
|
+
i += 2;
|
|
1857
|
+
}
|
|
1858
|
+
} else {
|
|
1859
|
+
const char = text.charAt(i);
|
|
1860
|
+
if (char === '"' && text[i - 1] !== "\\") {
|
|
1861
|
+
str += `\\${char}`;
|
|
1862
|
+
i++;
|
|
1863
|
+
} else if (isControlCharacter(char)) {
|
|
1864
|
+
str += controlCharacters[char];
|
|
1865
|
+
i++;
|
|
1866
|
+
} else {
|
|
1867
|
+
if (!isValidStringCharacter(char)) {
|
|
1868
|
+
throwInvalidCharacter(char);
|
|
1869
|
+
}
|
|
1870
|
+
str += char;
|
|
1871
|
+
i++;
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
if (skipEscapeChars) {
|
|
1875
|
+
skipEscapeCharacter();
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
return false;
|
|
1880
|
+
}
|
|
1881
|
+
function parseConcatenatedString() {
|
|
1882
|
+
let processed2 = false;
|
|
1883
|
+
parseWhitespaceAndSkipComments();
|
|
1884
|
+
while (text[i] === "+") {
|
|
1885
|
+
processed2 = true;
|
|
1886
|
+
i++;
|
|
1887
|
+
parseWhitespaceAndSkipComments();
|
|
1888
|
+
output = stripLastOccurrence(output, '"', true);
|
|
1889
|
+
const start = output.length;
|
|
1890
|
+
const parsedStr = parseString();
|
|
1891
|
+
if (parsedStr) {
|
|
1892
|
+
output = removeAtIndex(output, start, 1);
|
|
1893
|
+
} else {
|
|
1894
|
+
output = insertBeforeLastWhitespace(output, '"');
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
return processed2;
|
|
1898
|
+
}
|
|
1899
|
+
function parseNumber() {
|
|
1900
|
+
const start = i;
|
|
1901
|
+
if (text[i] === "-") {
|
|
1902
|
+
i++;
|
|
1903
|
+
if (atEndOfNumber()) {
|
|
1904
|
+
repairNumberEndingWithNumericSymbol(start);
|
|
1905
|
+
return true;
|
|
1906
|
+
}
|
|
1907
|
+
if (!isDigit(text[i])) {
|
|
1908
|
+
i = start;
|
|
1909
|
+
return false;
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
while (isDigit(text[i])) {
|
|
1913
|
+
i++;
|
|
1914
|
+
}
|
|
1915
|
+
if (text[i] === ".") {
|
|
1916
|
+
i++;
|
|
1917
|
+
if (atEndOfNumber()) {
|
|
1918
|
+
repairNumberEndingWithNumericSymbol(start);
|
|
1919
|
+
return true;
|
|
1920
|
+
}
|
|
1921
|
+
if (!isDigit(text[i])) {
|
|
1922
|
+
i = start;
|
|
1923
|
+
return false;
|
|
1924
|
+
}
|
|
1925
|
+
while (isDigit(text[i])) {
|
|
1926
|
+
i++;
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
if (text[i] === "e" || text[i] === "E") {
|
|
1930
|
+
i++;
|
|
1931
|
+
if (text[i] === "-" || text[i] === "+") {
|
|
1932
|
+
i++;
|
|
1933
|
+
}
|
|
1934
|
+
if (atEndOfNumber()) {
|
|
1935
|
+
repairNumberEndingWithNumericSymbol(start);
|
|
1936
|
+
return true;
|
|
1937
|
+
}
|
|
1938
|
+
if (!isDigit(text[i])) {
|
|
1939
|
+
i = start;
|
|
1940
|
+
return false;
|
|
1941
|
+
}
|
|
1942
|
+
while (isDigit(text[i])) {
|
|
1943
|
+
i++;
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
if (!atEndOfNumber()) {
|
|
1947
|
+
i = start;
|
|
1948
|
+
return false;
|
|
1949
|
+
}
|
|
1950
|
+
if (i > start) {
|
|
1951
|
+
const num = text.slice(start, i);
|
|
1952
|
+
const hasInvalidLeadingZero = /^0\d/.test(num);
|
|
1953
|
+
output += hasInvalidLeadingZero ? `"${num}"` : num;
|
|
1954
|
+
return true;
|
|
1955
|
+
}
|
|
1956
|
+
return false;
|
|
1957
|
+
}
|
|
1958
|
+
function parseKeywords() {
|
|
1959
|
+
return parseKeyword("true", "true") || parseKeyword("false", "false") || parseKeyword("null", "null") || parseKeyword("True", "true") || parseKeyword("False", "false") || parseKeyword("None", "null");
|
|
1960
|
+
}
|
|
1961
|
+
function parseKeyword(name, value) {
|
|
1962
|
+
if (text.slice(i, i + name.length) === name) {
|
|
1963
|
+
output += value;
|
|
1964
|
+
i += name.length;
|
|
1965
|
+
return true;
|
|
1966
|
+
}
|
|
1967
|
+
return false;
|
|
1968
|
+
}
|
|
1969
|
+
function parseUnquotedString(isKey) {
|
|
1970
|
+
const start = i;
|
|
1971
|
+
if (isFunctionNameCharStart(text[i])) {
|
|
1972
|
+
while (i < text.length && isFunctionNameChar(text[i])) {
|
|
1973
|
+
i++;
|
|
1974
|
+
}
|
|
1975
|
+
let j2 = i;
|
|
1976
|
+
while (isWhitespace(text, j2)) {
|
|
1977
|
+
j2++;
|
|
1978
|
+
}
|
|
1979
|
+
if (text[j2] === "(") {
|
|
1980
|
+
i = j2 + 1;
|
|
1981
|
+
parseValue();
|
|
1982
|
+
if (text[i] === ")") {
|
|
1983
|
+
i++;
|
|
1984
|
+
if (text[i] === ";") {
|
|
1985
|
+
i++;
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
return true;
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
while (i < text.length && !isUnquotedStringDelimiter(text[i]) && !isQuote(text[i]) && (!isKey || text[i] !== ":")) {
|
|
1992
|
+
i++;
|
|
1993
|
+
}
|
|
1994
|
+
if (text[i - 1] === ":" && regexUrlStart.test(text.substring(start, i + 2))) {
|
|
1995
|
+
while (i < text.length && regexUrlChar.test(text[i])) {
|
|
1996
|
+
i++;
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
if (i > start) {
|
|
2000
|
+
while (isWhitespace(text, i - 1) && i > 0) {
|
|
2001
|
+
i--;
|
|
2002
|
+
}
|
|
2003
|
+
const symbol = text.slice(start, i);
|
|
2004
|
+
output += symbol === "undefined" ? "null" : JSON.stringify(symbol);
|
|
2005
|
+
if (text[i] === '"') {
|
|
2006
|
+
i++;
|
|
2007
|
+
}
|
|
2008
|
+
return true;
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
function parseRegex() {
|
|
2012
|
+
if (text[i] === "/") {
|
|
2013
|
+
const start = i;
|
|
2014
|
+
i++;
|
|
2015
|
+
while (i < text.length && (text[i] !== "/" || text[i - 1] === "\\")) {
|
|
2016
|
+
i++;
|
|
2017
|
+
}
|
|
2018
|
+
i++;
|
|
2019
|
+
output += JSON.stringify(text.substring(start, i));
|
|
2020
|
+
return true;
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
function prevNonWhitespaceIndex(start) {
|
|
2024
|
+
let prev = start;
|
|
2025
|
+
while (prev > 0 && isWhitespace(text, prev)) {
|
|
2026
|
+
prev--;
|
|
2027
|
+
}
|
|
2028
|
+
return prev;
|
|
2029
|
+
}
|
|
2030
|
+
function atEndOfNumber() {
|
|
2031
|
+
return i >= text.length || isDelimiter(text[i]) || isWhitespace(text, i);
|
|
2032
|
+
}
|
|
2033
|
+
function repairNumberEndingWithNumericSymbol(start) {
|
|
2034
|
+
output += `${text.slice(start, i)}0`;
|
|
2035
|
+
}
|
|
2036
|
+
function throwInvalidCharacter(char) {
|
|
2037
|
+
throw new JSONRepairError(`Invalid character ${JSON.stringify(char)}`, i);
|
|
2038
|
+
}
|
|
2039
|
+
function throwUnexpectedCharacter() {
|
|
2040
|
+
throw new JSONRepairError(`Unexpected character ${JSON.stringify(text[i])}`, i);
|
|
2041
|
+
}
|
|
2042
|
+
function throwUnexpectedEnd() {
|
|
2043
|
+
throw new JSONRepairError("Unexpected end of json string", text.length);
|
|
2044
|
+
}
|
|
2045
|
+
function throwObjectKeyExpected() {
|
|
2046
|
+
throw new JSONRepairError("Object key expected", i);
|
|
2047
|
+
}
|
|
2048
|
+
function throwColonExpected() {
|
|
2049
|
+
throw new JSONRepairError("Colon expected", i);
|
|
2050
|
+
}
|
|
2051
|
+
function throwInvalidUnicodeCharacter() {
|
|
2052
|
+
const chars = text.slice(i, i + 6);
|
|
2053
|
+
throw new JSONRepairError(`Invalid unicode character "${chars}"`, i);
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
function atEndOfBlockComment(text, i) {
|
|
2057
|
+
return text[i] === "*" && text[i + 1] === "/";
|
|
2058
|
+
}
|
|
2059
|
+
// src/scaffold.ts
|
|
2060
|
+
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
2061
|
+
|
|
2062
|
+
// src/prompts.ts
|
|
2063
|
+
async function promptProjectName() {
|
|
2064
|
+
const projectName = await Pe({
|
|
2065
|
+
message: "What is the name of your Baresync project?",
|
|
2066
|
+
placeholder: "inventory-app",
|
|
2067
|
+
validate(value) {
|
|
2068
|
+
if (!value || value.length === 0) {
|
|
2069
|
+
return "Project name is required.";
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
});
|
|
2073
|
+
if (q(projectName)) {
|
|
2074
|
+
me("Scaffold cancelled.");
|
|
2075
|
+
process.exit(0);
|
|
2076
|
+
}
|
|
2077
|
+
return String(projectName);
|
|
2078
|
+
}
|
|
2079
|
+
async function promptPackageManager() {
|
|
2080
|
+
const packageManager = await xe({
|
|
2081
|
+
message: "Which package manager do you want to use?",
|
|
2082
|
+
options: [
|
|
2083
|
+
{ value: "bun", label: "Bun" },
|
|
2084
|
+
{ value: "pnpm", label: "pnpm" },
|
|
2085
|
+
{ value: "npm", label: "npm" },
|
|
2086
|
+
{ value: "yarn", label: "yarn" }
|
|
2087
|
+
]
|
|
2088
|
+
});
|
|
2089
|
+
if (q(packageManager)) {
|
|
2090
|
+
me("Scaffold cancelled.");
|
|
2091
|
+
process.exit(0);
|
|
2092
|
+
}
|
|
2093
|
+
return packageManager;
|
|
2094
|
+
}
|
|
2095
|
+
async function promptServerFramework() {
|
|
2096
|
+
const serverFramework = await xe({
|
|
2097
|
+
message: "Which server framework do you want to scaffold?",
|
|
2098
|
+
options: [
|
|
2099
|
+
{ value: "hono", label: "Hono" },
|
|
2100
|
+
{ value: "elysia", label: "Elysia" }
|
|
2101
|
+
]
|
|
2102
|
+
});
|
|
2103
|
+
if (q(serverFramework)) {
|
|
2104
|
+
me("Scaffold cancelled.");
|
|
2105
|
+
process.exit(0);
|
|
2106
|
+
}
|
|
2107
|
+
return serverFramework;
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
// src/templates.ts
|
|
2111
|
+
import fs from "fs";
|
|
2112
|
+
import path from "path";
|
|
2113
|
+
import { fileURLToPath } from "url";
|
|
2114
|
+
var baseDir = path.dirname(fileURLToPath(import.meta.url));
|
|
2115
|
+
var templatesRoot = path.join(baseDir, "templates");
|
|
2116
|
+
function readTemplateAsset(relativePath) {
|
|
2117
|
+
return fs.readFileSync(path.join(templatesRoot, relativePath), "utf8");
|
|
2118
|
+
}
|
|
2119
|
+
function file(filePath, content, executable = false) {
|
|
2120
|
+
return { content, executable, path: filePath };
|
|
2121
|
+
}
|
|
2122
|
+
function replaceProjectName(content, options) {
|
|
2123
|
+
return content.replaceAll("__PROJECT_NAME__", options.projectName);
|
|
2124
|
+
}
|
|
2125
|
+
function replaceContractDate(content) {
|
|
2126
|
+
const date = new Date().toISOString().slice(0, 10);
|
|
2127
|
+
return content.replaceAll("__CONTRACT_DATE__", date);
|
|
2128
|
+
}
|
|
2129
|
+
function replacePackageManager(content, options) {
|
|
2130
|
+
return content.replaceAll("__PACKAGE_MANAGER__", options.packageManager);
|
|
2131
|
+
}
|
|
2132
|
+
function runInWorkspaceCommand(pm) {
|
|
2133
|
+
switch (pm) {
|
|
2134
|
+
case "bun":
|
|
2135
|
+
return "bun run --cwd";
|
|
2136
|
+
case "pnpm":
|
|
2137
|
+
return "pnpm --filter";
|
|
2138
|
+
case "npm":
|
|
2139
|
+
return "npm run -w";
|
|
2140
|
+
case "yarn":
|
|
2141
|
+
return "yarn workspace";
|
|
2142
|
+
default:
|
|
2143
|
+
return "bun run --cwd";
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
function devScript(pm) {
|
|
2147
|
+
const run = runInWorkspaceCommand(pm);
|
|
2148
|
+
return `concurrently "${run} apps/server dev" "${run} apps/app tauri:dev"`;
|
|
2149
|
+
}
|
|
2150
|
+
function replaceRootScripts(content, options) {
|
|
2151
|
+
return content.replaceAll("__RUN_IN_WORKSPACE__", runInWorkspaceCommand(options.packageManager)).replaceAll("__DEV_SCRIPT__", devScript(options.packageManager));
|
|
2152
|
+
}
|
|
2153
|
+
function syncContractPackageJson() {
|
|
2154
|
+
return readTemplateAsset("sync-contract/package.json");
|
|
2155
|
+
}
|
|
2156
|
+
function syncContractTsconfig() {
|
|
2157
|
+
return readTemplateAsset("sync-contract/tsconfig.json");
|
|
2158
|
+
}
|
|
2159
|
+
function syncContractConstants(options) {
|
|
2160
|
+
return replaceProjectName(readTemplateAsset("sync-contract/src/constants.ts"), options);
|
|
2161
|
+
}
|
|
2162
|
+
function syncContractLocalSchema() {
|
|
2163
|
+
return readTemplateAsset("sync-contract/src/local-schema.ts");
|
|
2164
|
+
}
|
|
2165
|
+
function syncContractApiSchema() {
|
|
2166
|
+
return readTemplateAsset("sync-contract/src/api-schema.ts");
|
|
2167
|
+
}
|
|
2168
|
+
function syncContractLocalSyncedSchema() {
|
|
2169
|
+
return readTemplateAsset("sync-contract/src/local-synced-schema.ts");
|
|
2170
|
+
}
|
|
2171
|
+
function syncContractApiSyncedSchema() {
|
|
2172
|
+
return readTemplateAsset("sync-contract/src/api-synced-schema.ts");
|
|
2173
|
+
}
|
|
2174
|
+
function syncContractConfig() {
|
|
2175
|
+
return readTemplateAsset("sync-contract/sync.config.ts");
|
|
2176
|
+
}
|
|
2177
|
+
function projectRootPackageJson(options) {
|
|
2178
|
+
return replaceRootScripts(replaceProjectName(readTemplateAsset("root/package.json"), options), options);
|
|
2179
|
+
}
|
|
2180
|
+
function projectReadme(options) {
|
|
2181
|
+
return replacePackageManager(replaceProjectName(readTemplateAsset("root/README.md"), options), options);
|
|
2182
|
+
}
|
|
2183
|
+
function appPackageJson(options) {
|
|
2184
|
+
return replaceProjectName(readTemplateAsset("app/package.json"), options);
|
|
2185
|
+
}
|
|
2186
|
+
function appCargoToml(options) {
|
|
2187
|
+
return replaceProjectName(readTemplateAsset("app/src-tauri/Cargo.toml"), options);
|
|
2188
|
+
}
|
|
2189
|
+
function appBuildRs() {
|
|
2190
|
+
return readTemplateAsset("app/src-tauri/build.rs");
|
|
2191
|
+
}
|
|
2192
|
+
function appTauriConf(options) {
|
|
2193
|
+
return replaceProjectName(readTemplateAsset("app/src-tauri/tauri.conf.json"), options);
|
|
2194
|
+
}
|
|
2195
|
+
function appLibRs() {
|
|
2196
|
+
return replaceContractDate(readTemplateAsset("app/src/lib.rs"));
|
|
2197
|
+
}
|
|
2198
|
+
function appDbHelper() {
|
|
2199
|
+
return readTemplateAsset("app/db-helper.ts");
|
|
2200
|
+
}
|
|
2201
|
+
function appSyncClient() {
|
|
2202
|
+
return readTemplateAsset("app/sync-client.ts");
|
|
2203
|
+
}
|
|
2204
|
+
function serverPackageJson(options) {
|
|
2205
|
+
return replaceProjectName(readTemplateAsset("server/package.json"), options);
|
|
2206
|
+
}
|
|
2207
|
+
function prependPort(originalDevScript) {
|
|
2208
|
+
return `PORT=3001 ${originalDevScript}`;
|
|
2209
|
+
}
|
|
2210
|
+
function serverDrizzleConfig(options) {
|
|
2211
|
+
return replaceProjectName(readTemplateAsset("server/drizzle-config.ts"), options);
|
|
2212
|
+
}
|
|
2213
|
+
function serverDbClient(options) {
|
|
2214
|
+
return replaceProjectName(readTemplateAsset("server/src-db/client.ts"), options);
|
|
2215
|
+
}
|
|
2216
|
+
function serverSyncRepository() {
|
|
2217
|
+
return replaceContractDate(readTemplateAsset("server/src-db/v1/sync-repository.ts"));
|
|
2218
|
+
}
|
|
2219
|
+
function serverV1Routes(options) {
|
|
2220
|
+
if (options.serverFramework === "hono") {
|
|
2221
|
+
return replaceProjectName(readTemplateAsset("server/src/v1/routes-hono.ts"), options);
|
|
2222
|
+
}
|
|
2223
|
+
return replaceProjectName(readTemplateAsset("server/src/v1/routes-elysia.ts"), options);
|
|
2224
|
+
}
|
|
2225
|
+
function serverIndexPatch(options) {
|
|
2226
|
+
if (options.serverFramework === "hono") {
|
|
2227
|
+
return replaceProjectName(readTemplateAsset("server/src/index-hono.ts"), options);
|
|
2228
|
+
}
|
|
2229
|
+
return replaceProjectName(readTemplateAsset("server/src/index-elysia.ts"), options);
|
|
2230
|
+
}
|
|
2231
|
+
function serverFallbackInstructions(_options) {
|
|
2232
|
+
return readTemplateAsset("server/fallback-instructions.md");
|
|
2233
|
+
}
|
|
2234
|
+
function appHelperFiles() {
|
|
2235
|
+
return [
|
|
2236
|
+
file("apps/app/src/lib/db.ts", appDbHelper()),
|
|
2237
|
+
file("apps/app/src/lib/baresync-sync-client.ts", appSyncClient())
|
|
2238
|
+
];
|
|
2239
|
+
}
|
|
2240
|
+
function appTauriFiles(options) {
|
|
2241
|
+
return [
|
|
2242
|
+
file("apps/app/src-tauri/build.rs", appBuildRs()),
|
|
2243
|
+
file("apps/app/src-tauri/Cargo.toml", appCargoToml(options)),
|
|
2244
|
+
file("apps/app/src-tauri/src/lib.rs", appLibRs()),
|
|
2245
|
+
file("apps/app/src-tauri/tauri.conf.json", appTauriConf(options))
|
|
2246
|
+
];
|
|
2247
|
+
}
|
|
2248
|
+
function appDrizzleConfigFile(options) {
|
|
2249
|
+
return replaceProjectName(readTemplateAsset("app/drizzle-local-config.ts"), options);
|
|
2250
|
+
}
|
|
2251
|
+
function buildRootScaffoldFiles(options) {
|
|
2252
|
+
return [
|
|
2253
|
+
file("package.json", projectRootPackageJson(options)),
|
|
2254
|
+
file("README.md", projectReadme(options)),
|
|
2255
|
+
file("packages/sync-contract/package.json", syncContractPackageJson()),
|
|
2256
|
+
file("packages/sync-contract/tsconfig.json", syncContractTsconfig()),
|
|
2257
|
+
file("packages/sync-contract/src/constants.ts", syncContractConstants(options)),
|
|
2258
|
+
file("packages/sync-contract/src/local-schema.ts", syncContractLocalSchema()),
|
|
2259
|
+
file("packages/sync-contract/src/api-schema.ts", syncContractApiSchema()),
|
|
2260
|
+
file("packages/sync-contract/src/local-synced-schema.ts", syncContractLocalSyncedSchema()),
|
|
2261
|
+
file("packages/sync-contract/src/api-synced-schema.ts", syncContractApiSyncedSchema()),
|
|
2262
|
+
file("packages/sync-contract/sync.config.ts", syncContractConfig()),
|
|
2263
|
+
...appTauriFiles(options),
|
|
2264
|
+
file("apps/app/package.json", appPackageJson(options)),
|
|
2265
|
+
file("apps/app/drizzle.local.config.ts", appDrizzleConfigFile(options)),
|
|
2266
|
+
...appHelperFiles(),
|
|
2267
|
+
file("apps/server/package.json", serverPackageJson(options)),
|
|
2268
|
+
file("apps/server/drizzle.config.ts", serverDrizzleConfig(options)),
|
|
2269
|
+
file("apps/server/src/db/client.ts", serverDbClient(options)),
|
|
2270
|
+
file("apps/server/src/db/v1/sync-repository.ts", serverSyncRepository()),
|
|
2271
|
+
file("apps/server/src/v1/routes.ts", serverV1Routes(options)),
|
|
2272
|
+
file("apps/server/src/sync-fallback-instructions.md", serverFallbackInstructions(options)),
|
|
2273
|
+
file("apps/server/src/index.ts", serverIndexPatch(options))
|
|
2274
|
+
];
|
|
2275
|
+
}
|
|
2276
|
+
function buildUserFacingNextSteps(options) {
|
|
2277
|
+
return [
|
|
2278
|
+
`1. cd ${options.projectName}`,
|
|
2279
|
+
`2. ${options.packageManager} install`,
|
|
2280
|
+
`3. ${options.packageManager} run generate:sync`,
|
|
2281
|
+
`4. ${options.packageManager} run migrate:local`,
|
|
2282
|
+
`5. ${options.packageManager} run migrate:server`,
|
|
2283
|
+
`6. ${options.packageManager} run dev`
|
|
2284
|
+
].join(`
|
|
2285
|
+
`);
|
|
2286
|
+
}
|
|
2287
|
+
|
|
2288
|
+
// src/write.ts
|
|
2289
|
+
import fs2 from "fs/promises";
|
|
2290
|
+
import path2 from "path";
|
|
2291
|
+
async function writeScaffoldFiles(rootDir, files) {
|
|
2292
|
+
for (const file2 of files) {
|
|
2293
|
+
const absPath = path2.join(rootDir, file2.path);
|
|
2294
|
+
await fs2.mkdir(path2.dirname(absPath), { recursive: true });
|
|
2295
|
+
await fs2.writeFile(absPath, file2.content, "utf8");
|
|
2296
|
+
if (file2.executable) {
|
|
2297
|
+
await fs2.chmod(absPath, 493);
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
async function ensureEmptyTargetDir(targetDir) {
|
|
2302
|
+
await fs2.mkdir(targetDir, { recursive: true });
|
|
2303
|
+
const entries = await fs2.readdir(targetDir);
|
|
2304
|
+
if (entries.length > 0) {
|
|
2305
|
+
throw new Error(`Target directory is not empty: ${targetDir}. Choose an empty directory or a new project name.`);
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2309
|
+
// src/scaffold.ts
|
|
2310
|
+
async function runInteractive(command, args, cwd) {
|
|
2311
|
+
await new Promise((resolve, reject) => {
|
|
2312
|
+
const child = spawn(command, args, {
|
|
2313
|
+
cwd,
|
|
2314
|
+
shell: true,
|
|
2315
|
+
stdio: "inherit"
|
|
2316
|
+
});
|
|
2317
|
+
child.on("close", (code) => {
|
|
2318
|
+
if (code === 0) {
|
|
2319
|
+
resolve();
|
|
2320
|
+
return;
|
|
2321
|
+
}
|
|
2322
|
+
reject(new Error(`Command failed with exit code ${code ?? 1}`));
|
|
2323
|
+
});
|
|
2324
|
+
});
|
|
2325
|
+
}
|
|
2326
|
+
function createCommandArgs(packageManager, initializer, target) {
|
|
2327
|
+
if (packageManager === "npm") {
|
|
2328
|
+
return ["create", `${initializer}@latest`, target, "--"];
|
|
2329
|
+
}
|
|
2330
|
+
return ["create", initializer, target];
|
|
2331
|
+
}
|
|
2332
|
+
function mergeJson(baseText, patchText) {
|
|
2333
|
+
const base = JSON.parse(jsonrepair(baseText));
|
|
2334
|
+
const patch = JSON.parse(patchText);
|
|
2335
|
+
return `${JSON.stringify(deepMerge(base, patch), null, 2)}
|
|
2336
|
+
`;
|
|
2337
|
+
}
|
|
2338
|
+
function deepMerge(base, patch) {
|
|
2339
|
+
const result = { ...base };
|
|
2340
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
2341
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value) && typeof result[key] === "object" && result[key] !== null && !Array.isArray(result[key])) {
|
|
2342
|
+
result[key] = deepMerge(result[key], value);
|
|
2343
|
+
continue;
|
|
2344
|
+
}
|
|
2345
|
+
result[key] = value;
|
|
2346
|
+
}
|
|
2347
|
+
return result;
|
|
2348
|
+
}
|
|
2349
|
+
async function patchPackageJson(filePath, patch) {
|
|
2350
|
+
const current = await fs3.readFile(filePath, "utf8");
|
|
2351
|
+
await fs3.writeFile(filePath, mergeJson(current, JSON.stringify(patch)), "utf8");
|
|
2352
|
+
}
|
|
2353
|
+
async function patchTsconfig(filePath, patch) {
|
|
2354
|
+
const current = await fs3.readFile(filePath, "utf8");
|
|
2355
|
+
await fs3.writeFile(filePath, mergeJson(current, JSON.stringify(patch)), "utf8");
|
|
2356
|
+
}
|
|
2357
|
+
var VITE_EXPORT_RE = /export default \w+\(\{/;
|
|
2358
|
+
async function patchViteConfig(filePath) {
|
|
2359
|
+
let content = await fs3.readFile(filePath, "utf8");
|
|
2360
|
+
content = content.replace(VITE_EXPORT_RE, `$&
|
|
2361
|
+
resolve: { tsconfigPaths: true },`);
|
|
2362
|
+
await fs3.writeFile(filePath, content, "utf8");
|
|
2363
|
+
}
|
|
2364
|
+
function isRootTemplateFile(filePath) {
|
|
2365
|
+
return !(filePath.startsWith("apps/app/") || filePath.startsWith("apps/server/"));
|
|
2366
|
+
}
|
|
2367
|
+
async function writeTemplateSubset(rootDir, options) {
|
|
2368
|
+
const files = buildRootScaffoldFiles(options).filter((file2) => isRootTemplateFile(file2.path));
|
|
2369
|
+
await writeScaffoldFiles(rootDir, files);
|
|
2370
|
+
}
|
|
2371
|
+
async function patchAppFiles(projectDir, options, files) {
|
|
2372
|
+
const appCargoToml2 = files.find((file2) => file2.path === "apps/app/src-tauri/Cargo.toml");
|
|
2373
|
+
const appBuildRs2 = files.find((file2) => file2.path === "apps/app/src-tauri/build.rs");
|
|
2374
|
+
const appLibRs2 = files.find((file2) => file2.path === "apps/app/src-tauri/src/lib.rs");
|
|
2375
|
+
const appTauriConf2 = files.find((file2) => file2.path === "apps/app/src-tauri/tauri.conf.json");
|
|
2376
|
+
const appDrizzle = files.find((file2) => file2.path === "apps/app/drizzle.local.config.ts");
|
|
2377
|
+
const appDb = files.find((file2) => file2.path === "apps/app/src/lib/db.ts");
|
|
2378
|
+
const appSyncClient2 = files.find((file2) => file2.path === "apps/app/src/lib/baresync-sync-client.ts");
|
|
2379
|
+
if (!(appCargoToml2 && appBuildRs2 && appLibRs2 && appTauriConf2 && appDrizzle && appDb && appSyncClient2)) {
|
|
2380
|
+
throw new Error("Missing app scaffold files");
|
|
2381
|
+
}
|
|
2382
|
+
const appPackageJsonPath = path3.join(projectDir, "apps/app/package.json");
|
|
2383
|
+
const appPackageJsonContent = JSON.parse(jsonrepair(await fs3.readFile(appPackageJsonPath, "utf8")));
|
|
2384
|
+
const appTemplatePackageJson = JSON.parse(appPackageJson(options));
|
|
2385
|
+
const appPatch = {
|
|
2386
|
+
...appTemplatePackageJson,
|
|
2387
|
+
scripts: {
|
|
2388
|
+
...appTemplatePackageJson.scripts ?? {},
|
|
2389
|
+
...appPackageJsonContent.scripts ?? {}
|
|
2390
|
+
},
|
|
2391
|
+
dependencies: {
|
|
2392
|
+
...appTemplatePackageJson.dependencies ?? {},
|
|
2393
|
+
...appPackageJsonContent.dependencies ?? {}
|
|
2394
|
+
},
|
|
2395
|
+
devDependencies: {
|
|
2396
|
+
...appTemplatePackageJson.devDependencies ?? {},
|
|
2397
|
+
...appPackageJsonContent.devDependencies ?? {}
|
|
2398
|
+
}
|
|
2399
|
+
};
|
|
2400
|
+
await patchPackageJson(appPackageJsonPath, appPatch);
|
|
2401
|
+
await fs3.writeFile(path3.join(projectDir, "apps/app/src-tauri/build.rs"), appBuildRs2.content, "utf8");
|
|
2402
|
+
await fs3.writeFile(path3.join(projectDir, "apps/app/src-tauri/Cargo.toml"), appCargoToml2.content, "utf8");
|
|
2403
|
+
await fs3.writeFile(path3.join(projectDir, "apps/app/src-tauri/src/lib.rs"), appLibRs2.content, "utf8");
|
|
2404
|
+
await fs3.writeFile(path3.join(projectDir, "apps/app/src-tauri/tauri.conf.json"), appTauriConf2.content, "utf8");
|
|
2405
|
+
await fs3.writeFile(path3.join(projectDir, "apps/app/drizzle.local.config.ts"), appDrizzle.content, "utf8");
|
|
2406
|
+
await fs3.mkdir(path3.join(projectDir, "apps/app/src/lib"), {
|
|
2407
|
+
recursive: true
|
|
2408
|
+
});
|
|
2409
|
+
await fs3.writeFile(path3.join(projectDir, "apps/app/src/lib/db.ts"), appDb.content, "utf8");
|
|
2410
|
+
await fs3.writeFile(path3.join(projectDir, "apps/app/src/lib/baresync-sync-client.ts"), appSyncClient2.content, "utf8");
|
|
2411
|
+
await patchTsconfig(path3.join(projectDir, "apps/app/tsconfig.json"), {
|
|
2412
|
+
compilerOptions: {
|
|
2413
|
+
paths: {
|
|
2414
|
+
"@sync-contract/generated/*": [
|
|
2415
|
+
"../../packages/sync-contract/generated/*"
|
|
2416
|
+
],
|
|
2417
|
+
"@sync-contract/*": ["../../packages/sync-contract/src/*"]
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
});
|
|
2421
|
+
await patchViteConfig(path3.join(projectDir, "apps/app/vite.config.ts"));
|
|
2422
|
+
}
|
|
2423
|
+
async function patchServerFiles(projectDir, options, files) {
|
|
2424
|
+
const serverDrizzle = files.find((file2) => file2.path === "apps/server/drizzle.config.ts");
|
|
2425
|
+
const serverIndex = files.find((file2) => file2.path === "apps/server/src/index.ts");
|
|
2426
|
+
const serverDbClient2 = files.find((file2) => file2.path === "apps/server/src/db/client.ts");
|
|
2427
|
+
const serverSyncRepo = files.find((file2) => file2.path === "apps/server/src/db/v1/sync-repository.ts");
|
|
2428
|
+
const serverV1Route = files.find((file2) => file2.path === "apps/server/src/v1/routes.ts");
|
|
2429
|
+
const serverFallback = files.find((file2) => file2.path === "apps/server/src/sync-fallback-instructions.md");
|
|
2430
|
+
if (!(serverDrizzle && serverIndex && serverDbClient2 && serverSyncRepo && serverV1Route && serverFallback)) {
|
|
2431
|
+
throw new Error("Missing server scaffold files");
|
|
2432
|
+
}
|
|
2433
|
+
const honoPackageJsonPath = path3.join(projectDir, "apps/server/package.json");
|
|
2434
|
+
const honoPackageJson = JSON.parse(jsonrepair(await fs3.readFile(honoPackageJsonPath, "utf8")));
|
|
2435
|
+
const originalDevScript = honoPackageJson.scripts?.dev;
|
|
2436
|
+
const templatePackageJson = JSON.parse(serverPackageJson(options));
|
|
2437
|
+
const patch = {
|
|
2438
|
+
...templatePackageJson,
|
|
2439
|
+
scripts: {
|
|
2440
|
+
...templatePackageJson.scripts,
|
|
2441
|
+
...originalDevScript ? { dev: prependPort(originalDevScript) } : {}
|
|
2442
|
+
}
|
|
2443
|
+
};
|
|
2444
|
+
await patchPackageJson(honoPackageJsonPath, patch);
|
|
2445
|
+
await fs3.writeFile(path3.join(projectDir, "apps/server/drizzle.config.ts"), serverDrizzle.content, "utf8");
|
|
2446
|
+
await fs3.mkdir(path3.join(projectDir, "apps/server/data"), {
|
|
2447
|
+
recursive: true
|
|
2448
|
+
});
|
|
2449
|
+
await fs3.mkdir(path3.join(projectDir, "apps/server/src/db/v1"), {
|
|
2450
|
+
recursive: true
|
|
2451
|
+
});
|
|
2452
|
+
await fs3.writeFile(path3.join(projectDir, "apps/server/src/db/client.ts"), serverDbClient2.content, "utf8");
|
|
2453
|
+
await fs3.writeFile(path3.join(projectDir, "apps/server/src/db/v1/sync-repository.ts"), serverSyncRepo.content, "utf8");
|
|
2454
|
+
await fs3.mkdir(path3.join(projectDir, "apps/server/src/v1"), {
|
|
2455
|
+
recursive: true
|
|
2456
|
+
});
|
|
2457
|
+
await fs3.writeFile(path3.join(projectDir, serverV1Route.path), serverV1Route.content, "utf8");
|
|
2458
|
+
await fs3.writeFile(path3.join(projectDir, "apps/server/src/index.ts"), serverIndex.content, "utf8");
|
|
2459
|
+
await fs3.writeFile(path3.join(projectDir, "apps/server/src/sync-fallback-instructions.md"), serverFallback.content, "utf8");
|
|
2460
|
+
await patchTsconfig(path3.join(projectDir, "apps/server/tsconfig.json"), {
|
|
2461
|
+
compilerOptions: {
|
|
2462
|
+
paths: {
|
|
2463
|
+
"@sync-contract/generated/*": [
|
|
2464
|
+
"../../packages/sync-contract/generated/*"
|
|
2465
|
+
],
|
|
2466
|
+
"@sync-contract/*": ["../../packages/sync-contract/src/*"]
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
});
|
|
2470
|
+
}
|
|
2471
|
+
async function scaffoldProject() {
|
|
2472
|
+
ge(import_picocolors.default.bgCyan(import_picocolors.default.black(" create-baresync ")));
|
|
2473
|
+
const projectName = await promptProjectName();
|
|
2474
|
+
const detectedPackageManager = detectPackageManager();
|
|
2475
|
+
const packageManager = detectedPackageManager ?? await promptPackageManager();
|
|
2476
|
+
const projectDir = path3.join(process.cwd(), projectName);
|
|
2477
|
+
await ensureEmptyTargetDir(projectDir);
|
|
2478
|
+
await fs3.mkdir(path3.join(projectDir, "apps"), { recursive: true });
|
|
2479
|
+
await fs3.mkdir(path3.join(projectDir, "packages"), { recursive: true });
|
|
2480
|
+
R2.info(`Detected package manager: ${packageManager}`);
|
|
2481
|
+
const appTargetDir = path3.join(projectDir, "apps");
|
|
2482
|
+
await runInteractive(packageManager, createCommandArgs(packageManager, "tauri-app", "app"), appTargetDir);
|
|
2483
|
+
const serverFramework = await promptServerFramework();
|
|
2484
|
+
const options = {
|
|
2485
|
+
packageManager,
|
|
2486
|
+
projectName,
|
|
2487
|
+
serverFramework
|
|
2488
|
+
};
|
|
2489
|
+
const allFiles = buildRootScaffoldFiles(options);
|
|
2490
|
+
await writeTemplateSubset(projectDir, options);
|
|
2491
|
+
const serverTargetDir = path3.join(projectDir, "apps");
|
|
2492
|
+
const serverInitializer = serverFramework === "hono" ? "hono" : "elysia";
|
|
2493
|
+
try {
|
|
2494
|
+
await runInteractive(packageManager, createCommandArgs(packageManager, serverInitializer, "server"), serverTargetDir);
|
|
2495
|
+
} catch {
|
|
2496
|
+
R2.warn("\u26A0\uFE0F\u2003Note: create-hono exited with an error (likely an install failure).");
|
|
2497
|
+
R2.warn("This is safe to ignore \u2014 you can just run install at the workspace root later.");
|
|
2498
|
+
}
|
|
2499
|
+
await patchAppFiles(projectDir, options, allFiles);
|
|
2500
|
+
await patchServerFiles(projectDir, options, allFiles);
|
|
2501
|
+
await fs3.writeFile(path3.join(projectDir, "package.json"), JSON.stringify({
|
|
2502
|
+
name: projectName,
|
|
2503
|
+
private: true,
|
|
2504
|
+
workspaces: ["apps/*", "packages/*"],
|
|
2505
|
+
scripts: {
|
|
2506
|
+
dev: "node ./scripts/dev.mjs",
|
|
2507
|
+
"generate:sync": "node ./scripts/run-workspace.mjs packages/sync-contract generate",
|
|
2508
|
+
"migrate:local": "node ./scripts/run-workspace.mjs apps/app db:generate:local",
|
|
2509
|
+
"migrate:server": "node ./scripts/run-workspace.mjs apps/server db:generate"
|
|
2510
|
+
}
|
|
2511
|
+
}, null, 2), "utf8");
|
|
2512
|
+
await fs3.writeFile(path3.join(projectDir, "README.md"), `# ${projectName}
|
|
2513
|
+
|
|
2514
|
+
Generated with create-baresync.
|
|
2515
|
+
|
|
2516
|
+
## Next steps
|
|
2517
|
+
|
|
2518
|
+
${buildUserFacingNextSteps(options)}
|
|
2519
|
+
`, "utf8");
|
|
2520
|
+
ye(`${import_picocolors.default.green("Success!")} Baresync monorepo starter is ready!
|
|
2521
|
+
|
|
2522
|
+
${buildUserFacingNextSteps(options)}`);
|
|
2523
|
+
}
|
|
2524
|
+
export {
|
|
2525
|
+
scaffoldProject,
|
|
2526
|
+
detectPackageManager,
|
|
2527
|
+
buildUserFacingNextSteps,
|
|
2528
|
+
buildRootScaffoldFiles
|
|
2529
|
+
};
|