@boon4681/giri 0.0.3-alpha-11 → 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/adapters/hono.d.ts +31 -3
- package/dist/adapters/hono.js +36 -2
- package/dist/adapters/hono.js.map +1 -1
- 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/dist/validators/zod.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8,6 +8,9 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
8
8
|
var __esm = (fn, res) => function __init() {
|
|
9
9
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
10
|
};
|
|
11
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
12
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
13
|
+
};
|
|
11
14
|
var __export = (target, all) => {
|
|
12
15
|
for (var name in all)
|
|
13
16
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -30,6 +33,62 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
33
|
));
|
|
31
34
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
35
|
|
|
36
|
+
// node_modules/sisteransi/src/index.js
|
|
37
|
+
var require_src = __commonJS({
|
|
38
|
+
"node_modules/sisteransi/src/index.js"(exports2, module2) {
|
|
39
|
+
"use strict";
|
|
40
|
+
var ESC = "\x1B";
|
|
41
|
+
var CSI = `${ESC}[`;
|
|
42
|
+
var beep = "\x07";
|
|
43
|
+
var cursor3 = {
|
|
44
|
+
to(x, y) {
|
|
45
|
+
if (!y) return `${CSI}${x + 1}G`;
|
|
46
|
+
return `${CSI}${y + 1};${x + 1}H`;
|
|
47
|
+
},
|
|
48
|
+
move(x, y) {
|
|
49
|
+
let ret = "";
|
|
50
|
+
if (x < 0) ret += `${CSI}${-x}D`;
|
|
51
|
+
else if (x > 0) ret += `${CSI}${x}C`;
|
|
52
|
+
if (y < 0) ret += `${CSI}${-y}A`;
|
|
53
|
+
else if (y > 0) ret += `${CSI}${y}B`;
|
|
54
|
+
return ret;
|
|
55
|
+
},
|
|
56
|
+
up: (count = 1) => `${CSI}${count}A`,
|
|
57
|
+
down: (count = 1) => `${CSI}${count}B`,
|
|
58
|
+
forward: (count = 1) => `${CSI}${count}C`,
|
|
59
|
+
backward: (count = 1) => `${CSI}${count}D`,
|
|
60
|
+
nextLine: (count = 1) => `${CSI}E`.repeat(count),
|
|
61
|
+
prevLine: (count = 1) => `${CSI}F`.repeat(count),
|
|
62
|
+
left: `${CSI}G`,
|
|
63
|
+
hide: `${CSI}?25l`,
|
|
64
|
+
show: `${CSI}?25h`,
|
|
65
|
+
save: `${ESC}7`,
|
|
66
|
+
restore: `${ESC}8`
|
|
67
|
+
};
|
|
68
|
+
var scroll = {
|
|
69
|
+
up: (count = 1) => `${CSI}S`.repeat(count),
|
|
70
|
+
down: (count = 1) => `${CSI}T`.repeat(count)
|
|
71
|
+
};
|
|
72
|
+
var erase3 = {
|
|
73
|
+
screen: `${CSI}2J`,
|
|
74
|
+
up: (count = 1) => `${CSI}1J`.repeat(count),
|
|
75
|
+
down: (count = 1) => `${CSI}J`.repeat(count),
|
|
76
|
+
line: `${CSI}2K`,
|
|
77
|
+
lineEnd: `${CSI}K`,
|
|
78
|
+
lineStart: `${CSI}1K`,
|
|
79
|
+
lines(count) {
|
|
80
|
+
let clear = "";
|
|
81
|
+
for (let i2 = 0; i2 < count; i2++)
|
|
82
|
+
clear += this.line + (i2 < count - 1 ? cursor3.up() : "");
|
|
83
|
+
if (count)
|
|
84
|
+
clear += cursor3.left;
|
|
85
|
+
return clear;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
module2.exports = { cursor: cursor3, scroll, erase: erase3, beep };
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
33
92
|
// src/loader/_es5.ts
|
|
34
93
|
var es5_exports = {};
|
|
35
94
|
__export(es5_exports, {
|
|
@@ -130,7 +189,7 @@ function buildObjectSchema(type, ctx) {
|
|
|
130
189
|
for (const symbol of checker.getPropertiesOfType(type)) {
|
|
131
190
|
const name = symbol.getName();
|
|
132
191
|
const propType = checker.getTypeOfSymbolAtLocation(symbol, ctx.location);
|
|
133
|
-
const optional = Boolean(symbol.getFlags() & import_typescript4.default.SymbolFlags.Optional) || Boolean(propType.flags & import_typescript4.default.TypeFlags.Union && propType.types.some((
|
|
192
|
+
const optional = Boolean(symbol.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));
|
|
134
193
|
properties[name] = walkType(propType, ctx);
|
|
135
194
|
if (!optional) {
|
|
136
195
|
required.push(name);
|
|
@@ -382,7 +441,7 @@ function extractRouteResponses(program, file) {
|
|
|
382
441
|
const schema = schemas.length === 1 ? schemas[0] : { anyOf: schemas };
|
|
383
442
|
result.responses.push({ status, format, schema });
|
|
384
443
|
}
|
|
385
|
-
result.responses.sort((
|
|
444
|
+
result.responses.sort((a2, b) => Number(a2.status) - Number(b.status));
|
|
386
445
|
result.warnings = ctx.warnings;
|
|
387
446
|
result.$defs = ctx.defs;
|
|
388
447
|
return result;
|
|
@@ -591,16 +650,16 @@ function toResponse(response, context) {
|
|
|
591
650
|
async function composeMiddleware(middleware, handle, context) {
|
|
592
651
|
let index = -1;
|
|
593
652
|
let result;
|
|
594
|
-
const dispatch = async (
|
|
595
|
-
if (
|
|
653
|
+
const dispatch = async (i2) => {
|
|
654
|
+
if (i2 <= index) {
|
|
596
655
|
throw new Error("next() called multiple times in giri middleware.");
|
|
597
656
|
}
|
|
598
|
-
index =
|
|
599
|
-
if (
|
|
657
|
+
index = i2;
|
|
658
|
+
if (i2 === middleware.length) {
|
|
600
659
|
result = await handle(context);
|
|
601
660
|
return result;
|
|
602
661
|
}
|
|
603
|
-
const returned = await middleware[
|
|
662
|
+
const returned = await middleware[i2](context, () => dispatch(i2 + 1));
|
|
604
663
|
if (returned !== void 0) {
|
|
605
664
|
result = returned;
|
|
606
665
|
return returned;
|
|
@@ -820,13 +879,162 @@ async function prepareRequestInput(request, input) {
|
|
|
820
879
|
|
|
821
880
|
// src/app.ts
|
|
822
881
|
var import_node_module = __toESM(require("module"));
|
|
823
|
-
var
|
|
882
|
+
var import_node_path4 = require("path");
|
|
824
883
|
|
|
825
|
-
//
|
|
826
|
-
var
|
|
884
|
+
// node_modules/@clack/core/dist/index.mjs
|
|
885
|
+
var import_node_util = require("util");
|
|
886
|
+
var import_node_process = require("process");
|
|
887
|
+
var l = __toESM(require("readline"), 1);
|
|
888
|
+
var import_node_readline = __toESM(require("readline"), 1);
|
|
889
|
+
|
|
890
|
+
// node_modules/fast-wrap-ansi/lib/main.js
|
|
891
|
+
var ANSI_ESCAPE_BELL = "\x07";
|
|
892
|
+
var ANSI_CSI = "[";
|
|
893
|
+
var ANSI_OSC = "]";
|
|
894
|
+
var ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
895
|
+
var GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
|
|
896
|
+
|
|
897
|
+
// node_modules/@clack/core/dist/index.mjs
|
|
898
|
+
var import_sisteransi = __toESM(require_src(), 1);
|
|
899
|
+
var import_node_tty = require("tty");
|
|
900
|
+
var a$2 = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
901
|
+
var t = [
|
|
902
|
+
"January",
|
|
903
|
+
"February",
|
|
904
|
+
"March",
|
|
905
|
+
"April",
|
|
906
|
+
"May",
|
|
907
|
+
"June",
|
|
908
|
+
"July",
|
|
909
|
+
"August",
|
|
910
|
+
"September",
|
|
911
|
+
"October",
|
|
912
|
+
"November",
|
|
913
|
+
"December"
|
|
914
|
+
];
|
|
915
|
+
var settings = {
|
|
916
|
+
actions: new Set(a$2),
|
|
917
|
+
aliases: /* @__PURE__ */ new Map([
|
|
918
|
+
// vim support
|
|
919
|
+
["k", "up"],
|
|
920
|
+
["j", "down"],
|
|
921
|
+
["h", "left"],
|
|
922
|
+
["l", "right"],
|
|
923
|
+
["", "cancel"],
|
|
924
|
+
// opinionated defaults!
|
|
925
|
+
["escape", "cancel"]
|
|
926
|
+
]),
|
|
927
|
+
messages: {
|
|
928
|
+
cancel: "Canceled",
|
|
929
|
+
error: "Something went wrong"
|
|
930
|
+
},
|
|
931
|
+
withGuide: true,
|
|
932
|
+
date: {
|
|
933
|
+
monthNames: [...t],
|
|
934
|
+
messages: {
|
|
935
|
+
required: "Please enter a valid date",
|
|
936
|
+
invalidMonth: "There are only 12 months in a year",
|
|
937
|
+
invalidDay: (n2, e) => `There are only ${n2} days in ${e}`,
|
|
938
|
+
afterMin: (n2) => `Date must be on or after ${n2.toISOString().slice(0, 10)}`,
|
|
939
|
+
beforeMax: (n2) => `Date must be on or before ${n2.toISOString().slice(0, 10)}`
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
var R = globalThis.process.platform.startsWith("win");
|
|
944
|
+
|
|
945
|
+
// node_modules/@clack/prompts/dist/index.mjs
|
|
946
|
+
var import_node_util2 = require("util");
|
|
947
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
827
948
|
var import_node_fs = require("fs");
|
|
828
949
|
var import_node_path = require("path");
|
|
829
|
-
var
|
|
950
|
+
var import_sisteransi2 = __toESM(require_src(), 1);
|
|
951
|
+
function isUnicodeSupported() {
|
|
952
|
+
if (import_node_process2.default.platform !== "win32") {
|
|
953
|
+
return import_node_process2.default.env.TERM !== "linux";
|
|
954
|
+
}
|
|
955
|
+
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";
|
|
956
|
+
}
|
|
957
|
+
var unicode = isUnicodeSupported();
|
|
958
|
+
var unicodeOr = (e, o2) => unicode ? e : o2;
|
|
959
|
+
var S_STEP_ACTIVE = unicodeOr("\u25C6", "*");
|
|
960
|
+
var S_STEP_CANCEL = unicodeOr("\u25A0", "x");
|
|
961
|
+
var S_STEP_ERROR = unicodeOr("\u25B2", "x");
|
|
962
|
+
var S_STEP_SUBMIT = unicodeOr("\u25C7", "o");
|
|
963
|
+
var S_BAR_START = unicodeOr("\u250C", "T");
|
|
964
|
+
var S_BAR = unicodeOr("\u2502", "|");
|
|
965
|
+
var S_BAR_END = unicodeOr("\u2514", "\u2014");
|
|
966
|
+
var S_BAR_START_RIGHT = unicodeOr("\u2510", "T");
|
|
967
|
+
var S_BAR_END_RIGHT = unicodeOr("\u2518", "\u2014");
|
|
968
|
+
var S_RADIO_ACTIVE = unicodeOr("\u25CF", ">");
|
|
969
|
+
var S_RADIO_INACTIVE = unicodeOr("\u25CB", " ");
|
|
970
|
+
var S_CHECKBOX_ACTIVE = unicodeOr("\u25FB", "[\u2022]");
|
|
971
|
+
var S_CHECKBOX_SELECTED = unicodeOr("\u25FC", "[+]");
|
|
972
|
+
var S_CHECKBOX_INACTIVE = unicodeOr("\u25FB", "[ ]");
|
|
973
|
+
var S_PASSWORD_MASK = unicodeOr("\u25AA", "\u2022");
|
|
974
|
+
var S_BAR_H = unicodeOr("\u2500", "-");
|
|
975
|
+
var S_CORNER_TOP_RIGHT = unicodeOr("\u256E", "+");
|
|
976
|
+
var S_CONNECT_LEFT = unicodeOr("\u251C", "+");
|
|
977
|
+
var S_CORNER_BOTTOM_RIGHT = unicodeOr("\u256F", "+");
|
|
978
|
+
var S_CORNER_BOTTOM_LEFT = unicodeOr("\u2570", "+");
|
|
979
|
+
var S_CORNER_TOP_LEFT = unicodeOr("\u256D", "+");
|
|
980
|
+
var S_INFO = unicodeOr("\u25CF", "\u2022");
|
|
981
|
+
var S_SUCCESS = unicodeOr("\u25C6", "*");
|
|
982
|
+
var S_WARN = unicodeOr("\u25B2", "!");
|
|
983
|
+
var S_ERROR = unicodeOr("\u25A0", "x");
|
|
984
|
+
var log = {
|
|
985
|
+
message: (s = [], {
|
|
986
|
+
symbol: e = (0, import_node_util2.styleText)("gray", S_BAR),
|
|
987
|
+
secondarySymbol: r2 = (0, import_node_util2.styleText)("gray", S_BAR),
|
|
988
|
+
output: m = process.stdout,
|
|
989
|
+
spacing: l2 = 1,
|
|
990
|
+
withGuide: c
|
|
991
|
+
} = {}) => {
|
|
992
|
+
const t2 = [], o2 = c ?? settings.withGuide, f = o2 ? r2 : "", O = o2 ? `${e} ` : "", u3 = o2 ? `${r2} ` : "";
|
|
993
|
+
for (let i2 = 0; i2 < l2; i2++)
|
|
994
|
+
t2.push(f);
|
|
995
|
+
const g = Array.isArray(s) ? s : s.split(`
|
|
996
|
+
`);
|
|
997
|
+
if (g.length > 0) {
|
|
998
|
+
const [i2, ...y] = g;
|
|
999
|
+
i2.length > 0 ? t2.push(`${O}${i2}`) : t2.push(o2 ? e : "");
|
|
1000
|
+
for (const p of y)
|
|
1001
|
+
p.length > 0 ? t2.push(`${u3}${p}`) : t2.push(o2 ? r2 : "");
|
|
1002
|
+
}
|
|
1003
|
+
m.write(`${t2.join(`
|
|
1004
|
+
`)}
|
|
1005
|
+
`);
|
|
1006
|
+
},
|
|
1007
|
+
info: (s, e) => {
|
|
1008
|
+
log.message(s, { ...e, symbol: (0, import_node_util2.styleText)("blue", S_INFO) });
|
|
1009
|
+
},
|
|
1010
|
+
success: (s, e) => {
|
|
1011
|
+
log.message(s, { ...e, symbol: (0, import_node_util2.styleText)("green", S_SUCCESS) });
|
|
1012
|
+
},
|
|
1013
|
+
step: (s, e) => {
|
|
1014
|
+
log.message(s, { ...e, symbol: (0, import_node_util2.styleText)("green", S_STEP_SUBMIT) });
|
|
1015
|
+
},
|
|
1016
|
+
warn: (s, e) => {
|
|
1017
|
+
log.message(s, { ...e, symbol: (0, import_node_util2.styleText)("yellow", S_WARN) });
|
|
1018
|
+
},
|
|
1019
|
+
/** alias for `log.warn()`. */
|
|
1020
|
+
warning: (s, e) => {
|
|
1021
|
+
log.warn(s, e);
|
|
1022
|
+
},
|
|
1023
|
+
error: (s, e) => {
|
|
1024
|
+
log.message(s, { ...e, symbol: (0, import_node_util2.styleText)("red", S_ERROR) });
|
|
1025
|
+
}
|
|
1026
|
+
};
|
|
1027
|
+
var u2 = {
|
|
1028
|
+
light: unicodeOr("\u2500", "-"),
|
|
1029
|
+
heavy: unicodeOr("\u2501", "="),
|
|
1030
|
+
block: unicodeOr("\u2588", "#")
|
|
1031
|
+
};
|
|
1032
|
+
var i = `${(0, import_node_util2.styleText)("gray", S_BAR)} `;
|
|
1033
|
+
|
|
1034
|
+
// src/loader/loader.ts
|
|
1035
|
+
var import_node_fs2 = require("fs");
|
|
1036
|
+
var import_node_path2 = require("path");
|
|
1037
|
+
var import_node_process3 = require("process");
|
|
830
1038
|
|
|
831
1039
|
// src/config/schema.ts
|
|
832
1040
|
var import_typebox = require("@sinclair/typebox");
|
|
@@ -854,14 +1062,14 @@ var assertES5 = async (unregister) => {
|
|
|
854
1062
|
if ("errors" in e && Array.isArray(e.errors) && e.errors.length > 0) {
|
|
855
1063
|
const es5Error = e.errors.filter((it) => it.text?.includes(`("es5") is not supported yet`)).length > 0;
|
|
856
1064
|
if (es5Error) {
|
|
857
|
-
|
|
1065
|
+
log.error(
|
|
858
1066
|
`Please change compilerOptions.target from 'es5' to 'es6' or above in your tsconfig.json`
|
|
859
1067
|
);
|
|
860
|
-
(0,
|
|
1068
|
+
(0, import_node_process3.exit)(1);
|
|
861
1069
|
}
|
|
862
1070
|
}
|
|
863
|
-
|
|
864
|
-
(0,
|
|
1071
|
+
log.error(e);
|
|
1072
|
+
(0, import_node_process3.exit)(1);
|
|
865
1073
|
}
|
|
866
1074
|
};
|
|
867
1075
|
var safeRegister = async () => {
|
|
@@ -883,9 +1091,9 @@ var safeRegister = async () => {
|
|
|
883
1091
|
};
|
|
884
1092
|
|
|
885
1093
|
// src/routes.ts
|
|
886
|
-
var
|
|
1094
|
+
var import_node_fs3 = require("fs");
|
|
887
1095
|
var import_promises = require("fs/promises");
|
|
888
|
-
var
|
|
1096
|
+
var import_node_path3 = require("path");
|
|
889
1097
|
var import_tinyglobby = require("tinyglobby");
|
|
890
1098
|
var import_typescript = __toESM(require("typescript"));
|
|
891
1099
|
var METHOD_ORDER = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"];
|
|
@@ -893,7 +1101,7 @@ var METHOD_FROM_FILE = new Map(
|
|
|
893
1101
|
METHOD_ORDER.map((method) => [`+${method.toLowerCase()}`, method])
|
|
894
1102
|
);
|
|
895
1103
|
function normalizeSlashes(path) {
|
|
896
|
-
return path.split(
|
|
1104
|
+
return path.split(import_node_path3.sep).join("/");
|
|
897
1105
|
}
|
|
898
1106
|
function isRouteSourceFile(fileName) {
|
|
899
1107
|
return /\.(?:[cm]?[jt]s|[jt]sx)$/.test(fileName) && !fileName.endsWith(".d.ts");
|
|
@@ -984,7 +1192,7 @@ function hasNamedHandleExport(source) {
|
|
|
984
1192
|
function parseSource(file) {
|
|
985
1193
|
return import_typescript.default.createSourceFile(
|
|
986
1194
|
file,
|
|
987
|
-
(0,
|
|
1195
|
+
(0, import_node_fs3.readFileSync)(file, "utf8"),
|
|
988
1196
|
import_typescript.default.ScriptTarget.Latest,
|
|
989
1197
|
true
|
|
990
1198
|
);
|
|
@@ -1012,8 +1220,8 @@ function sharedFileIn(dir, cache) {
|
|
|
1012
1220
|
return cache.get(dir);
|
|
1013
1221
|
}
|
|
1014
1222
|
for (const ext of ["ts", "tsx", "js", "jsx", "mjs", "cjs", "mts", "cts"]) {
|
|
1015
|
-
const file = (0,
|
|
1016
|
-
if ((0,
|
|
1223
|
+
const file = (0, import_node_path3.join)(dir, `+shared.${ext}`);
|
|
1224
|
+
if ((0, import_node_fs3.existsSync)(file)) {
|
|
1017
1225
|
cache?.set(dir, file);
|
|
1018
1226
|
return file;
|
|
1019
1227
|
}
|
|
@@ -1022,7 +1230,7 @@ function sharedFileIn(dir, cache) {
|
|
|
1022
1230
|
return void 0;
|
|
1023
1231
|
}
|
|
1024
1232
|
function physicalRouteSegments(routesDir, routeDir) {
|
|
1025
|
-
const rel = (0,
|
|
1233
|
+
const rel = (0, import_node_path3.relative)(routesDir, routeDir);
|
|
1026
1234
|
if (!rel) {
|
|
1027
1235
|
return [];
|
|
1028
1236
|
}
|
|
@@ -1071,14 +1279,14 @@ function compareRoutes(left, right) {
|
|
|
1071
1279
|
const leftRanks = segmentRanks(left.routeSegments);
|
|
1072
1280
|
const rightRanks = segmentRanks(right.routeSegments);
|
|
1073
1281
|
const shared = Math.min(leftRanks.length, rightRanks.length);
|
|
1074
|
-
for (let
|
|
1075
|
-
const
|
|
1076
|
-
const b = rightRanks[
|
|
1077
|
-
if (
|
|
1078
|
-
return
|
|
1282
|
+
for (let i2 = 0; i2 < shared; i2++) {
|
|
1283
|
+
const a2 = leftRanks[i2];
|
|
1284
|
+
const b = rightRanks[i2];
|
|
1285
|
+
if (a2.rank !== b.rank) {
|
|
1286
|
+
return a2.rank - b.rank;
|
|
1079
1287
|
}
|
|
1080
|
-
if (
|
|
1081
|
-
return
|
|
1288
|
+
if (a2.rank === 0 && a2.text !== b.text) {
|
|
1289
|
+
return a2.text.localeCompare(b.text);
|
|
1082
1290
|
}
|
|
1083
1291
|
}
|
|
1084
1292
|
if (leftRanks.length !== rightRanks.length) {
|
|
@@ -1104,14 +1312,14 @@ function pathFromSegments(segments) {
|
|
|
1104
1312
|
};
|
|
1105
1313
|
}
|
|
1106
1314
|
async function scanRouteFolders(routesDir) {
|
|
1107
|
-
if (!(0,
|
|
1315
|
+
if (!(0, import_node_fs3.existsSync)(routesDir)) {
|
|
1108
1316
|
return [];
|
|
1109
1317
|
}
|
|
1110
1318
|
const folders = [routesDir];
|
|
1111
1319
|
const walk = async (dir) => {
|
|
1112
1320
|
for (const entry of await (0, import_promises.readdir)(dir, { withFileTypes: true })) {
|
|
1113
1321
|
if (entry.isDirectory() && entry.name !== "node_modules") {
|
|
1114
|
-
const full = (0,
|
|
1322
|
+
const full = (0, import_node_path3.join)(dir, entry.name);
|
|
1115
1323
|
folders.push(full);
|
|
1116
1324
|
await walk(full);
|
|
1117
1325
|
}
|
|
@@ -1128,13 +1336,13 @@ function sharedFilesForDir(routesDir, dir, cache) {
|
|
|
1128
1336
|
const dirs = [routesDir];
|
|
1129
1337
|
let current = routesDir;
|
|
1130
1338
|
for (const segment of segments) {
|
|
1131
|
-
current = (0,
|
|
1339
|
+
current = (0, import_node_path3.join)(current, segment);
|
|
1132
1340
|
dirs.push(current);
|
|
1133
1341
|
}
|
|
1134
1342
|
return dirs.map((currentDir) => sharedFileIn(currentDir, cache)).filter((file) => Boolean(file));
|
|
1135
1343
|
}
|
|
1136
1344
|
async function scanRoutes(routesDir) {
|
|
1137
|
-
if (!(0,
|
|
1345
|
+
if (!(0, import_node_fs3.existsSync)(routesDir)) {
|
|
1138
1346
|
return [];
|
|
1139
1347
|
}
|
|
1140
1348
|
const files = await (0, import_tinyglobby.glob)("**/+*.{ts,tsx,js,jsx,mjs,cjs,mts,cts}", {
|
|
@@ -1145,11 +1353,11 @@ async function scanRoutes(routesDir) {
|
|
|
1145
1353
|
const routes = [];
|
|
1146
1354
|
const sharedCache = /* @__PURE__ */ new Map();
|
|
1147
1355
|
for (const file of files) {
|
|
1148
|
-
const method = methodFromFile((0,
|
|
1356
|
+
const method = methodFromFile((0, import_node_path3.basename)(file));
|
|
1149
1357
|
if (!method) {
|
|
1150
1358
|
continue;
|
|
1151
1359
|
}
|
|
1152
|
-
const routeDir = (0,
|
|
1360
|
+
const routeDir = (0, import_node_path3.dirname)(file);
|
|
1153
1361
|
const routeSegments = physicalRouteSegments(routesDir, routeDir);
|
|
1154
1362
|
const { path, params } = pathFromSegments(routeSegments);
|
|
1155
1363
|
routes.push({
|
|
@@ -1212,7 +1420,7 @@ function aliasValues(value) {
|
|
|
1212
1420
|
}
|
|
1213
1421
|
function resolveAliasTarget(cwd, target, capture = "") {
|
|
1214
1422
|
const replaced = target.includes("*") ? target.replaceAll("*", capture) : target;
|
|
1215
|
-
return (0,
|
|
1423
|
+
return (0, import_node_path4.isAbsolute)(replaced) ? replaced : (0, import_node_path4.resolve)(cwd, replaced);
|
|
1216
1424
|
}
|
|
1217
1425
|
function matchAlias(request, key) {
|
|
1218
1426
|
if (key.includes("*")) {
|
|
@@ -1270,15 +1478,15 @@ function ensureGiriAliasResolver(outDir) {
|
|
|
1270
1478
|
const moduleWithResolver = import_node_module.default;
|
|
1271
1479
|
const originalResolveFilename = moduleWithResolver._resolveFilename;
|
|
1272
1480
|
moduleWithResolver._resolveFilename = function resolveWithGiriInternalAlias(request, parent, isMain, options) {
|
|
1273
|
-
const mapped = typeof request === "string" && request.startsWith(GIRI_ALIAS_PREFIX) && giriOutDir ? (0,
|
|
1481
|
+
const mapped = typeof request === "string" && request.startsWith(GIRI_ALIAS_PREFIX) && giriOutDir ? (0, import_node_path4.join)(giriOutDir, request.slice(GIRI_ALIAS_PREFIX.length)) : request;
|
|
1274
1482
|
return originalResolveFilename.call(this, mapped, parent, isMain, options);
|
|
1275
1483
|
};
|
|
1276
1484
|
}
|
|
1277
1485
|
function resolveGiriPaths(config, cwd = process.cwd()) {
|
|
1278
1486
|
return {
|
|
1279
|
-
cwd: (0,
|
|
1280
|
-
routesDir: (0,
|
|
1281
|
-
outDir: (0,
|
|
1487
|
+
cwd: (0, import_node_path4.resolve)(cwd),
|
|
1488
|
+
routesDir: (0, import_node_path4.resolve)(cwd, "src/routes"),
|
|
1489
|
+
outDir: (0, import_node_path4.resolve)(cwd, config.outDir ?? ".giri")
|
|
1282
1490
|
};
|
|
1283
1491
|
}
|
|
1284
1492
|
async function buildGiriApp(config, options = {}) {
|
|
@@ -1361,59 +1569,59 @@ async function buildGiriApp(config, options = {}) {
|
|
|
1361
1569
|
}
|
|
1362
1570
|
|
|
1363
1571
|
// src/generator/sync.ts
|
|
1364
|
-
var
|
|
1572
|
+
var import_node_fs9 = require("fs");
|
|
1365
1573
|
var import_promises4 = require("fs/promises");
|
|
1366
|
-
var
|
|
1574
|
+
var import_node_path13 = require("path");
|
|
1367
1575
|
|
|
1368
1576
|
// src/generator/app-types.ts
|
|
1369
|
-
var
|
|
1370
|
-
var
|
|
1577
|
+
var import_node_fs5 = require("fs");
|
|
1578
|
+
var import_node_path6 = require("path");
|
|
1371
1579
|
|
|
1372
1580
|
// src/generator/util.ts
|
|
1373
|
-
var
|
|
1581
|
+
var import_node_fs4 = require("fs");
|
|
1374
1582
|
var import_promises2 = require("fs/promises");
|
|
1375
|
-
var
|
|
1583
|
+
var import_node_path5 = require("path");
|
|
1376
1584
|
var GENERATED_HEADER = "// Generated by giri sync. Do not edit.";
|
|
1377
1585
|
function slash(path) {
|
|
1378
|
-
return path.split(
|
|
1586
|
+
return path.split(import_node_path5.sep).join("/");
|
|
1379
1587
|
}
|
|
1380
1588
|
function importPath(fromFile, toFile) {
|
|
1381
|
-
let path = slash((0,
|
|
1589
|
+
let path = slash((0, import_node_path5.relative)((0, import_node_path5.dirname)(fromFile), toFile)).replace(/\.d\.ts$/, "");
|
|
1382
1590
|
if (!path.startsWith(".")) {
|
|
1383
1591
|
path = `./${path}`;
|
|
1384
1592
|
}
|
|
1385
1593
|
return path;
|
|
1386
1594
|
}
|
|
1387
1595
|
function relativeConfigPath(fromDir, toPath) {
|
|
1388
|
-
let path = slash((0,
|
|
1596
|
+
let path = slash((0, import_node_path5.relative)(fromDir, toPath));
|
|
1389
1597
|
if (!path.startsWith(".")) {
|
|
1390
1598
|
path = `./${path}`;
|
|
1391
1599
|
}
|
|
1392
1600
|
return path;
|
|
1393
1601
|
}
|
|
1394
1602
|
function moduleSpecifier(fromDir, target) {
|
|
1395
|
-
let path = slash((0,
|
|
1603
|
+
let path = slash((0, import_node_path5.relative)(fromDir, target)).replace(/\.(?:[cm]?[jt]sx?)$/, "");
|
|
1396
1604
|
if (!path.startsWith(".")) {
|
|
1397
1605
|
path = `./${path}`;
|
|
1398
1606
|
}
|
|
1399
1607
|
return path;
|
|
1400
1608
|
}
|
|
1401
1609
|
function typeFilePath(paths, routeDir) {
|
|
1402
|
-
const sourceDir = (0,
|
|
1403
|
-
return (0,
|
|
1610
|
+
const sourceDir = (0, import_node_path5.relative)(paths.cwd, routeDir);
|
|
1611
|
+
return (0, import_node_path5.join)(paths.outDir, "types", sourceDir, "$types.d.ts");
|
|
1404
1612
|
}
|
|
1405
1613
|
function assertSafeOutDir(paths) {
|
|
1406
|
-
const rel = (0,
|
|
1407
|
-
if (!rel || rel.startsWith("..") || rel.includes(`..${
|
|
1614
|
+
const rel = (0, import_node_path5.relative)(paths.cwd, paths.outDir);
|
|
1615
|
+
if (!rel || rel.startsWith("..") || rel.includes(`..${import_node_path5.sep}`)) {
|
|
1408
1616
|
throw new Error(`Refusing to sync outside the project root: ${paths.outDir}`);
|
|
1409
1617
|
}
|
|
1410
1618
|
}
|
|
1411
1619
|
var writeCache = /* @__PURE__ */ new Map();
|
|
1412
1620
|
async function writeGenerated(path, content) {
|
|
1413
|
-
if (writeCache.get(path) === content && (0,
|
|
1621
|
+
if (writeCache.get(path) === content && (0, import_node_fs4.existsSync)(path)) {
|
|
1414
1622
|
return;
|
|
1415
1623
|
}
|
|
1416
|
-
await (0, import_promises2.mkdir)((0,
|
|
1624
|
+
await (0, import_promises2.mkdir)((0, import_node_path5.dirname)(path), { recursive: true });
|
|
1417
1625
|
await (0, import_promises2.writeFile)(path, content);
|
|
1418
1626
|
writeCache.set(path, content);
|
|
1419
1627
|
}
|
|
@@ -1429,7 +1637,7 @@ async function pruneDir(dir, keep) {
|
|
|
1429
1637
|
return;
|
|
1430
1638
|
}
|
|
1431
1639
|
for (const entry of entries) {
|
|
1432
|
-
const full = (0,
|
|
1640
|
+
const full = (0, import_node_path5.join)(dir, entry.name);
|
|
1433
1641
|
if (entry.isDirectory()) {
|
|
1434
1642
|
await pruneDir(full, keep);
|
|
1435
1643
|
await (0, import_promises2.rmdir)(full).catch(() => {
|
|
@@ -1445,28 +1653,28 @@ async function pruneDir(dir, keep) {
|
|
|
1445
1653
|
var MAIN_EXTENSIONS = ["ts", "tsx", "mts", "cts", "js", "jsx", "mjs", "cjs"];
|
|
1446
1654
|
function findMainFile(cwd) {
|
|
1447
1655
|
for (const ext of MAIN_EXTENSIONS) {
|
|
1448
|
-
const file = (0,
|
|
1449
|
-
if ((0,
|
|
1656
|
+
const file = (0, import_node_path6.join)(cwd, "src", `main.${ext}`);
|
|
1657
|
+
if ((0, import_node_fs5.existsSync)(file)) {
|
|
1450
1658
|
return file;
|
|
1451
1659
|
}
|
|
1452
1660
|
}
|
|
1453
1661
|
return void 0;
|
|
1454
1662
|
}
|
|
1455
1663
|
function moduleSpecifier2(fromDir, target) {
|
|
1456
|
-
let path = slash((0,
|
|
1664
|
+
let path = slash((0, import_node_path6.relative)(fromDir, target)).replace(/\.(?:[cm]?[jt]sx?)$/, "");
|
|
1457
1665
|
if (!path.startsWith(".")) {
|
|
1458
1666
|
path = `./${path}`;
|
|
1459
1667
|
}
|
|
1460
1668
|
return path;
|
|
1461
1669
|
}
|
|
1462
1670
|
async function writeAppTypes(paths) {
|
|
1463
|
-
const file = (0,
|
|
1671
|
+
const file = (0, import_node_path6.join)(paths.outDir, "types", "app.d.ts");
|
|
1464
1672
|
const mainFile = findMainFile(paths.cwd);
|
|
1465
1673
|
if (!mainFile) {
|
|
1466
1674
|
await writeGenerated(file, [GENERATED_HEADER, "export {};", ""].join("\n"));
|
|
1467
1675
|
return;
|
|
1468
1676
|
}
|
|
1469
|
-
const spec = moduleSpecifier2((0,
|
|
1677
|
+
const spec = moduleSpecifier2((0, import_node_path6.join)(paths.outDir, "types"), mainFile);
|
|
1470
1678
|
await writeGenerated(
|
|
1471
1679
|
file,
|
|
1472
1680
|
[
|
|
@@ -1489,7 +1697,7 @@ async function writeAppTypes(paths) {
|
|
|
1489
1697
|
}
|
|
1490
1698
|
|
|
1491
1699
|
// src/generator/manifest.ts
|
|
1492
|
-
var
|
|
1700
|
+
var import_node_path7 = require("path");
|
|
1493
1701
|
async function writeManifest(paths, routes, data = {}) {
|
|
1494
1702
|
const manifest = {
|
|
1495
1703
|
version: 1,
|
|
@@ -1500,10 +1708,10 @@ async function writeManifest(paths, routes, data = {}) {
|
|
|
1500
1708
|
return {
|
|
1501
1709
|
method: route.method,
|
|
1502
1710
|
path: route.path,
|
|
1503
|
-
file: slash((0,
|
|
1711
|
+
file: slash((0, import_node_path7.relative)(paths.cwd, route.file)),
|
|
1504
1712
|
params: route.params,
|
|
1505
|
-
shared: route.sharedFiles.map((file) => slash((0,
|
|
1506
|
-
types: slash((0,
|
|
1713
|
+
shared: route.sharedFiles.map((file) => slash((0, import_node_path7.relative)(paths.cwd, file))),
|
|
1714
|
+
types: slash((0, import_node_path7.relative)(paths.cwd, typeFilePath(paths, route.routeDir))),
|
|
1507
1715
|
...data.hiddenFiles?.has(route.file) ? { hidden: true } : {},
|
|
1508
1716
|
...input ? { input } : {},
|
|
1509
1717
|
...security && security.security.length > 0 ? { security: security.security } : {},
|
|
@@ -1512,12 +1720,12 @@ async function writeManifest(paths, routes, data = {}) {
|
|
|
1512
1720
|
};
|
|
1513
1721
|
})
|
|
1514
1722
|
};
|
|
1515
|
-
await writeJson((0,
|
|
1723
|
+
await writeJson((0, import_node_path7.join)(paths.outDir, "manifest.json"), manifest);
|
|
1516
1724
|
}
|
|
1517
1725
|
|
|
1518
1726
|
// src/generator/openapi.ts
|
|
1519
|
-
var
|
|
1520
|
-
var
|
|
1727
|
+
var import_node_fs6 = require("fs");
|
|
1728
|
+
var import_node_path8 = require("path");
|
|
1521
1729
|
var REASON = {
|
|
1522
1730
|
200: "OK",
|
|
1523
1731
|
201: "Created",
|
|
@@ -1601,10 +1809,10 @@ function queryParameters(query) {
|
|
|
1601
1809
|
}));
|
|
1602
1810
|
}
|
|
1603
1811
|
function readProjectInfo(cwd) {
|
|
1604
|
-
const file = (0,
|
|
1605
|
-
if ((0,
|
|
1812
|
+
const file = (0, import_node_path8.join)(cwd, "package.json");
|
|
1813
|
+
if ((0, import_node_fs6.existsSync)(file)) {
|
|
1606
1814
|
try {
|
|
1607
|
-
const pkg = JSON.parse((0,
|
|
1815
|
+
const pkg = JSON.parse((0, import_node_fs6.readFileSync)(file, "utf8"));
|
|
1608
1816
|
return { title: pkg.name ?? "giri API", version: pkg.version ?? "0.0.0" };
|
|
1609
1817
|
} catch {
|
|
1610
1818
|
}
|
|
@@ -1696,11 +1904,11 @@ function buildOpenApiDocument(paths, routes, data = {}) {
|
|
|
1696
1904
|
return document;
|
|
1697
1905
|
}
|
|
1698
1906
|
async function writeOpenApi(paths, routes, data = {}) {
|
|
1699
|
-
await writeJson((0,
|
|
1907
|
+
await writeJson((0, import_node_path8.join)(paths.outDir, "openapi.json"), buildOpenApiDocument(paths, routes, data));
|
|
1700
1908
|
}
|
|
1701
1909
|
|
|
1702
1910
|
// src/generator/param-types.ts
|
|
1703
|
-
var
|
|
1911
|
+
var import_node_path9 = require("path");
|
|
1704
1912
|
function paramsType(params) {
|
|
1705
1913
|
if (params.length === 0) {
|
|
1706
1914
|
return "{}";
|
|
@@ -1724,17 +1932,17 @@ function middlewareInputType(typesDir, sharedFile) {
|
|
|
1724
1932
|
}
|
|
1725
1933
|
function ownSharedFile(dir, sharedFiles) {
|
|
1726
1934
|
for (let index = sharedFiles.length - 1; index >= 0; index -= 1) {
|
|
1727
|
-
if ((0,
|
|
1935
|
+
if ((0, import_node_path9.dirname)(sharedFiles[index]) === dir) {
|
|
1728
1936
|
return sharedFiles[index];
|
|
1729
1937
|
}
|
|
1730
1938
|
}
|
|
1731
1939
|
return void 0;
|
|
1732
1940
|
}
|
|
1733
1941
|
function varsType(paths, file, dir, sharedFiles) {
|
|
1734
|
-
const typesDir = (0,
|
|
1942
|
+
const typesDir = (0, import_node_path9.dirname)(file);
|
|
1735
1943
|
const parts = [];
|
|
1736
1944
|
if (dir !== paths.routesDir) {
|
|
1737
|
-
parts.push(`import(${JSON.stringify(importPath(file, typeFilePath(paths, (0,
|
|
1945
|
+
parts.push(`import(${JSON.stringify(importPath(file, typeFilePath(paths, (0, import_node_path9.dirname)(dir))))}).Vars`);
|
|
1738
1946
|
}
|
|
1739
1947
|
const ownShared = ownSharedFile(dir, sharedFiles);
|
|
1740
1948
|
if (ownShared) {
|
|
@@ -1743,10 +1951,10 @@ function varsType(paths, file, dir, sharedFiles) {
|
|
|
1743
1951
|
return parts.length > 0 ? parts.join("\n & ") : "{}";
|
|
1744
1952
|
}
|
|
1745
1953
|
function inputType(paths, file, dir, sharedFiles) {
|
|
1746
|
-
const typesDir = (0,
|
|
1954
|
+
const typesDir = (0, import_node_path9.dirname)(file);
|
|
1747
1955
|
const parts = [];
|
|
1748
1956
|
if (dir !== paths.routesDir) {
|
|
1749
|
-
parts.push(`import(${JSON.stringify(importPath(file, typeFilePath(paths, (0,
|
|
1957
|
+
parts.push(`import(${JSON.stringify(importPath(file, typeFilePath(paths, (0, import_node_path9.dirname)(dir))))}).Input`);
|
|
1750
1958
|
}
|
|
1751
1959
|
const ownShared = ownSharedFile(dir, sharedFiles);
|
|
1752
1960
|
if (ownShared) {
|
|
@@ -1769,7 +1977,7 @@ function methodExports(typesDir, verbs) {
|
|
|
1769
1977
|
async function writeParamTypes(paths, folders) {
|
|
1770
1978
|
await Promise.all(folders.map(({ dir, params, sharedFiles, verbs }) => {
|
|
1771
1979
|
const file = typeFilePath(paths, dir);
|
|
1772
|
-
const typesDir = (0,
|
|
1980
|
+
const typesDir = (0, import_node_path9.dirname)(file);
|
|
1773
1981
|
const lines = [
|
|
1774
1982
|
GENERATED_HEADER,
|
|
1775
1983
|
`export type Params = ${paramsType(params)};`,
|
|
@@ -1790,7 +1998,7 @@ async function writeParamTypes(paths, folders) {
|
|
|
1790
1998
|
}
|
|
1791
1999
|
|
|
1792
2000
|
// src/generator/route-meta.ts
|
|
1793
|
-
var
|
|
2001
|
+
var import_node_fs7 = require("fs");
|
|
1794
2002
|
var import_typescript2 = __toESM(require("typescript"));
|
|
1795
2003
|
|
|
1796
2004
|
// src/generator/inputs.ts
|
|
@@ -1905,19 +2113,19 @@ function parseRouteOpenApi(value) {
|
|
|
1905
2113
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1906
2114
|
return void 0;
|
|
1907
2115
|
}
|
|
1908
|
-
const
|
|
2116
|
+
const o2 = value;
|
|
1909
2117
|
const parsed = {};
|
|
1910
|
-
if ("hidden" in
|
|
1911
|
-
parsed.hidden = Boolean(
|
|
2118
|
+
if ("hidden" in o2) {
|
|
2119
|
+
parsed.hidden = Boolean(o2.hidden);
|
|
1912
2120
|
}
|
|
1913
|
-
const tags = pick(StringArraySchema,
|
|
2121
|
+
const tags = pick(StringArraySchema, o2.tags);
|
|
1914
2122
|
if (tags) {
|
|
1915
2123
|
parsed.tags = tags;
|
|
1916
2124
|
}
|
|
1917
|
-
parsed.summary = pick(StringSchema,
|
|
1918
|
-
parsed.description = pick(StringSchema,
|
|
1919
|
-
parsed.operationId = pick(StringSchema,
|
|
1920
|
-
parsed.deprecated = pick(BooleanSchema,
|
|
2125
|
+
parsed.summary = pick(StringSchema, o2.summary);
|
|
2126
|
+
parsed.description = pick(StringSchema, o2.description);
|
|
2127
|
+
parsed.operationId = pick(StringSchema, o2.operationId);
|
|
2128
|
+
parsed.deprecated = pick(BooleanSchema, o2.deprecated);
|
|
1921
2129
|
return parsed;
|
|
1922
2130
|
}
|
|
1923
2131
|
|
|
@@ -2100,7 +2308,7 @@ function parseStaticOpenApi(expression) {
|
|
|
2100
2308
|
function readStaticModuleMeta(file) {
|
|
2101
2309
|
let source;
|
|
2102
2310
|
try {
|
|
2103
|
-
source = import_typescript2.default.createSourceFile(file, (0,
|
|
2311
|
+
source = import_typescript2.default.createSourceFile(file, (0, import_node_fs7.readFileSync)(file, "utf8"), import_typescript2.default.ScriptTarget.Latest, true);
|
|
2104
2312
|
} catch {
|
|
2105
2313
|
return void 0;
|
|
2106
2314
|
}
|
|
@@ -2396,9 +2604,9 @@ async function extractRouteMeta(config, paths, routes) {
|
|
|
2396
2604
|
}
|
|
2397
2605
|
|
|
2398
2606
|
// src/generator/route-types.ts
|
|
2399
|
-
var
|
|
2607
|
+
var import_node_path10 = require("path");
|
|
2400
2608
|
async function writeRouteTypes(paths, routes) {
|
|
2401
|
-
const file = (0,
|
|
2609
|
+
const file = (0, import_node_path10.join)(paths.outDir, "routes.d.ts");
|
|
2402
2610
|
const lines = [
|
|
2403
2611
|
GENERATED_HEADER,
|
|
2404
2612
|
"export interface RouteParams {"
|
|
@@ -2416,19 +2624,19 @@ async function writeRouteTypes(paths, routes) {
|
|
|
2416
2624
|
}
|
|
2417
2625
|
|
|
2418
2626
|
// src/generator/tsconfig.ts
|
|
2419
|
-
var
|
|
2627
|
+
var import_node_path11 = require("path");
|
|
2420
2628
|
function normalizeAlias(alias, paths) {
|
|
2421
2629
|
const result = {};
|
|
2422
2630
|
for (const [key, value] of Object.entries(alias ?? {})) {
|
|
2423
2631
|
const targets = Array.isArray(value) ? value : [value];
|
|
2424
2632
|
result[key] = targets.map(
|
|
2425
|
-
(target) => relativeConfigPath(paths.outDir, (0,
|
|
2633
|
+
(target) => relativeConfigPath(paths.outDir, (0, import_node_path11.resolve)(paths.cwd, target))
|
|
2426
2634
|
);
|
|
2427
2635
|
}
|
|
2428
2636
|
return result;
|
|
2429
2637
|
}
|
|
2430
2638
|
async function writeTsConfig(paths, config) {
|
|
2431
|
-
const file = (0,
|
|
2639
|
+
const file = (0, import_node_path11.join)(paths.outDir, "tsconfig.json");
|
|
2432
2640
|
await writeJson(file, {
|
|
2433
2641
|
compilerOptions: {
|
|
2434
2642
|
rootDirs: [
|
|
@@ -2447,8 +2655,8 @@ async function writeTsConfig(paths, config) {
|
|
|
2447
2655
|
]
|
|
2448
2656
|
},
|
|
2449
2657
|
include: [
|
|
2450
|
-
relativeConfigPath(paths.outDir, (0,
|
|
2451
|
-
relativeConfigPath(paths.outDir, (0,
|
|
2658
|
+
relativeConfigPath(paths.outDir, (0, import_node_path11.join)(paths.cwd, "src")),
|
|
2659
|
+
relativeConfigPath(paths.outDir, (0, import_node_path11.join)(paths.cwd, "giri.config.ts")),
|
|
2452
2660
|
"./types/**/*.d.ts"
|
|
2453
2661
|
]
|
|
2454
2662
|
});
|
|
@@ -2456,9 +2664,9 @@ async function writeTsConfig(paths, config) {
|
|
|
2456
2664
|
|
|
2457
2665
|
// src/generator/cache.ts
|
|
2458
2666
|
var import_node_crypto = require("crypto");
|
|
2459
|
-
var
|
|
2667
|
+
var import_node_fs8 = require("fs");
|
|
2460
2668
|
var import_promises3 = require("fs/promises");
|
|
2461
|
-
var
|
|
2669
|
+
var import_node_path12 = require("path");
|
|
2462
2670
|
var import_tinyglobby2 = require("tinyglobby");
|
|
2463
2671
|
var CACHE_VERSION = 1;
|
|
2464
2672
|
var SYNC_CACHE_NAME = ".sync-cache.json";
|
|
@@ -2467,7 +2675,7 @@ function stableConfig(config) {
|
|
|
2467
2675
|
return { alias, outDir: config.outDir ?? ".giri" };
|
|
2468
2676
|
}
|
|
2469
2677
|
async function syncFingerprint(config, paths) {
|
|
2470
|
-
const outRelative = slash((0,
|
|
2678
|
+
const outRelative = slash((0, import_node_path12.relative)(paths.cwd, paths.outDir));
|
|
2471
2679
|
const ignore = ["**/node_modules/**", "**/.git/**"];
|
|
2472
2680
|
if (outRelative && !outRelative.startsWith("..")) {
|
|
2473
2681
|
ignore.push(`${outRelative}/**`);
|
|
@@ -2496,18 +2704,18 @@ async function syncFingerprint(config, paths) {
|
|
|
2496
2704
|
hash.update("\0");
|
|
2497
2705
|
hash.update(slash(file));
|
|
2498
2706
|
hash.update("\0");
|
|
2499
|
-
hash.update(await (0, import_promises3.readFile)((0,
|
|
2707
|
+
hash.update(await (0, import_promises3.readFile)((0, import_node_path12.resolve)(paths.cwd, file)));
|
|
2500
2708
|
}
|
|
2501
2709
|
return hash.digest("hex");
|
|
2502
2710
|
}
|
|
2503
2711
|
function cachePath(paths) {
|
|
2504
|
-
return (0,
|
|
2712
|
+
return (0, import_node_path12.join)(paths.outDir, SYNC_CACHE_NAME);
|
|
2505
2713
|
}
|
|
2506
2714
|
function serializePath(paths, file) {
|
|
2507
|
-
return slash((0,
|
|
2715
|
+
return slash((0, import_node_path12.relative)(paths.cwd, file));
|
|
2508
2716
|
}
|
|
2509
2717
|
function deserializePath(paths, file) {
|
|
2510
|
-
return slash((0,
|
|
2718
|
+
return slash((0, import_node_path12.resolve)(paths.cwd, file.split("/").join(import_node_path12.sep)));
|
|
2511
2719
|
}
|
|
2512
2720
|
function serializeMap(paths, values) {
|
|
2513
2721
|
return [...values].map(([file, value]) => [serializePath(paths, file), value]);
|
|
@@ -2517,7 +2725,7 @@ function deserializeMap(paths, values) {
|
|
|
2517
2725
|
}
|
|
2518
2726
|
async function readSyncCache(paths, fingerprint) {
|
|
2519
2727
|
const file = cachePath(paths);
|
|
2520
|
-
if (!(0,
|
|
2728
|
+
if (!(0, import_node_fs8.existsSync)(file)) {
|
|
2521
2729
|
return void 0;
|
|
2522
2730
|
}
|
|
2523
2731
|
try {
|
|
@@ -2577,8 +2785,8 @@ async function extractResponses(paths, routes) {
|
|
|
2577
2785
|
try {
|
|
2578
2786
|
const { createSchemaProgram: createSchemaProgram2, extractRouteResponses: extractRouteResponses2 } = await Promise.resolve().then(() => (init_schema(), schema_exports));
|
|
2579
2787
|
const files = [...new Set(routes.map((route) => route.file))];
|
|
2580
|
-
const appTypes = (0,
|
|
2581
|
-
const roots = (0,
|
|
2788
|
+
const appTypes = (0, import_node_path13.join)(paths.outDir, "types", "app.d.ts");
|
|
2789
|
+
const roots = (0, import_node_fs9.existsSync)(appTypes) ? [...files, appTypes] : files;
|
|
2582
2790
|
const program = createSchemaProgram2(paths, roots);
|
|
2583
2791
|
for (const file of files) {
|
|
2584
2792
|
byFile.set(file, extractRouteResponses2(program, file));
|
|
@@ -2623,20 +2831,20 @@ async function extractMeta(config, paths, routes) {
|
|
|
2623
2831
|
async function syncProject(config, options = {}) {
|
|
2624
2832
|
const paths = resolveGiriPaths(config, options.cwd);
|
|
2625
2833
|
assertSafeOutDir(paths);
|
|
2626
|
-
const hadOutDir = (0,
|
|
2834
|
+
const hadOutDir = (0, import_node_fs9.existsSync)(paths.outDir);
|
|
2627
2835
|
const routes = await scanRoutes(paths.routesDir);
|
|
2628
2836
|
const folders = await typeFolders(paths, routes);
|
|
2629
2837
|
const fingerprint = await syncFingerprint(config, paths);
|
|
2630
2838
|
const cached = await readSyncCache(paths, fingerprint);
|
|
2631
2839
|
const generatedFiles = [
|
|
2632
|
-
(0,
|
|
2633
|
-
(0,
|
|
2634
|
-
(0,
|
|
2635
|
-
(0,
|
|
2636
|
-
(0,
|
|
2840
|
+
(0, import_node_path13.join)(paths.outDir, "tsconfig.json"),
|
|
2841
|
+
(0, import_node_path13.join)(paths.outDir, "manifest.json"),
|
|
2842
|
+
(0, import_node_path13.join)(paths.outDir, "openapi.json"),
|
|
2843
|
+
(0, import_node_path13.join)(paths.outDir, "routes.d.ts"),
|
|
2844
|
+
(0, import_node_path13.join)(paths.outDir, "types", "app.d.ts"),
|
|
2637
2845
|
...folders.map((folder) => typeFilePath(paths, folder.dir))
|
|
2638
2846
|
];
|
|
2639
|
-
if (cached && generatedFiles.every(
|
|
2847
|
+
if (cached && generatedFiles.every(import_node_fs9.existsSync)) {
|
|
2640
2848
|
return { paths, routes, folders, data: cached };
|
|
2641
2849
|
}
|
|
2642
2850
|
await (0, import_promises4.mkdir)(paths.outDir, { recursive: true });
|
|
@@ -2655,12 +2863,12 @@ async function syncProject(config, options = {}) {
|
|
|
2655
2863
|
await pruneDir(
|
|
2656
2864
|
paths.outDir,
|
|
2657
2865
|
/* @__PURE__ */ new Set([
|
|
2658
|
-
(0,
|
|
2659
|
-
(0,
|
|
2660
|
-
(0,
|
|
2661
|
-
(0,
|
|
2662
|
-
(0,
|
|
2663
|
-
(0,
|
|
2866
|
+
(0, import_node_path13.join)(paths.outDir, "tsconfig.json"),
|
|
2867
|
+
(0, import_node_path13.join)(paths.outDir, "manifest.json"),
|
|
2868
|
+
(0, import_node_path13.join)(paths.outDir, "openapi.json"),
|
|
2869
|
+
(0, import_node_path13.join)(paths.outDir, "routes.d.ts"),
|
|
2870
|
+
(0, import_node_path13.join)(paths.outDir, SYNC_CACHE_NAME),
|
|
2871
|
+
(0, import_node_path13.join)(paths.outDir, "types", "app.d.ts"),
|
|
2664
2872
|
...folders.map((folder) => typeFilePath(paths, folder.dir))
|
|
2665
2873
|
])
|
|
2666
2874
|
);
|
|
@@ -2669,33 +2877,33 @@ async function syncProject(config, options = {}) {
|
|
|
2669
2877
|
}
|
|
2670
2878
|
|
|
2671
2879
|
// src/generator/watch.ts
|
|
2672
|
-
var
|
|
2673
|
-
var
|
|
2880
|
+
var import_node_fs11 = require("fs");
|
|
2881
|
+
var import_node_path16 = require("path");
|
|
2674
2882
|
|
|
2675
2883
|
// src/loader/import-graph.ts
|
|
2676
|
-
var
|
|
2677
|
-
var
|
|
2884
|
+
var import_node_fs10 = require("fs");
|
|
2885
|
+
var import_node_path14 = require("path");
|
|
2678
2886
|
var import_typescript6 = __toESM(require("typescript"));
|
|
2679
2887
|
var import_tinyglobby3 = require("tinyglobby");
|
|
2680
2888
|
|
|
2681
2889
|
// src/loader/module-loader.ts
|
|
2682
|
-
var
|
|
2890
|
+
var import_node_path15 = require("path");
|
|
2683
2891
|
|
|
2684
2892
|
// src/lifecycle.ts
|
|
2685
|
-
var
|
|
2686
|
-
var
|
|
2893
|
+
var import_node_fs12 = require("fs");
|
|
2894
|
+
var import_node_path17 = require("path");
|
|
2687
2895
|
var MAIN_EXTENSIONS2 = ["ts", "tsx", "mts", "cts", "js", "jsx", "mjs", "cjs"];
|
|
2688
2896
|
function resolveMainFile(cwd) {
|
|
2689
2897
|
for (const ext of MAIN_EXTENSIONS2) {
|
|
2690
|
-
const file = (0,
|
|
2691
|
-
if ((0,
|
|
2898
|
+
const file = (0, import_node_path17.join)(cwd, "src", `main.${ext}`);
|
|
2899
|
+
if ((0, import_node_fs12.existsSync)(file)) {
|
|
2692
2900
|
return file;
|
|
2693
2901
|
}
|
|
2694
2902
|
}
|
|
2695
2903
|
return void 0;
|
|
2696
2904
|
}
|
|
2697
2905
|
async function loadLifecycle(cwd = process.cwd()) {
|
|
2698
|
-
const file = resolveMainFile((0,
|
|
2906
|
+
const file = resolveMainFile((0, import_node_path17.resolve)(cwd));
|
|
2699
2907
|
if (!file) {
|
|
2700
2908
|
return {};
|
|
2701
2909
|
}
|