create-guren-app 1.8.8 → 1.8.9
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 +1851 -2139
- package/dist/prompt-BU6Ge-7H.js +886 -0
- package/package.json +4 -4
- package/templates/api-only/package.json +4 -4
- package/templates/api-only/tsconfig.json +1 -2
- package/templates/default/package.json +5 -5
- package/templates/default/resources/js/vite-env.d.ts +4 -0
- package/templates/default/tsconfig.json +0 -1
- package/dist/prompt-NH7GB4RH.js +0 -754
package/dist/cli.js
CHANGED
|
@@ -1,506 +1,385 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
2
|
+
import { cp, mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
import g$1 from "node:process";
|
|
5
|
+
import { formatWithOptions } from "node:util";
|
|
6
|
+
import * as tty from "node:tty";
|
|
7
|
+
import { randomBytes } from "node:crypto";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { spawnSync } from "node:child_process";
|
|
10
|
+
//#region ../../node_modules/.bun/consola@3.4.2/node_modules/consola/dist/core.mjs
|
|
11
|
+
const LogLevels = {
|
|
12
|
+
silent: Number.NEGATIVE_INFINITY,
|
|
13
|
+
fatal: 0,
|
|
14
|
+
error: 0,
|
|
15
|
+
warn: 1,
|
|
16
|
+
log: 2,
|
|
17
|
+
info: 3,
|
|
18
|
+
success: 3,
|
|
19
|
+
fail: 3,
|
|
20
|
+
ready: 3,
|
|
21
|
+
start: 3,
|
|
22
|
+
box: 3,
|
|
23
|
+
debug: 4,
|
|
24
|
+
trace: 5,
|
|
25
|
+
verbose: Number.POSITIVE_INFINITY
|
|
24
26
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
// Level 2
|
|
42
|
-
log: {
|
|
43
|
-
level: LogLevels.log
|
|
44
|
-
},
|
|
45
|
-
// Level 3
|
|
46
|
-
info: {
|
|
47
|
-
level: LogLevels.info
|
|
48
|
-
},
|
|
49
|
-
success: {
|
|
50
|
-
level: LogLevels.success
|
|
51
|
-
},
|
|
52
|
-
fail: {
|
|
53
|
-
level: LogLevels.fail
|
|
54
|
-
},
|
|
55
|
-
ready: {
|
|
56
|
-
level: LogLevels.info
|
|
57
|
-
},
|
|
58
|
-
start: {
|
|
59
|
-
level: LogLevels.info
|
|
60
|
-
},
|
|
61
|
-
box: {
|
|
62
|
-
level: LogLevels.info
|
|
63
|
-
},
|
|
64
|
-
// Level 4
|
|
65
|
-
debug: {
|
|
66
|
-
level: LogLevels.debug
|
|
67
|
-
},
|
|
68
|
-
// Level 5
|
|
69
|
-
trace: {
|
|
70
|
-
level: LogLevels.trace
|
|
71
|
-
},
|
|
72
|
-
// Verbose
|
|
73
|
-
verbose: {
|
|
74
|
-
level: LogLevels.verbose
|
|
75
|
-
}
|
|
27
|
+
const LogTypes = {
|
|
28
|
+
silent: { level: -1 },
|
|
29
|
+
fatal: { level: LogLevels.fatal },
|
|
30
|
+
error: { level: LogLevels.error },
|
|
31
|
+
warn: { level: LogLevels.warn },
|
|
32
|
+
log: { level: LogLevels.log },
|
|
33
|
+
info: { level: LogLevels.info },
|
|
34
|
+
success: { level: LogLevels.success },
|
|
35
|
+
fail: { level: LogLevels.fail },
|
|
36
|
+
ready: { level: LogLevels.info },
|
|
37
|
+
start: { level: LogLevels.info },
|
|
38
|
+
box: { level: LogLevels.info },
|
|
39
|
+
debug: { level: LogLevels.debug },
|
|
40
|
+
trace: { level: LogLevels.trace },
|
|
41
|
+
verbose: { level: LogLevels.verbose }
|
|
76
42
|
};
|
|
77
43
|
function isPlainObject$1(value) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
if (Symbol.iterator in value) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
if (Symbol.toStringTag in value) {
|
|
89
|
-
return Object.prototype.toString.call(value) === "[object Module]";
|
|
90
|
-
}
|
|
91
|
-
return true;
|
|
44
|
+
if (value === null || typeof value !== "object") return false;
|
|
45
|
+
const prototype = Object.getPrototypeOf(value);
|
|
46
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) return false;
|
|
47
|
+
if (Symbol.iterator in value) return false;
|
|
48
|
+
if (Symbol.toStringTag in value) return Object.prototype.toString.call(value) === "[object Module]";
|
|
49
|
+
return true;
|
|
92
50
|
}
|
|
93
51
|
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (merger && merger(object, key, value, namespace)) {
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
110
|
-
object[key] = [...value, ...object[key]];
|
|
111
|
-
} else if (isPlainObject$1(value) && isPlainObject$1(object[key])) {
|
|
112
|
-
object[key] = _defu(
|
|
113
|
-
value,
|
|
114
|
-
object[key],
|
|
115
|
-
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
116
|
-
merger
|
|
117
|
-
);
|
|
118
|
-
} else {
|
|
119
|
-
object[key] = value;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return object;
|
|
52
|
+
if (!isPlainObject$1(defaults)) return _defu(baseObject, {}, namespace, merger);
|
|
53
|
+
const object = Object.assign({}, defaults);
|
|
54
|
+
for (const key in baseObject) {
|
|
55
|
+
if (key === "__proto__" || key === "constructor") continue;
|
|
56
|
+
const value = baseObject[key];
|
|
57
|
+
if (value === null || value === void 0) continue;
|
|
58
|
+
if (merger && merger(object, key, value, namespace)) continue;
|
|
59
|
+
if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
|
|
60
|
+
else if (isPlainObject$1(value) && isPlainObject$1(object[key])) object[key] = _defu(value, object[key], (namespace ? `${namespace}.` : "") + key.toString(), merger);
|
|
61
|
+
else object[key] = value;
|
|
62
|
+
}
|
|
63
|
+
return object;
|
|
123
64
|
}
|
|
124
65
|
function createDefu(merger) {
|
|
125
|
-
|
|
126
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
127
|
-
arguments_.reduce((p, c2) => _defu(p, c2, "", merger), {})
|
|
128
|
-
);
|
|
66
|
+
return (...arguments_) => arguments_.reduce((p, c) => _defu(p, c, "", merger), {});
|
|
129
67
|
}
|
|
130
|
-
|
|
68
|
+
const defu = createDefu();
|
|
131
69
|
function isPlainObject(obj) {
|
|
132
|
-
|
|
70
|
+
return Object.prototype.toString.call(obj) === "[object Object]";
|
|
133
71
|
}
|
|
134
72
|
function isLogObj(arg) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
delete logObj.additional;
|
|
440
|
-
}
|
|
441
|
-
logObj.type = typeof logObj.type === "string" ? logObj.type.toLowerCase() : "log";
|
|
442
|
-
logObj.tag = typeof logObj.tag === "string" ? logObj.tag : "";
|
|
443
|
-
const resolveLog = (newLog = false) => {
|
|
444
|
-
const repeated = (this._lastLog.count || 0) - this.options.throttleMin;
|
|
445
|
-
if (this._lastLog.object && repeated > 0) {
|
|
446
|
-
const args2 = [...this._lastLog.object.args];
|
|
447
|
-
if (repeated > 1) {
|
|
448
|
-
args2.push(`(repeated ${repeated} times)`);
|
|
449
|
-
}
|
|
450
|
-
this._log({ ...this._lastLog.object, args: args2 });
|
|
451
|
-
this._lastLog.count = 1;
|
|
452
|
-
}
|
|
453
|
-
if (newLog) {
|
|
454
|
-
this._lastLog.object = logObj;
|
|
455
|
-
this._log(logObj);
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
clearTimeout(this._lastLog.timeout);
|
|
459
|
-
const diffTime = this._lastLog.time && logObj.date ? logObj.date.getTime() - this._lastLog.time.getTime() : 0;
|
|
460
|
-
this._lastLog.time = logObj.date;
|
|
461
|
-
if (diffTime < this.options.throttle) {
|
|
462
|
-
try {
|
|
463
|
-
const serializedLog = JSON.stringify([
|
|
464
|
-
logObj.type,
|
|
465
|
-
logObj.tag,
|
|
466
|
-
logObj.args
|
|
467
|
-
]);
|
|
468
|
-
const isSameLog = this._lastLog.serialized === serializedLog;
|
|
469
|
-
this._lastLog.serialized = serializedLog;
|
|
470
|
-
if (isSameLog) {
|
|
471
|
-
this._lastLog.count = (this._lastLog.count || 0) + 1;
|
|
472
|
-
if (this._lastLog.count > this.options.throttleMin) {
|
|
473
|
-
this._lastLog.timeout = setTimeout(
|
|
474
|
-
resolveLog,
|
|
475
|
-
this.options.throttle
|
|
476
|
-
);
|
|
477
|
-
return;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
} catch {
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
resolveLog(true);
|
|
484
|
-
}
|
|
485
|
-
_log(logObj) {
|
|
486
|
-
for (const reporter of this.options.reporters) {
|
|
487
|
-
reporter.log(logObj, {
|
|
488
|
-
options: this.options
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
}
|
|
73
|
+
if (!isPlainObject(arg)) return false;
|
|
74
|
+
if (!arg.message && !arg.args) return false;
|
|
75
|
+
if (arg.stack) return false;
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
let paused = false;
|
|
79
|
+
const queue = [];
|
|
80
|
+
var Consola = class Consola {
|
|
81
|
+
options;
|
|
82
|
+
_lastLog;
|
|
83
|
+
_mockFn;
|
|
84
|
+
/**
|
|
85
|
+
* Creates an instance of Consola with specified options or defaults.
|
|
86
|
+
*
|
|
87
|
+
* @param {Partial<ConsolaOptions>} [options={}] - Configuration options for the Consola instance.
|
|
88
|
+
*/
|
|
89
|
+
constructor(options = {}) {
|
|
90
|
+
const types = options.types || LogTypes;
|
|
91
|
+
this.options = defu({
|
|
92
|
+
...options,
|
|
93
|
+
defaults: { ...options.defaults },
|
|
94
|
+
level: _normalizeLogLevel(options.level, types),
|
|
95
|
+
reporters: [...options.reporters || []]
|
|
96
|
+
}, {
|
|
97
|
+
types: LogTypes,
|
|
98
|
+
throttle: 1e3,
|
|
99
|
+
throttleMin: 5,
|
|
100
|
+
formatOptions: {
|
|
101
|
+
date: true,
|
|
102
|
+
colors: false,
|
|
103
|
+
compact: true
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
for (const type in types) {
|
|
107
|
+
const defaults = {
|
|
108
|
+
type,
|
|
109
|
+
...this.options.defaults,
|
|
110
|
+
...types[type]
|
|
111
|
+
};
|
|
112
|
+
this[type] = this._wrapLogFn(defaults);
|
|
113
|
+
this[type].raw = this._wrapLogFn(defaults, true);
|
|
114
|
+
}
|
|
115
|
+
if (this.options.mockFn) this.mockTypes();
|
|
116
|
+
this._lastLog = {};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Gets the current log level of the Consola instance.
|
|
120
|
+
*
|
|
121
|
+
* @returns {number} The current log level.
|
|
122
|
+
*/
|
|
123
|
+
get level() {
|
|
124
|
+
return this.options.level;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Sets the minimum log level that will be output by the instance.
|
|
128
|
+
*
|
|
129
|
+
* @param {number} level - The new log level to set.
|
|
130
|
+
*/
|
|
131
|
+
set level(level) {
|
|
132
|
+
this.options.level = _normalizeLogLevel(level, this.options.types, this.options.level);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Displays a prompt to the user and returns the response.
|
|
136
|
+
* Throw an error if `prompt` is not supported by the current configuration.
|
|
137
|
+
*
|
|
138
|
+
* @template T
|
|
139
|
+
* @param {string} message - The message to display in the prompt.
|
|
140
|
+
* @param {T} [opts] - Optional options for the prompt. See {@link PromptOptions}.
|
|
141
|
+
* @returns {promise<T>} A promise that infer with the prompt options. See {@link PromptOptions}.
|
|
142
|
+
*/
|
|
143
|
+
prompt(message, opts) {
|
|
144
|
+
if (!this.options.prompt) throw new Error("prompt is not supported!");
|
|
145
|
+
return this.options.prompt(message, opts);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Creates a new instance of Consola, inheriting options from the current instance, with possible overrides.
|
|
149
|
+
*
|
|
150
|
+
* @param {Partial<ConsolaOptions>} options - Optional overrides for the new instance. See {@link ConsolaOptions}.
|
|
151
|
+
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
|
152
|
+
*/
|
|
153
|
+
create(options) {
|
|
154
|
+
const instance = new Consola({
|
|
155
|
+
...this.options,
|
|
156
|
+
...options
|
|
157
|
+
});
|
|
158
|
+
if (this._mockFn) instance.mockTypes(this._mockFn);
|
|
159
|
+
return instance;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Creates a new Consola instance with the specified default log object properties.
|
|
163
|
+
*
|
|
164
|
+
* @param {InputLogObject} defaults - Default properties to include in any log from the new instance. See {@link InputLogObject}.
|
|
165
|
+
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
|
166
|
+
*/
|
|
167
|
+
withDefaults(defaults) {
|
|
168
|
+
return this.create({
|
|
169
|
+
...this.options,
|
|
170
|
+
defaults: {
|
|
171
|
+
...this.options.defaults,
|
|
172
|
+
...defaults
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Creates a new Consola instance with a specified tag, which will be included in every log.
|
|
178
|
+
*
|
|
179
|
+
* @param {string} tag - The tag to include in each log of the new instance.
|
|
180
|
+
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
|
181
|
+
*/
|
|
182
|
+
withTag(tag) {
|
|
183
|
+
return this.withDefaults({ tag: this.options.defaults.tag ? this.options.defaults.tag + ":" + tag : tag });
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Adds a custom reporter to the Consola instance.
|
|
187
|
+
* Reporters will be called for each log message, depending on their implementation and log level.
|
|
188
|
+
*
|
|
189
|
+
* @param {ConsolaReporter} reporter - The reporter to add. See {@link ConsolaReporter}.
|
|
190
|
+
* @returns {Consola} The current Consola instance.
|
|
191
|
+
*/
|
|
192
|
+
addReporter(reporter) {
|
|
193
|
+
this.options.reporters.push(reporter);
|
|
194
|
+
return this;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Removes a custom reporter from the Consola instance.
|
|
198
|
+
* If no reporter is specified, all reporters will be removed.
|
|
199
|
+
*
|
|
200
|
+
* @param {ConsolaReporter} reporter - The reporter to remove. See {@link ConsolaReporter}.
|
|
201
|
+
* @returns {Consola} The current Consola instance.
|
|
202
|
+
*/
|
|
203
|
+
removeReporter(reporter) {
|
|
204
|
+
if (reporter) {
|
|
205
|
+
const i = this.options.reporters.indexOf(reporter);
|
|
206
|
+
if (i !== -1) return this.options.reporters.splice(i, 1);
|
|
207
|
+
} else this.options.reporters.splice(0);
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Replaces all reporters of the Consola instance with the specified array of reporters.
|
|
212
|
+
*
|
|
213
|
+
* @param {ConsolaReporter[]} reporters - The new reporters to set. See {@link ConsolaReporter}.
|
|
214
|
+
* @returns {Consola} The current Consola instance.
|
|
215
|
+
*/
|
|
216
|
+
setReporters(reporters) {
|
|
217
|
+
this.options.reporters = Array.isArray(reporters) ? reporters : [reporters];
|
|
218
|
+
return this;
|
|
219
|
+
}
|
|
220
|
+
wrapAll() {
|
|
221
|
+
this.wrapConsole();
|
|
222
|
+
this.wrapStd();
|
|
223
|
+
}
|
|
224
|
+
restoreAll() {
|
|
225
|
+
this.restoreConsole();
|
|
226
|
+
this.restoreStd();
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Overrides console methods with Consola logging methods for consistent logging.
|
|
230
|
+
*/
|
|
231
|
+
wrapConsole() {
|
|
232
|
+
for (const type in this.options.types) {
|
|
233
|
+
if (!console["__" + type]) console["__" + type] = console[type];
|
|
234
|
+
console[type] = this[type].raw;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Restores the original console methods, removing Consola overrides.
|
|
239
|
+
*/
|
|
240
|
+
restoreConsole() {
|
|
241
|
+
for (const type in this.options.types) if (console["__" + type]) {
|
|
242
|
+
console[type] = console["__" + type];
|
|
243
|
+
delete console["__" + type];
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Overrides standard output and error streams to redirect them through Consola.
|
|
248
|
+
*/
|
|
249
|
+
wrapStd() {
|
|
250
|
+
this._wrapStream(this.options.stdout, "log");
|
|
251
|
+
this._wrapStream(this.options.stderr, "log");
|
|
252
|
+
}
|
|
253
|
+
_wrapStream(stream, type) {
|
|
254
|
+
if (!stream) return;
|
|
255
|
+
if (!stream.__write) stream.__write = stream.write;
|
|
256
|
+
stream.write = (data) => {
|
|
257
|
+
this[type].raw(String(data).trim());
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Restores the original standard output and error streams, removing the Consola redirection.
|
|
262
|
+
*/
|
|
263
|
+
restoreStd() {
|
|
264
|
+
this._restoreStream(this.options.stdout);
|
|
265
|
+
this._restoreStream(this.options.stderr);
|
|
266
|
+
}
|
|
267
|
+
_restoreStream(stream) {
|
|
268
|
+
if (!stream) return;
|
|
269
|
+
if (stream.__write) {
|
|
270
|
+
stream.write = stream.__write;
|
|
271
|
+
delete stream.__write;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Pauses logging, queues incoming logs until resumed.
|
|
276
|
+
*/
|
|
277
|
+
pauseLogs() {
|
|
278
|
+
paused = true;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Resumes logging, processing any queued logs.
|
|
282
|
+
*/
|
|
283
|
+
resumeLogs() {
|
|
284
|
+
paused = false;
|
|
285
|
+
const _queue = queue.splice(0);
|
|
286
|
+
for (const item of _queue) item[0]._logFn(item[1], item[2]);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Replaces logging methods with mocks if a mock function is provided.
|
|
290
|
+
*
|
|
291
|
+
* @param {ConsolaOptions["mockFn"]} mockFn - The function to use for mocking logging methods. See {@link ConsolaOptions["mockFn"]}.
|
|
292
|
+
*/
|
|
293
|
+
mockTypes(mockFn) {
|
|
294
|
+
const _mockFn = mockFn || this.options.mockFn;
|
|
295
|
+
this._mockFn = _mockFn;
|
|
296
|
+
if (typeof _mockFn !== "function") return;
|
|
297
|
+
for (const type in this.options.types) {
|
|
298
|
+
this[type] = _mockFn(type, this.options.types[type]) || this[type];
|
|
299
|
+
this[type].raw = this[type];
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
_wrapLogFn(defaults, isRaw) {
|
|
303
|
+
return (...args) => {
|
|
304
|
+
if (paused) {
|
|
305
|
+
queue.push([
|
|
306
|
+
this,
|
|
307
|
+
defaults,
|
|
308
|
+
args,
|
|
309
|
+
isRaw
|
|
310
|
+
]);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
return this._logFn(defaults, args, isRaw);
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
_logFn(defaults, args, isRaw) {
|
|
317
|
+
if ((defaults.level || 0) > this.level) return false;
|
|
318
|
+
const logObj = {
|
|
319
|
+
date: /* @__PURE__ */ new Date(),
|
|
320
|
+
args: [],
|
|
321
|
+
...defaults,
|
|
322
|
+
level: _normalizeLogLevel(defaults.level, this.options.types)
|
|
323
|
+
};
|
|
324
|
+
if (!isRaw && args.length === 1 && isLogObj(args[0])) Object.assign(logObj, args[0]);
|
|
325
|
+
else logObj.args = [...args];
|
|
326
|
+
if (logObj.message) {
|
|
327
|
+
logObj.args.unshift(logObj.message);
|
|
328
|
+
delete logObj.message;
|
|
329
|
+
}
|
|
330
|
+
if (logObj.additional) {
|
|
331
|
+
if (!Array.isArray(logObj.additional)) logObj.additional = logObj.additional.split("\n");
|
|
332
|
+
logObj.args.push("\n" + logObj.additional.join("\n"));
|
|
333
|
+
delete logObj.additional;
|
|
334
|
+
}
|
|
335
|
+
logObj.type = typeof logObj.type === "string" ? logObj.type.toLowerCase() : "log";
|
|
336
|
+
logObj.tag = typeof logObj.tag === "string" ? logObj.tag : "";
|
|
337
|
+
const resolveLog = (newLog = false) => {
|
|
338
|
+
const repeated = (this._lastLog.count || 0) - this.options.throttleMin;
|
|
339
|
+
if (this._lastLog.object && repeated > 0) {
|
|
340
|
+
const args2 = [...this._lastLog.object.args];
|
|
341
|
+
if (repeated > 1) args2.push(`(repeated ${repeated} times)`);
|
|
342
|
+
this._log({
|
|
343
|
+
...this._lastLog.object,
|
|
344
|
+
args: args2
|
|
345
|
+
});
|
|
346
|
+
this._lastLog.count = 1;
|
|
347
|
+
}
|
|
348
|
+
if (newLog) {
|
|
349
|
+
this._lastLog.object = logObj;
|
|
350
|
+
this._log(logObj);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
clearTimeout(this._lastLog.timeout);
|
|
354
|
+
const diffTime = this._lastLog.time && logObj.date ? logObj.date.getTime() - this._lastLog.time.getTime() : 0;
|
|
355
|
+
this._lastLog.time = logObj.date;
|
|
356
|
+
if (diffTime < this.options.throttle) try {
|
|
357
|
+
const serializedLog = JSON.stringify([
|
|
358
|
+
logObj.type,
|
|
359
|
+
logObj.tag,
|
|
360
|
+
logObj.args
|
|
361
|
+
]);
|
|
362
|
+
const isSameLog = this._lastLog.serialized === serializedLog;
|
|
363
|
+
this._lastLog.serialized = serializedLog;
|
|
364
|
+
if (isSameLog) {
|
|
365
|
+
this._lastLog.count = (this._lastLog.count || 0) + 1;
|
|
366
|
+
if (this._lastLog.count > this.options.throttleMin) {
|
|
367
|
+
this._lastLog.timeout = setTimeout(resolveLog, this.options.throttle);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
} catch {}
|
|
372
|
+
resolveLog(true);
|
|
373
|
+
}
|
|
374
|
+
_log(logObj) {
|
|
375
|
+
for (const reporter of this.options.reporters) reporter.log(logObj, { options: this.options });
|
|
376
|
+
}
|
|
492
377
|
};
|
|
493
378
|
function _normalizeLogLevel(input, types = {}, defaultLevel = 3) {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
return input;
|
|
499
|
-
}
|
|
500
|
-
if (types[input] && types[input].level !== void 0) {
|
|
501
|
-
return types[input].level;
|
|
502
|
-
}
|
|
503
|
-
return defaultLevel;
|
|
379
|
+
if (input === void 0) return defaultLevel;
|
|
380
|
+
if (typeof input === "number") return input;
|
|
381
|
+
if (types[input] && types[input].level !== void 0) return types[input].level;
|
|
382
|
+
return defaultLevel;
|
|
504
383
|
}
|
|
505
384
|
Consola.prototype.add = Consola.prototype.addReporter;
|
|
506
385
|
Consola.prototype.remove = Consola.prototype.removeReporter;
|
|
@@ -509,1278 +388,1137 @@ Consola.prototype.withScope = Consola.prototype.withTag;
|
|
|
509
388
|
Consola.prototype.mock = Consola.prototype.mockTypes;
|
|
510
389
|
Consola.prototype.pause = Consola.prototype.pauseLogs;
|
|
511
390
|
Consola.prototype.resume = Consola.prototype.resumeLogs;
|
|
512
|
-
function createConsola(options = {}) {
|
|
513
|
-
|
|
391
|
+
function createConsola$1(options = {}) {
|
|
392
|
+
return new Consola(options);
|
|
514
393
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
import { formatWithOptions } from "util";
|
|
518
|
-
import { sep } from "path";
|
|
394
|
+
//#endregion
|
|
395
|
+
//#region ../../node_modules/.bun/consola@3.4.2/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs
|
|
519
396
|
function parseStack(stack, message) {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
return lines;
|
|
397
|
+
const cwd = process.cwd() + sep;
|
|
398
|
+
return stack.split("\n").splice(message.split("\n").length).map((l) => l.trim().replace("file://", "").replace(cwd, ""));
|
|
523
399
|
}
|
|
524
400
|
function writeStream(data, stream) {
|
|
525
|
-
|
|
526
|
-
return write.call(stream, data);
|
|
401
|
+
return (stream.__write || stream.write).call(stream, data);
|
|
527
402
|
}
|
|
528
|
-
|
|
403
|
+
const bracket = (x) => x ? `[${x}]` : "";
|
|
529
404
|
var BasicReporter = class {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
405
|
+
formatStack(stack, message, opts) {
|
|
406
|
+
const indent = " ".repeat((opts?.errorLevel || 0) + 1);
|
|
407
|
+
return indent + parseStack(stack, message).join(`
|
|
533
408
|
${indent}`);
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
return writeStream(
|
|
579
|
-
line + "\n",
|
|
580
|
-
logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout
|
|
581
|
-
);
|
|
582
|
-
}
|
|
409
|
+
}
|
|
410
|
+
formatError(err, opts) {
|
|
411
|
+
const message = err.message ?? formatWithOptions(opts, err);
|
|
412
|
+
const stack = err.stack ? this.formatStack(err.stack, message, opts) : "";
|
|
413
|
+
const level = opts?.errorLevel || 0;
|
|
414
|
+
const causedPrefix = level > 0 ? `${" ".repeat(level)}[cause]: ` : "";
|
|
415
|
+
const causedError = err.cause ? "\n\n" + this.formatError(err.cause, {
|
|
416
|
+
...opts,
|
|
417
|
+
errorLevel: level + 1
|
|
418
|
+
}) : "";
|
|
419
|
+
return causedPrefix + message + "\n" + stack + causedError;
|
|
420
|
+
}
|
|
421
|
+
formatArgs(args, opts) {
|
|
422
|
+
const _args = args.map((arg) => {
|
|
423
|
+
if (arg && typeof arg.stack === "string") return this.formatError(arg, opts);
|
|
424
|
+
return arg;
|
|
425
|
+
});
|
|
426
|
+
return formatWithOptions(opts, ..._args);
|
|
427
|
+
}
|
|
428
|
+
formatDate(date, opts) {
|
|
429
|
+
return opts.date ? date.toLocaleTimeString() : "";
|
|
430
|
+
}
|
|
431
|
+
filterAndJoin(arr) {
|
|
432
|
+
return arr.filter(Boolean).join(" ");
|
|
433
|
+
}
|
|
434
|
+
formatLogObj(logObj, opts) {
|
|
435
|
+
const message = this.formatArgs(logObj.args, opts);
|
|
436
|
+
if (logObj.type === "box") return "\n" + [
|
|
437
|
+
bracket(logObj.tag),
|
|
438
|
+
logObj.title && logObj.title,
|
|
439
|
+
...message.split("\n")
|
|
440
|
+
].filter(Boolean).map((l) => " > " + l).join("\n") + "\n";
|
|
441
|
+
return this.filterAndJoin([
|
|
442
|
+
bracket(logObj.type),
|
|
443
|
+
bracket(logObj.tag),
|
|
444
|
+
message
|
|
445
|
+
]);
|
|
446
|
+
}
|
|
447
|
+
log(logObj, ctx) {
|
|
448
|
+
return writeStream(this.formatLogObj(logObj, {
|
|
449
|
+
columns: ctx.options.stdout.columns || 0,
|
|
450
|
+
...ctx.options.formatOptions
|
|
451
|
+
}) + "\n", logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout);
|
|
452
|
+
}
|
|
583
453
|
};
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
} = typeof process === "undefined" ? {} : process;
|
|
595
|
-
var isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
|
|
596
|
-
var isForced = "FORCE_COLOR" in env || argv.includes("--color");
|
|
597
|
-
var isWindows = platform === "win32";
|
|
598
|
-
var isDumbTerminal = env.TERM === "dumb";
|
|
599
|
-
var isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;
|
|
600
|
-
var isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
|
|
601
|
-
var isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
|
|
454
|
+
//#endregion
|
|
455
|
+
//#region ../../node_modules/.bun/consola@3.4.2/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs
|
|
456
|
+
const { env = {}, argv = [], platform = "" } = typeof process === "undefined" ? {} : process;
|
|
457
|
+
const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
|
|
458
|
+
const isForced = "FORCE_COLOR" in env || argv.includes("--color");
|
|
459
|
+
const isWindows = platform === "win32";
|
|
460
|
+
const isDumbTerminal = env.TERM === "dumb";
|
|
461
|
+
const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;
|
|
462
|
+
const isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
|
|
463
|
+
const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
|
|
602
464
|
function replaceClose(index, string, close, replace, head = string.slice(0, Math.max(0, index)) + replace, tail = string.slice(Math.max(0, index + close.length)), next = tail.indexOf(close)) {
|
|
603
|
-
|
|
465
|
+
return head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
|
|
604
466
|
}
|
|
605
467
|
function clearBleed(index, string, open, close, replace) {
|
|
606
|
-
|
|
468
|
+
return index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
|
|
607
469
|
}
|
|
608
470
|
function filterEmpty(open, close, replace = open, at = open.length + 1) {
|
|
609
|
-
|
|
610
|
-
("" + string).indexOf(close, at),
|
|
611
|
-
string,
|
|
612
|
-
open,
|
|
613
|
-
close,
|
|
614
|
-
replace
|
|
615
|
-
) : "";
|
|
471
|
+
return (string) => string || !(string === "" || string === void 0) ? clearBleed(("" + string).indexOf(close, at), string, open, close, replace) : "";
|
|
616
472
|
}
|
|
617
473
|
function init(open, close, replace) {
|
|
618
|
-
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
474
|
+
return filterEmpty(`\x1B[${open}m`, `\x1B[${close}m`, replace);
|
|
475
|
+
}
|
|
476
|
+
const colorDefs = {
|
|
477
|
+
reset: init(0, 0),
|
|
478
|
+
bold: init(1, 22, "\x1B[22m\x1B[1m"),
|
|
479
|
+
dim: init(2, 22, "\x1B[22m\x1B[2m"),
|
|
480
|
+
italic: init(3, 23),
|
|
481
|
+
underline: init(4, 24),
|
|
482
|
+
inverse: init(7, 27),
|
|
483
|
+
hidden: init(8, 28),
|
|
484
|
+
strikethrough: init(9, 29),
|
|
485
|
+
black: init(30, 39),
|
|
486
|
+
red: init(31, 39),
|
|
487
|
+
green: init(32, 39),
|
|
488
|
+
yellow: init(33, 39),
|
|
489
|
+
blue: init(34, 39),
|
|
490
|
+
magenta: init(35, 39),
|
|
491
|
+
cyan: init(36, 39),
|
|
492
|
+
white: init(37, 39),
|
|
493
|
+
gray: init(90, 39),
|
|
494
|
+
bgBlack: init(40, 49),
|
|
495
|
+
bgRed: init(41, 49),
|
|
496
|
+
bgGreen: init(42, 49),
|
|
497
|
+
bgYellow: init(43, 49),
|
|
498
|
+
bgBlue: init(44, 49),
|
|
499
|
+
bgMagenta: init(45, 49),
|
|
500
|
+
bgCyan: init(46, 49),
|
|
501
|
+
bgWhite: init(47, 49),
|
|
502
|
+
blackBright: init(90, 39),
|
|
503
|
+
redBright: init(91, 39),
|
|
504
|
+
greenBright: init(92, 39),
|
|
505
|
+
yellowBright: init(93, 39),
|
|
506
|
+
blueBright: init(94, 39),
|
|
507
|
+
magentaBright: init(95, 39),
|
|
508
|
+
cyanBright: init(96, 39),
|
|
509
|
+
whiteBright: init(97, 39),
|
|
510
|
+
bgBlackBright: init(100, 49),
|
|
511
|
+
bgRedBright: init(101, 49),
|
|
512
|
+
bgGreenBright: init(102, 49),
|
|
513
|
+
bgYellowBright: init(103, 49),
|
|
514
|
+
bgBlueBright: init(104, 49),
|
|
515
|
+
bgMagentaBright: init(105, 49),
|
|
516
|
+
bgCyanBright: init(106, 49),
|
|
517
|
+
bgWhiteBright: init(107, 49)
|
|
662
518
|
};
|
|
663
519
|
function createColors(useColor = isColorSupported) {
|
|
664
|
-
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
function getColor(color, fallback = "reset") {
|
|
668
|
-
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
h: "\u2500",
|
|
740
|
-
v: "\u2502"
|
|
741
|
-
}
|
|
520
|
+
return useColor ? colorDefs : Object.fromEntries(Object.keys(colorDefs).map((key) => [key, String]));
|
|
521
|
+
}
|
|
522
|
+
const colors = createColors();
|
|
523
|
+
function getColor$1(color, fallback = "reset") {
|
|
524
|
+
return colors[color] || colors[fallback];
|
|
525
|
+
}
|
|
526
|
+
const ansiRegex$1 = [String.raw`[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)`, String.raw`(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))`].join("|");
|
|
527
|
+
function stripAnsi$1(text) {
|
|
528
|
+
return text.replace(new RegExp(ansiRegex$1, "g"), "");
|
|
529
|
+
}
|
|
530
|
+
const boxStylePresets = {
|
|
531
|
+
solid: {
|
|
532
|
+
tl: "┌",
|
|
533
|
+
tr: "┐",
|
|
534
|
+
bl: "└",
|
|
535
|
+
br: "┘",
|
|
536
|
+
h: "─",
|
|
537
|
+
v: "│"
|
|
538
|
+
},
|
|
539
|
+
double: {
|
|
540
|
+
tl: "╔",
|
|
541
|
+
tr: "╗",
|
|
542
|
+
bl: "╚",
|
|
543
|
+
br: "╝",
|
|
544
|
+
h: "═",
|
|
545
|
+
v: "║"
|
|
546
|
+
},
|
|
547
|
+
doubleSingle: {
|
|
548
|
+
tl: "╓",
|
|
549
|
+
tr: "╖",
|
|
550
|
+
bl: "╙",
|
|
551
|
+
br: "╜",
|
|
552
|
+
h: "─",
|
|
553
|
+
v: "║"
|
|
554
|
+
},
|
|
555
|
+
doubleSingleRounded: {
|
|
556
|
+
tl: "╭",
|
|
557
|
+
tr: "╮",
|
|
558
|
+
bl: "╰",
|
|
559
|
+
br: "╯",
|
|
560
|
+
h: "─",
|
|
561
|
+
v: "║"
|
|
562
|
+
},
|
|
563
|
+
singleThick: {
|
|
564
|
+
tl: "┏",
|
|
565
|
+
tr: "┓",
|
|
566
|
+
bl: "┗",
|
|
567
|
+
br: "┛",
|
|
568
|
+
h: "━",
|
|
569
|
+
v: "┃"
|
|
570
|
+
},
|
|
571
|
+
singleDouble: {
|
|
572
|
+
tl: "╒",
|
|
573
|
+
tr: "╕",
|
|
574
|
+
bl: "╘",
|
|
575
|
+
br: "╛",
|
|
576
|
+
h: "═",
|
|
577
|
+
v: "│"
|
|
578
|
+
},
|
|
579
|
+
singleDoubleRounded: {
|
|
580
|
+
tl: "╭",
|
|
581
|
+
tr: "╮",
|
|
582
|
+
bl: "╰",
|
|
583
|
+
br: "╯",
|
|
584
|
+
h: "═",
|
|
585
|
+
v: "│"
|
|
586
|
+
},
|
|
587
|
+
rounded: {
|
|
588
|
+
tl: "╭",
|
|
589
|
+
tr: "╮",
|
|
590
|
+
bl: "╰",
|
|
591
|
+
br: "╯",
|
|
592
|
+
h: "─",
|
|
593
|
+
v: "│"
|
|
594
|
+
}
|
|
742
595
|
};
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
596
|
+
const defaultStyle = {
|
|
597
|
+
borderColor: "white",
|
|
598
|
+
borderStyle: "rounded",
|
|
599
|
+
valign: "center",
|
|
600
|
+
padding: 2,
|
|
601
|
+
marginLeft: 1,
|
|
602
|
+
marginTop: 1,
|
|
603
|
+
marginBottom: 1
|
|
751
604
|
};
|
|
752
605
|
function box(text, _opts = {}) {
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
606
|
+
const opts = {
|
|
607
|
+
..._opts,
|
|
608
|
+
style: {
|
|
609
|
+
...defaultStyle,
|
|
610
|
+
..._opts.style
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
const textLines = text.split("\n");
|
|
614
|
+
const boxLines = [];
|
|
615
|
+
const _color = getColor$1(opts.style.borderColor);
|
|
616
|
+
const borderStyle = { ...typeof opts.style.borderStyle === "string" ? boxStylePresets[opts.style.borderStyle] || boxStylePresets.solid : opts.style.borderStyle };
|
|
617
|
+
if (_color) for (const key in borderStyle) borderStyle[key] = _color(borderStyle[key]);
|
|
618
|
+
const paddingOffset = opts.style.padding % 2 === 0 ? opts.style.padding : opts.style.padding + 1;
|
|
619
|
+
const height = textLines.length + paddingOffset;
|
|
620
|
+
const width = Math.max(...textLines.map((line) => stripAnsi$1(line).length), opts.title ? stripAnsi$1(opts.title).length : 0) + paddingOffset;
|
|
621
|
+
const widthOffset = width + paddingOffset;
|
|
622
|
+
const leftSpace = opts.style.marginLeft > 0 ? " ".repeat(opts.style.marginLeft) : "";
|
|
623
|
+
if (opts.style.marginTop > 0) boxLines.push("".repeat(opts.style.marginTop));
|
|
624
|
+
if (opts.title) {
|
|
625
|
+
const title = _color ? _color(opts.title) : opts.title;
|
|
626
|
+
const left = borderStyle.h.repeat(Math.floor((width - stripAnsi$1(opts.title).length) / 2));
|
|
627
|
+
const right = borderStyle.h.repeat(width - stripAnsi$1(opts.title).length - stripAnsi$1(left).length + paddingOffset);
|
|
628
|
+
boxLines.push(`${leftSpace}${borderStyle.tl}${left}${title}${right}${borderStyle.tr}`);
|
|
629
|
+
} else boxLines.push(`${leftSpace}${borderStyle.tl}${borderStyle.h.repeat(widthOffset)}${borderStyle.tr}`);
|
|
630
|
+
const valignOffset = opts.style.valign === "center" ? Math.floor((height - textLines.length) / 2) : opts.style.valign === "top" ? height - textLines.length - paddingOffset : height - textLines.length;
|
|
631
|
+
for (let i = 0; i < height; i++) if (i < valignOffset || i >= valignOffset + textLines.length) boxLines.push(`${leftSpace}${borderStyle.v}${" ".repeat(widthOffset)}${borderStyle.v}`);
|
|
632
|
+
else {
|
|
633
|
+
const line = textLines[i - valignOffset];
|
|
634
|
+
const left = " ".repeat(paddingOffset);
|
|
635
|
+
const right = " ".repeat(width - stripAnsi$1(line).length);
|
|
636
|
+
boxLines.push(`${leftSpace}${borderStyle.v}${left}${line}${right}${borderStyle.v}`);
|
|
637
|
+
}
|
|
638
|
+
boxLines.push(`${leftSpace}${borderStyle.bl}${borderStyle.h.repeat(widthOffset)}${borderStyle.br}`);
|
|
639
|
+
if (opts.style.marginBottom > 0) boxLines.push("".repeat(opts.style.marginBottom));
|
|
640
|
+
return boxLines.join("\n");
|
|
641
|
+
}
|
|
642
|
+
//#endregion
|
|
643
|
+
//#region ../../node_modules/.bun/consola@3.4.2/node_modules/consola/dist/index.mjs
|
|
644
|
+
const r = Object.create(null);
|
|
645
|
+
const i = (e) => globalThis.process?.env || import.meta.env || globalThis.Deno?.env.toObject() || globalThis.__env__ || (e ? r : globalThis);
|
|
646
|
+
const o = new Proxy(r, {
|
|
647
|
+
get(e, s) {
|
|
648
|
+
return i()[s] ?? r[s];
|
|
649
|
+
},
|
|
650
|
+
has(e, s) {
|
|
651
|
+
return s in i() || s in r;
|
|
652
|
+
},
|
|
653
|
+
set(e, s, E) {
|
|
654
|
+
const B = i(true);
|
|
655
|
+
return B[s] = E, true;
|
|
656
|
+
},
|
|
657
|
+
deleteProperty(e, s) {
|
|
658
|
+
if (!s) return false;
|
|
659
|
+
const E = i(true);
|
|
660
|
+
return delete E[s], true;
|
|
661
|
+
},
|
|
662
|
+
ownKeys() {
|
|
663
|
+
const e = i(true);
|
|
664
|
+
return Object.keys(e);
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
const t = typeof process < "u" && process.env && process.env.NODE_ENV || "";
|
|
668
|
+
const f = [
|
|
669
|
+
["APPVEYOR"],
|
|
670
|
+
[
|
|
671
|
+
"AWS_AMPLIFY",
|
|
672
|
+
"AWS_APP_ID",
|
|
673
|
+
{ ci: true }
|
|
674
|
+
],
|
|
675
|
+
["AZURE_PIPELINES", "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"],
|
|
676
|
+
["AZURE_STATIC", "INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN"],
|
|
677
|
+
["APPCIRCLE", "AC_APPCIRCLE"],
|
|
678
|
+
["BAMBOO", "bamboo_planKey"],
|
|
679
|
+
["BITBUCKET", "BITBUCKET_COMMIT"],
|
|
680
|
+
["BITRISE", "BITRISE_IO"],
|
|
681
|
+
["BUDDY", "BUDDY_WORKSPACE_ID"],
|
|
682
|
+
["BUILDKITE"],
|
|
683
|
+
["CIRCLE", "CIRCLECI"],
|
|
684
|
+
["CIRRUS", "CIRRUS_CI"],
|
|
685
|
+
[
|
|
686
|
+
"CLOUDFLARE_PAGES",
|
|
687
|
+
"CF_PAGES",
|
|
688
|
+
{ ci: true }
|
|
689
|
+
],
|
|
690
|
+
["CODEBUILD", "CODEBUILD_BUILD_ARN"],
|
|
691
|
+
["CODEFRESH", "CF_BUILD_ID"],
|
|
692
|
+
["DRONE"],
|
|
693
|
+
["DRONE", "DRONE_BUILD_EVENT"],
|
|
694
|
+
["DSARI"],
|
|
695
|
+
["GITHUB_ACTIONS"],
|
|
696
|
+
["GITLAB", "GITLAB_CI"],
|
|
697
|
+
["GITLAB", "CI_MERGE_REQUEST_ID"],
|
|
698
|
+
["GOCD", "GO_PIPELINE_LABEL"],
|
|
699
|
+
["LAYERCI"],
|
|
700
|
+
["HUDSON", "HUDSON_URL"],
|
|
701
|
+
["JENKINS", "JENKINS_URL"],
|
|
702
|
+
["MAGNUM"],
|
|
703
|
+
["NETLIFY"],
|
|
704
|
+
[
|
|
705
|
+
"NETLIFY",
|
|
706
|
+
"NETLIFY_LOCAL",
|
|
707
|
+
{ ci: false }
|
|
708
|
+
],
|
|
709
|
+
["NEVERCODE"],
|
|
710
|
+
["RENDER"],
|
|
711
|
+
["SAIL", "SAILCI"],
|
|
712
|
+
["SEMAPHORE"],
|
|
713
|
+
["SCREWDRIVER"],
|
|
714
|
+
["SHIPPABLE"],
|
|
715
|
+
["SOLANO", "TDDIUM"],
|
|
716
|
+
["STRIDER"],
|
|
717
|
+
["TEAMCITY", "TEAMCITY_VERSION"],
|
|
718
|
+
["TRAVIS"],
|
|
719
|
+
["VERCEL", "NOW_BUILDER"],
|
|
720
|
+
[
|
|
721
|
+
"VERCEL",
|
|
722
|
+
"VERCEL",
|
|
723
|
+
{ ci: false }
|
|
724
|
+
],
|
|
725
|
+
[
|
|
726
|
+
"VERCEL",
|
|
727
|
+
"VERCEL_ENV",
|
|
728
|
+
{ ci: false }
|
|
729
|
+
],
|
|
730
|
+
["APPCENTER", "APPCENTER_BUILD_ID"],
|
|
731
|
+
[
|
|
732
|
+
"CODESANDBOX",
|
|
733
|
+
"CODESANDBOX_SSE",
|
|
734
|
+
{ ci: false }
|
|
735
|
+
],
|
|
736
|
+
[
|
|
737
|
+
"CODESANDBOX",
|
|
738
|
+
"CODESANDBOX_HOST",
|
|
739
|
+
{ ci: false }
|
|
740
|
+
],
|
|
741
|
+
["STACKBLITZ"],
|
|
742
|
+
["STORMKIT"],
|
|
743
|
+
["CLEAVR"],
|
|
744
|
+
["ZEABUR"],
|
|
745
|
+
[
|
|
746
|
+
"CODESPHERE",
|
|
747
|
+
"CODESPHERE_APP_ID",
|
|
748
|
+
{ ci: true }
|
|
749
|
+
],
|
|
750
|
+
["RAILWAY", "RAILWAY_PROJECT_ID"],
|
|
751
|
+
["RAILWAY", "RAILWAY_SERVICE_ID"],
|
|
752
|
+
["DENO-DEPLOY", "DENO_DEPLOYMENT_ID"],
|
|
753
|
+
[
|
|
754
|
+
"FIREBASE_APP_HOSTING",
|
|
755
|
+
"FIREBASE_APP_HOSTING",
|
|
756
|
+
{ ci: true }
|
|
757
|
+
]
|
|
758
|
+
];
|
|
848
759
|
function b() {
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
}
|
|
855
|
-
|
|
760
|
+
if (globalThis.process?.env) for (const e of f) {
|
|
761
|
+
const s = e[1] || e[0];
|
|
762
|
+
if (globalThis.process?.env[s]) return {
|
|
763
|
+
name: e[0].toLowerCase(),
|
|
764
|
+
...e[2]
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
return globalThis.process?.env?.SHELL === "/bin/jsh" && globalThis.process?.versions?.webcontainer ? {
|
|
768
|
+
name: "stackblitz",
|
|
769
|
+
ci: false
|
|
770
|
+
} : {
|
|
771
|
+
name: "",
|
|
772
|
+
ci: false
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
const l = b();
|
|
856
776
|
l.name;
|
|
857
777
|
function n(e) {
|
|
858
|
-
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
!n(o.NO_COLOR) && (n(o.FORCE_COLOR) || (a || A) && o.TERM
|
|
868
|
-
|
|
869
|
-
Number(C?.split(".")[0])
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
new Proxy(y, { get(e,
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
778
|
+
return e ? e !== "false" : false;
|
|
779
|
+
}
|
|
780
|
+
const I = globalThis.process?.platform || "";
|
|
781
|
+
const T = n(o.CI) || l.ci !== false;
|
|
782
|
+
const a = n(globalThis.process?.stdout && globalThis.process?.stdout.isTTY);
|
|
783
|
+
const g = n(o.DEBUG);
|
|
784
|
+
const R = t === "test" || n(o.TEST);
|
|
785
|
+
o.MINIMAL;
|
|
786
|
+
const A = /^win/i.test(I);
|
|
787
|
+
!n(o.NO_COLOR) && (n(o.FORCE_COLOR) || (a || A) && o.TERM);
|
|
788
|
+
const C = (globalThis.process?.versions?.node || "").replace(/^v/, "") || null;
|
|
789
|
+
Number(C?.split(".")[0]);
|
|
790
|
+
const y = globalThis.process || Object.create(null);
|
|
791
|
+
const _ = { versions: {} };
|
|
792
|
+
new Proxy(y, { get(e, s) {
|
|
793
|
+
if (s === "env") return o;
|
|
794
|
+
if (s in e) return e[s];
|
|
795
|
+
if (s in _) return _[s];
|
|
876
796
|
} });
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
797
|
+
const c = globalThis.process?.release?.name === "node";
|
|
798
|
+
const O = !!globalThis.Bun || !!globalThis.process?.versions?.bun;
|
|
799
|
+
const D = !!globalThis.Deno;
|
|
800
|
+
const L = !!globalThis.fastly;
|
|
801
|
+
const S = !!globalThis.Netlify;
|
|
802
|
+
const u = !!globalThis.EdgeRuntime;
|
|
803
|
+
const N = globalThis.navigator?.userAgent === "Cloudflare-Workers";
|
|
804
|
+
const F = [
|
|
805
|
+
[S, "netlify"],
|
|
806
|
+
[u, "edge-light"],
|
|
807
|
+
[N, "workerd"],
|
|
808
|
+
[L, "fastly"],
|
|
809
|
+
[D, "deno"],
|
|
810
|
+
[O, "bun"],
|
|
811
|
+
[c, "node"]
|
|
812
|
+
];
|
|
885
813
|
function G() {
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
}
|
|
899
|
-
var regex = ansiRegex2();
|
|
900
|
-
function stripAnsi2(string) {
|
|
901
|
-
if (typeof string !== "string") {
|
|
902
|
-
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
903
|
-
}
|
|
904
|
-
return string.replace(regex, "");
|
|
814
|
+
const e = F.find((s) => s[0]);
|
|
815
|
+
if (e) return { name: e[1] };
|
|
816
|
+
}
|
|
817
|
+
G()?.name;
|
|
818
|
+
function ansiRegex({ onlyFirst = false } = {}) {
|
|
819
|
+
const pattern = [`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))`, "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
|
|
820
|
+
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
821
|
+
}
|
|
822
|
+
const regex = ansiRegex();
|
|
823
|
+
function stripAnsi(string) {
|
|
824
|
+
if (typeof string !== "string") throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
825
|
+
return string.replace(regex, "");
|
|
905
826
|
}
|
|
906
827
|
function isAmbiguous(x) {
|
|
907
|
-
|
|
828
|
+
return x === 161 || x === 164 || x === 167 || x === 168 || x === 170 || x === 173 || x === 174 || x >= 176 && x <= 180 || x >= 182 && x <= 186 || x >= 188 && x <= 191 || x === 198 || x === 208 || x === 215 || x === 216 || x >= 222 && x <= 225 || x === 230 || x >= 232 && x <= 234 || x === 236 || x === 237 || x === 240 || x === 242 || x === 243 || x >= 247 && x <= 250 || x === 252 || x === 254 || x === 257 || x === 273 || x === 275 || x === 283 || x === 294 || x === 295 || x === 299 || x >= 305 && x <= 307 || x === 312 || x >= 319 && x <= 322 || x === 324 || x >= 328 && x <= 331 || x === 333 || x === 338 || x === 339 || x === 358 || x === 359 || x === 363 || x === 462 || x === 464 || x === 466 || x === 468 || x === 470 || x === 472 || x === 474 || x === 476 || x === 593 || x === 609 || x === 708 || x === 711 || x >= 713 && x <= 715 || x === 717 || x === 720 || x >= 728 && x <= 731 || x === 733 || x === 735 || x >= 768 && x <= 879 || x >= 913 && x <= 929 || x >= 931 && x <= 937 || x >= 945 && x <= 961 || x >= 963 && x <= 969 || x === 1025 || x >= 1040 && x <= 1103 || x === 1105 || x === 8208 || x >= 8211 && x <= 8214 || x === 8216 || x === 8217 || x === 8220 || x === 8221 || x >= 8224 && x <= 8226 || x >= 8228 && x <= 8231 || x === 8240 || x === 8242 || x === 8243 || x === 8245 || x === 8251 || x === 8254 || x === 8308 || x === 8319 || x >= 8321 && x <= 8324 || x === 8364 || x === 8451 || x === 8453 || x === 8457 || x === 8467 || x === 8470 || x === 8481 || x === 8482 || x === 8486 || x === 8491 || x === 8531 || x === 8532 || x >= 8539 && x <= 8542 || x >= 8544 && x <= 8555 || x >= 8560 && x <= 8569 || x === 8585 || x >= 8592 && x <= 8601 || x === 8632 || x === 8633 || x === 8658 || x === 8660 || x === 8679 || x === 8704 || x === 8706 || x === 8707 || x === 8711 || x === 8712 || x === 8715 || x === 8719 || x === 8721 || x === 8725 || x === 8730 || x >= 8733 && x <= 8736 || x === 8739 || x === 8741 || x >= 8743 && x <= 8748 || x === 8750 || x >= 8756 && x <= 8759 || x === 8764 || x === 8765 || x === 8776 || x === 8780 || x === 8786 || x === 8800 || x === 8801 || x >= 8804 && x <= 8807 || x === 8810 || x === 8811 || x === 8814 || x === 8815 || x === 8834 || x === 8835 || x === 8838 || x === 8839 || x === 8853 || x === 8857 || x === 8869 || x === 8895 || x === 8978 || x >= 9312 && x <= 9449 || x >= 9451 && x <= 9547 || x >= 9552 && x <= 9587 || x >= 9600 && x <= 9615 || x >= 9618 && x <= 9621 || x === 9632 || x === 9633 || x >= 9635 && x <= 9641 || x === 9650 || x === 9651 || x === 9654 || x === 9655 || x === 9660 || x === 9661 || x === 9664 || x === 9665 || x >= 9670 && x <= 9672 || x === 9675 || x >= 9678 && x <= 9681 || x >= 9698 && x <= 9701 || x === 9711 || x === 9733 || x === 9734 || x === 9737 || x === 9742 || x === 9743 || x === 9756 || x === 9758 || x === 9792 || x === 9794 || x === 9824 || x === 9825 || x >= 9827 && x <= 9829 || x >= 9831 && x <= 9834 || x === 9836 || x === 9837 || x === 9839 || x === 9886 || x === 9887 || x === 9919 || x >= 9926 && x <= 9933 || x >= 9935 && x <= 9939 || x >= 9941 && x <= 9953 || x === 9955 || x === 9960 || x === 9961 || x >= 9963 && x <= 9969 || x === 9972 || x >= 9974 && x <= 9977 || x === 9979 || x === 9980 || x === 9982 || x === 9983 || x === 10045 || x >= 10102 && x <= 10111 || x >= 11094 && x <= 11097 || x >= 12872 && x <= 12879 || x >= 57344 && x <= 63743 || x >= 65024 && x <= 65039 || x === 65533 || x >= 127232 && x <= 127242 || x >= 127248 && x <= 127277 || x >= 127280 && x <= 127337 || x >= 127344 && x <= 127373 || x === 127375 || x === 127376 || x >= 127387 && x <= 127404 || x >= 917760 && x <= 917999 || x >= 983040 && x <= 1048573 || x >= 1048576 && x <= 1114109;
|
|
908
829
|
}
|
|
909
830
|
function isFullWidth(x) {
|
|
910
|
-
|
|
831
|
+
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
911
832
|
}
|
|
912
833
|
function isWide(x) {
|
|
913
|
-
|
|
834
|
+
return x >= 4352 && x <= 4447 || x === 8986 || x === 8987 || x === 9001 || x === 9002 || x >= 9193 && x <= 9196 || x === 9200 || x === 9203 || x === 9725 || x === 9726 || x === 9748 || x === 9749 || x >= 9776 && x <= 9783 || x >= 9800 && x <= 9811 || x === 9855 || x >= 9866 && x <= 9871 || x === 9875 || x === 9889 || x === 9898 || x === 9899 || x === 9917 || x === 9918 || x === 9924 || x === 9925 || x === 9934 || x === 9940 || x === 9962 || x === 9970 || x === 9971 || x === 9973 || x === 9978 || x === 9981 || x === 9989 || x === 9994 || x === 9995 || x === 10024 || x === 10060 || x === 10062 || x >= 10067 && x <= 10069 || x === 10071 || x >= 10133 && x <= 10135 || x === 10160 || x === 10175 || x === 11035 || x === 11036 || x === 11088 || x === 11093 || x >= 11904 && x <= 11929 || x >= 11931 && x <= 12019 || x >= 12032 && x <= 12245 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12353 && x <= 12438 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12773 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 42124 || x >= 42128 && x <= 42182 || x >= 43360 && x <= 43388 || x >= 44032 && x <= 55203 || x >= 63744 && x <= 64255 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 94176 && x <= 94180 || x === 94192 || x === 94193 || x >= 94208 && x <= 100343 || x >= 100352 && x <= 101589 || x >= 101631 && x <= 101640 || x >= 110576 && x <= 110579 || x >= 110581 && x <= 110587 || x === 110589 || x === 110590 || x >= 110592 && x <= 110882 || x === 110898 || x >= 110928 && x <= 110930 || x === 110933 || x >= 110948 && x <= 110951 || x >= 110960 && x <= 111355 || x >= 119552 && x <= 119638 || x >= 119648 && x <= 119670 || x === 126980 || x === 127183 || x === 127374 || x >= 127377 && x <= 127386 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x === 127568 || x === 127569 || x >= 127584 && x <= 127589 || x >= 127744 && x <= 127776 || x >= 127789 && x <= 127797 || x >= 127799 && x <= 127868 || x >= 127870 && x <= 127891 || x >= 127904 && x <= 127946 || x >= 127951 && x <= 127955 || x >= 127968 && x <= 127984 || x === 127988 || x >= 127992 && x <= 128062 || x === 128064 || x >= 128066 && x <= 128252 || x >= 128255 && x <= 128317 || x >= 128331 && x <= 128334 || x >= 128336 && x <= 128359 || x === 128378 || x === 128405 || x === 128406 || x === 128420 || x >= 128507 && x <= 128591 || x >= 128640 && x <= 128709 || x === 128716 || x >= 128720 && x <= 128722 || x >= 128725 && x <= 128727 || x >= 128732 && x <= 128735 || x === 128747 || x === 128748 || x >= 128756 && x <= 128764 || x >= 128992 && x <= 129003 || x === 129008 || x >= 129292 && x <= 129338 || x >= 129340 && x <= 129349 || x >= 129351 && x <= 129535 || x >= 129648 && x <= 129660 || x >= 129664 && x <= 129673 || x >= 129679 && x <= 129734 || x >= 129742 && x <= 129756 || x >= 129759 && x <= 129769 || x >= 129776 && x <= 129784 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
|
|
914
835
|
}
|
|
915
836
|
function validate(codePoint) {
|
|
916
|
-
|
|
917
|
-
throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
918
|
-
}
|
|
837
|
+
if (!Number.isSafeInteger(codePoint)) throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
919
838
|
}
|
|
920
839
|
function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
}
|
|
927
|
-
var emojiRegex = () => {
|
|
928
|
-
return /[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE89\uDE8F-\uDEC2\uDEC6\uDECE-\uDEDC\uDEDF-\uDEE9]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g;
|
|
840
|
+
validate(codePoint);
|
|
841
|
+
if (isFullWidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) return 2;
|
|
842
|
+
return 1;
|
|
843
|
+
}
|
|
844
|
+
const emojiRegex = () => {
|
|
845
|
+
return /[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE89\uDE8F-\uDEC2\uDEC6\uDECE-\uDEDC\uDEDF-\uDEE9]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g;
|
|
929
846
|
};
|
|
930
|
-
|
|
931
|
-
|
|
847
|
+
const segmenter = globalThis.Intl?.Segmenter ? new Intl.Segmenter() : { segment: (str) => str.split("") };
|
|
848
|
+
const defaultIgnorableCodePointRegex = /^\p{Default_Ignorable_Code_Point}$/u;
|
|
932
849
|
function stringWidth$1(string, options = {}) {
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
continue;
|
|
955
|
-
}
|
|
956
|
-
if (codePoint >= 768 && codePoint <= 879 || codePoint >= 6832 && codePoint <= 6911 || codePoint >= 7616 && codePoint <= 7679 || codePoint >= 8400 && codePoint <= 8447 || codePoint >= 65056 && codePoint <= 65071) {
|
|
957
|
-
continue;
|
|
958
|
-
}
|
|
959
|
-
if (codePoint >= 55296 && codePoint <= 57343) {
|
|
960
|
-
continue;
|
|
961
|
-
}
|
|
962
|
-
if (codePoint >= 65024 && codePoint <= 65039) {
|
|
963
|
-
continue;
|
|
964
|
-
}
|
|
965
|
-
if (defaultIgnorableCodePointRegex.test(character)) {
|
|
966
|
-
continue;
|
|
967
|
-
}
|
|
968
|
-
if (emojiRegex().test(character)) {
|
|
969
|
-
width += 2;
|
|
970
|
-
continue;
|
|
971
|
-
}
|
|
972
|
-
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
973
|
-
}
|
|
974
|
-
return width;
|
|
850
|
+
if (typeof string !== "string" || string.length === 0) return 0;
|
|
851
|
+
const { ambiguousIsNarrow = true, countAnsiEscapeCodes = false } = options;
|
|
852
|
+
if (!countAnsiEscapeCodes) string = stripAnsi(string);
|
|
853
|
+
if (string.length === 0) return 0;
|
|
854
|
+
let width = 0;
|
|
855
|
+
const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
|
|
856
|
+
for (const { segment: character } of segmenter.segment(string)) {
|
|
857
|
+
const codePoint = character.codePointAt(0);
|
|
858
|
+
if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159) continue;
|
|
859
|
+
if (codePoint >= 8203 && codePoint <= 8207 || codePoint === 65279) continue;
|
|
860
|
+
if (codePoint >= 768 && codePoint <= 879 || codePoint >= 6832 && codePoint <= 6911 || codePoint >= 7616 && codePoint <= 7679 || codePoint >= 8400 && codePoint <= 8447 || codePoint >= 65056 && codePoint <= 65071) continue;
|
|
861
|
+
if (codePoint >= 55296 && codePoint <= 57343) continue;
|
|
862
|
+
if (codePoint >= 65024 && codePoint <= 65039) continue;
|
|
863
|
+
if (defaultIgnorableCodePointRegex.test(character)) continue;
|
|
864
|
+
if (emojiRegex().test(character)) {
|
|
865
|
+
width += 2;
|
|
866
|
+
continue;
|
|
867
|
+
}
|
|
868
|
+
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
869
|
+
}
|
|
870
|
+
return width;
|
|
975
871
|
}
|
|
976
872
|
function isUnicodeSupported() {
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
ready: "green",
|
|
989
|
-
start: "magenta"
|
|
873
|
+
const { env } = g$1;
|
|
874
|
+
const { TERM, TERM_PROGRAM } = env;
|
|
875
|
+
if (g$1.platform !== "win32") return TERM !== "linux";
|
|
876
|
+
return Boolean(env.WT_SESSION) || Boolean(env.TERMINUS_SUBLIME) || env.ConEmuTask === "{cmd::Cmder}" || TERM_PROGRAM === "Terminus-Sublime" || TERM_PROGRAM === "vscode" || TERM === "xterm-256color" || TERM === "alacritty" || TERM === "rxvt-unicode" || TERM === "rxvt-unicode-256color" || env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
877
|
+
}
|
|
878
|
+
const TYPE_COLOR_MAP = {
|
|
879
|
+
info: "cyan",
|
|
880
|
+
fail: "red",
|
|
881
|
+
success: "green",
|
|
882
|
+
ready: "green",
|
|
883
|
+
start: "magenta"
|
|
990
884
|
};
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
885
|
+
const LEVEL_COLOR_MAP = {
|
|
886
|
+
0: "red",
|
|
887
|
+
1: "yellow"
|
|
994
888
|
};
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
889
|
+
const unicode = isUnicodeSupported();
|
|
890
|
+
const s = (c, fallback) => unicode ? c : fallback;
|
|
891
|
+
const TYPE_ICONS = {
|
|
892
|
+
error: s("✖", "×"),
|
|
893
|
+
fatal: s("✖", "×"),
|
|
894
|
+
ready: s("✔", "√"),
|
|
895
|
+
warn: s("⚠", "‼"),
|
|
896
|
+
info: s("ℹ", "i"),
|
|
897
|
+
success: s("✔", "√"),
|
|
898
|
+
debug: s("⚙", "D"),
|
|
899
|
+
trace: s("→", "→"),
|
|
900
|
+
fail: s("✖", "×"),
|
|
901
|
+
start: s("◐", "o"),
|
|
902
|
+
log: ""
|
|
1009
903
|
};
|
|
1010
904
|
function stringWidth(str) {
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
return stripAnsi(str).length;
|
|
1014
|
-
}
|
|
1015
|
-
return stringWidth$1(str);
|
|
905
|
+
if (!(typeof Intl === "object") || !Intl.Segmenter) return stripAnsi$1(str).length;
|
|
906
|
+
return stringWidth$1(str);
|
|
1016
907
|
}
|
|
1017
908
|
var FancyReporter = class extends BasicReporter {
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
${indent}` + parseStack(stack, message).map(
|
|
1022
|
-
(line) => " " + line.replace(/^at +/, (m) => colors.gray(m)).replace(/\((.+)\)/, (_2, m) => `(${colors.cyan(m)})`)
|
|
1023
|
-
).join(`
|
|
909
|
+
formatStack(stack, message, opts) {
|
|
910
|
+
const indent = " ".repeat((opts?.errorLevel || 0) + 1);
|
|
911
|
+
return `
|
|
912
|
+
${indent}` + parseStack(stack, message).map((line) => " " + line.replace(/^at +/, (m) => colors.gray(m)).replace(/\((.+)\)/, (_, m) => `(${colors.cyan(m)})`)).join(`
|
|
1024
913
|
${indent}`);
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
const tag = logObj.tag ? colors.gray(logObj.tag) : "";
|
|
1056
|
-
let line;
|
|
1057
|
-
const left = this.filterAndJoin([type, characterFormat(message)]);
|
|
1058
|
-
const right = this.filterAndJoin(opts.columns ? [tag, coloredDate] : [tag]);
|
|
1059
|
-
const space = (opts.columns || 0) - stringWidth(left) - stringWidth(right) - 2;
|
|
1060
|
-
line = space > 0 && (opts.columns || 0) >= 80 ? left + " ".repeat(space) + right : (right ? `${colors.gray(`[${right}]`)} ` : "") + left;
|
|
1061
|
-
line += characterFormat(
|
|
1062
|
-
additional.length > 0 ? "\n" + additional.join("\n") : ""
|
|
1063
|
-
);
|
|
1064
|
-
if (logObj.type === "trace") {
|
|
1065
|
-
const _err = new Error("Trace: " + logObj.message);
|
|
1066
|
-
line += this.formatStack(_err.stack || "", _err.message);
|
|
1067
|
-
}
|
|
1068
|
-
return isBadge ? "\n" + line + "\n" : line;
|
|
1069
|
-
}
|
|
914
|
+
}
|
|
915
|
+
formatType(logObj, isBadge, opts) {
|
|
916
|
+
const typeColor = TYPE_COLOR_MAP[logObj.type] || LEVEL_COLOR_MAP[logObj.level] || "gray";
|
|
917
|
+
if (isBadge) return getBgColor(typeColor)(colors.black(` ${logObj.type.toUpperCase()} `));
|
|
918
|
+
const _type = typeof TYPE_ICONS[logObj.type] === "string" ? TYPE_ICONS[logObj.type] : logObj.icon || logObj.type;
|
|
919
|
+
return _type ? getColor(typeColor)(_type) : "";
|
|
920
|
+
}
|
|
921
|
+
formatLogObj(logObj, opts) {
|
|
922
|
+
const [message, ...additional] = this.formatArgs(logObj.args, opts).split("\n");
|
|
923
|
+
if (logObj.type === "box") return box(characterFormat(message + (additional.length > 0 ? "\n" + additional.join("\n") : "")), {
|
|
924
|
+
title: logObj.title ? characterFormat(logObj.title) : void 0,
|
|
925
|
+
style: logObj.style
|
|
926
|
+
});
|
|
927
|
+
const date = this.formatDate(logObj.date, opts);
|
|
928
|
+
const coloredDate = date && colors.gray(date);
|
|
929
|
+
const isBadge = logObj.badge ?? logObj.level < 2;
|
|
930
|
+
const type = this.formatType(logObj, isBadge, opts);
|
|
931
|
+
const tag = logObj.tag ? colors.gray(logObj.tag) : "";
|
|
932
|
+
let line;
|
|
933
|
+
const left = this.filterAndJoin([type, characterFormat(message)]);
|
|
934
|
+
const right = this.filterAndJoin(opts.columns ? [tag, coloredDate] : [tag]);
|
|
935
|
+
const space = (opts.columns || 0) - stringWidth(left) - stringWidth(right) - 2;
|
|
936
|
+
line = space > 0 && (opts.columns || 0) >= 80 ? left + " ".repeat(space) + right : (right ? `${colors.gray(`[${right}]`)} ` : "") + left;
|
|
937
|
+
line += characterFormat(additional.length > 0 ? "\n" + additional.join("\n") : "");
|
|
938
|
+
if (logObj.type === "trace") {
|
|
939
|
+
const _err = /* @__PURE__ */ new Error("Trace: " + logObj.message);
|
|
940
|
+
line += this.formatStack(_err.stack || "", _err.message);
|
|
941
|
+
}
|
|
942
|
+
return isBadge ? "\n" + line + "\n" : line;
|
|
943
|
+
}
|
|
1070
944
|
};
|
|
1071
945
|
function characterFormat(str) {
|
|
1072
|
-
|
|
946
|
+
return str.replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m)).replace(/\s+_([^_]+)_\s+/gm, (_, m) => ` ${colors.underline(m)} `);
|
|
1073
947
|
}
|
|
1074
|
-
function
|
|
1075
|
-
|
|
948
|
+
function getColor(color = "white") {
|
|
949
|
+
return colors[color] || colors.white;
|
|
1076
950
|
}
|
|
1077
951
|
function getBgColor(color = "bgWhite") {
|
|
1078
|
-
|
|
1079
|
-
}
|
|
1080
|
-
function
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
options.fancy ?? !(T || R) ? new FancyReporter() : new BasicReporter()
|
|
1093
|
-
],
|
|
1094
|
-
...options
|
|
1095
|
-
});
|
|
1096
|
-
return consola2;
|
|
952
|
+
return colors[`bg${color[0].toUpperCase()}${color.slice(1)}`] || colors.bgWhite;
|
|
953
|
+
}
|
|
954
|
+
function createConsola(options = {}) {
|
|
955
|
+
let level = _getDefaultLogLevel();
|
|
956
|
+
if (process.env.CONSOLA_LEVEL) level = Number.parseInt(process.env.CONSOLA_LEVEL) ?? level;
|
|
957
|
+
return createConsola$1({
|
|
958
|
+
level,
|
|
959
|
+
defaults: { level },
|
|
960
|
+
stdout: process.stdout,
|
|
961
|
+
stderr: process.stderr,
|
|
962
|
+
prompt: (...args) => import("./prompt-BU6Ge-7H.js").then((m) => m.prompt(...args)),
|
|
963
|
+
reporters: options.reporters || [options.fancy ?? !(T || R) ? new FancyReporter() : new BasicReporter()],
|
|
964
|
+
...options
|
|
965
|
+
});
|
|
1097
966
|
}
|
|
1098
967
|
function _getDefaultLogLevel() {
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
}
|
|
1107
|
-
var consola = createConsola2();
|
|
1108
|
-
|
|
1109
|
-
// ../../node_modules/.bun/consola@3.4.2/node_modules/consola/dist/utils.mjs
|
|
1110
|
-
import "tty";
|
|
1111
|
-
|
|
1112
|
-
// ../../node_modules/.bun/citty@0.1.6/node_modules/citty/dist/index.mjs
|
|
968
|
+
if (g) return LogLevels.debug;
|
|
969
|
+
if (R) return LogLevels.warn;
|
|
970
|
+
return LogLevels.info;
|
|
971
|
+
}
|
|
972
|
+
const consola = createConsola();
|
|
973
|
+
//#endregion
|
|
974
|
+
//#region ../../node_modules/.bun/citty@0.1.6/node_modules/citty/dist/index.mjs
|
|
1113
975
|
function toArray(val) {
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
}
|
|
1117
|
-
return val === void 0 ? [] : [val];
|
|
976
|
+
if (Array.isArray(val)) return val;
|
|
977
|
+
return val === void 0 ? [] : [val];
|
|
1118
978
|
}
|
|
1119
979
|
function formatLineColumns(lines, linePrefix = "") {
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
maxLengh[i2] = Math.max(maxLengh[i2] || 0, element.length);
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
return lines.map(
|
|
1127
|
-
(l2) => l2.map(
|
|
1128
|
-
(c2, i2) => linePrefix + c2[i2 === 0 ? "padStart" : "padEnd"](maxLengh[i2])
|
|
1129
|
-
).join(" ")
|
|
1130
|
-
).join("\n");
|
|
980
|
+
const maxLengh = [];
|
|
981
|
+
for (const line of lines) for (const [i, element] of line.entries()) maxLengh[i] = Math.max(maxLengh[i] || 0, element.length);
|
|
982
|
+
return lines.map((l) => l.map((c, i) => linePrefix + c[i === 0 ? "padStart" : "padEnd"](maxLengh[i])).join(" ")).join("\n");
|
|
1131
983
|
}
|
|
1132
984
|
function resolveValue(input) {
|
|
1133
|
-
|
|
985
|
+
return typeof input === "function" ? input() : input;
|
|
1134
986
|
}
|
|
1135
987
|
var CLIError = class extends Error {
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
988
|
+
constructor(message, code) {
|
|
989
|
+
super(message);
|
|
990
|
+
this.code = code;
|
|
991
|
+
this.name = "CLIError";
|
|
992
|
+
}
|
|
1141
993
|
};
|
|
1142
|
-
|
|
1143
|
-
|
|
994
|
+
const NUMBER_CHAR_RE = /\d/;
|
|
995
|
+
const STR_SPLITTERS = [
|
|
996
|
+
"-",
|
|
997
|
+
"_",
|
|
998
|
+
"/",
|
|
999
|
+
"."
|
|
1000
|
+
];
|
|
1144
1001
|
function isUppercase(char = "") {
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
}
|
|
1148
|
-
return char !== char.toLowerCase();
|
|
1002
|
+
if (NUMBER_CHAR_RE.test(char)) return;
|
|
1003
|
+
return char !== char.toLowerCase();
|
|
1149
1004
|
}
|
|
1150
1005
|
function splitByCase(str, separators) {
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
parts.push(buff);
|
|
1188
|
-
return parts;
|
|
1006
|
+
const splitters = separators ?? STR_SPLITTERS;
|
|
1007
|
+
const parts = [];
|
|
1008
|
+
if (!str || typeof str !== "string") return parts;
|
|
1009
|
+
let buff = "";
|
|
1010
|
+
let previousUpper;
|
|
1011
|
+
let previousSplitter;
|
|
1012
|
+
for (const char of str) {
|
|
1013
|
+
const isSplitter = splitters.includes(char);
|
|
1014
|
+
if (isSplitter === true) {
|
|
1015
|
+
parts.push(buff);
|
|
1016
|
+
buff = "";
|
|
1017
|
+
previousUpper = void 0;
|
|
1018
|
+
continue;
|
|
1019
|
+
}
|
|
1020
|
+
const isUpper = isUppercase(char);
|
|
1021
|
+
if (previousSplitter === false) {
|
|
1022
|
+
if (previousUpper === false && isUpper === true) {
|
|
1023
|
+
parts.push(buff);
|
|
1024
|
+
buff = char;
|
|
1025
|
+
previousUpper = isUpper;
|
|
1026
|
+
continue;
|
|
1027
|
+
}
|
|
1028
|
+
if (previousUpper === true && isUpper === false && buff.length > 1) {
|
|
1029
|
+
const lastChar = buff.at(-1);
|
|
1030
|
+
parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
|
|
1031
|
+
buff = lastChar + char;
|
|
1032
|
+
previousUpper = isUpper;
|
|
1033
|
+
continue;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
buff += char;
|
|
1037
|
+
previousUpper = isUpper;
|
|
1038
|
+
previousSplitter = isSplitter;
|
|
1039
|
+
}
|
|
1040
|
+
parts.push(buff);
|
|
1041
|
+
return parts;
|
|
1189
1042
|
}
|
|
1190
1043
|
function upperFirst(str) {
|
|
1191
|
-
|
|
1044
|
+
return str ? str[0].toUpperCase() + str.slice(1) : "";
|
|
1192
1045
|
}
|
|
1193
1046
|
function lowerFirst(str) {
|
|
1194
|
-
|
|
1047
|
+
return str ? str[0].toLowerCase() + str.slice(1) : "";
|
|
1195
1048
|
}
|
|
1196
1049
|
function pascalCase(str, opts) {
|
|
1197
|
-
|
|
1050
|
+
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
|
|
1198
1051
|
}
|
|
1199
1052
|
function camelCase(str, opts) {
|
|
1200
|
-
|
|
1053
|
+
return lowerFirst(pascalCase(str || "", opts));
|
|
1201
1054
|
}
|
|
1202
1055
|
function kebabCase(str, joiner) {
|
|
1203
|
-
|
|
1056
|
+
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
|
|
1204
1057
|
}
|
|
1205
1058
|
function toArr(any) {
|
|
1206
|
-
|
|
1059
|
+
return any == void 0 ? [] : Array.isArray(any) ? any : [any];
|
|
1207
1060
|
}
|
|
1208
1061
|
function toVal(out, key, val, opts) {
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1062
|
+
let x;
|
|
1063
|
+
const old = out[key];
|
|
1064
|
+
const nxt = ~opts.string.indexOf(key) ? val == void 0 || val === true ? "" : String(val) : typeof val === "boolean" ? val : ~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
|
|
1065
|
+
out[key] = old == void 0 ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
|
1213
1066
|
}
|
|
1214
1067
|
function parseRawArgs(args = [], opts = {}) {
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
for (idx = j + 1; idx < arg.length; idx++) {
|
|
1285
|
-
if (arg.charCodeAt(idx) === 61) {
|
|
1286
|
-
break;
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
name = arg.substring(j, idx);
|
|
1290
|
-
val = arg.slice(Math.max(0, ++idx)) || i2 + 1 === len || ("" + args[i2 + 1]).charCodeAt(0) === 45 || args[++i2];
|
|
1291
|
-
arr = j === 2 ? [name] : name;
|
|
1292
|
-
for (idx = 0; idx < arr.length; idx++) {
|
|
1293
|
-
name = arr[idx];
|
|
1294
|
-
if (strict && !~keys.indexOf(name)) {
|
|
1295
|
-
return opts.unknown("-".repeat(j) + name);
|
|
1296
|
-
}
|
|
1297
|
-
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
if (defaults) {
|
|
1302
|
-
for (k in opts.default) {
|
|
1303
|
-
if (out[k] === void 0) {
|
|
1304
|
-
out[k] = opts.default[k];
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
if (alibi) {
|
|
1309
|
-
for (k in out) {
|
|
1310
|
-
arr = opts.alias[k] || [];
|
|
1311
|
-
while (arr.length > 0) {
|
|
1312
|
-
out[arr.shift()] = out[k];
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
}
|
|
1316
|
-
return out;
|
|
1068
|
+
let k;
|
|
1069
|
+
let arr;
|
|
1070
|
+
let arg;
|
|
1071
|
+
let name;
|
|
1072
|
+
let val;
|
|
1073
|
+
const out = { _: [] };
|
|
1074
|
+
let i = 0;
|
|
1075
|
+
let j = 0;
|
|
1076
|
+
let idx = 0;
|
|
1077
|
+
const len = args.length;
|
|
1078
|
+
const alibi = opts.alias !== void 0;
|
|
1079
|
+
const strict = opts.unknown !== void 0;
|
|
1080
|
+
const defaults = opts.default !== void 0;
|
|
1081
|
+
opts.alias = opts.alias || {};
|
|
1082
|
+
opts.string = toArr(opts.string);
|
|
1083
|
+
opts.boolean = toArr(opts.boolean);
|
|
1084
|
+
if (alibi) for (k in opts.alias) {
|
|
1085
|
+
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
1086
|
+
for (i = 0; i < arr.length; i++) (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
1087
|
+
}
|
|
1088
|
+
for (i = opts.boolean.length; i-- > 0;) {
|
|
1089
|
+
arr = opts.alias[opts.boolean[i]] || [];
|
|
1090
|
+
for (j = arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
|
1091
|
+
}
|
|
1092
|
+
for (i = opts.string.length; i-- > 0;) {
|
|
1093
|
+
arr = opts.alias[opts.string[i]] || [];
|
|
1094
|
+
for (j = arr.length; j-- > 0;) opts.string.push(arr[j]);
|
|
1095
|
+
}
|
|
1096
|
+
if (defaults) for (k in opts.default) {
|
|
1097
|
+
name = typeof opts.default[k];
|
|
1098
|
+
arr = opts.alias[k] = opts.alias[k] || [];
|
|
1099
|
+
if (opts[name] !== void 0) {
|
|
1100
|
+
opts[name].push(k);
|
|
1101
|
+
for (i = 0; i < arr.length; i++) opts[name].push(arr[i]);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
const keys = strict ? Object.keys(opts.alias) : [];
|
|
1105
|
+
for (i = 0; i < len; i++) {
|
|
1106
|
+
arg = args[i];
|
|
1107
|
+
if (arg === "--") {
|
|
1108
|
+
out._ = out._.concat(args.slice(++i));
|
|
1109
|
+
break;
|
|
1110
|
+
}
|
|
1111
|
+
for (j = 0; j < arg.length; j++) if (arg.charCodeAt(j) !== 45) break;
|
|
1112
|
+
if (j === 0) out._.push(arg);
|
|
1113
|
+
else if (arg.substring(j, j + 3) === "no-") {
|
|
1114
|
+
name = arg.slice(Math.max(0, j + 3));
|
|
1115
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
|
|
1116
|
+
out[name] = false;
|
|
1117
|
+
} else {
|
|
1118
|
+
for (idx = j + 1; idx < arg.length; idx++) if (arg.charCodeAt(idx) === 61) break;
|
|
1119
|
+
name = arg.substring(j, idx);
|
|
1120
|
+
val = arg.slice(Math.max(0, ++idx)) || i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i];
|
|
1121
|
+
arr = j === 2 ? [name] : name;
|
|
1122
|
+
for (idx = 0; idx < arr.length; idx++) {
|
|
1123
|
+
name = arr[idx];
|
|
1124
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
|
|
1125
|
+
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
if (defaults) {
|
|
1130
|
+
for (k in opts.default) if (out[k] === void 0) out[k] = opts.default[k];
|
|
1131
|
+
}
|
|
1132
|
+
if (alibi) for (k in out) {
|
|
1133
|
+
arr = opts.alias[k] || [];
|
|
1134
|
+
while (arr.length > 0) out[arr.shift()] = out[k];
|
|
1135
|
+
}
|
|
1136
|
+
return out;
|
|
1317
1137
|
}
|
|
1318
1138
|
function parseArgs(rawArgs, argsDef) {
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
get(target, prop) {
|
|
1347
|
-
return target[prop] ?? target[camelCase(prop)] ?? target[kebabCase(prop)];
|
|
1348
|
-
}
|
|
1349
|
-
});
|
|
1350
|
-
for (const [, arg] of args.entries()) {
|
|
1351
|
-
if (arg.type === "positional") {
|
|
1352
|
-
const nextPositionalArgument = positionalArguments.shift();
|
|
1353
|
-
if (nextPositionalArgument !== void 0) {
|
|
1354
|
-
parsedArgsProxy[arg.name] = nextPositionalArgument;
|
|
1355
|
-
} else if (arg.default === void 0 && arg.required !== false) {
|
|
1356
|
-
throw new CLIError(
|
|
1357
|
-
`Missing required positional argument: ${arg.name.toUpperCase()}`,
|
|
1358
|
-
"EARG"
|
|
1359
|
-
);
|
|
1360
|
-
} else {
|
|
1361
|
-
parsedArgsProxy[arg.name] = arg.default;
|
|
1362
|
-
}
|
|
1363
|
-
} else if (arg.required && parsedArgsProxy[arg.name] === void 0) {
|
|
1364
|
-
throw new CLIError(`Missing required argument: --${arg.name}`, "EARG");
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
return parsedArgsProxy;
|
|
1139
|
+
const parseOptions = {
|
|
1140
|
+
boolean: [],
|
|
1141
|
+
string: [],
|
|
1142
|
+
mixed: [],
|
|
1143
|
+
alias: {},
|
|
1144
|
+
default: {}
|
|
1145
|
+
};
|
|
1146
|
+
const args = resolveArgs(argsDef);
|
|
1147
|
+
for (const arg of args) {
|
|
1148
|
+
if (arg.type === "positional") continue;
|
|
1149
|
+
if (arg.type === "string") parseOptions.string.push(arg.name);
|
|
1150
|
+
else if (arg.type === "boolean") parseOptions.boolean.push(arg.name);
|
|
1151
|
+
if (arg.default !== void 0) parseOptions.default[arg.name] = arg.default;
|
|
1152
|
+
if (arg.alias) parseOptions.alias[arg.name] = arg.alias;
|
|
1153
|
+
}
|
|
1154
|
+
const parsed = parseRawArgs(rawArgs, parseOptions);
|
|
1155
|
+
const [ ...positionalArguments] = parsed._;
|
|
1156
|
+
const parsedArgsProxy = new Proxy(parsed, { get(target, prop) {
|
|
1157
|
+
return target[prop] ?? target[camelCase(prop)] ?? target[kebabCase(prop)];
|
|
1158
|
+
} });
|
|
1159
|
+
for (const [, arg] of args.entries()) if (arg.type === "positional") {
|
|
1160
|
+
const nextPositionalArgument = positionalArguments.shift();
|
|
1161
|
+
if (nextPositionalArgument !== void 0) parsedArgsProxy[arg.name] = nextPositionalArgument;
|
|
1162
|
+
else if (arg.default === void 0 && arg.required !== false) throw new CLIError(`Missing required positional argument: ${arg.name.toUpperCase()}`, "EARG");
|
|
1163
|
+
else parsedArgsProxy[arg.name] = arg.default;
|
|
1164
|
+
} else if (arg.required && parsedArgsProxy[arg.name] === void 0) throw new CLIError(`Missing required argument: --${arg.name}`, "EARG");
|
|
1165
|
+
return parsedArgsProxy;
|
|
1368
1166
|
}
|
|
1369
1167
|
function resolveArgs(argsDef) {
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
}
|
|
1378
|
-
return args;
|
|
1168
|
+
const args = [];
|
|
1169
|
+
for (const [name, argDef] of Object.entries(argsDef || {})) args.push({
|
|
1170
|
+
...argDef,
|
|
1171
|
+
name,
|
|
1172
|
+
alias: toArray(argDef.alias)
|
|
1173
|
+
});
|
|
1174
|
+
return args;
|
|
1379
1175
|
}
|
|
1380
1176
|
function defineCommand(def) {
|
|
1381
|
-
|
|
1177
|
+
return def;
|
|
1382
1178
|
}
|
|
1383
1179
|
async function runCommand(cmd, opts) {
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
const subCommand = await resolveValue(subCommands[subCommandName]);
|
|
1411
|
-
if (subCommand) {
|
|
1412
|
-
await runCommand(subCommand, {
|
|
1413
|
-
rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1)
|
|
1414
|
-
});
|
|
1415
|
-
}
|
|
1416
|
-
} else if (!cmd.run) {
|
|
1417
|
-
throw new CLIError(`No command specified.`, "E_NO_COMMAND");
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
if (typeof cmd.run === "function") {
|
|
1421
|
-
result = await cmd.run(context);
|
|
1422
|
-
}
|
|
1423
|
-
} finally {
|
|
1424
|
-
if (typeof cmd.cleanup === "function") {
|
|
1425
|
-
await cmd.cleanup(context);
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
return { result };
|
|
1180
|
+
const cmdArgs = await resolveValue(cmd.args || {});
|
|
1181
|
+
const parsedArgs = parseArgs(opts.rawArgs, cmdArgs);
|
|
1182
|
+
const context = {
|
|
1183
|
+
rawArgs: opts.rawArgs,
|
|
1184
|
+
args: parsedArgs,
|
|
1185
|
+
data: opts.data,
|
|
1186
|
+
cmd
|
|
1187
|
+
};
|
|
1188
|
+
if (typeof cmd.setup === "function") await cmd.setup(context);
|
|
1189
|
+
let result;
|
|
1190
|
+
try {
|
|
1191
|
+
const subCommands = await resolveValue(cmd.subCommands);
|
|
1192
|
+
if (subCommands && Object.keys(subCommands).length > 0) {
|
|
1193
|
+
const subCommandArgIndex = opts.rawArgs.findIndex((arg) => !arg.startsWith("-"));
|
|
1194
|
+
const subCommandName = opts.rawArgs[subCommandArgIndex];
|
|
1195
|
+
if (subCommandName) {
|
|
1196
|
+
if (!subCommands[subCommandName]) throw new CLIError(`Unknown command \`${subCommandName}\``, "E_UNKNOWN_COMMAND");
|
|
1197
|
+
const subCommand = await resolveValue(subCommands[subCommandName]);
|
|
1198
|
+
if (subCommand) await runCommand(subCommand, { rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1) });
|
|
1199
|
+
} else if (!cmd.run) throw new CLIError(`No command specified.`, "E_NO_COMMAND");
|
|
1200
|
+
}
|
|
1201
|
+
if (typeof cmd.run === "function") result = await cmd.run(context);
|
|
1202
|
+
} finally {
|
|
1203
|
+
if (typeof cmd.cleanup === "function") await cmd.cleanup(context);
|
|
1204
|
+
}
|
|
1205
|
+
return { result };
|
|
1429
1206
|
}
|
|
1430
1207
|
async function resolveSubCommand(cmd, rawArgs, parent) {
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
rawArgs.slice(subCommandArgIndex + 1),
|
|
1440
|
-
cmd
|
|
1441
|
-
);
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
return [cmd, parent];
|
|
1208
|
+
const subCommands = await resolveValue(cmd.subCommands);
|
|
1209
|
+
if (subCommands && Object.keys(subCommands).length > 0) {
|
|
1210
|
+
const subCommandArgIndex = rawArgs.findIndex((arg) => !arg.startsWith("-"));
|
|
1211
|
+
const subCommandName = rawArgs[subCommandArgIndex];
|
|
1212
|
+
const subCommand = await resolveValue(subCommands[subCommandName]);
|
|
1213
|
+
if (subCommand) return resolveSubCommand(subCommand, rawArgs.slice(subCommandArgIndex + 1), cmd);
|
|
1214
|
+
}
|
|
1215
|
+
return [cmd, parent];
|
|
1445
1216
|
}
|
|
1446
1217
|
async function showUsage(cmd, parent) {
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1218
|
+
try {
|
|
1219
|
+
consola.log(await renderUsage(cmd, parent) + "\n");
|
|
1220
|
+
} catch (error) {
|
|
1221
|
+
consola.error(error);
|
|
1222
|
+
}
|
|
1452
1223
|
}
|
|
1453
1224
|
async function renderUsage(cmd, parent) {
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
const hasOptions = argLines.length > 0 || posLines.length > 0;
|
|
1510
|
-
usageLines.push(
|
|
1511
|
-
`${colors.underline(colors.bold("USAGE"))} \`${commandName}${hasOptions ? " [OPTIONS]" : ""} ${usageLine.join(" ")}\``,
|
|
1512
|
-
""
|
|
1513
|
-
);
|
|
1514
|
-
if (posLines.length > 0) {
|
|
1515
|
-
usageLines.push(colors.underline(colors.bold("ARGUMENTS")), "");
|
|
1516
|
-
usageLines.push(formatLineColumns(posLines, " "));
|
|
1517
|
-
usageLines.push("");
|
|
1518
|
-
}
|
|
1519
|
-
if (argLines.length > 0) {
|
|
1520
|
-
usageLines.push(colors.underline(colors.bold("OPTIONS")), "");
|
|
1521
|
-
usageLines.push(formatLineColumns(argLines, " "));
|
|
1522
|
-
usageLines.push("");
|
|
1523
|
-
}
|
|
1524
|
-
if (commandsLines.length > 0) {
|
|
1525
|
-
usageLines.push(colors.underline(colors.bold("COMMANDS")), "");
|
|
1526
|
-
usageLines.push(formatLineColumns(commandsLines, " "));
|
|
1527
|
-
usageLines.push(
|
|
1528
|
-
"",
|
|
1529
|
-
`Use \`${commandName} <command> --help\` for more information about a command.`
|
|
1530
|
-
);
|
|
1531
|
-
}
|
|
1532
|
-
return usageLines.filter((l2) => typeof l2 === "string").join("\n");
|
|
1225
|
+
const cmdMeta = await resolveValue(cmd.meta || {});
|
|
1226
|
+
const cmdArgs = resolveArgs(await resolveValue(cmd.args || {}));
|
|
1227
|
+
const parentMeta = await resolveValue(parent?.meta || {});
|
|
1228
|
+
const commandName = `${parentMeta.name ? `${parentMeta.name} ` : ""}` + (cmdMeta.name || process.argv[1]);
|
|
1229
|
+
const argLines = [];
|
|
1230
|
+
const posLines = [];
|
|
1231
|
+
const commandsLines = [];
|
|
1232
|
+
const usageLine = [];
|
|
1233
|
+
for (const arg of cmdArgs) if (arg.type === "positional") {
|
|
1234
|
+
const name = arg.name.toUpperCase();
|
|
1235
|
+
const isRequired = arg.required !== false && arg.default === void 0;
|
|
1236
|
+
const defaultHint = arg.default ? `="${arg.default}"` : "";
|
|
1237
|
+
posLines.push([
|
|
1238
|
+
"`" + name + defaultHint + "`",
|
|
1239
|
+
arg.description || "",
|
|
1240
|
+
arg.valueHint ? `<${arg.valueHint}>` : ""
|
|
1241
|
+
]);
|
|
1242
|
+
usageLine.push(isRequired ? `<${name}>` : `[${name}]`);
|
|
1243
|
+
} else {
|
|
1244
|
+
const isRequired = arg.required === true && arg.default === void 0;
|
|
1245
|
+
const argStr = (arg.type === "boolean" && arg.default === true ? [...(arg.alias || []).map((a) => `--no-${a}`), `--no-${arg.name}`].join(", ") : [...(arg.alias || []).map((a) => `-${a}`), `--${arg.name}`].join(", ")) + (arg.type === "string" && (arg.valueHint || arg.default) ? `=${arg.valueHint ? `<${arg.valueHint}>` : `"${arg.default || ""}"`}` : "");
|
|
1246
|
+
argLines.push(["`" + argStr + (isRequired ? " (required)" : "") + "`", arg.description || ""]);
|
|
1247
|
+
if (isRequired) usageLine.push(argStr);
|
|
1248
|
+
}
|
|
1249
|
+
if (cmd.subCommands) {
|
|
1250
|
+
const commandNames = [];
|
|
1251
|
+
const subCommands = await resolveValue(cmd.subCommands);
|
|
1252
|
+
for (const [name, sub] of Object.entries(subCommands)) {
|
|
1253
|
+
const meta = await resolveValue((await resolveValue(sub))?.meta);
|
|
1254
|
+
commandsLines.push([`\`${name}\``, meta?.description || ""]);
|
|
1255
|
+
commandNames.push(name);
|
|
1256
|
+
}
|
|
1257
|
+
usageLine.push(commandNames.join("|"));
|
|
1258
|
+
}
|
|
1259
|
+
const usageLines = [];
|
|
1260
|
+
const version = cmdMeta.version || parentMeta.version;
|
|
1261
|
+
usageLines.push(colors.gray(`${cmdMeta.description} (${commandName + (version ? ` v${version}` : "")})`), "");
|
|
1262
|
+
const hasOptions = argLines.length > 0 || posLines.length > 0;
|
|
1263
|
+
usageLines.push(`${colors.underline(colors.bold("USAGE"))} \`${commandName}${hasOptions ? " [OPTIONS]" : ""} ${usageLine.join(" ")}\``, "");
|
|
1264
|
+
if (posLines.length > 0) {
|
|
1265
|
+
usageLines.push(colors.underline(colors.bold("ARGUMENTS")), "");
|
|
1266
|
+
usageLines.push(formatLineColumns(posLines, " "));
|
|
1267
|
+
usageLines.push("");
|
|
1268
|
+
}
|
|
1269
|
+
if (argLines.length > 0) {
|
|
1270
|
+
usageLines.push(colors.underline(colors.bold("OPTIONS")), "");
|
|
1271
|
+
usageLines.push(formatLineColumns(argLines, " "));
|
|
1272
|
+
usageLines.push("");
|
|
1273
|
+
}
|
|
1274
|
+
if (commandsLines.length > 0) {
|
|
1275
|
+
usageLines.push(colors.underline(colors.bold("COMMANDS")), "");
|
|
1276
|
+
usageLines.push(formatLineColumns(commandsLines, " "));
|
|
1277
|
+
usageLines.push("", `Use \`${commandName} <command> --help\` for more information about a command.`);
|
|
1278
|
+
}
|
|
1279
|
+
return usageLines.filter((l) => typeof l === "string").join("\n");
|
|
1533
1280
|
}
|
|
1534
1281
|
async function runMain(cmd, opts = {}) {
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
|
|
1557
|
-
}
|
|
1558
|
-
consola.error(error.message);
|
|
1559
|
-
process.exit(1);
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
// src/blueprints.ts
|
|
1564
|
-
import { randomBytes } from "crypto";
|
|
1565
|
-
import { cp, readdir as readdir2, readFile, rename, rm, writeFile } from "fs/promises";
|
|
1566
|
-
import { basename, dirname, join, relative } from "path";
|
|
1567
|
-
import process2 from "process";
|
|
1568
|
-
import { fileURLToPath } from "url";
|
|
1569
|
-
|
|
1570
|
-
// src/utils.ts
|
|
1571
|
-
import { readdir, stat } from "fs/promises";
|
|
1282
|
+
const rawArgs = opts.rawArgs || process.argv.slice(2);
|
|
1283
|
+
const showUsage$1 = opts.showUsage || showUsage;
|
|
1284
|
+
try {
|
|
1285
|
+
if (rawArgs.includes("--help") || rawArgs.includes("-h")) {
|
|
1286
|
+
await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
|
|
1287
|
+
process.exit(0);
|
|
1288
|
+
} else if (rawArgs.length === 1 && rawArgs[0] === "--version") {
|
|
1289
|
+
const meta = typeof cmd.meta === "function" ? await cmd.meta() : await cmd.meta;
|
|
1290
|
+
if (!meta?.version) throw new CLIError("No version specified", "E_NO_VERSION");
|
|
1291
|
+
consola.log(meta.version);
|
|
1292
|
+
} else await runCommand(cmd, { rawArgs });
|
|
1293
|
+
} catch (error) {
|
|
1294
|
+
const isCLIError = error instanceof CLIError;
|
|
1295
|
+
if (!isCLIError) consola.error(error, "\n");
|
|
1296
|
+
if (isCLIError) await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
|
|
1297
|
+
consola.error(error.message);
|
|
1298
|
+
process.exit(1);
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
//#endregion
|
|
1302
|
+
//#region src/utils.ts
|
|
1572
1303
|
async function directoryExists(path) {
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
}
|
|
1580
|
-
throw error;
|
|
1581
|
-
}
|
|
1304
|
+
try {
|
|
1305
|
+
return (await stat(path)).isDirectory();
|
|
1306
|
+
} catch (error) {
|
|
1307
|
+
if (error.code === "ENOENT") return false;
|
|
1308
|
+
throw error;
|
|
1309
|
+
}
|
|
1582
1310
|
}
|
|
1583
1311
|
async function fileExists(path) {
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
}
|
|
1591
|
-
throw error;
|
|
1592
|
-
}
|
|
1312
|
+
try {
|
|
1313
|
+
return (await stat(path)).isFile();
|
|
1314
|
+
} catch (error) {
|
|
1315
|
+
if (error.code === "ENOENT") return false;
|
|
1316
|
+
throw error;
|
|
1317
|
+
}
|
|
1593
1318
|
}
|
|
1594
1319
|
async function isDirectoryEmpty(path) {
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
}
|
|
1602
|
-
throw error;
|
|
1603
|
-
}
|
|
1320
|
+
try {
|
|
1321
|
+
return (await readdir(path)).length === 0;
|
|
1322
|
+
} catch (error) {
|
|
1323
|
+
if (error.code === "ENOENT") return true;
|
|
1324
|
+
throw error;
|
|
1325
|
+
}
|
|
1604
1326
|
}
|
|
1605
1327
|
function toKebabCase(value) {
|
|
1606
|
-
|
|
1328
|
+
return value.replace(/([a-z0-9])([A-Z])/gu, "$1-$2").replace(/[^a-zA-Z0-9]+/gu, "-").toLowerCase().replace(/^-+|-+$/gu, "");
|
|
1607
1329
|
}
|
|
1608
1330
|
function toTitleCase(value) {
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
}
|
|
1613
|
-
return words.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
1331
|
+
const words = value.replace(/[-_]+/gu, " ").split(/\s+/u).filter(Boolean);
|
|
1332
|
+
if (words.length === 0) return "Guren App";
|
|
1333
|
+
return words.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
1614
1334
|
}
|
|
1615
1335
|
function toPackageName(value) {
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1336
|
+
const trimmed = value.trim();
|
|
1337
|
+
if (trimmed.startsWith("@")) {
|
|
1338
|
+
const [scope, name = "guren-app"] = trimmed.slice(1).split("/", 2);
|
|
1339
|
+
const safeScope = toKebabCase(scope);
|
|
1340
|
+
const safeName = toKebabCase(name);
|
|
1341
|
+
return `@${safeScope || "guren"}/${safeName || "app"}`;
|
|
1342
|
+
}
|
|
1343
|
+
return toKebabCase(trimmed) || "guren-app";
|
|
1344
|
+
}
|
|
1345
|
+
//#endregion
|
|
1346
|
+
//#region src/blueprints.ts
|
|
1347
|
+
const APP_BLUEPRINTS = [
|
|
1348
|
+
"default",
|
|
1349
|
+
"api",
|
|
1350
|
+
"blog",
|
|
1351
|
+
"worker"
|
|
1352
|
+
];
|
|
1353
|
+
const DATABASE_DRIVERS = [
|
|
1354
|
+
"sqlite",
|
|
1355
|
+
"postgres",
|
|
1356
|
+
"mysql"
|
|
1357
|
+
];
|
|
1358
|
+
/**
|
|
1359
|
+
* The directory holding every template a blueprint can copy from. It is the
|
|
1360
|
+
* only source tree in this package's `files` field, so a layer resolved outside
|
|
1361
|
+
* it scaffolds fine from the monorepo and ENOENTs from an npm install: that is
|
|
1362
|
+
* how the `blog` blueprint shipped broken for releases, overlaying
|
|
1363
|
+
* `examples/blog`, which no tarball contains.
|
|
1364
|
+
*
|
|
1365
|
+
* Layers are therefore named, not pathed — `TemplateName` makes a layer outside
|
|
1366
|
+
* this directory unrepresentable rather than merely asserted against.
|
|
1367
|
+
*/
|
|
1368
|
+
const TEMPLATES_ROOT = fileURLToPath(new URL("../templates", import.meta.url));
|
|
1632
1369
|
function templateDir(name) {
|
|
1633
|
-
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1370
|
+
return join(TEMPLATES_ROOT, name);
|
|
1371
|
+
}
|
|
1372
|
+
const DEFAULT_TRANSFORM_FILES = [
|
|
1373
|
+
"README.md",
|
|
1374
|
+
"package.json",
|
|
1375
|
+
"public/index.html",
|
|
1376
|
+
"bin/serve.ts",
|
|
1377
|
+
"app/Http/Controllers/HomeController.ts",
|
|
1378
|
+
"resources/js/pages/Home.tsx"
|
|
1642
1379
|
];
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1380
|
+
const API_TRANSFORM_FILES = [
|
|
1381
|
+
"README.md",
|
|
1382
|
+
"package.json",
|
|
1383
|
+
"bin/serve.ts"
|
|
1647
1384
|
];
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1385
|
+
const BLOG_TRANSFORM_FILES = [
|
|
1386
|
+
...DEFAULT_TRANSFORM_FILES,
|
|
1387
|
+
"resources/js/components/Layout.tsx",
|
|
1388
|
+
"db/seeders/001_users.ts"
|
|
1652
1389
|
];
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
await runBlueprint("events", { force: true });
|
|
1705
|
-
await runBlueprint("cache", { force: true });
|
|
1706
|
-
await runBlueprint("schedule", { force: true });
|
|
1707
|
-
} finally {
|
|
1708
|
-
process2.chdir(originalCwd);
|
|
1709
|
-
}
|
|
1710
|
-
}
|
|
1711
|
-
}
|
|
1390
|
+
const blueprintRegistry = {
|
|
1391
|
+
default: {
|
|
1392
|
+
name: "default",
|
|
1393
|
+
description: "The standard Guren starter blueprint.",
|
|
1394
|
+
baseTemplate: "default",
|
|
1395
|
+
overlayTemplates: { ssr: ["default-ssr"] },
|
|
1396
|
+
transformFiles: DEFAULT_TRANSFORM_FILES
|
|
1397
|
+
},
|
|
1398
|
+
api: {
|
|
1399
|
+
name: "api",
|
|
1400
|
+
description: "API-only starter — no Inertia, no React, no frontend assets.",
|
|
1401
|
+
baseTemplate: "api-only",
|
|
1402
|
+
overlayTemplates: {},
|
|
1403
|
+
transformFiles: API_TRANSFORM_FILES
|
|
1404
|
+
},
|
|
1405
|
+
blog: {
|
|
1406
|
+
name: "blog",
|
|
1407
|
+
description: "Blog starter — posts CRUD, session auth, and a seeded demo account.",
|
|
1408
|
+
baseTemplate: "default",
|
|
1409
|
+
overlayTemplates: {
|
|
1410
|
+
spa: ["blog"],
|
|
1411
|
+
ssr: ["default-ssr", "blog"]
|
|
1412
|
+
},
|
|
1413
|
+
transformFiles: BLOG_TRANSFORM_FILES,
|
|
1414
|
+
includesAuth: true
|
|
1415
|
+
},
|
|
1416
|
+
worker: {
|
|
1417
|
+
name: "worker",
|
|
1418
|
+
description: "Full-stack app pre-configured with queue, events, cache, and scheduling",
|
|
1419
|
+
baseTemplate: "default",
|
|
1420
|
+
overlayTemplates: { ssr: ["default-ssr"] },
|
|
1421
|
+
transformFiles: DEFAULT_TRANSFORM_FILES,
|
|
1422
|
+
postScaffold: async ({ destination }) => {
|
|
1423
|
+
let runBlueprint;
|
|
1424
|
+
try {
|
|
1425
|
+
({runBlueprint} = await import("@guren/cli"));
|
|
1426
|
+
} catch {
|
|
1427
|
+
return;
|
|
1428
|
+
}
|
|
1429
|
+
const originalCwd = g$1.cwd();
|
|
1430
|
+
try {
|
|
1431
|
+
g$1.chdir(destination);
|
|
1432
|
+
await runBlueprint("queue", { force: true });
|
|
1433
|
+
await runBlueprint("events", { force: true });
|
|
1434
|
+
await runBlueprint("cache", { force: true });
|
|
1435
|
+
await runBlueprint("schedule", { force: true });
|
|
1436
|
+
} finally {
|
|
1437
|
+
g$1.chdir(originalCwd);
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1712
1441
|
};
|
|
1713
1442
|
function replaceTokens(content, tokens) {
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
}
|
|
1718
|
-
return updated;
|
|
1443
|
+
let updated = content;
|
|
1444
|
+
for (const [token, replacement] of tokens) updated = updated.split(token).join(replacement);
|
|
1445
|
+
return updated;
|
|
1719
1446
|
}
|
|
1720
|
-
|
|
1447
|
+
const TEMPLATE_DOTFILES = /* @__PURE__ */ new Map([["_gitignore", ".gitignore"]]);
|
|
1721
1448
|
async function copyLayer(layer, destination) {
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
await rename(join(destination, path), join(destination, dirname(path), dotted));
|
|
1737
|
-
}
|
|
1449
|
+
const dotfiles = /* @__PURE__ */ new Set();
|
|
1450
|
+
const source = templateDir(layer);
|
|
1451
|
+
await cp(source, destination, {
|
|
1452
|
+
recursive: true,
|
|
1453
|
+
force: true,
|
|
1454
|
+
filter: (sourcePath) => {
|
|
1455
|
+
if (TEMPLATE_DOTFILES.has(basename(sourcePath))) dotfiles.add(relative(source, sourcePath));
|
|
1456
|
+
return true;
|
|
1457
|
+
}
|
|
1458
|
+
});
|
|
1459
|
+
for (const path of dotfiles) {
|
|
1460
|
+
const dotted = TEMPLATE_DOTFILES.get(basename(path));
|
|
1461
|
+
await rename(join(destination, path), join(destination, dirname(path), dotted));
|
|
1462
|
+
}
|
|
1738
1463
|
}
|
|
1739
1464
|
async function applyTokenTransforms(destination, files, tokens) {
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1465
|
+
for (const file of files) {
|
|
1466
|
+
const path = join(destination, file);
|
|
1467
|
+
const content = await readFile(path, "utf8");
|
|
1468
|
+
const updated = replaceTokens(content, tokens);
|
|
1469
|
+
if (updated !== content) await writeFile(path, updated, "utf8");
|
|
1470
|
+
}
|
|
1748
1471
|
}
|
|
1749
1472
|
async function scaffoldEnvFiles(destination) {
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1473
|
+
const envExamplePath = join(destination, ".env.example");
|
|
1474
|
+
const envPath = join(destination, ".env");
|
|
1475
|
+
let envExample;
|
|
1476
|
+
try {
|
|
1477
|
+
envExample = await readFile(envExamplePath, "utf8");
|
|
1478
|
+
} catch {
|
|
1479
|
+
return;
|
|
1480
|
+
}
|
|
1481
|
+
const appKey = `base64:${randomBytes(32).toString("base64")}`;
|
|
1482
|
+
const envContent = envExample.replace(/^APP_KEY=.*$/mu, `APP_KEY=${appKey}`);
|
|
1483
|
+
await writeFile(envPath, envContent.endsWith("\n") ? envContent : `${envContent}\n`, "utf8");
|
|
1484
|
+
}
|
|
1485
|
+
const DATABASE_DEFAULTS = {
|
|
1486
|
+
postgres: {
|
|
1487
|
+
url: "postgres://guren:guren@localhost:54322/guren",
|
|
1488
|
+
dialect: "postgresql",
|
|
1489
|
+
dep: { postgres: "^3.4.3" }
|
|
1490
|
+
},
|
|
1491
|
+
mysql: {
|
|
1492
|
+
url: "mysql://guren:guren@localhost:33306/guren",
|
|
1493
|
+
dialect: "mysql",
|
|
1494
|
+
dep: { mysql2: "^3.11.3" }
|
|
1495
|
+
},
|
|
1496
|
+
sqlite: {
|
|
1497
|
+
url: "./data/guren.db",
|
|
1498
|
+
dialect: "sqlite",
|
|
1499
|
+
dep: null
|
|
1500
|
+
}
|
|
1767
1501
|
};
|
|
1502
|
+
/**
|
|
1503
|
+
* `config/database.ts` ships as one real source file per driver, copied
|
|
1504
|
+
* verbatim — no tokens, and `templates/database` is not a `TemplateName`
|
|
1505
|
+
* layer, so only the selected driver's file reaches the app. The full
|
|
1506
|
+
* rationale lives in this package's CLAUDE.md;
|
|
1507
|
+
* `tests/database-config-template.test.ts` pins the files to this path and to
|
|
1508
|
+
* the `DATABASE_DEFAULTS` constants they hardcode.
|
|
1509
|
+
*/
|
|
1768
1510
|
function databaseConfigTemplatePath(driver) {
|
|
1769
|
-
|
|
1511
|
+
return join(TEMPLATES_ROOT, "database", driver, "config/database.ts");
|
|
1770
1512
|
}
|
|
1771
1513
|
async function loadDatabaseConfig(driver) {
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
{ cause }
|
|
1778
|
-
);
|
|
1779
|
-
}
|
|
1514
|
+
try {
|
|
1515
|
+
return await readFile(databaseConfigTemplatePath(driver), "utf8");
|
|
1516
|
+
} catch (cause) {
|
|
1517
|
+
throw new Error(`Could not read the ${driver} database config template at "${databaseConfigTemplatePath(driver)}". This build of create-guren-app may be incomplete — please report it at https://github.com/gurenjs/guren/issues and try \`npm create guren-app@latest\` meanwhile.`, { cause });
|
|
1518
|
+
}
|
|
1780
1519
|
}
|
|
1781
1520
|
function generateSchema(driver) {
|
|
1782
|
-
|
|
1783
|
-
return `import { pgTable, serial, text, timestamp } from '@guren/orm/drizzle/pg'
|
|
1521
|
+
if (driver === "postgres") return `import { pgTable, serial, text, timestamp } from '@guren/orm/drizzle/pg'
|
|
1784
1522
|
|
|
1785
1523
|
export const users = pgTable('users', {
|
|
1786
1524
|
id: serial('id').primaryKey(),
|
|
@@ -1789,9 +1527,7 @@ export const users = pgTable('users', {
|
|
|
1789
1527
|
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
|
1790
1528
|
})
|
|
1791
1529
|
`;
|
|
1792
|
-
|
|
1793
|
-
if (driver === "mysql") {
|
|
1794
|
-
return `import { mysqlTable, int, varchar, timestamp } from '@guren/orm/drizzle/mysql'
|
|
1530
|
+
if (driver === "mysql") return `import { mysqlTable, int, varchar, timestamp } from '@guren/orm/drizzle/mysql'
|
|
1795
1531
|
|
|
1796
1532
|
export const users = mysqlTable('users', {
|
|
1797
1533
|
id: int('id').primaryKey().autoincrement(),
|
|
@@ -1800,8 +1536,7 @@ export const users = mysqlTable('users', {
|
|
|
1800
1536
|
createdAt: timestamp('created_at').notNull().defaultNow(),
|
|
1801
1537
|
})
|
|
1802
1538
|
`;
|
|
1803
|
-
|
|
1804
|
-
return `import { sqliteTable, integer, text } from '@guren/orm/drizzle/sqlite'
|
|
1539
|
+
return `import { sqliteTable, integer, text } from '@guren/orm/drizzle/sqlite'
|
|
1805
1540
|
|
|
1806
1541
|
export const users = sqliteTable('users', {
|
|
1807
1542
|
id: integer('id').primaryKey({ autoIncrement: true }),
|
|
@@ -1811,33 +1546,41 @@ export const users = sqliteTable('users', {
|
|
|
1811
1546
|
})
|
|
1812
1547
|
`;
|
|
1813
1548
|
}
|
|
1549
|
+
/**
|
|
1550
|
+
* Templates whose app code needs more than the single `users` table above ship
|
|
1551
|
+
* their own schema, one file per driver, as `db/schema.<driver>.ts`. The variant
|
|
1552
|
+
* for the selected driver becomes `db/schema.ts` and the rest are deleted.
|
|
1553
|
+
*
|
|
1554
|
+
* The indirection exists because `applyDatabaseConfig` has to overwrite
|
|
1555
|
+
* `db/schema.ts` — a template carrying a plain `db/schema.ts` written for one
|
|
1556
|
+
* driver would otherwise be handed to users who picked another. The blueprint
|
|
1557
|
+
* this replaced worked around that by regenerating its schema from a copy kept
|
|
1558
|
+
* in this file, which then drifted from the columns its own controllers read.
|
|
1559
|
+
*
|
|
1560
|
+
* A template that ships some variants but not the selected one is a packaging
|
|
1561
|
+
* bug, not a reason to fall back to the generic schema: the fallback would
|
|
1562
|
+
* scaffold an app whose models reference tables that do not exist.
|
|
1563
|
+
*/
|
|
1814
1564
|
function schemaVariantPath(destination, driver) {
|
|
1815
|
-
|
|
1565
|
+
return join(destination, `db/schema.${driver}.ts`);
|
|
1816
1566
|
}
|
|
1817
1567
|
async function resolveSchema(destination, driver) {
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
return generateSchema(driver);
|
|
1823
|
-
}
|
|
1824
|
-
if (!shipped.includes(driver)) {
|
|
1825
|
-
throw new Error(
|
|
1826
|
-
`This template ships a database schema for ${shipped.join(", ")} but not for ${driver}. This build of create-guren-app is incomplete \u2014 please report it at https://github.com/gurenjs/guren/issues.`
|
|
1827
|
-
);
|
|
1828
|
-
}
|
|
1829
|
-
return readFile(schemaVariantPath(destination, driver), "utf8");
|
|
1568
|
+
const shipped = (await Promise.all(DATABASE_DRIVERS.map(async (name) => await fileExists(schemaVariantPath(destination, name)) ? name : null))).filter((name) => name !== null);
|
|
1569
|
+
if (shipped.length === 0) return generateSchema(driver);
|
|
1570
|
+
if (!shipped.includes(driver)) throw new Error(`This template ships a database schema for ${shipped.join(", ")} but not for ${driver}. This build of create-guren-app is incomplete — please report it at https://github.com/gurenjs/guren/issues.`);
|
|
1571
|
+
return readFile(schemaVariantPath(destination, driver), "utf8");
|
|
1830
1572
|
}
|
|
1831
1573
|
function generateDrizzleConfig(driver) {
|
|
1832
|
-
|
|
1833
|
-
|
|
1574
|
+
const { url, dialect } = DATABASE_DEFAULTS[driver];
|
|
1575
|
+
return `import { defineConfig } from 'drizzle-kit'
|
|
1576
|
+
${driver !== "sqlite" ? "" : `
|
|
1834
1577
|
const filename = process.env.DATABASE_URL ?? '${url}'
|
|
1835
1578
|
|
|
1836
1579
|
/**
|
|
1837
1580
|
* DATABASE_URL is read by two different SQLite implementations that disagree
|
|
1838
1581
|
* about URI filenames: the app opens it with \`bun:sqlite\`, which honours them,
|
|
1839
1582
|
* while drizzle-kit opens it with \`node:sqlite\`, which does not. So \`file:\` is
|
|
1840
|
-
* not a shared spelling of anything
|
|
1583
|
+
* not a shared spelling of anything — \`file:local.db\` migrates the app into
|
|
1841
1584
|
* \`local.db\` and drizzle-kit into a file *named* \`file:local.db\`. The safe set
|
|
1842
1585
|
* is what both agree on: plain paths, and \`:memory:\`.
|
|
1843
1586
|
*
|
|
@@ -1852,26 +1595,27 @@ if (uriScheme) {
|
|
|
1852
1595
|
'Point it at a file such as ${url}, or use ":memory:".',
|
|
1853
1596
|
)
|
|
1854
1597
|
}
|
|
1855
|
-
|
|
1856
|
-
const credentialUrl = driver === "sqlite" ? "filename" : `process.env.DATABASE_URL ?? '${url}'`;
|
|
1857
|
-
return `import { defineConfig } from 'drizzle-kit'
|
|
1858
|
-
${preamble}
|
|
1598
|
+
`}
|
|
1859
1599
|
export default defineConfig({
|
|
1860
1600
|
schema: './db/schema.ts',
|
|
1861
1601
|
out: './db/migrations',
|
|
1862
1602
|
dialect: '${dialect}',
|
|
1863
1603
|
dbCredentials: {
|
|
1864
|
-
url: ${
|
|
1604
|
+
url: ${driver === "sqlite" ? "filename" : `process.env.DATABASE_URL ?? '${url}'`},
|
|
1865
1605
|
},
|
|
1866
1606
|
})
|
|
1867
1607
|
`;
|
|
1868
1608
|
}
|
|
1609
|
+
/**
|
|
1610
|
+
* True when the driver runs in a container the scaffolder provisions — the one
|
|
1611
|
+
* fact that decides docker-compose.yml, the db:up/db:down scripts, and whether
|
|
1612
|
+
* the next-steps output mentions starting a database.
|
|
1613
|
+
*/
|
|
1869
1614
|
function usesDatabaseContainer(driver) {
|
|
1870
|
-
|
|
1615
|
+
return generateDockerCompose(driver) !== null;
|
|
1871
1616
|
}
|
|
1872
1617
|
function generateDockerCompose(driver) {
|
|
1873
|
-
|
|
1874
|
-
return `services:
|
|
1618
|
+
if (driver === "postgres") return `services:
|
|
1875
1619
|
postgres:
|
|
1876
1620
|
image: postgres:17-alpine
|
|
1877
1621
|
ports:
|
|
@@ -1886,9 +1630,7 @@ function generateDockerCompose(driver) {
|
|
|
1886
1630
|
volumes:
|
|
1887
1631
|
postgres_data:
|
|
1888
1632
|
`;
|
|
1889
|
-
|
|
1890
|
-
if (driver === "mysql") {
|
|
1891
|
-
return `services:
|
|
1633
|
+
if (driver === "mysql") return `services:
|
|
1892
1634
|
mysql:
|
|
1893
1635
|
image: mysql:8.4
|
|
1894
1636
|
ports:
|
|
@@ -1904,510 +1646,480 @@ volumes:
|
|
|
1904
1646
|
volumes:
|
|
1905
1647
|
mysql_data:
|
|
1906
1648
|
`;
|
|
1907
|
-
|
|
1908
|
-
return null;
|
|
1649
|
+
return null;
|
|
1909
1650
|
}
|
|
1910
1651
|
async function applyDatabaseConfig(destination, driver) {
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
pkg.scripts["db:down"] = "docker compose down";
|
|
1945
|
-
}
|
|
1946
|
-
await writeFile(packageJsonPath, `${JSON.stringify(pkg, null, 2)}
|
|
1947
|
-
`, "utf8");
|
|
1948
|
-
}
|
|
1652
|
+
const { url, dep } = DATABASE_DEFAULTS[driver];
|
|
1653
|
+
const dockerCompose = generateDockerCompose(driver);
|
|
1654
|
+
const schema = await resolveSchema(destination, driver);
|
|
1655
|
+
const databaseConfig = await loadDatabaseConfig(driver);
|
|
1656
|
+
await Promise.all([
|
|
1657
|
+
writeFile(join(destination, "config/database.ts"), databaseConfig, "utf8"),
|
|
1658
|
+
writeFile(join(destination, "db/schema.ts"), schema, "utf8"),
|
|
1659
|
+
...DATABASE_DRIVERS.map((name) => rm(schemaVariantPath(destination, name), { force: true })),
|
|
1660
|
+
writeFile(join(destination, "drizzle.config.ts"), generateDrizzleConfig(driver), "utf8"),
|
|
1661
|
+
dockerCompose ? writeFile(join(destination, "docker-compose.yml"), dockerCompose, "utf8") : Promise.resolve(),
|
|
1662
|
+
...[".env", ".env.example"].map(async (envFile) => {
|
|
1663
|
+
const envPath = join(destination, envFile);
|
|
1664
|
+
try {
|
|
1665
|
+
const content = await readFile(envPath, "utf8");
|
|
1666
|
+
await writeFile(envPath, content.replace(/^DATABASE_URL=.*$/mu, `DATABASE_URL=${url}`), "utf8");
|
|
1667
|
+
} catch {}
|
|
1668
|
+
})
|
|
1669
|
+
]);
|
|
1670
|
+
if (dep || dockerCompose) {
|
|
1671
|
+
const packageJsonPath = join(destination, "package.json");
|
|
1672
|
+
const raw = await readFile(packageJsonPath, "utf8");
|
|
1673
|
+
const pkg = JSON.parse(raw);
|
|
1674
|
+
if (dep) {
|
|
1675
|
+
pkg.dependencies ??= {};
|
|
1676
|
+
Object.assign(pkg.dependencies, dep);
|
|
1677
|
+
}
|
|
1678
|
+
if (dockerCompose) {
|
|
1679
|
+
pkg.scripts ??= {};
|
|
1680
|
+
pkg.scripts["db:up"] = "docker compose up -d";
|
|
1681
|
+
pkg.scripts["db:down"] = "docker compose down";
|
|
1682
|
+
}
|
|
1683
|
+
await writeFile(packageJsonPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf8");
|
|
1684
|
+
}
|
|
1949
1685
|
}
|
|
1950
1686
|
function listAppBlueprints() {
|
|
1951
|
-
|
|
1687
|
+
return [...APP_BLUEPRINTS];
|
|
1952
1688
|
}
|
|
1689
|
+
/**
|
|
1690
|
+
* The templates a blueprint copies from, in copy order: base first, then
|
|
1691
|
+
* overlays, each overwriting what came before. Omit `renderingMode` for every
|
|
1692
|
+
* mode the blueprint supports — what the packaging checks need; pass one for
|
|
1693
|
+
* the templates a single scaffold will actually copy.
|
|
1694
|
+
*
|
|
1695
|
+
* Repeats are returned as-is rather than deduped: a name listed twice means
|
|
1696
|
+
* "copy it again at this point", and collapsing it would silently change which
|
|
1697
|
+
* template wins.
|
|
1698
|
+
*/
|
|
1953
1699
|
function listBlueprintTemplates(blueprint, renderingMode) {
|
|
1954
|
-
|
|
1955
|
-
|
|
1700
|
+
const overlays = renderingMode ? blueprint.overlayTemplates[renderingMode] ?? [] : Object.values(blueprint.overlayTemplates).flat();
|
|
1701
|
+
return [blueprint.baseTemplate, ...overlays];
|
|
1956
1702
|
}
|
|
1957
1703
|
async function assertBlueprintLayersExist(blueprint, renderingMode) {
|
|
1958
|
-
|
|
1959
|
-
if (!await directoryExists(templateDir(layer))) {
|
|
1960
|
-
throw new Error(
|
|
1961
|
-
`Blueprint "${blueprint.name}" is missing its template directory "${templateDir(layer)}". This build of create-guren-app is incomplete \u2014 please report it at https://github.com/gurenjs/guren/issues and try \`npm create guren-app@latest\` meanwhile.`
|
|
1962
|
-
);
|
|
1963
|
-
}
|
|
1964
|
-
}
|
|
1704
|
+
for (const layer of listBlueprintTemplates(blueprint, renderingMode)) if (!await directoryExists(templateDir(layer))) throw new Error(`Blueprint "${blueprint.name}" is missing its template directory "${templateDir(layer)}". This build of create-guren-app is incomplete — please report it at https://github.com/gurenjs/guren/issues and try \`npm create guren-app@latest\` meanwhile.`);
|
|
1965
1705
|
}
|
|
1966
1706
|
function getAppBlueprint(name) {
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
throw new Error(`Unknown blueprint "${name}". Available blueprints: ${listAppBlueprints().join(", ")}`);
|
|
1971
|
-
}
|
|
1972
|
-
return blueprint;
|
|
1707
|
+
const blueprint = blueprintRegistry[name ?? "default"];
|
|
1708
|
+
if (!blueprint) throw new Error(`Unknown blueprint "${name}". Available blueprints: ${listAppBlueprints().join(", ")}`);
|
|
1709
|
+
return blueprint;
|
|
1973
1710
|
}
|
|
1974
1711
|
async function scaffoldAppBlueprint(options) {
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
1712
|
+
const blueprint = getAppBlueprint(options.blueprint);
|
|
1713
|
+
const appName = basename(options.destination);
|
|
1714
|
+
const packageName = toPackageName(appName);
|
|
1715
|
+
const appTitle = toTitleCase(appName);
|
|
1716
|
+
const context = {
|
|
1717
|
+
appName,
|
|
1718
|
+
appTitle,
|
|
1719
|
+
destination: options.destination,
|
|
1720
|
+
packageName,
|
|
1721
|
+
renderingMode: options.renderingMode,
|
|
1722
|
+
database: options.database
|
|
1723
|
+
};
|
|
1724
|
+
const tokenMap = /* @__PURE__ */ new Map([
|
|
1725
|
+
["guren-app-placeholder", packageName],
|
|
1726
|
+
["__APP_TITLE__", appTitle],
|
|
1727
|
+
["__APP_NAME__", appName]
|
|
1728
|
+
]);
|
|
1729
|
+
await assertBlueprintLayersExist(blueprint, options.renderingMode);
|
|
1730
|
+
for (const layer of listBlueprintTemplates(blueprint, options.renderingMode)) await copyLayer(layer, options.destination);
|
|
1731
|
+
await applyTokenTransforms(options.destination, blueprint.transformFiles, tokenMap);
|
|
1732
|
+
await scaffoldEnvFiles(options.destination);
|
|
1733
|
+
await applyDatabaseConfig(options.destination, options.database);
|
|
1734
|
+
await blueprint.postScaffold?.(context);
|
|
1735
|
+
return blueprint;
|
|
1736
|
+
}
|
|
1737
|
+
//#endregion
|
|
1738
|
+
//#region src/git.ts
|
|
1739
|
+
/**
|
|
1740
|
+
* How long the scaffolder waits on `git` before giving up.
|
|
1741
|
+
*
|
|
1742
|
+
* The bound is tied to how these children are run, not applied to every child
|
|
1743
|
+
* the scaffolder spawns. `bun install` and the app's own CLI inherit the
|
|
1744
|
+
* terminal: they can answer a prompt, they show progress, and a long one is
|
|
1745
|
+
* visibly working. These run with `stdio: 'pipe'` and no terminal, where a
|
|
1746
|
+
* signing passphrase prompt, a credential helper, or a stalled name lookup
|
|
1747
|
+
* while git guesses the committer identity waits on input that can never
|
|
1748
|
+
* arrive — silently, with the app already written to disk. Generous enough
|
|
1749
|
+
* that an ordinary commit on a loaded machine never trips it.
|
|
1750
|
+
*/
|
|
1751
|
+
const GIT_TIMEOUT_MS = 3e4;
|
|
2006
1752
|
function runGit(cwd, args, timeoutMs = GIT_TIMEOUT_MS) {
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
// SIGTERM leaves a git blocked in a syscall alive, and spawnSync would go
|
|
2018
|
-
// on blocking with it.
|
|
2019
|
-
killSignal: "SIGKILL"
|
|
2020
|
-
});
|
|
1753
|
+
return spawnSync("git", args, {
|
|
1754
|
+
cwd,
|
|
1755
|
+
stdio: "pipe",
|
|
1756
|
+
env: {
|
|
1757
|
+
...process.env,
|
|
1758
|
+
GIT_TERMINAL_PROMPT: "0"
|
|
1759
|
+
},
|
|
1760
|
+
timeout: Math.max(1, timeoutMs),
|
|
1761
|
+
killSignal: "SIGKILL"
|
|
1762
|
+
});
|
|
2021
1763
|
}
|
|
2022
1764
|
function wasKilledByTimeout(result) {
|
|
2023
|
-
|
|
1765
|
+
return result.error?.code === "ETIMEDOUT";
|
|
2024
1766
|
}
|
|
2025
1767
|
function isInsideGitWorkTree(cwd, options = {}) {
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
}
|
|
2030
|
-
return result.status === 0 && result.stdout.toString().trim() === "true";
|
|
1768
|
+
const result = runGit(cwd, ["rev-parse", "--is-inside-work-tree"], options.timeoutMs);
|
|
1769
|
+
if (wasKilledByTimeout(result)) return true;
|
|
1770
|
+
return result.status === 0 && result.stdout.toString().trim() === "true";
|
|
2031
1771
|
}
|
|
2032
1772
|
function initGitRepository(cwd, options = {}) {
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
1773
|
+
const deadline = Date.now() + (options.timeoutMs ?? 3e4);
|
|
1774
|
+
const run = (failedStep, args) => {
|
|
1775
|
+
const remaining = deadline - Date.now();
|
|
1776
|
+
return remaining > 0 && runGit(cwd, args, remaining).status === 0 ? { ok: true } : {
|
|
1777
|
+
ok: false,
|
|
1778
|
+
failedStep,
|
|
1779
|
+
command: `git ${args.join(" ")}`
|
|
1780
|
+
};
|
|
1781
|
+
};
|
|
1782
|
+
const init = run("init", ["init"]);
|
|
1783
|
+
if (!init.ok) return init;
|
|
1784
|
+
const add = run("add", ["add", "-A"]);
|
|
1785
|
+
if (!add.ok) return add;
|
|
1786
|
+
return run("commit", [
|
|
1787
|
+
"commit",
|
|
1788
|
+
"-m",
|
|
1789
|
+
"chore: initial commit"
|
|
1790
|
+
]);
|
|
1791
|
+
}
|
|
1792
|
+
//#endregion
|
|
1793
|
+
//#region src/cli.ts
|
|
1794
|
+
const RENDERING_MODE_SET = /* @__PURE__ */ new Set(["spa", "ssr"]);
|
|
1795
|
+
const DATABASE_DRIVER_SET = new Set(DATABASE_DRIVERS);
|
|
2050
1796
|
async function ensureTargetDirectory(path, force) {
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
const empty = await isDirectoryEmpty(path);
|
|
2061
|
-
if (!empty) {
|
|
2062
|
-
throw new Error(`Directory "${path}" is not empty. Use --force to scaffold anyway.`);
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
1797
|
+
try {
|
|
1798
|
+
await mkdir(path, { recursive: true });
|
|
1799
|
+
} catch (error) {
|
|
1800
|
+
if (error.code === "EEXIST") throw new Error(`Path "${path}" exists and is not a directory.`);
|
|
1801
|
+
throw error;
|
|
1802
|
+
}
|
|
1803
|
+
if (!force) {
|
|
1804
|
+
if (!await isDirectoryEmpty(path)) throw new Error(`Directory "${path}" is not empty. Use --force to scaffold anyway.`);
|
|
1805
|
+
}
|
|
2065
1806
|
}
|
|
2066
1807
|
async function updateSsrPackageJson(destination) {
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
`, "utf8");
|
|
1808
|
+
const packageJsonPath = resolve(destination, "package.json");
|
|
1809
|
+
const raw = await readFile(packageJsonPath, "utf8");
|
|
1810
|
+
const pkg = JSON.parse(raw);
|
|
1811
|
+
pkg.scripts ??= {};
|
|
1812
|
+
pkg.scripts.build = "bun run codegen && bunx vite build && bunx vite build --ssr";
|
|
1813
|
+
await writeFile(packageJsonPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf8");
|
|
2074
1814
|
}
|
|
2075
1815
|
async function runAppCli(targetDir, cliArgs) {
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
});
|
|
2082
|
-
return result.status === 0;
|
|
1816
|
+
const { spawnSync } = await import("node:child_process");
|
|
1817
|
+
return spawnSync("bun", [resolve(targetDir, "node_modules/@guren/cli/dist/bin.js"), ...cliArgs], {
|
|
1818
|
+
cwd: targetDir,
|
|
1819
|
+
stdio: "inherit"
|
|
1820
|
+
}).status === 0;
|
|
2083
1821
|
}
|
|
2084
1822
|
async function resolveRenderingMode(flagValue) {
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
const value = typeof result === "string" ? result : "ssr";
|
|
2105
|
-
return value ?? "ssr";
|
|
1823
|
+
if (typeof flagValue === "string") {
|
|
1824
|
+
const normalized = flagValue.toLowerCase();
|
|
1825
|
+
if (!RENDERING_MODE_SET.has(normalized)) throw new Error("Invalid rendering mode. Supported values are \"spa\" or \"ssr\".");
|
|
1826
|
+
return normalized;
|
|
1827
|
+
}
|
|
1828
|
+
if (!g$1.stdin.isTTY) return "ssr";
|
|
1829
|
+
const result = await consola.prompt("Choose the rendering mode for this project", {
|
|
1830
|
+
type: "select",
|
|
1831
|
+
options: [{
|
|
1832
|
+
value: "ssr",
|
|
1833
|
+
label: "SSR (server-side rendering)"
|
|
1834
|
+
}, {
|
|
1835
|
+
value: "spa",
|
|
1836
|
+
label: "SPA (client-side rendering only)"
|
|
1837
|
+
}],
|
|
1838
|
+
initial: "ssr",
|
|
1839
|
+
default: "ssr"
|
|
1840
|
+
});
|
|
1841
|
+
return (typeof result === "string" ? result : "ssr") ?? "ssr";
|
|
2106
1842
|
}
|
|
2107
1843
|
async function resolveDatabase(flagValue) {
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
1844
|
+
if (typeof flagValue === "string") {
|
|
1845
|
+
const normalized = flagValue.toLowerCase();
|
|
1846
|
+
if (!DATABASE_DRIVER_SET.has(normalized)) throw new Error(`Invalid database driver. Supported values are: ${DATABASE_DRIVERS.join(", ")}`);
|
|
1847
|
+
return normalized;
|
|
1848
|
+
}
|
|
1849
|
+
if (!g$1.stdin.isTTY) return "sqlite";
|
|
1850
|
+
const result = await consola.prompt("Choose the database driver", {
|
|
1851
|
+
type: "select",
|
|
1852
|
+
options: [
|
|
1853
|
+
{
|
|
1854
|
+
value: "sqlite",
|
|
1855
|
+
label: "SQLite (zero-config, recommended for getting started)"
|
|
1856
|
+
},
|
|
1857
|
+
{
|
|
1858
|
+
value: "postgres",
|
|
1859
|
+
label: "PostgreSQL"
|
|
1860
|
+
},
|
|
1861
|
+
{
|
|
1862
|
+
value: "mysql",
|
|
1863
|
+
label: "MySQL"
|
|
1864
|
+
}
|
|
1865
|
+
],
|
|
1866
|
+
initial: "sqlite",
|
|
1867
|
+
default: "sqlite"
|
|
1868
|
+
});
|
|
1869
|
+
return (typeof result === "string" ? result : "sqlite") ?? "sqlite";
|
|
1870
|
+
}
|
|
1871
|
+
const AGENT_CHOICES = [
|
|
1872
|
+
"claude",
|
|
1873
|
+
"codex",
|
|
1874
|
+
"cursor",
|
|
1875
|
+
"copilot",
|
|
1876
|
+
"opencode"
|
|
1877
|
+
];
|
|
1878
|
+
const AGENT_CHOICE_SET = new Set(AGENT_CHOICES);
|
|
1879
|
+
const AGENT_CHOICES_HELP = `Supported values are: ${AGENT_CHOICES.join(", ")}, all, none.`;
|
|
1880
|
+
const DEFAULT_AGENTS = ["claude"];
|
|
1881
|
+
/**
|
|
1882
|
+
* The selection handed to `guren agent:init --target`: agent names, `['all']`
|
|
1883
|
+
* forwarded verbatim (the app's CLI owns the expansion, so a framework
|
|
1884
|
+
* release that learns a new target is not narrowed by this list), or null
|
|
1885
|
+
* when the user opted out of the harness entirely.
|
|
1886
|
+
*/
|
|
2135
1887
|
async function resolveAgents(flagValue) {
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
(entry) => String(
|
|
2180
|
-
typeof entry === "object" && entry !== null && "value" in entry ? entry.value : entry
|
|
2181
|
-
)
|
|
2182
|
-
).filter((value) => AGENT_CHOICE_SET.has(value));
|
|
2183
|
-
return agents.length > 0 ? agents : DEFAULT_AGENTS;
|
|
1888
|
+
const raw = Array.isArray(flagValue) ? flagValue.join(",") : flagValue;
|
|
1889
|
+
if (typeof raw === "string") {
|
|
1890
|
+
const parts = new Set(raw.split(",").map((part) => part.trim().toLowerCase()).filter(Boolean));
|
|
1891
|
+
if (parts.size === 0) throw new Error(`Invalid --agents value. ${AGENT_CHOICES_HELP}`);
|
|
1892
|
+
if (parts.has("none")) {
|
|
1893
|
+
if (parts.size > 1) throw new Error("--agents \"none\" cannot be combined with other values.");
|
|
1894
|
+
return null;
|
|
1895
|
+
}
|
|
1896
|
+
for (const part of parts) if (part !== "all" && !AGENT_CHOICE_SET.has(part)) throw new Error(`Invalid agent "${part}". ${AGENT_CHOICES_HELP}`);
|
|
1897
|
+
return parts.has("all") ? ["all"] : [...parts];
|
|
1898
|
+
}
|
|
1899
|
+
if (!g$1.stdin.isTTY) return DEFAULT_AGENTS;
|
|
1900
|
+
const result = await consola.prompt("Which AI coding agents should the agent harness support?", {
|
|
1901
|
+
type: "multiselect",
|
|
1902
|
+
options: [
|
|
1903
|
+
{
|
|
1904
|
+
value: "claude",
|
|
1905
|
+
label: "Claude Code"
|
|
1906
|
+
},
|
|
1907
|
+
{
|
|
1908
|
+
value: "codex",
|
|
1909
|
+
label: "Codex"
|
|
1910
|
+
},
|
|
1911
|
+
{
|
|
1912
|
+
value: "cursor",
|
|
1913
|
+
label: "Cursor"
|
|
1914
|
+
},
|
|
1915
|
+
{
|
|
1916
|
+
value: "copilot",
|
|
1917
|
+
label: "GitHub Copilot"
|
|
1918
|
+
},
|
|
1919
|
+
{
|
|
1920
|
+
value: "opencode",
|
|
1921
|
+
label: "OpenCode"
|
|
1922
|
+
}
|
|
1923
|
+
],
|
|
1924
|
+
initial: DEFAULT_AGENTS,
|
|
1925
|
+
required: false
|
|
1926
|
+
});
|
|
1927
|
+
if (!Array.isArray(result)) return DEFAULT_AGENTS;
|
|
1928
|
+
if (result.length === 0) return null;
|
|
1929
|
+
const agents = result.map((entry) => String(typeof entry === "object" && entry !== null && "value" in entry ? entry.value : entry)).filter((value) => AGENT_CHOICE_SET.has(value));
|
|
1930
|
+
return agents.length > 0 ? agents : DEFAULT_AGENTS;
|
|
2184
1931
|
}
|
|
2185
1932
|
async function resolveGitInit(flagValue, target) {
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
return declined("the target directory already contained files.");
|
|
2200
|
-
}
|
|
2201
|
-
if (isInsideGitWorkTree(target.dir)) {
|
|
2202
|
-
return declined("the target directory is already inside a git repository.");
|
|
2203
|
-
}
|
|
2204
|
-
if (flagValue === true) {
|
|
2205
|
-
return true;
|
|
2206
|
-
}
|
|
2207
|
-
const result = await consola.prompt("Initialize a git repository with an initial commit?", {
|
|
2208
|
-
type: "confirm",
|
|
2209
|
-
initial: true
|
|
2210
|
-
});
|
|
2211
|
-
return result === true;
|
|
1933
|
+
if (flagValue === false) return false;
|
|
1934
|
+
if (flagValue !== true && !g$1.stdin.isTTY) return false;
|
|
1935
|
+
const declined = (reason) => {
|
|
1936
|
+
if (flagValue === true) consola.warn(`Skipping git initialization: ${reason}`);
|
|
1937
|
+
return false;
|
|
1938
|
+
};
|
|
1939
|
+
if (!target.wasEmpty) return declined("the target directory already contained files.");
|
|
1940
|
+
if (isInsideGitWorkTree(target.dir)) return declined("the target directory is already inside a git repository.");
|
|
1941
|
+
if (flagValue === true) return true;
|
|
1942
|
+
return await consola.prompt("Initialize a git repository with an initial commit?", {
|
|
1943
|
+
type: "confirm",
|
|
1944
|
+
initial: true
|
|
1945
|
+
}) === true;
|
|
2212
1946
|
}
|
|
2213
1947
|
function reportGitInit(cwd) {
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
1948
|
+
consola.start("Initializing git repository...");
|
|
1949
|
+
const result = initGitRepository(cwd);
|
|
1950
|
+
if (result.ok) {
|
|
1951
|
+
consola.success("Initialized a git repository with an initial commit");
|
|
1952
|
+
return;
|
|
1953
|
+
}
|
|
1954
|
+
if (result.failedStep === "commit") {
|
|
1955
|
+
consola.warn("Created a git repository, but the initial commit failed (git identity may be unset).");
|
|
1956
|
+
consola.warn("Set `git config user.name` and `git config user.email`, then run `git commit -m \"chore: initial commit\"`.");
|
|
1957
|
+
return;
|
|
1958
|
+
}
|
|
1959
|
+
consola.warn(`Failed to run \`${result.command}\`. Initialize the repository manually.`);
|
|
2226
1960
|
}
|
|
2227
1961
|
async function installDependencies(cwd) {
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
consola.log(" bun run dev");
|
|
2390
|
-
if (authInstalled) {
|
|
2391
|
-
consola.log("");
|
|
2392
|
-
consola.info("Auth scaffolding was included automatically.");
|
|
2393
|
-
consola.info("Set up the users table with: bun run db:make && bun run db:migrate && bun run db:seed");
|
|
2394
|
-
}
|
|
2395
|
-
if (renderingMode === "ssr") {
|
|
2396
|
-
consola.log("");
|
|
2397
|
-
consola.info("Production build:");
|
|
2398
|
-
consola.log(" bun run build");
|
|
2399
|
-
consola.log("");
|
|
2400
|
-
consola.info("Optional deploy path:");
|
|
2401
|
-
consola.log(" bunx guren plugin @guren/plugin-vercel");
|
|
2402
|
-
consola.log(" bun add @guren/plugin-vercel");
|
|
2403
|
-
}
|
|
2404
|
-
}
|
|
2405
|
-
});
|
|
2406
|
-
runMain(command).catch((error) => {
|
|
2407
|
-
if (error instanceof Error) {
|
|
2408
|
-
consola.error(error.message);
|
|
2409
|
-
} else {
|
|
2410
|
-
consola.error(String(error));
|
|
2411
|
-
}
|
|
2412
|
-
process3.exit(1);
|
|
1962
|
+
try {
|
|
1963
|
+
consola.start("Installing dependencies...");
|
|
1964
|
+
const { spawnSync } = await import("node:child_process");
|
|
1965
|
+
if (spawnSync("bun", ["install"], {
|
|
1966
|
+
cwd,
|
|
1967
|
+
stdio: "inherit"
|
|
1968
|
+
}).status !== 0) {
|
|
1969
|
+
consola.warn("Failed to install dependencies. Run `bun install` manually.");
|
|
1970
|
+
return false;
|
|
1971
|
+
}
|
|
1972
|
+
consola.success("Dependencies installed");
|
|
1973
|
+
return true;
|
|
1974
|
+
} catch {
|
|
1975
|
+
consola.warn("Failed to install dependencies. Run `bun install` manually.");
|
|
1976
|
+
return false;
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
runMain(defineCommand({
|
|
1980
|
+
meta: {
|
|
1981
|
+
name: "create-guren-app",
|
|
1982
|
+
description: "Scaffold a new Guren application."
|
|
1983
|
+
},
|
|
1984
|
+
args: {
|
|
1985
|
+
target: {
|
|
1986
|
+
type: "positional",
|
|
1987
|
+
description: "Directory to create the application in",
|
|
1988
|
+
default: "."
|
|
1989
|
+
},
|
|
1990
|
+
force: {
|
|
1991
|
+
type: "boolean",
|
|
1992
|
+
alias: "f",
|
|
1993
|
+
description: "Overwrite existing files in the target directory"
|
|
1994
|
+
},
|
|
1995
|
+
mode: {
|
|
1996
|
+
type: "string",
|
|
1997
|
+
description: "Rendering mode to scaffold (spa or ssr)"
|
|
1998
|
+
},
|
|
1999
|
+
auth: {
|
|
2000
|
+
type: "boolean",
|
|
2001
|
+
description: "Include authentication scaffolding with auto-configured providers and middleware"
|
|
2002
|
+
},
|
|
2003
|
+
blueprint: {
|
|
2004
|
+
type: "string",
|
|
2005
|
+
description: `Starter blueprint to scaffold (${listAppBlueprints().join(", ")})`
|
|
2006
|
+
},
|
|
2007
|
+
db: {
|
|
2008
|
+
type: "string",
|
|
2009
|
+
description: `Database driver (${DATABASE_DRIVERS.join(", ")})`
|
|
2010
|
+
},
|
|
2011
|
+
install: {
|
|
2012
|
+
type: "boolean",
|
|
2013
|
+
description: "Install dependencies after scaffolding (default: true)",
|
|
2014
|
+
default: true
|
|
2015
|
+
},
|
|
2016
|
+
git: {
|
|
2017
|
+
type: "boolean",
|
|
2018
|
+
description: "Initialize a git repository and create an initial commit (prompted when interactive, off otherwise)"
|
|
2019
|
+
},
|
|
2020
|
+
agents: {
|
|
2021
|
+
type: "string",
|
|
2022
|
+
description: "AI agents to set up the harness for: claude, codex, cursor, copilot, opencode, all, or none (prompted when interactive; default: claude)"
|
|
2023
|
+
}
|
|
2024
|
+
},
|
|
2025
|
+
async run({ args }) {
|
|
2026
|
+
const target = args.target;
|
|
2027
|
+
const force = Boolean(args.force);
|
|
2028
|
+
const targetDir = resolve(g$1.cwd(), target);
|
|
2029
|
+
let targetWasEmpty = true;
|
|
2030
|
+
if (await directoryExists(targetDir)) {
|
|
2031
|
+
targetWasEmpty = await isDirectoryEmpty(targetDir);
|
|
2032
|
+
if (!force && !targetWasEmpty) throw new Error(`Directory "${targetDir}" is not empty. Use --force to scaffold anyway.`);
|
|
2033
|
+
} else await ensureTargetDirectory(targetDir, true);
|
|
2034
|
+
const blueprint = getAppBlueprint(typeof args.blueprint === "string" ? args.blueprint : void 0);
|
|
2035
|
+
const renderingMode = blueprint.name === "api" ? "spa" : await resolveRenderingMode(args.mode);
|
|
2036
|
+
const database = await resolveDatabase(args.db);
|
|
2037
|
+
const agents = await resolveAgents(args.agents);
|
|
2038
|
+
const shouldInitGit = await resolveGitInit(args.git, {
|
|
2039
|
+
dir: targetDir,
|
|
2040
|
+
wasEmpty: targetWasEmpty
|
|
2041
|
+
});
|
|
2042
|
+
await scaffoldAppBlueprint({
|
|
2043
|
+
blueprint: blueprint.name,
|
|
2044
|
+
destination: targetDir,
|
|
2045
|
+
renderingMode,
|
|
2046
|
+
database
|
|
2047
|
+
});
|
|
2048
|
+
if (renderingMode === "ssr") await updateSsrPackageJson(targetDir);
|
|
2049
|
+
if (args.auth && blueprint.includesAuth) consola.info(`The ${blueprint.name} blueprint already ships authentication — ignoring --auth.`);
|
|
2050
|
+
const includeAuth = Boolean(args.auth) && !blueprint.includesAuth;
|
|
2051
|
+
const shouldInstall = args.install !== false;
|
|
2052
|
+
let installed = false;
|
|
2053
|
+
if (shouldInstall) installed = await installDependencies(targetDir);
|
|
2054
|
+
if (agents === null) consola.info("Skipping the AI agent harness. Add it later with `bunx guren agent:init --target <agents>`.");
|
|
2055
|
+
else {
|
|
2056
|
+
const targetList = agents.join(",");
|
|
2057
|
+
let harnessInstalled = false;
|
|
2058
|
+
if (installed) {
|
|
2059
|
+
consola.start("Setting up AI agent harness...");
|
|
2060
|
+
harnessInstalled = await runAppCli(targetDir, [
|
|
2061
|
+
"agent:init",
|
|
2062
|
+
"--target",
|
|
2063
|
+
targetList
|
|
2064
|
+
]);
|
|
2065
|
+
if (harnessInstalled) consola.success(`AI agent harness installed for: ${targetList}`);
|
|
2066
|
+
}
|
|
2067
|
+
if (!harnessInstalled) consola.warn(`AI agent harness was not installed automatically. Run \`bunx guren agent:init --target ${targetList}\` inside the app after installing dependencies.`);
|
|
2068
|
+
}
|
|
2069
|
+
let authInstalled = false;
|
|
2070
|
+
if (includeAuth) {
|
|
2071
|
+
if (installed) {
|
|
2072
|
+
consola.start("Adding authentication scaffolding...");
|
|
2073
|
+
authInstalled = await runAppCli(targetDir, [
|
|
2074
|
+
"add",
|
|
2075
|
+
"auth",
|
|
2076
|
+
"--force"
|
|
2077
|
+
]);
|
|
2078
|
+
if (authInstalled) consola.success("Authentication scaffolding added");
|
|
2079
|
+
}
|
|
2080
|
+
if (!authInstalled) consola.warn("Authentication was not scaffolded automatically. Run `bunx guren add auth` inside the app after installing dependencies.");
|
|
2081
|
+
}
|
|
2082
|
+
if (shouldInitGit) reportGitInit(targetDir);
|
|
2083
|
+
const relativeTarget = relative(g$1.cwd(), targetDir) || ".";
|
|
2084
|
+
consola.success(`Scaffolded a new Guren app (${blueprint.name}/${renderingMode.toUpperCase()}/${database}) in ${relativeTarget}`);
|
|
2085
|
+
consola.info("Next steps:");
|
|
2086
|
+
if (relativeTarget !== ".") consola.log(` cd ${relativeTarget}`);
|
|
2087
|
+
if (!installed) consola.log(" bun install");
|
|
2088
|
+
if (usesDatabaseContainer(database)) consola.log(" bun run db:up");
|
|
2089
|
+
consola.log("");
|
|
2090
|
+
consola.info("Add features:");
|
|
2091
|
+
if (!blueprint.includesAuth) consola.log(" bunx guren add auth");
|
|
2092
|
+
consola.log(" bunx guren add resource posts --fields \"title:string,body:text\"");
|
|
2093
|
+
consola.log("");
|
|
2094
|
+
consola.info("Generate types and set up database:");
|
|
2095
|
+
consola.log(" bun run codegen");
|
|
2096
|
+
consola.log(" bun run db:make");
|
|
2097
|
+
consola.log(" bun run db:migrate");
|
|
2098
|
+
consola.log(" bun run db:seed");
|
|
2099
|
+
consola.log("");
|
|
2100
|
+
consola.info("Verify and run:");
|
|
2101
|
+
consola.log(" bun run typecheck");
|
|
2102
|
+
consola.log(" bun run test");
|
|
2103
|
+
consola.log(" bun run dev");
|
|
2104
|
+
if (authInstalled) {
|
|
2105
|
+
consola.log("");
|
|
2106
|
+
consola.info("Auth scaffolding was included automatically.");
|
|
2107
|
+
consola.info("Set up the users table with: bun run db:make && bun run db:migrate && bun run db:seed");
|
|
2108
|
+
}
|
|
2109
|
+
if (renderingMode === "ssr") {
|
|
2110
|
+
consola.log("");
|
|
2111
|
+
consola.info("Production build:");
|
|
2112
|
+
consola.log(" bun run build");
|
|
2113
|
+
consola.log("");
|
|
2114
|
+
consola.info("Optional deploy path:");
|
|
2115
|
+
consola.log(" bunx guren plugin @guren/plugin-vercel");
|
|
2116
|
+
consola.log(" bun add @guren/plugin-vercel");
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
})).catch((error) => {
|
|
2120
|
+
if (error instanceof Error) consola.error(error.message);
|
|
2121
|
+
else consola.error(String(error));
|
|
2122
|
+
g$1.exit(1);
|
|
2413
2123
|
});
|
|
2124
|
+
//#endregion
|
|
2125
|
+
export {};
|