@boon4681/giri 0.0.3-alpha-12 → 0.0.3-alpha-13
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 +1231 -206
- package/dist/cli.js.map +1 -1
- package/dist/index.js +338 -130
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -9,6 +9,9 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
9
9
|
var __esm = (fn, res) => function __init() {
|
|
10
10
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
11
11
|
};
|
|
12
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
13
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
14
|
+
};
|
|
12
15
|
var __export = (target, all) => {
|
|
13
16
|
for (var name in all)
|
|
14
17
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -31,6 +34,62 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
31
34
|
));
|
|
32
35
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
36
|
|
|
37
|
+
// node_modules/sisteransi/src/index.js
|
|
38
|
+
var require_src = __commonJS({
|
|
39
|
+
"node_modules/sisteransi/src/index.js"(exports2, module2) {
|
|
40
|
+
"use strict";
|
|
41
|
+
var ESC2 = "\x1B";
|
|
42
|
+
var CSI2 = `${ESC2}[`;
|
|
43
|
+
var beep = "\x07";
|
|
44
|
+
var cursor3 = {
|
|
45
|
+
to(x, y) {
|
|
46
|
+
if (!y) return `${CSI2}${x + 1}G`;
|
|
47
|
+
return `${CSI2}${y + 1};${x + 1}H`;
|
|
48
|
+
},
|
|
49
|
+
move(x, y) {
|
|
50
|
+
let ret = "";
|
|
51
|
+
if (x < 0) ret += `${CSI2}${-x}D`;
|
|
52
|
+
else if (x > 0) ret += `${CSI2}${x}C`;
|
|
53
|
+
if (y < 0) ret += `${CSI2}${-y}A`;
|
|
54
|
+
else if (y > 0) ret += `${CSI2}${y}B`;
|
|
55
|
+
return ret;
|
|
56
|
+
},
|
|
57
|
+
up: (count = 1) => `${CSI2}${count}A`,
|
|
58
|
+
down: (count = 1) => `${CSI2}${count}B`,
|
|
59
|
+
forward: (count = 1) => `${CSI2}${count}C`,
|
|
60
|
+
backward: (count = 1) => `${CSI2}${count}D`,
|
|
61
|
+
nextLine: (count = 1) => `${CSI2}E`.repeat(count),
|
|
62
|
+
prevLine: (count = 1) => `${CSI2}F`.repeat(count),
|
|
63
|
+
left: `${CSI2}G`,
|
|
64
|
+
hide: `${CSI2}?25l`,
|
|
65
|
+
show: `${CSI2}?25h`,
|
|
66
|
+
save: `${ESC2}7`,
|
|
67
|
+
restore: `${ESC2}8`
|
|
68
|
+
};
|
|
69
|
+
var scroll = {
|
|
70
|
+
up: (count = 1) => `${CSI2}S`.repeat(count),
|
|
71
|
+
down: (count = 1) => `${CSI2}T`.repeat(count)
|
|
72
|
+
};
|
|
73
|
+
var erase3 = {
|
|
74
|
+
screen: `${CSI2}2J`,
|
|
75
|
+
up: (count = 1) => `${CSI2}1J`.repeat(count),
|
|
76
|
+
down: (count = 1) => `${CSI2}J`.repeat(count),
|
|
77
|
+
line: `${CSI2}2K`,
|
|
78
|
+
lineEnd: `${CSI2}K`,
|
|
79
|
+
lineStart: `${CSI2}1K`,
|
|
80
|
+
lines(count) {
|
|
81
|
+
let clear = "";
|
|
82
|
+
for (let i2 = 0; i2 < count; i2++)
|
|
83
|
+
clear += this.line + (i2 < count - 1 ? cursor3.up() : "");
|
|
84
|
+
if (count)
|
|
85
|
+
clear += cursor3.left;
|
|
86
|
+
return clear;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
module2.exports = { cursor: cursor3, scroll, erase: erase3, beep };
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
34
93
|
// src/loader/_es5.ts
|
|
35
94
|
var es5_exports = {};
|
|
36
95
|
__export(es5_exports, {
|
|
@@ -95,8 +154,8 @@ function intrinsicName(type) {
|
|
|
95
154
|
return type.intrinsicName;
|
|
96
155
|
}
|
|
97
156
|
function isDateType(type) {
|
|
98
|
-
const
|
|
99
|
-
return
|
|
157
|
+
const symbol2 = type.getSymbol() ?? type.aliasSymbol;
|
|
158
|
+
return symbol2?.getName() === "Date";
|
|
100
159
|
}
|
|
101
160
|
function literalValuesOf(types) {
|
|
102
161
|
const values = [];
|
|
@@ -128,10 +187,10 @@ function buildObjectSchema(type, ctx) {
|
|
|
128
187
|
const indexInfo = checker.getIndexInfoOfType(type, import_typescript4.default.IndexKind.String) ?? checker.getIndexInfoOfType(type, import_typescript4.default.IndexKind.Number);
|
|
129
188
|
const properties = {};
|
|
130
189
|
const required = [];
|
|
131
|
-
for (const
|
|
132
|
-
const name =
|
|
133
|
-
const propType = checker.getTypeOfSymbolAtLocation(
|
|
134
|
-
const optional = Boolean(
|
|
190
|
+
for (const symbol2 of checker.getPropertiesOfType(type)) {
|
|
191
|
+
const name = symbol2.getName();
|
|
192
|
+
const propType = checker.getTypeOfSymbolAtLocation(symbol2, ctx.location);
|
|
193
|
+
const optional = Boolean(symbol2.getFlags() & import_typescript4.default.SymbolFlags.Optional) || Boolean(propType.flags & import_typescript4.default.TypeFlags.Union && propType.types.some((t2) => t2.flags & import_typescript4.default.TypeFlags.Undefined));
|
|
135
194
|
properties[name] = walkType(propType, ctx);
|
|
136
195
|
if (!optional) {
|
|
137
196
|
required.push(name);
|
|
@@ -152,17 +211,17 @@ function buildObjectSchema(type, ctx) {
|
|
|
152
211
|
return schema;
|
|
153
212
|
}
|
|
154
213
|
function toJsonReturnType(type, ctx) {
|
|
155
|
-
const
|
|
156
|
-
if (!
|
|
214
|
+
const symbol2 = ctx.checker.getPropertyOfType(type, "toJSON");
|
|
215
|
+
if (!symbol2) {
|
|
157
216
|
return void 0;
|
|
158
217
|
}
|
|
159
|
-
const methodType = ctx.checker.getTypeOfSymbolAtLocation(
|
|
218
|
+
const methodType = ctx.checker.getTypeOfSymbolAtLocation(symbol2, ctx.location);
|
|
160
219
|
const [signature] = methodType.getCallSignatures();
|
|
161
220
|
return signature ? ctx.checker.getReturnTypeOfSignature(signature) : void 0;
|
|
162
221
|
}
|
|
163
222
|
function defName(type) {
|
|
164
|
-
const
|
|
165
|
-
const name =
|
|
223
|
+
const symbol2 = type.getSymbol() ?? type.aliasSymbol;
|
|
224
|
+
const name = symbol2?.getName();
|
|
166
225
|
if (name && name !== "__type" && name !== "__object") {
|
|
167
226
|
return name;
|
|
168
227
|
}
|
|
@@ -291,8 +350,8 @@ function collectReturnExpressions(fn) {
|
|
|
291
350
|
return expressions;
|
|
292
351
|
}
|
|
293
352
|
function propertyType(checker, type, name, location) {
|
|
294
|
-
const
|
|
295
|
-
return
|
|
353
|
+
const symbol2 = checker.getPropertyOfType(type, name);
|
|
354
|
+
return symbol2 ? checker.getTypeOfSymbolAtLocation(symbol2, location) : void 0;
|
|
296
355
|
}
|
|
297
356
|
function isTypedResponse(checker, type) {
|
|
298
357
|
return Boolean(
|
|
@@ -383,7 +442,7 @@ function extractRouteResponses(program, file) {
|
|
|
383
442
|
const schema = schemas.length === 1 ? schemas[0] : { anyOf: schemas };
|
|
384
443
|
result.responses.push({ status, format, schema });
|
|
385
444
|
}
|
|
386
|
-
result.responses.sort((
|
|
445
|
+
result.responses.sort((a2, b) => Number(a2.status) - Number(b.status));
|
|
387
446
|
result.warnings = ctx.warnings;
|
|
388
447
|
result.$defs = ctx.defs;
|
|
389
448
|
return result;
|
|
@@ -416,20 +475,986 @@ var init_schema = __esm({
|
|
|
416
475
|
|
|
417
476
|
// src/cli.ts
|
|
418
477
|
var import_node_child_process = require("child_process");
|
|
419
|
-
var
|
|
478
|
+
var import_node_fs13 = require("fs");
|
|
420
479
|
var import_promises5 = require("fs/promises");
|
|
421
|
-
var
|
|
422
|
-
|
|
480
|
+
var import_node_path18 = require("path");
|
|
481
|
+
|
|
482
|
+
// node_modules/@clack/core/dist/index.mjs
|
|
483
|
+
var import_node_util = require("util");
|
|
484
|
+
var import_node_process = require("process");
|
|
485
|
+
var l = __toESM(require("readline"), 1);
|
|
486
|
+
var import_node_readline = __toESM(require("readline"), 1);
|
|
487
|
+
|
|
488
|
+
// node_modules/fast-string-truncated-width/dist/utils.js
|
|
489
|
+
var getCodePointsLength = /* @__PURE__ */ (() => {
|
|
490
|
+
const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
|
491
|
+
return (input) => {
|
|
492
|
+
let surrogatePairsNr = 0;
|
|
493
|
+
SURROGATE_PAIR_RE.lastIndex = 0;
|
|
494
|
+
while (SURROGATE_PAIR_RE.test(input)) {
|
|
495
|
+
surrogatePairsNr += 1;
|
|
496
|
+
}
|
|
497
|
+
return input.length - surrogatePairsNr;
|
|
498
|
+
};
|
|
499
|
+
})();
|
|
500
|
+
var isFullWidth = (x) => {
|
|
501
|
+
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
502
|
+
};
|
|
503
|
+
var isWideNotCJKTNotEmoji = (x) => {
|
|
504
|
+
return x === 8987 || x === 9001 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12771 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 19903 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
// node_modules/fast-string-truncated-width/dist/index.js
|
|
508
|
+
var ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
|
|
509
|
+
var CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
|
|
510
|
+
var CJKT_WIDE_RE = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu;
|
|
511
|
+
var TAB_RE = /\t{1,1000}/y;
|
|
512
|
+
var EMOJI_RE = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu;
|
|
513
|
+
var LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
|
|
514
|
+
var MODIFIER_RE = /\p{M}+/gu;
|
|
515
|
+
var NO_TRUNCATION = { limit: Infinity, ellipsis: "" };
|
|
516
|
+
var getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
|
|
517
|
+
const LIMIT = truncationOptions.limit ?? Infinity;
|
|
518
|
+
const ELLIPSIS = truncationOptions.ellipsis ?? "";
|
|
519
|
+
const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION, widthOptions).width : 0);
|
|
520
|
+
const ANSI_WIDTH = 0;
|
|
521
|
+
const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
|
|
522
|
+
const TAB_WIDTH = widthOptions.tabWidth ?? 8;
|
|
523
|
+
const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
|
|
524
|
+
const FULL_WIDTH_WIDTH = 2;
|
|
525
|
+
const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
|
|
526
|
+
const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
|
|
527
|
+
const PARSE_BLOCKS = [
|
|
528
|
+
[LATIN_RE, REGULAR_WIDTH],
|
|
529
|
+
[ANSI_RE, ANSI_WIDTH],
|
|
530
|
+
[CONTROL_RE, CONTROL_WIDTH],
|
|
531
|
+
[TAB_RE, TAB_WIDTH],
|
|
532
|
+
[EMOJI_RE, EMOJI_WIDTH],
|
|
533
|
+
[CJKT_WIDE_RE, WIDE_WIDTH]
|
|
534
|
+
];
|
|
535
|
+
let indexPrev = 0;
|
|
536
|
+
let index = 0;
|
|
537
|
+
let length = input.length;
|
|
538
|
+
let lengthExtra = 0;
|
|
539
|
+
let truncationEnabled = false;
|
|
540
|
+
let truncationIndex = length;
|
|
541
|
+
let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
|
|
542
|
+
let unmatchedStart = 0;
|
|
543
|
+
let unmatchedEnd = 0;
|
|
544
|
+
let width = 0;
|
|
545
|
+
let widthExtra = 0;
|
|
546
|
+
outer: while (true) {
|
|
547
|
+
if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
|
|
548
|
+
const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
|
|
549
|
+
lengthExtra = 0;
|
|
550
|
+
for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
|
|
551
|
+
const codePoint = char.codePointAt(0) || 0;
|
|
552
|
+
if (isFullWidth(codePoint)) {
|
|
553
|
+
widthExtra = FULL_WIDTH_WIDTH;
|
|
554
|
+
} else if (isWideNotCJKTNotEmoji(codePoint)) {
|
|
555
|
+
widthExtra = WIDE_WIDTH;
|
|
556
|
+
} else {
|
|
557
|
+
widthExtra = REGULAR_WIDTH;
|
|
558
|
+
}
|
|
559
|
+
if (width + widthExtra > truncationLimit) {
|
|
560
|
+
truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
|
|
561
|
+
}
|
|
562
|
+
if (width + widthExtra > LIMIT) {
|
|
563
|
+
truncationEnabled = true;
|
|
564
|
+
break outer;
|
|
565
|
+
}
|
|
566
|
+
lengthExtra += char.length;
|
|
567
|
+
width += widthExtra;
|
|
568
|
+
}
|
|
569
|
+
unmatchedStart = unmatchedEnd = 0;
|
|
570
|
+
}
|
|
571
|
+
if (index >= length) {
|
|
572
|
+
break outer;
|
|
573
|
+
}
|
|
574
|
+
for (let i2 = 0, l2 = PARSE_BLOCKS.length; i2 < l2; i2++) {
|
|
575
|
+
const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i2];
|
|
576
|
+
BLOCK_RE.lastIndex = index;
|
|
577
|
+
if (BLOCK_RE.test(input)) {
|
|
578
|
+
lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
|
|
579
|
+
widthExtra = lengthExtra * BLOCK_WIDTH;
|
|
580
|
+
if (width + widthExtra > truncationLimit) {
|
|
581
|
+
truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
|
|
582
|
+
}
|
|
583
|
+
if (width + widthExtra > LIMIT) {
|
|
584
|
+
truncationEnabled = true;
|
|
585
|
+
break outer;
|
|
586
|
+
}
|
|
587
|
+
width += widthExtra;
|
|
588
|
+
unmatchedStart = indexPrev;
|
|
589
|
+
unmatchedEnd = index;
|
|
590
|
+
index = indexPrev = BLOCK_RE.lastIndex;
|
|
591
|
+
continue outer;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
index += 1;
|
|
595
|
+
}
|
|
596
|
+
return {
|
|
597
|
+
width: truncationEnabled ? truncationLimit : width,
|
|
598
|
+
index: truncationEnabled ? truncationIndex : length,
|
|
599
|
+
truncated: truncationEnabled,
|
|
600
|
+
ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
|
|
601
|
+
};
|
|
602
|
+
};
|
|
603
|
+
var dist_default = getStringTruncatedWidth;
|
|
604
|
+
|
|
605
|
+
// node_modules/fast-string-width/dist/index.js
|
|
606
|
+
var NO_TRUNCATION2 = {
|
|
607
|
+
limit: Infinity,
|
|
608
|
+
ellipsis: "",
|
|
609
|
+
ellipsisWidth: 0
|
|
610
|
+
};
|
|
611
|
+
var fastStringWidth = (input, options = {}) => {
|
|
612
|
+
return dist_default(input, NO_TRUNCATION2, options).width;
|
|
613
|
+
};
|
|
614
|
+
var dist_default2 = fastStringWidth;
|
|
615
|
+
|
|
616
|
+
// node_modules/fast-wrap-ansi/lib/main.js
|
|
617
|
+
var ESC = "\x1B";
|
|
618
|
+
var CSI = "\x9B";
|
|
619
|
+
var END_CODE = 39;
|
|
620
|
+
var ANSI_ESCAPE_BELL = "\x07";
|
|
621
|
+
var ANSI_CSI = "[";
|
|
622
|
+
var ANSI_OSC = "]";
|
|
623
|
+
var ANSI_SGR_TERMINATOR = "m";
|
|
624
|
+
var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
625
|
+
var GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
|
|
626
|
+
var getClosingCode = (openingCode) => {
|
|
627
|
+
if (openingCode >= 30 && openingCode <= 37)
|
|
628
|
+
return 39;
|
|
629
|
+
if (openingCode >= 90 && openingCode <= 97)
|
|
630
|
+
return 39;
|
|
631
|
+
if (openingCode >= 40 && openingCode <= 47)
|
|
632
|
+
return 49;
|
|
633
|
+
if (openingCode >= 100 && openingCode <= 107)
|
|
634
|
+
return 49;
|
|
635
|
+
if (openingCode === 1 || openingCode === 2)
|
|
636
|
+
return 22;
|
|
637
|
+
if (openingCode === 3)
|
|
638
|
+
return 23;
|
|
639
|
+
if (openingCode === 4)
|
|
640
|
+
return 24;
|
|
641
|
+
if (openingCode === 7)
|
|
642
|
+
return 27;
|
|
643
|
+
if (openingCode === 8)
|
|
644
|
+
return 28;
|
|
645
|
+
if (openingCode === 9)
|
|
646
|
+
return 29;
|
|
647
|
+
if (openingCode === 0)
|
|
648
|
+
return 0;
|
|
649
|
+
return void 0;
|
|
650
|
+
};
|
|
651
|
+
var wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
652
|
+
var wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
|
|
653
|
+
var wrapWord = (rows, word, columns) => {
|
|
654
|
+
const characters = word[Symbol.iterator]();
|
|
655
|
+
let isInsideEscape = false;
|
|
656
|
+
let isInsideLinkEscape = false;
|
|
657
|
+
let lastRow = rows.at(-1);
|
|
658
|
+
let visible = lastRow === void 0 ? 0 : dist_default2(lastRow);
|
|
659
|
+
let currentCharacter = characters.next();
|
|
660
|
+
let nextCharacter = characters.next();
|
|
661
|
+
let rawCharacterIndex = 0;
|
|
662
|
+
while (!currentCharacter.done) {
|
|
663
|
+
const character = currentCharacter.value;
|
|
664
|
+
const characterLength = dist_default2(character);
|
|
665
|
+
if (visible + characterLength <= columns) {
|
|
666
|
+
rows[rows.length - 1] += character;
|
|
667
|
+
} else {
|
|
668
|
+
rows.push(character);
|
|
669
|
+
visible = 0;
|
|
670
|
+
}
|
|
671
|
+
if (character === ESC || character === CSI) {
|
|
672
|
+
isInsideEscape = true;
|
|
673
|
+
isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
|
|
674
|
+
}
|
|
675
|
+
if (isInsideEscape) {
|
|
676
|
+
if (isInsideLinkEscape) {
|
|
677
|
+
if (character === ANSI_ESCAPE_BELL) {
|
|
678
|
+
isInsideEscape = false;
|
|
679
|
+
isInsideLinkEscape = false;
|
|
680
|
+
}
|
|
681
|
+
} else if (character === ANSI_SGR_TERMINATOR) {
|
|
682
|
+
isInsideEscape = false;
|
|
683
|
+
}
|
|
684
|
+
} else {
|
|
685
|
+
visible += characterLength;
|
|
686
|
+
if (visible === columns && !nextCharacter.done) {
|
|
687
|
+
rows.push("");
|
|
688
|
+
visible = 0;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
currentCharacter = nextCharacter;
|
|
692
|
+
nextCharacter = characters.next();
|
|
693
|
+
rawCharacterIndex += character.length;
|
|
694
|
+
}
|
|
695
|
+
lastRow = rows.at(-1);
|
|
696
|
+
if (!visible && lastRow !== void 0 && lastRow.length && rows.length > 1) {
|
|
697
|
+
rows[rows.length - 2] += rows.pop();
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
var stringVisibleTrimSpacesRight = (string) => {
|
|
701
|
+
const words = string.split(" ");
|
|
702
|
+
let last = words.length;
|
|
703
|
+
while (last) {
|
|
704
|
+
if (dist_default2(words[last - 1])) {
|
|
705
|
+
break;
|
|
706
|
+
}
|
|
707
|
+
last--;
|
|
708
|
+
}
|
|
709
|
+
if (last === words.length) {
|
|
710
|
+
return string;
|
|
711
|
+
}
|
|
712
|
+
return words.slice(0, last).join(" ") + words.slice(last).join("");
|
|
713
|
+
};
|
|
714
|
+
var exec = (string, columns, options = {}) => {
|
|
715
|
+
if (options.trim !== false && string.trim() === "") {
|
|
716
|
+
return "";
|
|
717
|
+
}
|
|
718
|
+
let returnValue = "";
|
|
719
|
+
let escapeCode;
|
|
720
|
+
let escapeUrl;
|
|
721
|
+
const words = string.split(" ");
|
|
722
|
+
let rows = [""];
|
|
723
|
+
let rowLength = 0;
|
|
724
|
+
for (let index = 0; index < words.length; index++) {
|
|
725
|
+
const word = words[index];
|
|
726
|
+
if (options.trim !== false) {
|
|
727
|
+
const row = rows.at(-1) ?? "";
|
|
728
|
+
const trimmed = row.trimStart();
|
|
729
|
+
if (row.length !== trimmed.length) {
|
|
730
|
+
rows[rows.length - 1] = trimmed;
|
|
731
|
+
rowLength = dist_default2(trimmed);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
if (index !== 0) {
|
|
735
|
+
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
736
|
+
rows.push("");
|
|
737
|
+
rowLength = 0;
|
|
738
|
+
}
|
|
739
|
+
if (rowLength || options.trim === false) {
|
|
740
|
+
rows[rows.length - 1] += " ";
|
|
741
|
+
rowLength++;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
const wordLength = dist_default2(word);
|
|
745
|
+
if (options.hard && wordLength > columns) {
|
|
746
|
+
const remainingColumns = columns - rowLength;
|
|
747
|
+
const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
|
|
748
|
+
const breaksStartingNextLine = Math.floor((wordLength - 1) / columns);
|
|
749
|
+
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
750
|
+
rows.push("");
|
|
751
|
+
}
|
|
752
|
+
wrapWord(rows, word, columns);
|
|
753
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
754
|
+
continue;
|
|
755
|
+
}
|
|
756
|
+
if (rowLength + wordLength > columns && rowLength && wordLength) {
|
|
757
|
+
if (options.wordWrap === false && rowLength < columns) {
|
|
758
|
+
wrapWord(rows, word, columns);
|
|
759
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
760
|
+
continue;
|
|
761
|
+
}
|
|
762
|
+
rows.push("");
|
|
763
|
+
rowLength = 0;
|
|
764
|
+
}
|
|
765
|
+
if (rowLength + wordLength > columns && options.wordWrap === false) {
|
|
766
|
+
wrapWord(rows, word, columns);
|
|
767
|
+
rowLength = dist_default2(rows.at(-1) ?? "");
|
|
768
|
+
continue;
|
|
769
|
+
}
|
|
770
|
+
rows[rows.length - 1] += word;
|
|
771
|
+
rowLength += wordLength;
|
|
772
|
+
}
|
|
773
|
+
if (options.trim !== false) {
|
|
774
|
+
rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
775
|
+
}
|
|
776
|
+
const preString = rows.join("\n");
|
|
777
|
+
let inSurrogate = false;
|
|
778
|
+
for (let i2 = 0; i2 < preString.length; i2++) {
|
|
779
|
+
const character = preString[i2];
|
|
780
|
+
returnValue += character;
|
|
781
|
+
if (!inSurrogate) {
|
|
782
|
+
inSurrogate = character >= "\uD800" && character <= "\uDBFF";
|
|
783
|
+
if (inSurrogate) {
|
|
784
|
+
continue;
|
|
785
|
+
}
|
|
786
|
+
} else {
|
|
787
|
+
inSurrogate = false;
|
|
788
|
+
}
|
|
789
|
+
if (character === ESC || character === CSI) {
|
|
790
|
+
GROUP_REGEX.lastIndex = i2 + 1;
|
|
791
|
+
const groupsResult = GROUP_REGEX.exec(preString);
|
|
792
|
+
const groups = groupsResult?.groups;
|
|
793
|
+
if (groups?.code !== void 0) {
|
|
794
|
+
const code = Number.parseFloat(groups.code);
|
|
795
|
+
escapeCode = code === END_CODE ? void 0 : code;
|
|
796
|
+
} else if (groups?.uri !== void 0) {
|
|
797
|
+
escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
if (preString[i2 + 1] === "\n") {
|
|
801
|
+
if (escapeUrl) {
|
|
802
|
+
returnValue += wrapAnsiHyperlink("");
|
|
803
|
+
}
|
|
804
|
+
const closingCode = escapeCode ? getClosingCode(escapeCode) : void 0;
|
|
805
|
+
if (escapeCode && closingCode) {
|
|
806
|
+
returnValue += wrapAnsiCode(closingCode);
|
|
807
|
+
}
|
|
808
|
+
} else if (character === "\n") {
|
|
809
|
+
if (escapeCode && getClosingCode(escapeCode)) {
|
|
810
|
+
returnValue += wrapAnsiCode(escapeCode);
|
|
811
|
+
}
|
|
812
|
+
if (escapeUrl) {
|
|
813
|
+
returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
return returnValue;
|
|
818
|
+
};
|
|
819
|
+
var CRLF_OR_LF = /\r?\n/;
|
|
820
|
+
function wrapAnsi(string, columns, options) {
|
|
821
|
+
return String(string).normalize().split(CRLF_OR_LF).map((line2) => exec(line2, columns, options)).join("\n");
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// node_modules/@clack/core/dist/index.mjs
|
|
825
|
+
var import_sisteransi = __toESM(require_src(), 1);
|
|
826
|
+
var import_node_tty = require("tty");
|
|
827
|
+
function findCursor(s, o2, l2) {
|
|
828
|
+
if (!l2.some((r2) => !r2.disabled))
|
|
829
|
+
return s;
|
|
830
|
+
const t2 = s + o2, n2 = Math.max(l2.length - 1, 0), e = t2 < 0 ? n2 : t2 > n2 ? 0 : t2;
|
|
831
|
+
return l2[e].disabled ? findCursor(e, o2 < 0 ? -1 : 1, l2) : e;
|
|
832
|
+
}
|
|
833
|
+
var a$2 = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
834
|
+
var t = [
|
|
835
|
+
"January",
|
|
836
|
+
"February",
|
|
837
|
+
"March",
|
|
838
|
+
"April",
|
|
839
|
+
"May",
|
|
840
|
+
"June",
|
|
841
|
+
"July",
|
|
842
|
+
"August",
|
|
843
|
+
"September",
|
|
844
|
+
"October",
|
|
845
|
+
"November",
|
|
846
|
+
"December"
|
|
847
|
+
];
|
|
848
|
+
var settings = {
|
|
849
|
+
actions: new Set(a$2),
|
|
850
|
+
aliases: /* @__PURE__ */ new Map([
|
|
851
|
+
// vim support
|
|
852
|
+
["k", "up"],
|
|
853
|
+
["j", "down"],
|
|
854
|
+
["h", "left"],
|
|
855
|
+
["l", "right"],
|
|
856
|
+
["", "cancel"],
|
|
857
|
+
// opinionated defaults!
|
|
858
|
+
["escape", "cancel"]
|
|
859
|
+
]),
|
|
860
|
+
messages: {
|
|
861
|
+
cancel: "Canceled",
|
|
862
|
+
error: "Something went wrong"
|
|
863
|
+
},
|
|
864
|
+
withGuide: true,
|
|
865
|
+
date: {
|
|
866
|
+
monthNames: [...t],
|
|
867
|
+
messages: {
|
|
868
|
+
required: "Please enter a valid date",
|
|
869
|
+
invalidMonth: "There are only 12 months in a year",
|
|
870
|
+
invalidDay: (n2, e) => `There are only ${n2} days in ${e}`,
|
|
871
|
+
afterMin: (n2) => `Date must be on or after ${n2.toISOString().slice(0, 10)}`,
|
|
872
|
+
beforeMax: (n2) => `Date must be on or before ${n2.toISOString().slice(0, 10)}`
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
function isActionKey(n2, e) {
|
|
877
|
+
if (typeof n2 == "string")
|
|
878
|
+
return settings.aliases.get(n2) === e;
|
|
879
|
+
for (const s of n2)
|
|
880
|
+
if (s !== void 0 && isActionKey(s, e))
|
|
881
|
+
return true;
|
|
882
|
+
return false;
|
|
883
|
+
}
|
|
884
|
+
function diffLines(i2, s) {
|
|
885
|
+
if (i2 === s) return;
|
|
886
|
+
const e = i2.split(`
|
|
887
|
+
`), t2 = s.split(`
|
|
888
|
+
`), r2 = Math.max(e.length, t2.length), f = [];
|
|
889
|
+
for (let n2 = 0; n2 < r2; n2++)
|
|
890
|
+
e[n2] !== t2[n2] && f.push(n2);
|
|
891
|
+
return {
|
|
892
|
+
lines: f,
|
|
893
|
+
numLinesBefore: e.length,
|
|
894
|
+
numLinesAfter: t2.length,
|
|
895
|
+
numLines: r2
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
var R = globalThis.process.platform.startsWith("win");
|
|
899
|
+
var CANCEL_SYMBOL = /* @__PURE__ */ Symbol("clack:cancel");
|
|
900
|
+
function isCancel(e) {
|
|
901
|
+
return e === CANCEL_SYMBOL;
|
|
902
|
+
}
|
|
903
|
+
function setRawMode(e, r2) {
|
|
904
|
+
const o2 = e;
|
|
905
|
+
o2.isTTY && o2.setRawMode(r2);
|
|
906
|
+
}
|
|
907
|
+
var getColumns = (e) => "columns" in e && typeof e.columns == "number" ? e.columns : 80;
|
|
908
|
+
var getRows = (e) => "rows" in e && typeof e.rows == "number" ? e.rows : 20;
|
|
909
|
+
function wrapTextWithPrefix(e, r2, o2, t2 = o2, s = o2, n2) {
|
|
910
|
+
const f = getColumns(e ?? import_node_process.stdout);
|
|
911
|
+
return wrapAnsi(r2, f - o2.length, {
|
|
912
|
+
hard: true,
|
|
913
|
+
trim: false
|
|
914
|
+
}).split(`
|
|
915
|
+
`).map((c2, i2, m) => {
|
|
916
|
+
const d = n2 ? n2(c2, i2) : c2;
|
|
917
|
+
return i2 === 0 ? `${t2}${d}` : i2 === m.length - 1 ? `${s}${d}` : `${o2}${d}`;
|
|
918
|
+
}).join(`
|
|
919
|
+
`);
|
|
920
|
+
}
|
|
921
|
+
function runValidation(e, n2) {
|
|
922
|
+
if ("~standard" in e) {
|
|
923
|
+
const a2 = e["~standard"].validate(n2);
|
|
924
|
+
if (a2 instanceof Promise)
|
|
925
|
+
throw new TypeError(
|
|
926
|
+
"Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic."
|
|
927
|
+
);
|
|
928
|
+
return a2.issues?.at(0)?.message;
|
|
929
|
+
}
|
|
930
|
+
return e(n2);
|
|
931
|
+
}
|
|
932
|
+
var V = class {
|
|
933
|
+
input;
|
|
934
|
+
output;
|
|
935
|
+
_abortSignal;
|
|
936
|
+
rl;
|
|
937
|
+
opts;
|
|
938
|
+
_render;
|
|
939
|
+
_track = false;
|
|
940
|
+
_prevFrame = "";
|
|
941
|
+
_subscribers = /* @__PURE__ */ new Map();
|
|
942
|
+
_cursor = 0;
|
|
943
|
+
state = "initial";
|
|
944
|
+
error = "";
|
|
945
|
+
value;
|
|
946
|
+
userInput = "";
|
|
947
|
+
constructor(t2, e = true) {
|
|
948
|
+
const { input: i2 = import_node_process.stdin, output: n2 = import_node_process.stdout, render: s, signal: r2, ...o2 } = t2;
|
|
949
|
+
this.opts = o2, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = s.bind(this), this._track = e, this._abortSignal = r2, this.input = i2, this.output = n2;
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* Unsubscribe all listeners
|
|
953
|
+
*/
|
|
954
|
+
unsubscribe() {
|
|
955
|
+
this._subscribers.clear();
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* Set a subscriber with opts
|
|
959
|
+
* @param event - The event name
|
|
960
|
+
*/
|
|
961
|
+
setSubscriber(t2, e) {
|
|
962
|
+
const i2 = this._subscribers.get(t2) ?? [];
|
|
963
|
+
i2.push(e), this._subscribers.set(t2, i2);
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Subscribe to an event
|
|
967
|
+
* @param event - The event name
|
|
968
|
+
* @param cb - The callback
|
|
969
|
+
*/
|
|
970
|
+
on(t2, e) {
|
|
971
|
+
this.setSubscriber(t2, { cb: e });
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* Subscribe to an event once
|
|
975
|
+
* @param event - The event name
|
|
976
|
+
* @param cb - The callback
|
|
977
|
+
*/
|
|
978
|
+
once(t2, e) {
|
|
979
|
+
this.setSubscriber(t2, { cb: e, once: true });
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* Emit an event with data
|
|
983
|
+
* @param event - The event name
|
|
984
|
+
* @param data - The data to pass to the callback
|
|
985
|
+
*/
|
|
986
|
+
emit(t2, ...e) {
|
|
987
|
+
const i2 = this._subscribers.get(t2) ?? [], n2 = [];
|
|
988
|
+
for (const s of i2)
|
|
989
|
+
s.cb(...e), s.once && n2.push(() => i2.splice(i2.indexOf(s), 1));
|
|
990
|
+
for (const s of n2)
|
|
991
|
+
s();
|
|
992
|
+
}
|
|
993
|
+
prompt() {
|
|
994
|
+
return new Promise((t2) => {
|
|
995
|
+
if (this._abortSignal) {
|
|
996
|
+
if (this._abortSignal.aborted)
|
|
997
|
+
return this.state = "cancel", this.close(), t2(CANCEL_SYMBOL);
|
|
998
|
+
this._abortSignal.addEventListener(
|
|
999
|
+
"abort",
|
|
1000
|
+
() => {
|
|
1001
|
+
this.state = "cancel", this.close();
|
|
1002
|
+
},
|
|
1003
|
+
{ once: true }
|
|
1004
|
+
);
|
|
1005
|
+
}
|
|
1006
|
+
this.rl = import_node_readline.default.createInterface({
|
|
1007
|
+
input: this.input,
|
|
1008
|
+
tabSize: 2,
|
|
1009
|
+
prompt: "",
|
|
1010
|
+
escapeCodeTimeout: 50,
|
|
1011
|
+
terminal: true
|
|
1012
|
+
}), this.rl.prompt(), this.opts.initialUserInput !== void 0 && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), setRawMode(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
|
|
1013
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(this.value);
|
|
1014
|
+
}), this.once("cancel", () => {
|
|
1015
|
+
this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t2(CANCEL_SYMBOL);
|
|
1016
|
+
});
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
_isActionKey(t2, e) {
|
|
1020
|
+
return t2 === " ";
|
|
1021
|
+
}
|
|
1022
|
+
_shouldSubmit(t2, e) {
|
|
1023
|
+
return true;
|
|
1024
|
+
}
|
|
1025
|
+
_setValue(t2) {
|
|
1026
|
+
this.value = t2, this.emit("value", this.value);
|
|
1027
|
+
}
|
|
1028
|
+
_setUserInput(t2, e) {
|
|
1029
|
+
this.userInput = t2 ?? "", this.emit("userInput", this.userInput), e && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
|
|
1030
|
+
}
|
|
1031
|
+
_clearUserInput() {
|
|
1032
|
+
this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
|
|
1033
|
+
}
|
|
1034
|
+
onKeypress(t2, e) {
|
|
1035
|
+
if (this._track && e.name !== "return" && (e.name && this._isActionKey(t2, e) && this.rl?.write(null, { ctrl: true, name: "h" }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), e?.name && (!this._track && settings.aliases.has(e.name) && this.emit("cursor", settings.aliases.get(e.name)), settings.actions.has(e.name) && this.emit("cursor", e.name)), t2 && (t2.toLowerCase() === "y" || t2.toLowerCase() === "n") && this.emit("confirm", t2.toLowerCase() === "y"), this.emit("key", t2, e), e?.name === "return" && this._shouldSubmit(t2, e)) {
|
|
1036
|
+
if (this.opts.validate) {
|
|
1037
|
+
const i2 = runValidation(this.opts.validate, this.value);
|
|
1038
|
+
i2 && (this.error = i2 instanceof Error ? i2.message : i2, this.state = "error", this.rl?.write(this.userInput));
|
|
1039
|
+
}
|
|
1040
|
+
this.state !== "error" && (this.state = "submit");
|
|
1041
|
+
}
|
|
1042
|
+
isActionKey([t2, e?.name, e?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
1043
|
+
}
|
|
1044
|
+
close() {
|
|
1045
|
+
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
1046
|
+
`), setRawMode(this.input, false), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
1047
|
+
}
|
|
1048
|
+
restoreCursor() {
|
|
1049
|
+
const t2 = wrapAnsi(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
|
|
1050
|
+
`).length - 1;
|
|
1051
|
+
this.output.write(import_sisteransi.cursor.move(-999, t2 * -1));
|
|
1052
|
+
}
|
|
1053
|
+
render() {
|
|
1054
|
+
const t2 = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
|
|
1055
|
+
hard: true,
|
|
1056
|
+
trim: false
|
|
1057
|
+
});
|
|
1058
|
+
if (t2 !== this._prevFrame) {
|
|
1059
|
+
if (this.state === "initial")
|
|
1060
|
+
this.output.write(import_sisteransi.cursor.hide);
|
|
1061
|
+
else {
|
|
1062
|
+
const e = diffLines(this._prevFrame, t2), i2 = getRows(this.output);
|
|
1063
|
+
if (this.restoreCursor(), e) {
|
|
1064
|
+
const n2 = Math.max(0, e.numLinesAfter - i2), s = Math.max(0, e.numLinesBefore - i2);
|
|
1065
|
+
let r2 = e.lines.find((o2) => o2 >= n2);
|
|
1066
|
+
if (r2 === void 0) {
|
|
1067
|
+
this._prevFrame = t2;
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
if (e.lines.length === 1) {
|
|
1071
|
+
this.output.write(import_sisteransi.cursor.move(0, r2 - s)), this.output.write(import_sisteransi.erase.lines(1));
|
|
1072
|
+
const o2 = t2.split(`
|
|
1073
|
+
`);
|
|
1074
|
+
this.output.write(o2[r2]), this._prevFrame = t2, this.output.write(import_sisteransi.cursor.move(0, o2.length - r2 - 1));
|
|
1075
|
+
return;
|
|
1076
|
+
} else if (e.lines.length > 1) {
|
|
1077
|
+
if (n2 < s)
|
|
1078
|
+
r2 = n2;
|
|
1079
|
+
else {
|
|
1080
|
+
const h2 = r2 - s;
|
|
1081
|
+
h2 > 0 && this.output.write(import_sisteransi.cursor.move(0, h2));
|
|
1082
|
+
}
|
|
1083
|
+
this.output.write(import_sisteransi.erase.down());
|
|
1084
|
+
const f = t2.split(`
|
|
1085
|
+
`).slice(r2);
|
|
1086
|
+
this.output.write(f.join(`
|
|
1087
|
+
`)), this._prevFrame = t2;
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
this.output.write(import_sisteransi.erase.down());
|
|
1092
|
+
}
|
|
1093
|
+
this.output.write(t2), this.state === "initial" && (this.state = "active"), this._prevFrame = t2;
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
var r = class extends V {
|
|
1098
|
+
get cursor() {
|
|
1099
|
+
return this.value ? 0 : 1;
|
|
1100
|
+
}
|
|
1101
|
+
get _value() {
|
|
1102
|
+
return this.cursor === 0;
|
|
1103
|
+
}
|
|
1104
|
+
constructor(t2) {
|
|
1105
|
+
super(t2, false), this.value = !!t2.initialValue, this.on("userInput", () => {
|
|
1106
|
+
this.value = this._value;
|
|
1107
|
+
}), this.on("confirm", (i2) => {
|
|
1108
|
+
this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = i2, this.state = "submit", this.close();
|
|
1109
|
+
}), this.on("cursor", () => {
|
|
1110
|
+
this.value = !this.value;
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
};
|
|
1114
|
+
var a = class extends V {
|
|
1115
|
+
options;
|
|
1116
|
+
cursor = 0;
|
|
1117
|
+
get _selectedValue() {
|
|
1118
|
+
return this.options[this.cursor];
|
|
1119
|
+
}
|
|
1120
|
+
changeValue() {
|
|
1121
|
+
this.value = this._selectedValue.value;
|
|
1122
|
+
}
|
|
1123
|
+
constructor(t2) {
|
|
1124
|
+
super(t2, false), this.options = t2.options;
|
|
1125
|
+
const i2 = this.options.findIndex(({ value: s }) => s === t2.initialValue), e = i2 === -1 ? 0 : i2;
|
|
1126
|
+
this.cursor = this.options[e].disabled ? findCursor(e, 1, this.options) : e, this.changeValue(), this.on("cursor", (s) => {
|
|
1127
|
+
switch (s) {
|
|
1128
|
+
case "left":
|
|
1129
|
+
case "up":
|
|
1130
|
+
this.cursor = findCursor(this.cursor, -1, this.options);
|
|
1131
|
+
break;
|
|
1132
|
+
case "down":
|
|
1133
|
+
case "right":
|
|
1134
|
+
this.cursor = findCursor(this.cursor, 1, this.options);
|
|
1135
|
+
break;
|
|
1136
|
+
}
|
|
1137
|
+
this.changeValue();
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
|
|
1142
|
+
// node_modules/@clack/prompts/dist/index.mjs
|
|
1143
|
+
var import_node_util2 = require("util");
|
|
1144
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
1145
|
+
var import_node_fs = require("fs");
|
|
1146
|
+
var import_node_path = require("path");
|
|
1147
|
+
var import_sisteransi2 = __toESM(require_src(), 1);
|
|
1148
|
+
function isUnicodeSupported() {
|
|
1149
|
+
if (import_node_process2.default.platform !== "win32") {
|
|
1150
|
+
return import_node_process2.default.env.TERM !== "linux";
|
|
1151
|
+
}
|
|
1152
|
+
return Boolean(import_node_process2.default.env.CI) || Boolean(import_node_process2.default.env.WT_SESSION) || Boolean(import_node_process2.default.env.TERMINUS_SUBLIME) || import_node_process2.default.env.ConEmuTask === "{cmd::Cmder}" || import_node_process2.default.env.TERM_PROGRAM === "Terminus-Sublime" || import_node_process2.default.env.TERM_PROGRAM === "vscode" || import_node_process2.default.env.TERM === "xterm-256color" || import_node_process2.default.env.TERM === "alacritty" || import_node_process2.default.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
1153
|
+
}
|
|
1154
|
+
var unicode = isUnicodeSupported();
|
|
1155
|
+
var unicodeOr = (e, o2) => unicode ? e : o2;
|
|
1156
|
+
var S_STEP_ACTIVE = unicodeOr("\u25C6", "*");
|
|
1157
|
+
var S_STEP_CANCEL = unicodeOr("\u25A0", "x");
|
|
1158
|
+
var S_STEP_ERROR = unicodeOr("\u25B2", "x");
|
|
1159
|
+
var S_STEP_SUBMIT = unicodeOr("\u25C7", "o");
|
|
1160
|
+
var S_BAR_START = unicodeOr("\u250C", "T");
|
|
1161
|
+
var S_BAR = unicodeOr("\u2502", "|");
|
|
1162
|
+
var S_BAR_END = unicodeOr("\u2514", "\u2014");
|
|
1163
|
+
var S_BAR_START_RIGHT = unicodeOr("\u2510", "T");
|
|
1164
|
+
var S_BAR_END_RIGHT = unicodeOr("\u2518", "\u2014");
|
|
1165
|
+
var S_RADIO_ACTIVE = unicodeOr("\u25CF", ">");
|
|
1166
|
+
var S_RADIO_INACTIVE = unicodeOr("\u25CB", " ");
|
|
1167
|
+
var S_CHECKBOX_ACTIVE = unicodeOr("\u25FB", "[\u2022]");
|
|
1168
|
+
var S_CHECKBOX_SELECTED = unicodeOr("\u25FC", "[+]");
|
|
1169
|
+
var S_CHECKBOX_INACTIVE = unicodeOr("\u25FB", "[ ]");
|
|
1170
|
+
var S_PASSWORD_MASK = unicodeOr("\u25AA", "\u2022");
|
|
1171
|
+
var S_BAR_H = unicodeOr("\u2500", "-");
|
|
1172
|
+
var S_CORNER_TOP_RIGHT = unicodeOr("\u256E", "+");
|
|
1173
|
+
var S_CONNECT_LEFT = unicodeOr("\u251C", "+");
|
|
1174
|
+
var S_CORNER_BOTTOM_RIGHT = unicodeOr("\u256F", "+");
|
|
1175
|
+
var S_CORNER_BOTTOM_LEFT = unicodeOr("\u2570", "+");
|
|
1176
|
+
var S_CORNER_TOP_LEFT = unicodeOr("\u256D", "+");
|
|
1177
|
+
var S_INFO = unicodeOr("\u25CF", "\u2022");
|
|
1178
|
+
var S_SUCCESS = unicodeOr("\u25C6", "*");
|
|
1179
|
+
var S_WARN = unicodeOr("\u25B2", "!");
|
|
1180
|
+
var S_ERROR = unicodeOr("\u25A0", "x");
|
|
1181
|
+
var symbol = (e) => {
|
|
1182
|
+
switch (e) {
|
|
1183
|
+
case "initial":
|
|
1184
|
+
case "active":
|
|
1185
|
+
return (0, import_node_util2.styleText)("cyan", S_STEP_ACTIVE);
|
|
1186
|
+
case "cancel":
|
|
1187
|
+
return (0, import_node_util2.styleText)("red", S_STEP_CANCEL);
|
|
1188
|
+
case "error":
|
|
1189
|
+
return (0, import_node_util2.styleText)("yellow", S_STEP_ERROR);
|
|
1190
|
+
case "submit":
|
|
1191
|
+
return (0, import_node_util2.styleText)("green", S_STEP_SUBMIT);
|
|
1192
|
+
}
|
|
1193
|
+
};
|
|
1194
|
+
var symbolBar = (e) => {
|
|
1195
|
+
switch (e) {
|
|
1196
|
+
case "initial":
|
|
1197
|
+
case "active":
|
|
1198
|
+
return (0, import_node_util2.styleText)("cyan", S_BAR);
|
|
1199
|
+
case "cancel":
|
|
1200
|
+
return (0, import_node_util2.styleText)("red", S_BAR);
|
|
1201
|
+
case "error":
|
|
1202
|
+
return (0, import_node_util2.styleText)("yellow", S_BAR);
|
|
1203
|
+
case "submit":
|
|
1204
|
+
return (0, import_node_util2.styleText)("green", S_BAR);
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
var E$1 = (l2, o2, g, c2, h2, O = false) => {
|
|
1208
|
+
let r2 = o2, w = 0;
|
|
1209
|
+
if (O)
|
|
1210
|
+
for (let i2 = c2 - 1; i2 >= g && (r2 -= l2[i2].length, w++, !(r2 <= h2)); i2--)
|
|
1211
|
+
;
|
|
1212
|
+
else
|
|
1213
|
+
for (let i2 = g; i2 < c2 && (r2 -= l2[i2].length, w++, !(r2 <= h2)); i2++)
|
|
1214
|
+
;
|
|
1215
|
+
return { lineCount: r2, removals: w };
|
|
1216
|
+
};
|
|
1217
|
+
var limitOptions = ({
|
|
1218
|
+
cursor: l2,
|
|
1219
|
+
options: o2,
|
|
1220
|
+
style: g,
|
|
1221
|
+
output: c2 = process.stdout,
|
|
1222
|
+
maxItems: h2 = Number.POSITIVE_INFINITY,
|
|
1223
|
+
columnPadding: O = 0,
|
|
1224
|
+
rowPadding: r2 = 4
|
|
1225
|
+
}) => {
|
|
1226
|
+
const i2 = getColumns(c2) - O, I = getRows(c2), C = (0, import_node_util2.styleText)("dim", "..."), x = Math.max(I - r2, 0), m = Math.max(Math.min(h2, x), 5);
|
|
1227
|
+
let p = 0;
|
|
1228
|
+
l2 >= m - 3 && (p = Math.max(
|
|
1229
|
+
Math.min(l2 - m + 3, o2.length - m),
|
|
1230
|
+
0
|
|
1231
|
+
));
|
|
1232
|
+
let f = m < o2.length && p > 0, u3 = m < o2.length && p + m < o2.length;
|
|
1233
|
+
const W = Math.min(
|
|
1234
|
+
p + m,
|
|
1235
|
+
o2.length
|
|
1236
|
+
), e = [];
|
|
1237
|
+
let d = 0;
|
|
1238
|
+
f && d++, u3 && d++;
|
|
1239
|
+
const v = p + (f ? 1 : 0), P = W - (u3 ? 1 : 0);
|
|
1240
|
+
for (let t2 = v; t2 < P; t2++) {
|
|
1241
|
+
const n2 = wrapAnsi(g(o2[t2], t2 === l2), i2, {
|
|
1242
|
+
hard: true,
|
|
1243
|
+
trim: false
|
|
1244
|
+
}).split(`
|
|
1245
|
+
`);
|
|
1246
|
+
e.push(n2), d += n2.length;
|
|
1247
|
+
}
|
|
1248
|
+
if (d > x) {
|
|
1249
|
+
let t2 = 0, n2 = 0, s = d;
|
|
1250
|
+
const M = l2 - v;
|
|
1251
|
+
let a2 = x;
|
|
1252
|
+
const T = () => E$1(e, s, 0, M, a2), L = () => E$1(
|
|
1253
|
+
e,
|
|
1254
|
+
s,
|
|
1255
|
+
M + 1,
|
|
1256
|
+
e.length,
|
|
1257
|
+
a2,
|
|
1258
|
+
true
|
|
1259
|
+
);
|
|
1260
|
+
f ? ({ lineCount: s, removals: t2 } = T(), s > a2 && (u3 || (a2 -= 1), { lineCount: s, removals: n2 } = L())) : (u3 || (a2 -= 1), { lineCount: s, removals: n2 } = L(), s > a2 && (a2 -= 1, { lineCount: s, removals: t2 } = T())), t2 > 0 && (f = true, e.splice(0, t2)), n2 > 0 && (u3 = true, e.splice(e.length - n2, n2));
|
|
1261
|
+
}
|
|
1262
|
+
const b = [];
|
|
1263
|
+
f && b.push(C);
|
|
1264
|
+
for (const t2 of e)
|
|
1265
|
+
for (const n2 of t2)
|
|
1266
|
+
b.push(n2);
|
|
1267
|
+
return u3 && b.push(C), b;
|
|
1268
|
+
};
|
|
1269
|
+
var confirm = (i2) => {
|
|
1270
|
+
const a2 = i2.active ?? "Yes", s = i2.inactive ?? "No";
|
|
1271
|
+
return new r({
|
|
1272
|
+
active: a2,
|
|
1273
|
+
inactive: s,
|
|
1274
|
+
signal: i2.signal,
|
|
1275
|
+
input: i2.input,
|
|
1276
|
+
output: i2.output,
|
|
1277
|
+
initialValue: i2.initialValue ?? true,
|
|
1278
|
+
render() {
|
|
1279
|
+
const e = i2.withGuide ?? settings.withGuide, u3 = `${symbol(this.state)} `, l2 = e ? `${(0, import_node_util2.styleText)("gray", S_BAR)} ` : "", f = wrapTextWithPrefix(
|
|
1280
|
+
i2.output,
|
|
1281
|
+
i2.message,
|
|
1282
|
+
l2,
|
|
1283
|
+
u3
|
|
1284
|
+
), o2 = `${e ? `${(0, import_node_util2.styleText)("gray", S_BAR)}
|
|
1285
|
+
` : ""}${f}
|
|
1286
|
+
`, c2 = this.value ? a2 : s;
|
|
1287
|
+
switch (this.state) {
|
|
1288
|
+
case "submit": {
|
|
1289
|
+
const r2 = e ? `${(0, import_node_util2.styleText)("gray", S_BAR)} ` : "";
|
|
1290
|
+
return `${o2}${r2}${(0, import_node_util2.styleText)("dim", c2)}`;
|
|
1291
|
+
}
|
|
1292
|
+
case "cancel": {
|
|
1293
|
+
const r2 = e ? `${(0, import_node_util2.styleText)("gray", S_BAR)} ` : "";
|
|
1294
|
+
return `${o2}${r2}${(0, import_node_util2.styleText)(["strikethrough", "dim"], c2)}${e ? `
|
|
1295
|
+
${(0, import_node_util2.styleText)("gray", S_BAR)}` : ""}`;
|
|
1296
|
+
}
|
|
1297
|
+
default: {
|
|
1298
|
+
const r2 = e ? `${(0, import_node_util2.styleText)("cyan", S_BAR)} ` : "", g = e ? (0, import_node_util2.styleText)("cyan", S_BAR_END) : "";
|
|
1299
|
+
return `${o2}${r2}${this.value ? `${(0, import_node_util2.styleText)("green", S_RADIO_ACTIVE)} ${a2}` : `${(0, import_node_util2.styleText)("dim", S_RADIO_INACTIVE)} ${(0, import_node_util2.styleText)("dim", a2)}`}${i2.vertical ? e ? `
|
|
1300
|
+
${(0, import_node_util2.styleText)("cyan", S_BAR)} ` : `
|
|
1301
|
+
` : ` ${(0, import_node_util2.styleText)("dim", "/")} `}${this.value ? `${(0, import_node_util2.styleText)("dim", S_RADIO_INACTIVE)} ${(0, import_node_util2.styleText)("dim", s)}` : `${(0, import_node_util2.styleText)("green", S_RADIO_ACTIVE)} ${s}`}
|
|
1302
|
+
${g}
|
|
1303
|
+
`;
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
}).prompt();
|
|
1308
|
+
};
|
|
1309
|
+
var log = {
|
|
1310
|
+
message: (s = [], {
|
|
1311
|
+
symbol: e = (0, import_node_util2.styleText)("gray", S_BAR),
|
|
1312
|
+
secondarySymbol: r2 = (0, import_node_util2.styleText)("gray", S_BAR),
|
|
1313
|
+
output: m = process.stdout,
|
|
1314
|
+
spacing: l2 = 1,
|
|
1315
|
+
withGuide: c2
|
|
1316
|
+
} = {}) => {
|
|
1317
|
+
const t2 = [], o2 = c2 ?? settings.withGuide, f = o2 ? r2 : "", O = o2 ? `${e} ` : "", u3 = o2 ? `${r2} ` : "";
|
|
1318
|
+
for (let i2 = 0; i2 < l2; i2++)
|
|
1319
|
+
t2.push(f);
|
|
1320
|
+
const g = Array.isArray(s) ? s : s.split(`
|
|
1321
|
+
`);
|
|
1322
|
+
if (g.length > 0) {
|
|
1323
|
+
const [i2, ...y] = g;
|
|
1324
|
+
i2.length > 0 ? t2.push(`${O}${i2}`) : t2.push(o2 ? e : "");
|
|
1325
|
+
for (const p of y)
|
|
1326
|
+
p.length > 0 ? t2.push(`${u3}${p}`) : t2.push(o2 ? r2 : "");
|
|
1327
|
+
}
|
|
1328
|
+
m.write(`${t2.join(`
|
|
1329
|
+
`)}
|
|
1330
|
+
`);
|
|
1331
|
+
},
|
|
1332
|
+
info: (s, e) => {
|
|
1333
|
+
log.message(s, { ...e, symbol: (0, import_node_util2.styleText)("blue", S_INFO) });
|
|
1334
|
+
},
|
|
1335
|
+
success: (s, e) => {
|
|
1336
|
+
log.message(s, { ...e, symbol: (0, import_node_util2.styleText)("green", S_SUCCESS) });
|
|
1337
|
+
},
|
|
1338
|
+
step: (s, e) => {
|
|
1339
|
+
log.message(s, { ...e, symbol: (0, import_node_util2.styleText)("green", S_STEP_SUBMIT) });
|
|
1340
|
+
},
|
|
1341
|
+
warn: (s, e) => {
|
|
1342
|
+
log.message(s, { ...e, symbol: (0, import_node_util2.styleText)("yellow", S_WARN) });
|
|
1343
|
+
},
|
|
1344
|
+
/** alias for `log.warn()`. */
|
|
1345
|
+
warning: (s, e) => {
|
|
1346
|
+
log.warn(s, e);
|
|
1347
|
+
},
|
|
1348
|
+
error: (s, e) => {
|
|
1349
|
+
log.message(s, { ...e, symbol: (0, import_node_util2.styleText)("red", S_ERROR) });
|
|
1350
|
+
}
|
|
1351
|
+
};
|
|
1352
|
+
var cancel = (o2 = "", t2) => {
|
|
1353
|
+
const i2 = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${(0, import_node_util2.styleText)("gray", S_BAR_END)} ` : "";
|
|
1354
|
+
i2.write(`${e}${(0, import_node_util2.styleText)("red", o2)}
|
|
1355
|
+
|
|
1356
|
+
`);
|
|
1357
|
+
};
|
|
1358
|
+
var intro = (o2 = "", t2) => {
|
|
1359
|
+
const i2 = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${(0, import_node_util2.styleText)("gray", S_BAR_START)} ` : "";
|
|
1360
|
+
i2.write(`${e}${o2}
|
|
1361
|
+
`);
|
|
1362
|
+
};
|
|
1363
|
+
var outro = (o2 = "", t2) => {
|
|
1364
|
+
const i2 = t2?.output ?? process.stdout, e = t2?.withGuide ?? settings.withGuide ? `${(0, import_node_util2.styleText)("gray", S_BAR)}
|
|
1365
|
+
${(0, import_node_util2.styleText)("gray", S_BAR_END)} ` : "";
|
|
1366
|
+
i2.write(`${e}${o2}
|
|
1367
|
+
|
|
1368
|
+
`);
|
|
1369
|
+
};
|
|
1370
|
+
var u2 = {
|
|
1371
|
+
light: unicodeOr("\u2500", "-"),
|
|
1372
|
+
heavy: unicodeOr("\u2501", "="),
|
|
1373
|
+
block: unicodeOr("\u2588", "#")
|
|
1374
|
+
};
|
|
1375
|
+
var c = (e, a2) => e.includes(`
|
|
1376
|
+
`) ? e.split(`
|
|
1377
|
+
`).map((t2) => a2(t2)).join(`
|
|
1378
|
+
`) : a2(e);
|
|
1379
|
+
var select = (e) => {
|
|
1380
|
+
const a2 = (t2, d) => {
|
|
1381
|
+
const s = t2.label ?? String(t2.value);
|
|
1382
|
+
switch (d) {
|
|
1383
|
+
case "disabled":
|
|
1384
|
+
return `${(0, import_node_util2.styleText)("gray", S_RADIO_INACTIVE)} ${c(s, (n2) => (0, import_node_util2.styleText)("gray", n2))}${t2.hint ? ` ${(0, import_node_util2.styleText)("dim", `(${t2.hint ?? "disabled"})`)}` : ""}`;
|
|
1385
|
+
case "selected":
|
|
1386
|
+
return `${c(s, (n2) => (0, import_node_util2.styleText)("dim", n2))}`;
|
|
1387
|
+
case "active":
|
|
1388
|
+
return `${(0, import_node_util2.styleText)("green", S_RADIO_ACTIVE)} ${s}${t2.hint ? ` ${(0, import_node_util2.styleText)("dim", `(${t2.hint})`)}` : ""}`;
|
|
1389
|
+
case "cancelled":
|
|
1390
|
+
return `${c(s, (n2) => (0, import_node_util2.styleText)(["strikethrough", "dim"], n2))}`;
|
|
1391
|
+
default:
|
|
1392
|
+
return `${(0, import_node_util2.styleText)("dim", S_RADIO_INACTIVE)} ${c(s, (n2) => (0, import_node_util2.styleText)("dim", n2))}`;
|
|
1393
|
+
}
|
|
1394
|
+
};
|
|
1395
|
+
return new a({
|
|
1396
|
+
options: e.options,
|
|
1397
|
+
signal: e.signal,
|
|
1398
|
+
input: e.input,
|
|
1399
|
+
output: e.output,
|
|
1400
|
+
initialValue: e.initialValue,
|
|
1401
|
+
render() {
|
|
1402
|
+
const t2 = e.withGuide ?? settings.withGuide, d = `${symbol(this.state)} `, s = `${symbolBar(this.state)} `, n2 = wrapTextWithPrefix(
|
|
1403
|
+
e.output,
|
|
1404
|
+
e.message,
|
|
1405
|
+
s,
|
|
1406
|
+
d
|
|
1407
|
+
), u3 = `${t2 ? `${(0, import_node_util2.styleText)("gray", S_BAR)}
|
|
1408
|
+
` : ""}${n2}
|
|
1409
|
+
`;
|
|
1410
|
+
switch (this.state) {
|
|
1411
|
+
case "submit": {
|
|
1412
|
+
const r2 = t2 ? `${(0, import_node_util2.styleText)("gray", S_BAR)} ` : "", l2 = wrapTextWithPrefix(
|
|
1413
|
+
e.output,
|
|
1414
|
+
a2(this.options[this.cursor], "selected"),
|
|
1415
|
+
r2
|
|
1416
|
+
);
|
|
1417
|
+
return `${u3}${l2}`;
|
|
1418
|
+
}
|
|
1419
|
+
case "cancel": {
|
|
1420
|
+
const r2 = t2 ? `${(0, import_node_util2.styleText)("gray", S_BAR)} ` : "", l2 = wrapTextWithPrefix(
|
|
1421
|
+
e.output,
|
|
1422
|
+
a2(this.options[this.cursor], "cancelled"),
|
|
1423
|
+
r2
|
|
1424
|
+
);
|
|
1425
|
+
return `${u3}${l2}${t2 ? `
|
|
1426
|
+
${(0, import_node_util2.styleText)("gray", S_BAR)}` : ""}`;
|
|
1427
|
+
}
|
|
1428
|
+
default: {
|
|
1429
|
+
const r2 = t2 ? `${(0, import_node_util2.styleText)("cyan", S_BAR)} ` : "", l2 = t2 ? (0, import_node_util2.styleText)("cyan", S_BAR_END) : "", g = u3.split(`
|
|
1430
|
+
`).length, h2 = t2 ? 2 : 1;
|
|
1431
|
+
return `${u3}${r2}${limitOptions({
|
|
1432
|
+
output: e.output,
|
|
1433
|
+
cursor: this.cursor,
|
|
1434
|
+
options: this.options,
|
|
1435
|
+
maxItems: e.maxItems,
|
|
1436
|
+
columnPadding: r2.length,
|
|
1437
|
+
rowPadding: g + h2,
|
|
1438
|
+
style: (p, b) => a2(p, p.disabled ? "disabled" : b ? "active" : "inactive")
|
|
1439
|
+
}).join(`
|
|
1440
|
+
${r2}`)}
|
|
1441
|
+
${l2}
|
|
1442
|
+
`;
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
}).prompt();
|
|
1447
|
+
};
|
|
1448
|
+
var i = `${(0, import_node_util2.styleText)("gray", S_BAR)} `;
|
|
423
1449
|
|
|
424
1450
|
// src/app.ts
|
|
425
1451
|
var import_node_module = __toESM(require("module"));
|
|
426
|
-
var
|
|
1452
|
+
var import_node_path4 = require("path");
|
|
427
1453
|
|
|
428
1454
|
// src/loader/loader.ts
|
|
429
|
-
var
|
|
430
|
-
var
|
|
431
|
-
var
|
|
432
|
-
var import_node_process = require("process");
|
|
1455
|
+
var import_node_fs2 = require("fs");
|
|
1456
|
+
var import_node_path2 = require("path");
|
|
1457
|
+
var import_node_process3 = require("process");
|
|
433
1458
|
|
|
434
1459
|
// src/config/schema.ts
|
|
435
1460
|
var import_typebox = require("@sinclair/typebox");
|
|
@@ -457,14 +1482,14 @@ var assertES5 = async (unregister) => {
|
|
|
457
1482
|
if ("errors" in e && Array.isArray(e.errors) && e.errors.length > 0) {
|
|
458
1483
|
const es5Error = e.errors.filter((it) => it.text?.includes(`("es5") is not supported yet`)).length > 0;
|
|
459
1484
|
if (es5Error) {
|
|
460
|
-
|
|
1485
|
+
log.error(
|
|
461
1486
|
`Please change compilerOptions.target from 'es5' to 'es6' or above in your tsconfig.json`
|
|
462
1487
|
);
|
|
463
|
-
(0,
|
|
1488
|
+
(0, import_node_process3.exit)(1);
|
|
464
1489
|
}
|
|
465
1490
|
}
|
|
466
|
-
|
|
467
|
-
(0,
|
|
1491
|
+
log.error(e);
|
|
1492
|
+
(0, import_node_process3.exit)(1);
|
|
468
1493
|
}
|
|
469
1494
|
};
|
|
470
1495
|
var safeRegister = async () => {
|
|
@@ -484,10 +1509,10 @@ var safeRegister = async () => {
|
|
|
484
1509
|
await assertES5(res.unregister);
|
|
485
1510
|
return res;
|
|
486
1511
|
};
|
|
487
|
-
var findConfigPath = (cwd = (0,
|
|
1512
|
+
var findConfigPath = (cwd = (0, import_node_path2.resolve)()) => {
|
|
488
1513
|
for (const name of ["giri.config.ts", "giri.config.js"]) {
|
|
489
|
-
const path = (0,
|
|
490
|
-
if ((0,
|
|
1514
|
+
const path = (0, import_node_path2.resolve)(cwd, name);
|
|
1515
|
+
if ((0, import_node_fs2.existsSync)(path)) {
|
|
491
1516
|
return path;
|
|
492
1517
|
}
|
|
493
1518
|
}
|
|
@@ -498,8 +1523,8 @@ var load = async (opts = {}) => {
|
|
|
498
1523
|
if (opts.throwOnError) {
|
|
499
1524
|
throw new Error(message);
|
|
500
1525
|
}
|
|
501
|
-
|
|
502
|
-
(0,
|
|
1526
|
+
log.error(message);
|
|
1527
|
+
(0, import_node_process3.exit)(1);
|
|
503
1528
|
};
|
|
504
1529
|
const path = findConfigPath();
|
|
505
1530
|
if (!path) {
|
|
@@ -518,7 +1543,7 @@ var load = async (opts = {}) => {
|
|
|
518
1543
|
const messages = [...import_value.Value.Errors(configSchema, content)].map((error) => error.message);
|
|
519
1544
|
if (!opts.throwOnError) {
|
|
520
1545
|
for (const message of messages) {
|
|
521
|
-
|
|
1546
|
+
log.error(message);
|
|
522
1547
|
}
|
|
523
1548
|
}
|
|
524
1549
|
fail(messages.join("\n"));
|
|
@@ -527,9 +1552,9 @@ var load = async (opts = {}) => {
|
|
|
527
1552
|
};
|
|
528
1553
|
|
|
529
1554
|
// src/routes.ts
|
|
530
|
-
var
|
|
1555
|
+
var import_node_fs3 = require("fs");
|
|
531
1556
|
var import_promises = require("fs/promises");
|
|
532
|
-
var
|
|
1557
|
+
var import_node_path3 = require("path");
|
|
533
1558
|
var import_tinyglobby = require("tinyglobby");
|
|
534
1559
|
var import_typescript = __toESM(require("typescript"));
|
|
535
1560
|
var METHOD_ORDER = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"];
|
|
@@ -537,7 +1562,7 @@ var METHOD_FROM_FILE = new Map(
|
|
|
537
1562
|
METHOD_ORDER.map((method) => [`+${method.toLowerCase()}`, method])
|
|
538
1563
|
);
|
|
539
1564
|
function normalizeSlashes(path) {
|
|
540
|
-
return path.split(
|
|
1565
|
+
return path.split(import_node_path3.sep).join("/");
|
|
541
1566
|
}
|
|
542
1567
|
function isRouteSourceFile(fileName) {
|
|
543
1568
|
return /\.(?:[cm]?[jt]s|[jt]sx)$/.test(fileName) && !fileName.endsWith(".d.ts");
|
|
@@ -628,7 +1653,7 @@ function hasNamedHandleExport(source) {
|
|
|
628
1653
|
function parseSource(file) {
|
|
629
1654
|
return import_typescript.default.createSourceFile(
|
|
630
1655
|
file,
|
|
631
|
-
(0,
|
|
1656
|
+
(0, import_node_fs3.readFileSync)(file, "utf8"),
|
|
632
1657
|
import_typescript.default.ScriptTarget.Latest,
|
|
633
1658
|
true
|
|
634
1659
|
);
|
|
@@ -665,8 +1690,8 @@ function sharedFileIn(dir, cache) {
|
|
|
665
1690
|
return cache.get(dir);
|
|
666
1691
|
}
|
|
667
1692
|
for (const ext of ["ts", "tsx", "js", "jsx", "mjs", "cjs", "mts", "cts"]) {
|
|
668
|
-
const file = (0,
|
|
669
|
-
if ((0,
|
|
1693
|
+
const file = (0, import_node_path3.join)(dir, `+shared.${ext}`);
|
|
1694
|
+
if ((0, import_node_fs3.existsSync)(file)) {
|
|
670
1695
|
cache?.set(dir, file);
|
|
671
1696
|
return file;
|
|
672
1697
|
}
|
|
@@ -675,7 +1700,7 @@ function sharedFileIn(dir, cache) {
|
|
|
675
1700
|
return void 0;
|
|
676
1701
|
}
|
|
677
1702
|
function physicalRouteSegments(routesDir, routeDir) {
|
|
678
|
-
const rel = (0,
|
|
1703
|
+
const rel = (0, import_node_path3.relative)(routesDir, routeDir);
|
|
679
1704
|
if (!rel) {
|
|
680
1705
|
return [];
|
|
681
1706
|
}
|
|
@@ -724,14 +1749,14 @@ function compareRoutes(left, right) {
|
|
|
724
1749
|
const leftRanks = segmentRanks(left.routeSegments);
|
|
725
1750
|
const rightRanks = segmentRanks(right.routeSegments);
|
|
726
1751
|
const shared = Math.min(leftRanks.length, rightRanks.length);
|
|
727
|
-
for (let
|
|
728
|
-
const
|
|
729
|
-
const b = rightRanks[
|
|
730
|
-
if (
|
|
731
|
-
return
|
|
1752
|
+
for (let i2 = 0; i2 < shared; i2++) {
|
|
1753
|
+
const a2 = leftRanks[i2];
|
|
1754
|
+
const b = rightRanks[i2];
|
|
1755
|
+
if (a2.rank !== b.rank) {
|
|
1756
|
+
return a2.rank - b.rank;
|
|
732
1757
|
}
|
|
733
|
-
if (
|
|
734
|
-
return
|
|
1758
|
+
if (a2.rank === 0 && a2.text !== b.text) {
|
|
1759
|
+
return a2.text.localeCompare(b.text);
|
|
735
1760
|
}
|
|
736
1761
|
}
|
|
737
1762
|
if (leftRanks.length !== rightRanks.length) {
|
|
@@ -757,14 +1782,14 @@ function pathFromSegments(segments) {
|
|
|
757
1782
|
};
|
|
758
1783
|
}
|
|
759
1784
|
async function scanRouteFolders(routesDir) {
|
|
760
|
-
if (!(0,
|
|
1785
|
+
if (!(0, import_node_fs3.existsSync)(routesDir)) {
|
|
761
1786
|
return [];
|
|
762
1787
|
}
|
|
763
1788
|
const folders = [routesDir];
|
|
764
1789
|
const walk = async (dir) => {
|
|
765
1790
|
for (const entry of await (0, import_promises.readdir)(dir, { withFileTypes: true })) {
|
|
766
1791
|
if (entry.isDirectory() && entry.name !== "node_modules") {
|
|
767
|
-
const full = (0,
|
|
1792
|
+
const full = (0, import_node_path3.join)(dir, entry.name);
|
|
768
1793
|
folders.push(full);
|
|
769
1794
|
await walk(full);
|
|
770
1795
|
}
|
|
@@ -781,13 +1806,13 @@ function sharedFilesForDir(routesDir, dir, cache) {
|
|
|
781
1806
|
const dirs = [routesDir];
|
|
782
1807
|
let current = routesDir;
|
|
783
1808
|
for (const segment of segments) {
|
|
784
|
-
current = (0,
|
|
1809
|
+
current = (0, import_node_path3.join)(current, segment);
|
|
785
1810
|
dirs.push(current);
|
|
786
1811
|
}
|
|
787
1812
|
return dirs.map((currentDir) => sharedFileIn(currentDir, cache)).filter((file) => Boolean(file));
|
|
788
1813
|
}
|
|
789
1814
|
async function scanRoutes(routesDir) {
|
|
790
|
-
if (!(0,
|
|
1815
|
+
if (!(0, import_node_fs3.existsSync)(routesDir)) {
|
|
791
1816
|
return [];
|
|
792
1817
|
}
|
|
793
1818
|
const files = await (0, import_tinyglobby.glob)("**/+*.{ts,tsx,js,jsx,mjs,cjs,mts,cts}", {
|
|
@@ -798,11 +1823,11 @@ async function scanRoutes(routesDir) {
|
|
|
798
1823
|
const routes = [];
|
|
799
1824
|
const sharedCache = /* @__PURE__ */ new Map();
|
|
800
1825
|
for (const file of files) {
|
|
801
|
-
const method = methodFromFile((0,
|
|
1826
|
+
const method = methodFromFile((0, import_node_path3.basename)(file));
|
|
802
1827
|
if (!method) {
|
|
803
1828
|
continue;
|
|
804
1829
|
}
|
|
805
|
-
const routeDir = (0,
|
|
1830
|
+
const routeDir = (0, import_node_path3.dirname)(file);
|
|
806
1831
|
const routeSegments = physicalRouteSegments(routesDir, routeDir);
|
|
807
1832
|
const { path, params } = pathFromSegments(routeSegments);
|
|
808
1833
|
routes.push({
|
|
@@ -914,7 +1939,7 @@ function aliasValues(value) {
|
|
|
914
1939
|
}
|
|
915
1940
|
function resolveAliasTarget(cwd, target, capture = "") {
|
|
916
1941
|
const replaced = target.includes("*") ? target.replaceAll("*", capture) : target;
|
|
917
|
-
return (0,
|
|
1942
|
+
return (0, import_node_path4.isAbsolute)(replaced) ? replaced : (0, import_node_path4.resolve)(cwd, replaced);
|
|
918
1943
|
}
|
|
919
1944
|
function matchAlias(request, key) {
|
|
920
1945
|
if (key.includes("*")) {
|
|
@@ -972,15 +1997,15 @@ function ensureGiriAliasResolver(outDir) {
|
|
|
972
1997
|
const moduleWithResolver = import_node_module.default;
|
|
973
1998
|
const originalResolveFilename = moduleWithResolver._resolveFilename;
|
|
974
1999
|
moduleWithResolver._resolveFilename = function resolveWithGiriInternalAlias(request, parent, isMain, options) {
|
|
975
|
-
const mapped = typeof request === "string" && request.startsWith(GIRI_ALIAS_PREFIX) && giriOutDir ? (0,
|
|
2000
|
+
const mapped = typeof request === "string" && request.startsWith(GIRI_ALIAS_PREFIX) && giriOutDir ? (0, import_node_path4.join)(giriOutDir, request.slice(GIRI_ALIAS_PREFIX.length)) : request;
|
|
976
2001
|
return originalResolveFilename.call(this, mapped, parent, isMain, options);
|
|
977
2002
|
};
|
|
978
2003
|
}
|
|
979
2004
|
function resolveGiriPaths(config, cwd = process.cwd()) {
|
|
980
2005
|
return {
|
|
981
|
-
cwd: (0,
|
|
982
|
-
routesDir: (0,
|
|
983
|
-
outDir: (0,
|
|
2006
|
+
cwd: (0, import_node_path4.resolve)(cwd),
|
|
2007
|
+
routesDir: (0, import_node_path4.resolve)(cwd, "src/routes"),
|
|
2008
|
+
outDir: (0, import_node_path4.resolve)(cwd, config.outDir ?? ".giri")
|
|
984
2009
|
};
|
|
985
2010
|
}
|
|
986
2011
|
async function buildGiriApp(config, options = {}) {
|
|
@@ -1063,59 +2088,59 @@ async function buildGiriApp(config, options = {}) {
|
|
|
1063
2088
|
}
|
|
1064
2089
|
|
|
1065
2090
|
// src/generator/sync.ts
|
|
1066
|
-
var
|
|
2091
|
+
var import_node_fs9 = require("fs");
|
|
1067
2092
|
var import_promises4 = require("fs/promises");
|
|
1068
|
-
var
|
|
2093
|
+
var import_node_path13 = require("path");
|
|
1069
2094
|
|
|
1070
2095
|
// src/generator/app-types.ts
|
|
1071
|
-
var
|
|
1072
|
-
var
|
|
2096
|
+
var import_node_fs5 = require("fs");
|
|
2097
|
+
var import_node_path6 = require("path");
|
|
1073
2098
|
|
|
1074
2099
|
// src/generator/util.ts
|
|
1075
|
-
var
|
|
2100
|
+
var import_node_fs4 = require("fs");
|
|
1076
2101
|
var import_promises2 = require("fs/promises");
|
|
1077
|
-
var
|
|
2102
|
+
var import_node_path5 = require("path");
|
|
1078
2103
|
var GENERATED_HEADER = "// Generated by giri sync. Do not edit.";
|
|
1079
2104
|
function slash(path) {
|
|
1080
|
-
return path.split(
|
|
2105
|
+
return path.split(import_node_path5.sep).join("/");
|
|
1081
2106
|
}
|
|
1082
2107
|
function importPath(fromFile, toFile) {
|
|
1083
|
-
let path = slash((0,
|
|
2108
|
+
let path = slash((0, import_node_path5.relative)((0, import_node_path5.dirname)(fromFile), toFile)).replace(/\.d\.ts$/, "");
|
|
1084
2109
|
if (!path.startsWith(".")) {
|
|
1085
2110
|
path = `./${path}`;
|
|
1086
2111
|
}
|
|
1087
2112
|
return path;
|
|
1088
2113
|
}
|
|
1089
2114
|
function relativeConfigPath(fromDir, toPath) {
|
|
1090
|
-
let path = slash((0,
|
|
2115
|
+
let path = slash((0, import_node_path5.relative)(fromDir, toPath));
|
|
1091
2116
|
if (!path.startsWith(".")) {
|
|
1092
2117
|
path = `./${path}`;
|
|
1093
2118
|
}
|
|
1094
2119
|
return path;
|
|
1095
2120
|
}
|
|
1096
2121
|
function moduleSpecifier(fromDir, target) {
|
|
1097
|
-
let path = slash((0,
|
|
2122
|
+
let path = slash((0, import_node_path5.relative)(fromDir, target)).replace(/\.(?:[cm]?[jt]sx?)$/, "");
|
|
1098
2123
|
if (!path.startsWith(".")) {
|
|
1099
2124
|
path = `./${path}`;
|
|
1100
2125
|
}
|
|
1101
2126
|
return path;
|
|
1102
2127
|
}
|
|
1103
2128
|
function typeFilePath(paths, routeDir) {
|
|
1104
|
-
const sourceDir = (0,
|
|
1105
|
-
return (0,
|
|
2129
|
+
const sourceDir = (0, import_node_path5.relative)(paths.cwd, routeDir);
|
|
2130
|
+
return (0, import_node_path5.join)(paths.outDir, "types", sourceDir, "$types.d.ts");
|
|
1106
2131
|
}
|
|
1107
2132
|
function assertSafeOutDir(paths) {
|
|
1108
|
-
const rel = (0,
|
|
1109
|
-
if (!rel || rel.startsWith("..") || rel.includes(`..${
|
|
2133
|
+
const rel = (0, import_node_path5.relative)(paths.cwd, paths.outDir);
|
|
2134
|
+
if (!rel || rel.startsWith("..") || rel.includes(`..${import_node_path5.sep}`)) {
|
|
1110
2135
|
throw new Error(`Refusing to sync outside the project root: ${paths.outDir}`);
|
|
1111
2136
|
}
|
|
1112
2137
|
}
|
|
1113
2138
|
var writeCache = /* @__PURE__ */ new Map();
|
|
1114
2139
|
async function writeGenerated(path, content) {
|
|
1115
|
-
if (writeCache.get(path) === content && (0,
|
|
2140
|
+
if (writeCache.get(path) === content && (0, import_node_fs4.existsSync)(path)) {
|
|
1116
2141
|
return;
|
|
1117
2142
|
}
|
|
1118
|
-
await (0, import_promises2.mkdir)((0,
|
|
2143
|
+
await (0, import_promises2.mkdir)((0, import_node_path5.dirname)(path), { recursive: true });
|
|
1119
2144
|
await (0, import_promises2.writeFile)(path, content);
|
|
1120
2145
|
writeCache.set(path, content);
|
|
1121
2146
|
}
|
|
@@ -1131,7 +2156,7 @@ async function pruneDir(dir, keep) {
|
|
|
1131
2156
|
return;
|
|
1132
2157
|
}
|
|
1133
2158
|
for (const entry of entries) {
|
|
1134
|
-
const full = (0,
|
|
2159
|
+
const full = (0, import_node_path5.join)(dir, entry.name);
|
|
1135
2160
|
if (entry.isDirectory()) {
|
|
1136
2161
|
await pruneDir(full, keep);
|
|
1137
2162
|
await (0, import_promises2.rmdir)(full).catch(() => {
|
|
@@ -1147,28 +2172,28 @@ async function pruneDir(dir, keep) {
|
|
|
1147
2172
|
var MAIN_EXTENSIONS = ["ts", "tsx", "mts", "cts", "js", "jsx", "mjs", "cjs"];
|
|
1148
2173
|
function findMainFile(cwd) {
|
|
1149
2174
|
for (const ext of MAIN_EXTENSIONS) {
|
|
1150
|
-
const file = (0,
|
|
1151
|
-
if ((0,
|
|
2175
|
+
const file = (0, import_node_path6.join)(cwd, "src", `main.${ext}`);
|
|
2176
|
+
if ((0, import_node_fs5.existsSync)(file)) {
|
|
1152
2177
|
return file;
|
|
1153
2178
|
}
|
|
1154
2179
|
}
|
|
1155
2180
|
return void 0;
|
|
1156
2181
|
}
|
|
1157
2182
|
function moduleSpecifier2(fromDir, target) {
|
|
1158
|
-
let path = slash((0,
|
|
2183
|
+
let path = slash((0, import_node_path6.relative)(fromDir, target)).replace(/\.(?:[cm]?[jt]sx?)$/, "");
|
|
1159
2184
|
if (!path.startsWith(".")) {
|
|
1160
2185
|
path = `./${path}`;
|
|
1161
2186
|
}
|
|
1162
2187
|
return path;
|
|
1163
2188
|
}
|
|
1164
2189
|
async function writeAppTypes(paths) {
|
|
1165
|
-
const file = (0,
|
|
2190
|
+
const file = (0, import_node_path6.join)(paths.outDir, "types", "app.d.ts");
|
|
1166
2191
|
const mainFile = findMainFile(paths.cwd);
|
|
1167
2192
|
if (!mainFile) {
|
|
1168
2193
|
await writeGenerated(file, [GENERATED_HEADER, "export {};", ""].join("\n"));
|
|
1169
2194
|
return;
|
|
1170
2195
|
}
|
|
1171
|
-
const spec = moduleSpecifier2((0,
|
|
2196
|
+
const spec = moduleSpecifier2((0, import_node_path6.join)(paths.outDir, "types"), mainFile);
|
|
1172
2197
|
await writeGenerated(
|
|
1173
2198
|
file,
|
|
1174
2199
|
[
|
|
@@ -1191,7 +2216,7 @@ async function writeAppTypes(paths) {
|
|
|
1191
2216
|
}
|
|
1192
2217
|
|
|
1193
2218
|
// src/generator/manifest.ts
|
|
1194
|
-
var
|
|
2219
|
+
var import_node_path7 = require("path");
|
|
1195
2220
|
async function writeManifest(paths, routes, data = {}) {
|
|
1196
2221
|
const manifest = {
|
|
1197
2222
|
version: 1,
|
|
@@ -1202,10 +2227,10 @@ async function writeManifest(paths, routes, data = {}) {
|
|
|
1202
2227
|
return {
|
|
1203
2228
|
method: route.method,
|
|
1204
2229
|
path: route.path,
|
|
1205
|
-
file: slash((0,
|
|
2230
|
+
file: slash((0, import_node_path7.relative)(paths.cwd, route.file)),
|
|
1206
2231
|
params: route.params,
|
|
1207
|
-
shared: route.sharedFiles.map((file) => slash((0,
|
|
1208
|
-
types: slash((0,
|
|
2232
|
+
shared: route.sharedFiles.map((file) => slash((0, import_node_path7.relative)(paths.cwd, file))),
|
|
2233
|
+
types: slash((0, import_node_path7.relative)(paths.cwd, typeFilePath(paths, route.routeDir))),
|
|
1209
2234
|
...data.hiddenFiles?.has(route.file) ? { hidden: true } : {},
|
|
1210
2235
|
...input ? { input } : {},
|
|
1211
2236
|
...security && security.security.length > 0 ? { security: security.security } : {},
|
|
@@ -1214,12 +2239,12 @@ async function writeManifest(paths, routes, data = {}) {
|
|
|
1214
2239
|
};
|
|
1215
2240
|
})
|
|
1216
2241
|
};
|
|
1217
|
-
await writeJson((0,
|
|
2242
|
+
await writeJson((0, import_node_path7.join)(paths.outDir, "manifest.json"), manifest);
|
|
1218
2243
|
}
|
|
1219
2244
|
|
|
1220
2245
|
// src/generator/openapi.ts
|
|
1221
|
-
var
|
|
1222
|
-
var
|
|
2246
|
+
var import_node_fs6 = require("fs");
|
|
2247
|
+
var import_node_path8 = require("path");
|
|
1223
2248
|
var REASON = {
|
|
1224
2249
|
200: "OK",
|
|
1225
2250
|
201: "Created",
|
|
@@ -1303,10 +2328,10 @@ function queryParameters(query) {
|
|
|
1303
2328
|
}));
|
|
1304
2329
|
}
|
|
1305
2330
|
function readProjectInfo(cwd) {
|
|
1306
|
-
const file = (0,
|
|
1307
|
-
if ((0,
|
|
2331
|
+
const file = (0, import_node_path8.join)(cwd, "package.json");
|
|
2332
|
+
if ((0, import_node_fs6.existsSync)(file)) {
|
|
1308
2333
|
try {
|
|
1309
|
-
const pkg = JSON.parse((0,
|
|
2334
|
+
const pkg = JSON.parse((0, import_node_fs6.readFileSync)(file, "utf8"));
|
|
1310
2335
|
return { title: pkg.name ?? "giri API", version: pkg.version ?? "0.0.0" };
|
|
1311
2336
|
} catch {
|
|
1312
2337
|
}
|
|
@@ -1398,11 +2423,11 @@ function buildOpenApiDocument(paths, routes, data = {}) {
|
|
|
1398
2423
|
return document;
|
|
1399
2424
|
}
|
|
1400
2425
|
async function writeOpenApi(paths, routes, data = {}) {
|
|
1401
|
-
await writeJson((0,
|
|
2426
|
+
await writeJson((0, import_node_path8.join)(paths.outDir, "openapi.json"), buildOpenApiDocument(paths, routes, data));
|
|
1402
2427
|
}
|
|
1403
2428
|
|
|
1404
2429
|
// src/generator/param-types.ts
|
|
1405
|
-
var
|
|
2430
|
+
var import_node_path9 = require("path");
|
|
1406
2431
|
function paramsType(params) {
|
|
1407
2432
|
if (params.length === 0) {
|
|
1408
2433
|
return "{}";
|
|
@@ -1426,17 +2451,17 @@ function middlewareInputType(typesDir, sharedFile) {
|
|
|
1426
2451
|
}
|
|
1427
2452
|
function ownSharedFile(dir, sharedFiles) {
|
|
1428
2453
|
for (let index = sharedFiles.length - 1; index >= 0; index -= 1) {
|
|
1429
|
-
if ((0,
|
|
2454
|
+
if ((0, import_node_path9.dirname)(sharedFiles[index]) === dir) {
|
|
1430
2455
|
return sharedFiles[index];
|
|
1431
2456
|
}
|
|
1432
2457
|
}
|
|
1433
2458
|
return void 0;
|
|
1434
2459
|
}
|
|
1435
2460
|
function varsType(paths, file, dir, sharedFiles) {
|
|
1436
|
-
const typesDir = (0,
|
|
2461
|
+
const typesDir = (0, import_node_path9.dirname)(file);
|
|
1437
2462
|
const parts = [];
|
|
1438
2463
|
if (dir !== paths.routesDir) {
|
|
1439
|
-
parts.push(`import(${JSON.stringify(importPath(file, typeFilePath(paths, (0,
|
|
2464
|
+
parts.push(`import(${JSON.stringify(importPath(file, typeFilePath(paths, (0, import_node_path9.dirname)(dir))))}).Vars`);
|
|
1440
2465
|
}
|
|
1441
2466
|
const ownShared = ownSharedFile(dir, sharedFiles);
|
|
1442
2467
|
if (ownShared) {
|
|
@@ -1445,10 +2470,10 @@ function varsType(paths, file, dir, sharedFiles) {
|
|
|
1445
2470
|
return parts.length > 0 ? parts.join("\n & ") : "{}";
|
|
1446
2471
|
}
|
|
1447
2472
|
function inputType(paths, file, dir, sharedFiles) {
|
|
1448
|
-
const typesDir = (0,
|
|
2473
|
+
const typesDir = (0, import_node_path9.dirname)(file);
|
|
1449
2474
|
const parts = [];
|
|
1450
2475
|
if (dir !== paths.routesDir) {
|
|
1451
|
-
parts.push(`import(${JSON.stringify(importPath(file, typeFilePath(paths, (0,
|
|
2476
|
+
parts.push(`import(${JSON.stringify(importPath(file, typeFilePath(paths, (0, import_node_path9.dirname)(dir))))}).Input`);
|
|
1452
2477
|
}
|
|
1453
2478
|
const ownShared = ownSharedFile(dir, sharedFiles);
|
|
1454
2479
|
if (ownShared) {
|
|
@@ -1471,7 +2496,7 @@ function methodExports(typesDir, verbs) {
|
|
|
1471
2496
|
async function writeParamTypes(paths, folders) {
|
|
1472
2497
|
await Promise.all(folders.map(({ dir, params, sharedFiles, verbs }) => {
|
|
1473
2498
|
const file = typeFilePath(paths, dir);
|
|
1474
|
-
const typesDir = (0,
|
|
2499
|
+
const typesDir = (0, import_node_path9.dirname)(file);
|
|
1475
2500
|
const lines = [
|
|
1476
2501
|
GENERATED_HEADER,
|
|
1477
2502
|
`export type Params = ${paramsType(params)};`,
|
|
@@ -1492,7 +2517,7 @@ async function writeParamTypes(paths, folders) {
|
|
|
1492
2517
|
}
|
|
1493
2518
|
|
|
1494
2519
|
// src/generator/route-meta.ts
|
|
1495
|
-
var
|
|
2520
|
+
var import_node_fs7 = require("fs");
|
|
1496
2521
|
var import_typescript2 = __toESM(require("typescript"));
|
|
1497
2522
|
|
|
1498
2523
|
// src/generator/inputs.ts
|
|
@@ -1607,19 +2632,19 @@ function parseRouteOpenApi(value) {
|
|
|
1607
2632
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1608
2633
|
return void 0;
|
|
1609
2634
|
}
|
|
1610
|
-
const
|
|
2635
|
+
const o2 = value;
|
|
1611
2636
|
const parsed = {};
|
|
1612
|
-
if ("hidden" in
|
|
1613
|
-
parsed.hidden = Boolean(
|
|
2637
|
+
if ("hidden" in o2) {
|
|
2638
|
+
parsed.hidden = Boolean(o2.hidden);
|
|
1614
2639
|
}
|
|
1615
|
-
const tags = pick(StringArraySchema,
|
|
2640
|
+
const tags = pick(StringArraySchema, o2.tags);
|
|
1616
2641
|
if (tags) {
|
|
1617
2642
|
parsed.tags = tags;
|
|
1618
2643
|
}
|
|
1619
|
-
parsed.summary = pick(StringSchema,
|
|
1620
|
-
parsed.description = pick(StringSchema,
|
|
1621
|
-
parsed.operationId = pick(StringSchema,
|
|
1622
|
-
parsed.deprecated = pick(BooleanSchema,
|
|
2644
|
+
parsed.summary = pick(StringSchema, o2.summary);
|
|
2645
|
+
parsed.description = pick(StringSchema, o2.description);
|
|
2646
|
+
parsed.operationId = pick(StringSchema, o2.operationId);
|
|
2647
|
+
parsed.deprecated = pick(BooleanSchema, o2.deprecated);
|
|
1623
2648
|
return parsed;
|
|
1624
2649
|
}
|
|
1625
2650
|
|
|
@@ -1802,7 +2827,7 @@ function parseStaticOpenApi(expression) {
|
|
|
1802
2827
|
function readStaticModuleMeta(file) {
|
|
1803
2828
|
let source;
|
|
1804
2829
|
try {
|
|
1805
|
-
source = import_typescript2.default.createSourceFile(file, (0,
|
|
2830
|
+
source = import_typescript2.default.createSourceFile(file, (0, import_node_fs7.readFileSync)(file, "utf8"), import_typescript2.default.ScriptTarget.Latest, true);
|
|
1806
2831
|
} catch {
|
|
1807
2832
|
return void 0;
|
|
1808
2833
|
}
|
|
@@ -2098,9 +3123,9 @@ async function extractRouteMeta(config, paths, routes) {
|
|
|
2098
3123
|
}
|
|
2099
3124
|
|
|
2100
3125
|
// src/generator/route-types.ts
|
|
2101
|
-
var
|
|
3126
|
+
var import_node_path10 = require("path");
|
|
2102
3127
|
async function writeRouteTypes(paths, routes) {
|
|
2103
|
-
const file = (0,
|
|
3128
|
+
const file = (0, import_node_path10.join)(paths.outDir, "routes.d.ts");
|
|
2104
3129
|
const lines = [
|
|
2105
3130
|
GENERATED_HEADER,
|
|
2106
3131
|
"export interface RouteParams {"
|
|
@@ -2118,19 +3143,19 @@ async function writeRouteTypes(paths, routes) {
|
|
|
2118
3143
|
}
|
|
2119
3144
|
|
|
2120
3145
|
// src/generator/tsconfig.ts
|
|
2121
|
-
var
|
|
3146
|
+
var import_node_path11 = require("path");
|
|
2122
3147
|
function normalizeAlias(alias, paths) {
|
|
2123
3148
|
const result = {};
|
|
2124
3149
|
for (const [key, value] of Object.entries(alias ?? {})) {
|
|
2125
3150
|
const targets = Array.isArray(value) ? value : [value];
|
|
2126
3151
|
result[key] = targets.map(
|
|
2127
|
-
(target) => relativeConfigPath(paths.outDir, (0,
|
|
3152
|
+
(target) => relativeConfigPath(paths.outDir, (0, import_node_path11.resolve)(paths.cwd, target))
|
|
2128
3153
|
);
|
|
2129
3154
|
}
|
|
2130
3155
|
return result;
|
|
2131
3156
|
}
|
|
2132
3157
|
async function writeTsConfig(paths, config) {
|
|
2133
|
-
const file = (0,
|
|
3158
|
+
const file = (0, import_node_path11.join)(paths.outDir, "tsconfig.json");
|
|
2134
3159
|
await writeJson(file, {
|
|
2135
3160
|
compilerOptions: {
|
|
2136
3161
|
rootDirs: [
|
|
@@ -2149,8 +3174,8 @@ async function writeTsConfig(paths, config) {
|
|
|
2149
3174
|
]
|
|
2150
3175
|
},
|
|
2151
3176
|
include: [
|
|
2152
|
-
relativeConfigPath(paths.outDir, (0,
|
|
2153
|
-
relativeConfigPath(paths.outDir, (0,
|
|
3177
|
+
relativeConfigPath(paths.outDir, (0, import_node_path11.join)(paths.cwd, "src")),
|
|
3178
|
+
relativeConfigPath(paths.outDir, (0, import_node_path11.join)(paths.cwd, "giri.config.ts")),
|
|
2154
3179
|
"./types/**/*.d.ts"
|
|
2155
3180
|
]
|
|
2156
3181
|
});
|
|
@@ -2158,9 +3183,9 @@ async function writeTsConfig(paths, config) {
|
|
|
2158
3183
|
|
|
2159
3184
|
// src/generator/cache.ts
|
|
2160
3185
|
var import_node_crypto = require("crypto");
|
|
2161
|
-
var
|
|
3186
|
+
var import_node_fs8 = require("fs");
|
|
2162
3187
|
var import_promises3 = require("fs/promises");
|
|
2163
|
-
var
|
|
3188
|
+
var import_node_path12 = require("path");
|
|
2164
3189
|
var import_tinyglobby2 = require("tinyglobby");
|
|
2165
3190
|
var CACHE_VERSION = 1;
|
|
2166
3191
|
var SYNC_CACHE_NAME = ".sync-cache.json";
|
|
@@ -2169,7 +3194,7 @@ function stableConfig(config) {
|
|
|
2169
3194
|
return { alias, outDir: config.outDir ?? ".giri" };
|
|
2170
3195
|
}
|
|
2171
3196
|
async function syncFingerprint(config, paths) {
|
|
2172
|
-
const outRelative = slash((0,
|
|
3197
|
+
const outRelative = slash((0, import_node_path12.relative)(paths.cwd, paths.outDir));
|
|
2173
3198
|
const ignore = ["**/node_modules/**", "**/.git/**"];
|
|
2174
3199
|
if (outRelative && !outRelative.startsWith("..")) {
|
|
2175
3200
|
ignore.push(`${outRelative}/**`);
|
|
@@ -2198,18 +3223,18 @@ async function syncFingerprint(config, paths) {
|
|
|
2198
3223
|
hash.update("\0");
|
|
2199
3224
|
hash.update(slash(file));
|
|
2200
3225
|
hash.update("\0");
|
|
2201
|
-
hash.update(await (0, import_promises3.readFile)((0,
|
|
3226
|
+
hash.update(await (0, import_promises3.readFile)((0, import_node_path12.resolve)(paths.cwd, file)));
|
|
2202
3227
|
}
|
|
2203
3228
|
return hash.digest("hex");
|
|
2204
3229
|
}
|
|
2205
3230
|
function cachePath(paths) {
|
|
2206
|
-
return (0,
|
|
3231
|
+
return (0, import_node_path12.join)(paths.outDir, SYNC_CACHE_NAME);
|
|
2207
3232
|
}
|
|
2208
3233
|
function serializePath(paths, file) {
|
|
2209
|
-
return slash((0,
|
|
3234
|
+
return slash((0, import_node_path12.relative)(paths.cwd, file));
|
|
2210
3235
|
}
|
|
2211
3236
|
function deserializePath(paths, file) {
|
|
2212
|
-
return slash((0,
|
|
3237
|
+
return slash((0, import_node_path12.resolve)(paths.cwd, file.split("/").join(import_node_path12.sep)));
|
|
2213
3238
|
}
|
|
2214
3239
|
function serializeMap(paths, values) {
|
|
2215
3240
|
return [...values].map(([file, value]) => [serializePath(paths, file), value]);
|
|
@@ -2219,7 +3244,7 @@ function deserializeMap(paths, values) {
|
|
|
2219
3244
|
}
|
|
2220
3245
|
async function readSyncCache(paths, fingerprint) {
|
|
2221
3246
|
const file = cachePath(paths);
|
|
2222
|
-
if (!(0,
|
|
3247
|
+
if (!(0, import_node_fs8.existsSync)(file)) {
|
|
2223
3248
|
return void 0;
|
|
2224
3249
|
}
|
|
2225
3250
|
try {
|
|
@@ -2279,8 +3304,8 @@ async function extractResponses(paths, routes) {
|
|
|
2279
3304
|
try {
|
|
2280
3305
|
const { createSchemaProgram: createSchemaProgram2, extractRouteResponses: extractRouteResponses2 } = await Promise.resolve().then(() => (init_schema(), schema_exports));
|
|
2281
3306
|
const files = [...new Set(routes.map((route) => route.file))];
|
|
2282
|
-
const appTypes = (0,
|
|
2283
|
-
const roots = (0,
|
|
3307
|
+
const appTypes = (0, import_node_path13.join)(paths.outDir, "types", "app.d.ts");
|
|
3308
|
+
const roots = (0, import_node_fs9.existsSync)(appTypes) ? [...files, appTypes] : files;
|
|
2284
3309
|
const program = createSchemaProgram2(paths, roots);
|
|
2285
3310
|
for (const file of files) {
|
|
2286
3311
|
byFile.set(file, extractRouteResponses2(program, file));
|
|
@@ -2325,20 +3350,20 @@ async function extractMeta(config, paths, routes) {
|
|
|
2325
3350
|
async function syncProject(config, options = {}) {
|
|
2326
3351
|
const paths = resolveGiriPaths(config, options.cwd);
|
|
2327
3352
|
assertSafeOutDir(paths);
|
|
2328
|
-
const hadOutDir = (0,
|
|
3353
|
+
const hadOutDir = (0, import_node_fs9.existsSync)(paths.outDir);
|
|
2329
3354
|
const routes = await scanRoutes(paths.routesDir);
|
|
2330
3355
|
const folders = await typeFolders(paths, routes);
|
|
2331
3356
|
const fingerprint = await syncFingerprint(config, paths);
|
|
2332
3357
|
const cached = await readSyncCache(paths, fingerprint);
|
|
2333
3358
|
const generatedFiles = [
|
|
2334
|
-
(0,
|
|
2335
|
-
(0,
|
|
2336
|
-
(0,
|
|
2337
|
-
(0,
|
|
2338
|
-
(0,
|
|
3359
|
+
(0, import_node_path13.join)(paths.outDir, "tsconfig.json"),
|
|
3360
|
+
(0, import_node_path13.join)(paths.outDir, "manifest.json"),
|
|
3361
|
+
(0, import_node_path13.join)(paths.outDir, "openapi.json"),
|
|
3362
|
+
(0, import_node_path13.join)(paths.outDir, "routes.d.ts"),
|
|
3363
|
+
(0, import_node_path13.join)(paths.outDir, "types", "app.d.ts"),
|
|
2339
3364
|
...folders.map((folder) => typeFilePath(paths, folder.dir))
|
|
2340
3365
|
];
|
|
2341
|
-
if (cached && generatedFiles.every(
|
|
3366
|
+
if (cached && generatedFiles.every(import_node_fs9.existsSync)) {
|
|
2342
3367
|
return { paths, routes, folders, data: cached };
|
|
2343
3368
|
}
|
|
2344
3369
|
await (0, import_promises4.mkdir)(paths.outDir, { recursive: true });
|
|
@@ -2357,12 +3382,12 @@ async function syncProject(config, options = {}) {
|
|
|
2357
3382
|
await pruneDir(
|
|
2358
3383
|
paths.outDir,
|
|
2359
3384
|
/* @__PURE__ */ new Set([
|
|
2360
|
-
(0,
|
|
2361
|
-
(0,
|
|
2362
|
-
(0,
|
|
2363
|
-
(0,
|
|
2364
|
-
(0,
|
|
2365
|
-
(0,
|
|
3385
|
+
(0, import_node_path13.join)(paths.outDir, "tsconfig.json"),
|
|
3386
|
+
(0, import_node_path13.join)(paths.outDir, "manifest.json"),
|
|
3387
|
+
(0, import_node_path13.join)(paths.outDir, "openapi.json"),
|
|
3388
|
+
(0, import_node_path13.join)(paths.outDir, "routes.d.ts"),
|
|
3389
|
+
(0, import_node_path13.join)(paths.outDir, SYNC_CACHE_NAME),
|
|
3390
|
+
(0, import_node_path13.join)(paths.outDir, "types", "app.d.ts"),
|
|
2366
3391
|
...folders.map((folder) => typeFilePath(paths, folder.dir))
|
|
2367
3392
|
])
|
|
2368
3393
|
);
|
|
@@ -2371,30 +3396,30 @@ async function syncProject(config, options = {}) {
|
|
|
2371
3396
|
}
|
|
2372
3397
|
|
|
2373
3398
|
// src/generator/watch.ts
|
|
2374
|
-
var
|
|
2375
|
-
var
|
|
3399
|
+
var import_node_fs11 = require("fs");
|
|
3400
|
+
var import_node_path16 = require("path");
|
|
2376
3401
|
|
|
2377
3402
|
// src/loader/import-graph.ts
|
|
2378
|
-
var
|
|
2379
|
-
var
|
|
3403
|
+
var import_node_fs10 = require("fs");
|
|
3404
|
+
var import_node_path14 = require("path");
|
|
2380
3405
|
var import_typescript6 = __toESM(require("typescript"));
|
|
2381
3406
|
var import_tinyglobby3 = require("tinyglobby");
|
|
2382
3407
|
var RESOLVE_EXTS = [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"];
|
|
2383
3408
|
var JS_EXT = /\.(?:c|m)?jsx?$/;
|
|
2384
|
-
var toSlash = (path) => path.split(
|
|
3409
|
+
var toSlash = (path) => path.split(import_node_path14.sep).join("/");
|
|
2385
3410
|
function probeFile(base) {
|
|
2386
|
-
if ((0,
|
|
3411
|
+
if ((0, import_node_fs10.existsSync)(base) && (0, import_node_fs10.statSync)(base).isFile()) {
|
|
2387
3412
|
return base;
|
|
2388
3413
|
}
|
|
2389
3414
|
for (const ext of RESOLVE_EXTS) {
|
|
2390
3415
|
const candidate = base + ext;
|
|
2391
|
-
if ((0,
|
|
3416
|
+
if ((0, import_node_fs10.existsSync)(candidate)) {
|
|
2392
3417
|
return candidate;
|
|
2393
3418
|
}
|
|
2394
3419
|
}
|
|
2395
3420
|
for (const ext of RESOLVE_EXTS) {
|
|
2396
|
-
const candidate = (0,
|
|
2397
|
-
if ((0,
|
|
3421
|
+
const candidate = (0, import_node_path14.join)(base, `index${ext}`);
|
|
3422
|
+
if ((0, import_node_fs10.existsSync)(candidate)) {
|
|
2398
3423
|
return candidate;
|
|
2399
3424
|
}
|
|
2400
3425
|
}
|
|
@@ -2403,7 +3428,7 @@ function probeFile(base) {
|
|
|
2403
3428
|
function resolveSpecifier(specifier, fromFile, alias, cwd) {
|
|
2404
3429
|
let target;
|
|
2405
3430
|
if (specifier.startsWith(".")) {
|
|
2406
|
-
target = (0,
|
|
3431
|
+
target = (0, import_node_path14.resolve)((0, import_node_path14.dirname)(fromFile), specifier);
|
|
2407
3432
|
} else {
|
|
2408
3433
|
const aliased = resolveAliasRequest(specifier, alias, cwd);
|
|
2409
3434
|
if (aliased === void 0) {
|
|
@@ -2423,7 +3448,7 @@ function resolveSpecifier(specifier, fromFile, alias, cwd) {
|
|
|
2423
3448
|
function importSpecifiers(file) {
|
|
2424
3449
|
let source;
|
|
2425
3450
|
try {
|
|
2426
|
-
source = import_typescript6.default.createSourceFile(file, (0,
|
|
3451
|
+
source = import_typescript6.default.createSourceFile(file, (0, import_node_fs10.readFileSync)(file, "utf8"), import_typescript6.default.ScriptTarget.Latest, false);
|
|
2427
3452
|
} catch {
|
|
2428
3453
|
return [];
|
|
2429
3454
|
}
|
|
@@ -2447,9 +3472,9 @@ function importSpecifiers(file) {
|
|
|
2447
3472
|
return specifiers;
|
|
2448
3473
|
}
|
|
2449
3474
|
async function buildImportGraph(config, cwd) {
|
|
2450
|
-
const root = (0,
|
|
2451
|
-
const outDir = (0,
|
|
2452
|
-
const outRel = (0,
|
|
3475
|
+
const root = (0, import_node_path14.resolve)(cwd);
|
|
3476
|
+
const outDir = (0, import_node_path14.resolve)(root, config.outDir ?? ".giri") + import_node_path14.sep;
|
|
3477
|
+
const outRel = (0, import_node_path14.relative)(root, outDir).split(import_node_path14.sep).join("/").replace(/\/$/, "");
|
|
2453
3478
|
const files = await (0, import_tinyglobby3.glob)("**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}", {
|
|
2454
3479
|
cwd: root,
|
|
2455
3480
|
absolute: true,
|
|
@@ -2483,10 +3508,10 @@ async function buildImportGraph(config, cwd) {
|
|
|
2483
3508
|
}
|
|
2484
3509
|
|
|
2485
3510
|
// src/loader/module-loader.ts
|
|
2486
|
-
var
|
|
2487
|
-
var toSlash2 = (path) => path.split(
|
|
3511
|
+
var import_node_path15 = require("path");
|
|
3512
|
+
var toSlash2 = (path) => path.split(import_node_path15.sep).join("/");
|
|
2488
3513
|
var isProjectModule = (id, root) => {
|
|
2489
|
-
return id.startsWith(root) && !id.includes(`${
|
|
3514
|
+
return id.startsWith(root) && !id.includes(`${import_node_path15.sep}node_modules${import_node_path15.sep}`) && !id.includes(`${import_node_path15.sep}.giri${import_node_path15.sep}`);
|
|
2490
3515
|
};
|
|
2491
3516
|
var collectDependents = (graph, start) => {
|
|
2492
3517
|
const out = /* @__PURE__ */ new Set([start]);
|
|
@@ -2510,7 +3535,7 @@ var purgeModules = (files) => {
|
|
|
2510
3535
|
}
|
|
2511
3536
|
};
|
|
2512
3537
|
var purgeProjectModules = (cwd) => {
|
|
2513
|
-
const root = (0,
|
|
3538
|
+
const root = (0, import_node_path15.resolve)(cwd) + import_node_path15.sep;
|
|
2514
3539
|
for (const id of Object.keys(require.cache)) {
|
|
2515
3540
|
if (isProjectModule(id, root)) {
|
|
2516
3541
|
delete require.cache[id];
|
|
@@ -2518,9 +3543,9 @@ var purgeProjectModules = (cwd) => {
|
|
|
2518
3543
|
}
|
|
2519
3544
|
};
|
|
2520
3545
|
var purgeGeneratedModules = (outDir) => {
|
|
2521
|
-
const root = (0,
|
|
3546
|
+
const root = (0, import_node_path15.resolve)(outDir) + import_node_path15.sep;
|
|
2522
3547
|
for (const id of Object.keys(require.cache)) {
|
|
2523
|
-
if ((0,
|
|
3548
|
+
if ((0, import_node_path15.resolve)(id).startsWith(root)) {
|
|
2524
3549
|
delete require.cache[id];
|
|
2525
3550
|
}
|
|
2526
3551
|
}
|
|
@@ -2551,11 +3576,11 @@ function createWatchUpdater(config, initial) {
|
|
|
2551
3576
|
}
|
|
2552
3577
|
try {
|
|
2553
3578
|
const { createSchemaProgram: createSchemaProgram2, extractRouteResponses: extractRouteResponses2 } = await Promise.resolve().then(() => (init_schema(), schema_exports));
|
|
2554
|
-
const appTypes = (0,
|
|
3579
|
+
const appTypes = (0, import_node_path16.join)(paths.outDir, "types", "app.d.ts");
|
|
2555
3580
|
const files = affected.map((route) => route.file);
|
|
2556
3581
|
const program = createSchemaProgram2(
|
|
2557
3582
|
paths,
|
|
2558
|
-
(0,
|
|
3583
|
+
(0, import_node_fs11.existsSync)(appTypes) ? [...files, appTypes] : files
|
|
2559
3584
|
);
|
|
2560
3585
|
for (const route of affected) {
|
|
2561
3586
|
data.responsesByFile.set(
|
|
@@ -2596,12 +3621,12 @@ function createWatchUpdater(config, initial) {
|
|
|
2596
3621
|
if (!filename) {
|
|
2597
3622
|
return fullResync();
|
|
2598
3623
|
}
|
|
2599
|
-
const abs = (0,
|
|
3624
|
+
const abs = (0, import_node_path16.resolve)((0, import_node_path16.dirname)(paths.routesDir), filename);
|
|
2600
3625
|
const file = slash(abs);
|
|
2601
|
-
if (!(0,
|
|
3626
|
+
if (!(0, import_node_fs11.existsSync)(abs)) {
|
|
2602
3627
|
return fullResync();
|
|
2603
3628
|
}
|
|
2604
|
-
if ((0,
|
|
3629
|
+
if ((0, import_node_fs11.statSync)(abs).isDirectory()) {
|
|
2605
3630
|
return "skip";
|
|
2606
3631
|
}
|
|
2607
3632
|
assertSourceSyntax(abs);
|
|
@@ -2609,8 +3634,8 @@ function createWatchUpdater(config, initial) {
|
|
|
2609
3634
|
const isShared = routes.some(
|
|
2610
3635
|
(route) => route.sharedFiles.some((shared) => slash(shared) === file)
|
|
2611
3636
|
);
|
|
2612
|
-
const isMethodFile = /^\+(?:get|post|put|patch|delete|options|head)\.(?:[cm]?[jt]s|[jt]sx)$/i.test((0,
|
|
2613
|
-
const isNewRouteStructure = file.startsWith(`${slash(paths.routesDir)}/`) && /^\+(?:get|post|put|patch|delete|options|head|shared)\.(?:[cm]?[jt]s|[jt]sx)$/i.test((0,
|
|
3637
|
+
const isMethodFile = /^\+(?:get|post|put|patch|delete|options|head)\.(?:[cm]?[jt]s|[jt]sx)$/i.test((0, import_node_path16.basename)(file));
|
|
3638
|
+
const isNewRouteStructure = file.startsWith(`${slash(paths.routesDir)}/`) && /^\+(?:get|post|put|patch|delete|options|head|shared)\.(?:[cm]?[jt]s|[jt]sx)$/i.test((0, import_node_path16.basename)(file)) && !isRoute && !isShared;
|
|
2614
3639
|
if (isRoute || isNewRouteStructure && isMethodFile) {
|
|
2615
3640
|
assertRouteHandleExport(abs);
|
|
2616
3641
|
}
|
|
@@ -2646,20 +3671,20 @@ function createWatchUpdater(config, initial) {
|
|
|
2646
3671
|
}
|
|
2647
3672
|
|
|
2648
3673
|
// src/lifecycle.ts
|
|
2649
|
-
var
|
|
2650
|
-
var
|
|
3674
|
+
var import_node_fs12 = require("fs");
|
|
3675
|
+
var import_node_path17 = require("path");
|
|
2651
3676
|
var MAIN_EXTENSIONS2 = ["ts", "tsx", "mts", "cts", "js", "jsx", "mjs", "cjs"];
|
|
2652
3677
|
function resolveMainFile(cwd) {
|
|
2653
3678
|
for (const ext of MAIN_EXTENSIONS2) {
|
|
2654
|
-
const file = (0,
|
|
2655
|
-
if ((0,
|
|
3679
|
+
const file = (0, import_node_path17.join)(cwd, "src", `main.${ext}`);
|
|
3680
|
+
if ((0, import_node_fs12.existsSync)(file)) {
|
|
2656
3681
|
return file;
|
|
2657
3682
|
}
|
|
2658
3683
|
}
|
|
2659
3684
|
return void 0;
|
|
2660
3685
|
}
|
|
2661
3686
|
async function loadLifecycle(cwd = process.cwd()) {
|
|
2662
|
-
const file = resolveMainFile((0,
|
|
3687
|
+
const file = resolveMainFile((0, import_node_path17.resolve)(cwd));
|
|
2663
3688
|
if (!file) {
|
|
2664
3689
|
return {};
|
|
2665
3690
|
}
|
|
@@ -2714,7 +3739,7 @@ var highlight = (text) => color.green(text);
|
|
|
2714
3739
|
var muted = (text) => color.dim(text);
|
|
2715
3740
|
function timestamp() {
|
|
2716
3741
|
const now = /* @__PURE__ */ new Date();
|
|
2717
|
-
const pad = (
|
|
3742
|
+
const pad = (n2) => String(n2).padStart(2, "0");
|
|
2718
3743
|
return `${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`;
|
|
2719
3744
|
}
|
|
2720
3745
|
var TAG = "giri";
|
|
@@ -2823,9 +3848,9 @@ function parseFlags(args) {
|
|
|
2823
3848
|
return flags;
|
|
2824
3849
|
}
|
|
2825
3850
|
async function ensureGitignore(cwd) {
|
|
2826
|
-
const file = (0,
|
|
3851
|
+
const file = (0, import_node_path18.join)(cwd, ".gitignore");
|
|
2827
3852
|
const entry = ".giri";
|
|
2828
|
-
if (!(0,
|
|
3853
|
+
if (!(0, import_node_fs13.existsSync)(file)) {
|
|
2829
3854
|
await (0, import_promises5.writeFile)(file, `${entry}
|
|
2830
3855
|
`);
|
|
2831
3856
|
return;
|
|
@@ -2837,8 +3862,8 @@ async function ensureGitignore(cwd) {
|
|
|
2837
3862
|
}
|
|
2838
3863
|
}
|
|
2839
3864
|
async function ensureTsConfig(cwd) {
|
|
2840
|
-
const file = (0,
|
|
2841
|
-
if ((0,
|
|
3865
|
+
const file = (0, import_node_path18.join)(cwd, "tsconfig.json");
|
|
3866
|
+
if ((0, import_node_fs13.existsSync)(file)) {
|
|
2842
3867
|
return;
|
|
2843
3868
|
}
|
|
2844
3869
|
await (0, import_promises5.writeFile)(
|
|
@@ -2867,7 +3892,7 @@ async function ensureTsConfig(cwd) {
|
|
|
2867
3892
|
async function missingDeps(cwd, candidates) {
|
|
2868
3893
|
let pkg = {};
|
|
2869
3894
|
try {
|
|
2870
|
-
pkg = JSON.parse(await (0, import_promises5.readFile)((0,
|
|
3895
|
+
pkg = JSON.parse(await (0, import_promises5.readFile)((0, import_node_path18.join)(cwd, "package.json"), "utf8"));
|
|
2871
3896
|
} catch {
|
|
2872
3897
|
}
|
|
2873
3898
|
const present = /* @__PURE__ */ new Set();
|
|
@@ -2921,7 +3946,7 @@ async function selectAdapter(interactive) {
|
|
|
2921
3946
|
if (!interactive || ADAPTERS.length === 1) {
|
|
2922
3947
|
return ADAPTERS[0];
|
|
2923
3948
|
}
|
|
2924
|
-
const picked = await
|
|
3949
|
+
const picked = await select({
|
|
2925
3950
|
message: "Which backend adapter?",
|
|
2926
3951
|
initialValue: "hono",
|
|
2927
3952
|
options: ADAPTERS.map((adapter) => ({
|
|
@@ -2930,44 +3955,44 @@ async function selectAdapter(interactive) {
|
|
|
2930
3955
|
hint: adapter.hint
|
|
2931
3956
|
}))
|
|
2932
3957
|
});
|
|
2933
|
-
if (
|
|
3958
|
+
if (isCancel(picked)) {
|
|
2934
3959
|
return null;
|
|
2935
3960
|
}
|
|
2936
3961
|
return ADAPTERS.find((adapter) => adapter.value === picked) ?? null;
|
|
2937
3962
|
}
|
|
2938
3963
|
async function initProject(cwd, flags) {
|
|
2939
|
-
if (!(0,
|
|
3964
|
+
if (!(0, import_node_fs13.existsSync)((0, import_node_path18.join)(cwd, "package.json"))) {
|
|
2940
3965
|
throw new Error(
|
|
2941
3966
|
"No package.json found. Run `giri init` inside an existing project - set one up first (e.g. `npm init -y` and install typescript), then re-run."
|
|
2942
3967
|
);
|
|
2943
3968
|
}
|
|
2944
3969
|
const interactive = Boolean(process.stdout.isTTY) && !flags.yes;
|
|
2945
|
-
|
|
3970
|
+
intro("giri init");
|
|
2946
3971
|
let adapter;
|
|
2947
3972
|
if (flags.adapter) {
|
|
2948
3973
|
adapter = ADAPTERS.find((choice) => choice.value === flags.adapter) ?? null;
|
|
2949
3974
|
if (!adapter) {
|
|
2950
|
-
|
|
3975
|
+
cancel(`Unknown adapter "${flags.adapter}". Available: ${ADAPTERS.map((a2) => a2.value).join(", ")}.`);
|
|
2951
3976
|
return;
|
|
2952
3977
|
}
|
|
2953
3978
|
} else {
|
|
2954
3979
|
adapter = await selectAdapter(interactive);
|
|
2955
3980
|
if (!adapter) {
|
|
2956
|
-
|
|
3981
|
+
cancel("Cancelled.");
|
|
2957
3982
|
return;
|
|
2958
3983
|
}
|
|
2959
3984
|
}
|
|
2960
3985
|
if (!adapter.available) {
|
|
2961
|
-
|
|
3986
|
+
cancel(`The ${adapter.label} adapter isn't available yet - only Hono ships today.`);
|
|
2962
3987
|
return;
|
|
2963
3988
|
}
|
|
2964
|
-
const configPath = (0,
|
|
2965
|
-
if (!(0,
|
|
3989
|
+
const configPath = (0, import_node_path18.join)(cwd, "giri.config.ts");
|
|
3990
|
+
if (!(0, import_node_fs13.existsSync)(configPath)) {
|
|
2966
3991
|
await (0, import_promises5.writeFile)(configPath, configSource(adapter));
|
|
2967
3992
|
}
|
|
2968
|
-
const routePath = (0,
|
|
2969
|
-
if (!(0,
|
|
2970
|
-
await (0, import_promises5.mkdir)((0,
|
|
3993
|
+
const routePath = (0, import_node_path18.join)(cwd, "src", "routes", "+get.ts");
|
|
3994
|
+
if (!(0, import_node_fs13.existsSync)(routePath)) {
|
|
3995
|
+
await (0, import_promises5.mkdir)((0, import_node_path18.join)(cwd, "src", "routes"), { recursive: true });
|
|
2971
3996
|
await (0, import_promises5.writeFile)(
|
|
2972
3997
|
routePath,
|
|
2973
3998
|
[
|
|
@@ -2980,12 +4005,12 @@ async function initProject(cwd, flags) {
|
|
|
2980
4005
|
}
|
|
2981
4006
|
await ensureGitignore(cwd);
|
|
2982
4007
|
await ensureTsConfig(cwd);
|
|
2983
|
-
|
|
4008
|
+
log.success(`scaffolded a ${adapter.label} project`);
|
|
2984
4009
|
const pm = flags.packageManager ?? detectPackageManager();
|
|
2985
4010
|
const deps = await missingDeps(cwd, ["@boon4681/giri", ...adapter.deps, "zod"]);
|
|
2986
4011
|
const devDeps = await missingDeps(cwd, ["typescript", "@types/node"]);
|
|
2987
4012
|
if (deps.length === 0 && devDeps.length === 0) {
|
|
2988
|
-
|
|
4013
|
+
outro("All dependencies already present. Run `giri serve` to start the dev server.");
|
|
2989
4014
|
return;
|
|
2990
4015
|
}
|
|
2991
4016
|
const planLines = [
|
|
@@ -2997,9 +4022,9 @@ async function initProject(cwd, flags) {
|
|
|
2997
4022
|
if (!interactive) {
|
|
2998
4023
|
install = flags.yes;
|
|
2999
4024
|
} else {
|
|
3000
|
-
const answer = await
|
|
3001
|
-
if (
|
|
3002
|
-
|
|
4025
|
+
const answer = await confirm({ message: `Install dependencies with ${pm}?` });
|
|
4026
|
+
if (isCancel(answer)) {
|
|
4027
|
+
cancel("Cancelled - files written, skipped install.");
|
|
3003
4028
|
return;
|
|
3004
4029
|
}
|
|
3005
4030
|
install = answer;
|
|
@@ -3008,23 +4033,23 @@ async function initProject(cwd, flags) {
|
|
|
3008
4033
|
if (install) {
|
|
3009
4034
|
try {
|
|
3010
4035
|
if (deps.length) {
|
|
3011
|
-
|
|
4036
|
+
log.step(`Installing ${deps.join(", ")}`);
|
|
3012
4037
|
await runCommand(pm, installArgs(pm, deps, false), cwd);
|
|
3013
4038
|
}
|
|
3014
4039
|
if (devDeps.length) {
|
|
3015
|
-
|
|
4040
|
+
log.step(`Installing dev deps ${devDeps.join(", ")}`);
|
|
3016
4041
|
await runCommand(pm, installArgs(pm, devDeps, true), cwd);
|
|
3017
4042
|
}
|
|
3018
4043
|
} catch (error) {
|
|
3019
|
-
|
|
3020
|
-
|
|
4044
|
+
log.error(error instanceof Error ? error.message : String(error));
|
|
4045
|
+
outro(`Install failed - run these yourself, then \`giri serve\`:
|
|
3021
4046
|
${planLines.join("\n")}`);
|
|
3022
4047
|
return;
|
|
3023
4048
|
}
|
|
3024
|
-
|
|
4049
|
+
outro("Ready. Run `giri serve` to start the dev server.");
|
|
3025
4050
|
return;
|
|
3026
4051
|
}
|
|
3027
|
-
|
|
4052
|
+
outro(`Next:
|
|
3028
4053
|
${planLines.join("\n")}
|
|
3029
4054
|
giri serve`);
|
|
3030
4055
|
}
|
|
@@ -3040,7 +4065,7 @@ async function serveProject(config, flags) {
|
|
|
3040
4065
|
let stop;
|
|
3041
4066
|
const boot = async (cfg) => {
|
|
3042
4067
|
const closers = [];
|
|
3043
|
-
closers.push(registerAliasResolver(cfg.alias, (0,
|
|
4068
|
+
closers.push(registerAliasResolver(cfg.alias, (0, import_node_path18.resolve)(process.cwd())));
|
|
3044
4069
|
const lifecycle = await loadLifecycle();
|
|
3045
4070
|
const sync = syncProject(cfg).then((initial2) => {
|
|
3046
4071
|
log2.success(
|
|
@@ -3061,8 +4086,8 @@ async function serveProject(config, flags) {
|
|
|
3061
4086
|
const port = flags.port ?? cfg.server?.port ?? 3e3;
|
|
3062
4087
|
const hostname = flags.hostname ?? cfg.server?.hostname;
|
|
3063
4088
|
if (flags.watch) {
|
|
3064
|
-
const srcDir = (0,
|
|
3065
|
-
if ((0,
|
|
4089
|
+
const srcDir = (0, import_node_path18.resolve)(current.paths.routesDir, "..");
|
|
4090
|
+
if ((0, import_node_fs13.existsSync)(srcDir)) {
|
|
3066
4091
|
let timer;
|
|
3067
4092
|
let syncing = false;
|
|
3068
4093
|
const changed = /* @__PURE__ */ new Set();
|
|
@@ -3094,7 +4119,7 @@ async function serveProject(config, flags) {
|
|
|
3094
4119
|
}
|
|
3095
4120
|
rebuild = true;
|
|
3096
4121
|
if (name) {
|
|
3097
|
-
dirtySet.add((0,
|
|
4122
|
+
dirtySet.add((0, import_node_path18.resolve)(srcDir, name));
|
|
3098
4123
|
}
|
|
3099
4124
|
const rel = name ? `src/${name.replace(/\\/g, "/")}` : "src";
|
|
3100
4125
|
log2.change(outcome === "full" ? "sync" : "update", rel, bump(rel));
|
|
@@ -3124,7 +4149,7 @@ async function serveProject(config, flags) {
|
|
|
3124
4149
|
};
|
|
3125
4150
|
const watcher = watch(srcDir, { persistent: true, ignoreInitial: true });
|
|
3126
4151
|
const onFileChange = (filename) => {
|
|
3127
|
-
changed.add((0,
|
|
4152
|
+
changed.add((0, import_node_path18.isAbsolute)(filename) ? (0, import_node_path18.relative)(srcDir, filename) : filename);
|
|
3128
4153
|
clearTimeout(timer);
|
|
3129
4154
|
timer = setTimeout(() => void flush(), 150);
|
|
3130
4155
|
};
|
|
@@ -3155,11 +4180,11 @@ async function serveProject(config, flags) {
|
|
|
3155
4180
|
};
|
|
3156
4181
|
};
|
|
3157
4182
|
await boot(config);
|
|
3158
|
-
const configPath = flags.watch ? findConfigPath((0,
|
|
4183
|
+
const configPath = flags.watch ? findConfigPath((0, import_node_path18.resolve)(process.cwd())) : void 0;
|
|
3159
4184
|
if (configPath) {
|
|
3160
4185
|
let timer;
|
|
3161
4186
|
let restarting = false;
|
|
3162
|
-
const configName = (0,
|
|
4187
|
+
const configName = (0, import_node_path18.basename)(configPath);
|
|
3163
4188
|
const restart = async () => {
|
|
3164
4189
|
if (restarting) {
|
|
3165
4190
|
return;
|
|
@@ -3207,7 +4232,7 @@ function registerShutdown(cleanup) {
|
|
|
3207
4232
|
}
|
|
3208
4233
|
async function main() {
|
|
3209
4234
|
const [command = "help", ...args] = process.argv.slice(2);
|
|
3210
|
-
const cwd = (0,
|
|
4235
|
+
const cwd = (0, import_node_path18.resolve)(process.cwd());
|
|
3211
4236
|
if (command === "help" || command === "--help" || command === "-h") {
|
|
3212
4237
|
help();
|
|
3213
4238
|
return;
|