@vc-shell/api-client-generator 2.0.0-alpha.2 → 2.0.0-alpha.20
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/CHANGELOG.md +2731 -0
- package/dist/api-client-generator.js +313 -292
- package/package.json +4 -5
- package/LICENSE +0 -12
|
@@ -1,235 +1,235 @@
|
|
|
1
1
|
import e from "chalk";
|
|
2
|
-
import { sync as
|
|
3
|
-
import { resolveConfig as
|
|
4
|
-
import { existsSync as
|
|
5
|
-
import
|
|
6
|
-
import { fileURLToPath as
|
|
7
|
-
import { cwd as
|
|
8
|
-
import
|
|
9
|
-
const
|
|
10
|
-
class
|
|
2
|
+
import { sync as k } from "cross-spawn";
|
|
3
|
+
import { resolveConfig as I } from "vite";
|
|
4
|
+
import { existsSync as A, mkdirSync as B, writeFileSync as x, readFileSync as T } from "node:fs";
|
|
5
|
+
import m, { dirname as R, resolve as S, join as b, relative as C } from "node:path";
|
|
6
|
+
import { fileURLToPath as j } from "node:url";
|
|
7
|
+
import { cwd as O } from "node:process";
|
|
8
|
+
import N from "mri";
|
|
9
|
+
const M = j(import.meta.url), L = R(M);
|
|
10
|
+
class U {
|
|
11
11
|
workingDirectory;
|
|
12
12
|
generatorDirectory;
|
|
13
13
|
assetsDirectory;
|
|
14
14
|
apiClientDirectory;
|
|
15
15
|
nswagPaths;
|
|
16
16
|
constructor(r) {
|
|
17
|
-
this.workingDirectory =
|
|
18
|
-
configuration:
|
|
17
|
+
this.workingDirectory = O(), this.generatorDirectory = S(L, ".."), this.assetsDirectory = b(this.generatorDirectory, "public", "assets"), this.apiClientDirectory = S(this.workingDirectory, r), this.nswagPaths = {
|
|
18
|
+
configuration: b(C(this.workingDirectory, this.assetsDirectory), "config.nswag"),
|
|
19
19
|
authApiBase: "authApiBase.ts",
|
|
20
20
|
templates: "templates"
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
resolveApiClientPaths(r) {
|
|
24
|
-
const
|
|
24
|
+
const n = `${r.toLowerCase()}.ts`;
|
|
25
25
|
return {
|
|
26
|
-
fileName:
|
|
27
|
-
nswag:
|
|
28
|
-
console:
|
|
26
|
+
fileName: n,
|
|
27
|
+
nswag: b(C(this.assetsDirectory, this.apiClientDirectory), n),
|
|
28
|
+
console: b(C(this.workingDirectory, this.apiClientDirectory), n)
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
const
|
|
34
|
-
for (const
|
|
35
|
-
|
|
36
|
-
for (const [
|
|
37
|
-
const
|
|
38
|
-
|
|
32
|
+
function v(o, r, n = []) {
|
|
33
|
+
const t = { ...o };
|
|
34
|
+
for (const i of n)
|
|
35
|
+
i in r && (t[i] = r[i]);
|
|
36
|
+
for (const [i, s] of Object.entries(r)) {
|
|
37
|
+
const a = i;
|
|
38
|
+
i in t && typeof t[a] == "object" && !Array.isArray(t[a]) && typeof s == "object" && !Array.isArray(s) && s !== null ? t[a] = { ...t[a], ...s } : n.includes(i) || (t[a] = s);
|
|
39
39
|
}
|
|
40
|
-
return
|
|
40
|
+
return t;
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
const
|
|
42
|
+
function $(o, r, n, t) {
|
|
43
|
+
const i = {
|
|
44
44
|
extends: "@vc-shell/ts-config/tsconfig.json",
|
|
45
45
|
compilerOptions: {
|
|
46
46
|
baseUrl: ".",
|
|
47
|
-
declarationDir:
|
|
48
|
-
outDir:
|
|
47
|
+
declarationDir: m.join(n, "types"),
|
|
48
|
+
outDir: t,
|
|
49
49
|
rootDir: "./"
|
|
50
50
|
},
|
|
51
51
|
files: [],
|
|
52
52
|
include: ["*.ts"]
|
|
53
53
|
};
|
|
54
|
-
let
|
|
55
|
-
if (
|
|
54
|
+
let s = { ...i };
|
|
55
|
+
if (A(o))
|
|
56
56
|
try {
|
|
57
|
-
const
|
|
57
|
+
const a = T(o, "utf-8");
|
|
58
58
|
try {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
...
|
|
62
|
-
...
|
|
63
|
-
},
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
} catch (
|
|
59
|
+
const l = JSON.parse(a);
|
|
60
|
+
s = v(i, l), l.compilerOptions && typeof l.compilerOptions == "object" && (s.compilerOptions = {
|
|
61
|
+
...i.compilerOptions,
|
|
62
|
+
...l.compilerOptions
|
|
63
|
+
}, s.compilerOptions.outDir = t, s.compilerOptions.declarationDir = m.join(t, "types"));
|
|
64
|
+
const p = Array.isArray(l.files) ? l.files : [];
|
|
65
|
+
s.files = Array.from(/* @__PURE__ */ new Set([...r, ...p])), console.log("api-client-generator %s Updated existing tsconfig.json", e.greenBright("success"));
|
|
66
|
+
} catch (l) {
|
|
67
67
|
console.error(
|
|
68
68
|
"api-client-generator %s Failed to parse existing tsconfig.json, creating new one",
|
|
69
69
|
e.yellow("warning"),
|
|
70
|
-
|
|
71
|
-
),
|
|
70
|
+
l
|
|
71
|
+
), s = { ...i }, s.files = r;
|
|
72
72
|
}
|
|
73
|
-
} catch (
|
|
74
|
-
console.error("api-client-generator %s Failed to read existing tsconfig.json", e.red("error"),
|
|
73
|
+
} catch (a) {
|
|
74
|
+
console.error("api-client-generator %s Failed to read existing tsconfig.json", e.red("error"), a);
|
|
75
75
|
}
|
|
76
76
|
else
|
|
77
|
-
|
|
78
|
-
return
|
|
77
|
+
s.files = r, console.log("api-client-generator %s Created new tsconfig.json", e.greenBright("success"));
|
|
78
|
+
return s;
|
|
79
79
|
}
|
|
80
|
-
function
|
|
81
|
-
let r =
|
|
82
|
-
const
|
|
83
|
-
let
|
|
80
|
+
function E(o) {
|
|
81
|
+
let r = o;
|
|
82
|
+
const n = [".d.ts", ".ts", ".js"];
|
|
83
|
+
let t;
|
|
84
84
|
do {
|
|
85
|
-
|
|
86
|
-
for (const
|
|
87
|
-
if (r.toLowerCase().endsWith(
|
|
88
|
-
r = r.substring(0, r.length -
|
|
85
|
+
t = !1;
|
|
86
|
+
for (const i of n)
|
|
87
|
+
if (r.toLowerCase().endsWith(i.toLowerCase())) {
|
|
88
|
+
r = r.substring(0, r.length - i.length), t = !0;
|
|
89
89
|
break;
|
|
90
90
|
}
|
|
91
|
-
} while (
|
|
92
|
-
return r = r.replace(/\/\.\//g, "/"), r = r.replace(/\/+/g, "/"), r = r.replace(/\.\.\//g, ""), r !== "." && !r.startsWith("./") && !r.startsWith("/") && !
|
|
91
|
+
} while (t);
|
|
92
|
+
return r = r.replace(/\/\.\//g, "/"), r = r.replace(/\/+/g, "/"), r = r.replace(/\.\.\//g, ""), r !== "." && !r.startsWith("./") && !r.startsWith("/") && !m.isAbsolute(r) && (r = "./" + r), r.startsWith("//") && (r = "./" + r.substring(2)), r !== "." && r.startsWith("/") && !r.startsWith("./") && !m.isAbsolute(r) && (r = "." + r), r !== "." && r.startsWith("././") && (r = "./" + r.substring(3)), r;
|
|
93
93
|
}
|
|
94
|
-
function
|
|
95
|
-
let r =
|
|
96
|
-
r =
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
99
|
-
const
|
|
94
|
+
function _(o) {
|
|
95
|
+
let r = E(o);
|
|
96
|
+
r = m.basename(r);
|
|
97
|
+
const n = r.toLowerCase(), t = n.indexOf(".");
|
|
98
|
+
if (t > 0) {
|
|
99
|
+
const i = n.substring(0, t), s = n.substring(t + 1);
|
|
100
100
|
return {
|
|
101
|
-
prefix:
|
|
102
|
-
coreName:
|
|
103
|
-
fullName:
|
|
101
|
+
prefix: i,
|
|
102
|
+
coreName: s,
|
|
103
|
+
fullName: n
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
106
|
return {
|
|
107
107
|
prefix: void 0,
|
|
108
|
-
coreName:
|
|
109
|
-
fullName:
|
|
108
|
+
coreName: n,
|
|
109
|
+
fullName: n
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
|
-
function
|
|
113
|
-
return
|
|
112
|
+
function D(o) {
|
|
113
|
+
return _(o).coreName;
|
|
114
114
|
}
|
|
115
|
-
function
|
|
116
|
-
if (!
|
|
115
|
+
function F(o, r) {
|
|
116
|
+
if (!o)
|
|
117
117
|
return [];
|
|
118
|
-
const
|
|
119
|
-
return r &&
|
|
118
|
+
const n = [`./${o}`];
|
|
119
|
+
return r && n.push(`./${r}.${o}`), n;
|
|
120
120
|
}
|
|
121
|
-
function
|
|
122
|
-
return
|
|
121
|
+
function P(o) {
|
|
122
|
+
return o.replace(/\\/g, "/");
|
|
123
123
|
}
|
|
124
|
-
function
|
|
125
|
-
const
|
|
126
|
-
for (const
|
|
127
|
-
const
|
|
128
|
-
if (!
|
|
129
|
-
const h =
|
|
130
|
-
for (const
|
|
131
|
-
|
|
124
|
+
function V(o, r, n, t) {
|
|
125
|
+
const i = {}, s = /* @__PURE__ */ new Set();
|
|
126
|
+
for (const d of o) {
|
|
127
|
+
const g = _(d);
|
|
128
|
+
if (!g.coreName) continue;
|
|
129
|
+
const h = g.fullName, c = P(`./${m.join(r, `${h}.js`)}`), y = P(`./${m.join(r, "types", `${h}.d.ts`)}`), u = { import: c, types: y }, f = F(g.coreName, g.prefix);
|
|
130
|
+
for (const w of f)
|
|
131
|
+
i[w] = u, t && console.log(
|
|
132
132
|
"api-client-generator %s Generated standard export: %s -> { import: %s, types: %s }",
|
|
133
133
|
e.blue("debug"),
|
|
134
|
-
e.whiteBright(
|
|
135
|
-
e.whiteBright(
|
|
136
|
-
e.whiteBright(
|
|
134
|
+
e.whiteBright(w),
|
|
135
|
+
e.whiteBright(c),
|
|
136
|
+
e.whiteBright(y)
|
|
137
137
|
);
|
|
138
|
-
|
|
138
|
+
s.add(g.coreName);
|
|
139
139
|
}
|
|
140
|
-
const
|
|
141
|
-
if (
|
|
142
|
-
for (const [
|
|
143
|
-
if (
|
|
140
|
+
const a = { ...i };
|
|
141
|
+
if (n)
|
|
142
|
+
for (const [d, g] of Object.entries(n)) {
|
|
143
|
+
if (d === ".")
|
|
144
144
|
continue;
|
|
145
|
-
if (typeof
|
|
146
|
-
|
|
145
|
+
if (typeof g != "object" || g === null) {
|
|
146
|
+
t && console.log(
|
|
147
147
|
"api-client-generator %s Skipping malformed existing export value for key: %s",
|
|
148
148
|
e.yellow("warning"),
|
|
149
|
-
|
|
149
|
+
d
|
|
150
150
|
);
|
|
151
151
|
continue;
|
|
152
152
|
}
|
|
153
|
-
const h =
|
|
153
|
+
const h = g;
|
|
154
154
|
if (!h.import || !h.types) {
|
|
155
|
-
|
|
155
|
+
t && console.log(
|
|
156
156
|
"api-client-generator %s Skipping existing export with missing import/types for key: %s",
|
|
157
157
|
e.yellow("warning"),
|
|
158
|
-
|
|
158
|
+
d
|
|
159
159
|
);
|
|
160
160
|
continue;
|
|
161
161
|
}
|
|
162
|
-
const
|
|
163
|
-
if (!(!
|
|
164
|
-
if (
|
|
165
|
-
|
|
162
|
+
const c = E(d);
|
|
163
|
+
if (!(!c || c === "."))
|
|
164
|
+
if (D(c), c in i)
|
|
165
|
+
t && console.log(
|
|
166
166
|
"api-client-generator %s Existing export key '%s' was handled by new generation.",
|
|
167
167
|
e.blue("debug"),
|
|
168
|
-
e.whiteBright(
|
|
168
|
+
e.whiteBright(c)
|
|
169
169
|
);
|
|
170
170
|
else {
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
import:
|
|
174
|
-
types:
|
|
175
|
-
},
|
|
171
|
+
const y = E(h.import), u = E(h.types);
|
|
172
|
+
a[c] = {
|
|
173
|
+
import: P(`${y}.js`),
|
|
174
|
+
types: P(`${u}.d.ts`)
|
|
175
|
+
}, t && console.log(
|
|
176
176
|
"api-client-generator %s Preserved existing export: %s -> { import: %s, types: %s }",
|
|
177
177
|
e.blue("debug"),
|
|
178
|
-
e.whiteBright(
|
|
179
|
-
e.whiteBright(`${
|
|
180
|
-
e.whiteBright(`${
|
|
178
|
+
e.whiteBright(c),
|
|
179
|
+
e.whiteBright(`${y}.js`),
|
|
180
|
+
e.whiteBright(`${u}.d.ts`)
|
|
181
181
|
);
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
|
-
const
|
|
185
|
-
for (const
|
|
186
|
-
if (
|
|
187
|
-
const
|
|
188
|
-
|
|
184
|
+
const l = /* @__PURE__ */ new Map();
|
|
185
|
+
for (const d in a) {
|
|
186
|
+
if (d === ".") continue;
|
|
187
|
+
const g = _(d);
|
|
188
|
+
g.coreName && l.set(g.coreName, g.fullName);
|
|
189
189
|
}
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
192
|
-
const
|
|
193
|
-
|
|
190
|
+
const p = Array.from(l.keys());
|
|
191
|
+
if (p.length === 1) {
|
|
192
|
+
const d = p[0], g = l.get(d), h = P(`./${m.join(r, `${g}.js`)}`), c = P(`./${m.join(r, "types", `${g}.d.ts`)}`);
|
|
193
|
+
a["."] = {
|
|
194
194
|
import: h,
|
|
195
|
-
types:
|
|
196
|
-
},
|
|
195
|
+
types: c
|
|
196
|
+
}, t && console.log(
|
|
197
197
|
"api-client-generator %s Set root export for single module '%s': { import: %s, types: %s }",
|
|
198
198
|
e.blue("debug"),
|
|
199
|
-
e.whiteBright(
|
|
199
|
+
e.whiteBright(g),
|
|
200
200
|
e.whiteBright(h),
|
|
201
|
-
e.whiteBright(
|
|
201
|
+
e.whiteBright(c)
|
|
202
202
|
);
|
|
203
|
-
} else if (
|
|
204
|
-
const
|
|
205
|
-
if (typeof
|
|
206
|
-
const
|
|
207
|
-
if (
|
|
208
|
-
const
|
|
209
|
-
if (
|
|
210
|
-
const
|
|
211
|
-
|
|
203
|
+
} else if (n && "." in n) {
|
|
204
|
+
const d = n["."];
|
|
205
|
+
if (typeof d == "object" && d !== null) {
|
|
206
|
+
const g = d;
|
|
207
|
+
if (g.import && g.types) {
|
|
208
|
+
const c = _(g.import).coreName;
|
|
209
|
+
if (c && p.includes(c)) {
|
|
210
|
+
const y = l.get(c), u = P(`./${m.join(r, `${y}.js`)}`), f = P(`./${m.join(r, "types", `${y}.d.ts`)}`);
|
|
211
|
+
a["."] = { import: u, types: f }, t && console.log(
|
|
212
212
|
"api-client-generator %s Preserved and standardized existing root export pointing to module '%s'",
|
|
213
213
|
e.blue("debug"),
|
|
214
|
-
e.whiteBright(
|
|
214
|
+
e.whiteBright(y)
|
|
215
215
|
);
|
|
216
|
-
} else
|
|
216
|
+
} else t && console.log(
|
|
217
217
|
"api-client-generator %s Removed existing root export as it pointed to an unknown or unhandled module '%s'",
|
|
218
218
|
e.yellow("warning"),
|
|
219
|
-
|
|
219
|
+
c || "unknown"
|
|
220
220
|
);
|
|
221
|
-
} else
|
|
221
|
+
} else t && console.log("api-client-generator %s Removed malformed existing root export.", e.yellow("warning"));
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
|
-
return
|
|
224
|
+
return a;
|
|
225
225
|
}
|
|
226
|
-
function
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
name:
|
|
231
|
-
version:
|
|
232
|
-
files:
|
|
226
|
+
function G(o, r, n) {
|
|
227
|
+
const t = n.VERBOSE ?? !1, i = n.APP_BUILD_DIR ?? "dist", s = [];
|
|
228
|
+
i && s.push(i), s.push("package.json");
|
|
229
|
+
const a = {
|
|
230
|
+
name: n.APP_PACKAGE_NAME || "api-client",
|
|
231
|
+
version: n.APP_PACKAGE_VERSION || "1.0.0",
|
|
232
|
+
files: s,
|
|
233
233
|
exports: {},
|
|
234
234
|
// Add metadata to track generated content
|
|
235
235
|
apiClientGenerator: {
|
|
@@ -237,13 +237,13 @@ function H(t, r, i) {
|
|
|
237
237
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
238
238
|
}
|
|
239
239
|
};
|
|
240
|
-
let
|
|
241
|
-
if (
|
|
240
|
+
let l = { ...a }, p, d, g;
|
|
241
|
+
if (A(o))
|
|
242
242
|
try {
|
|
243
|
-
const
|
|
243
|
+
const u = T(o, "utf-8");
|
|
244
244
|
try {
|
|
245
|
-
const
|
|
246
|
-
typeof
|
|
245
|
+
const f = JSON.parse(u);
|
|
246
|
+
typeof f.module == "string" && (d = f.module), typeof f.types == "string" && (g = f.types), l = v(a, f, [
|
|
247
247
|
"name",
|
|
248
248
|
"version",
|
|
249
249
|
"description",
|
|
@@ -254,171 +254,192 @@ function H(t, r, i) {
|
|
|
254
254
|
"scripts",
|
|
255
255
|
"devDependencies",
|
|
256
256
|
"dependencies"
|
|
257
|
-
]),
|
|
258
|
-
} catch (
|
|
257
|
+
]), l.apiClientGenerator = a.apiClientGenerator, f.files && Array.isArray(f.files) && (l.files = Array.from(/* @__PURE__ */ new Set([...s, ...f.files]))), p = f.exports, console.log("api-client-generator %s Updated existing package.json", e.greenBright("success"));
|
|
258
|
+
} catch (f) {
|
|
259
259
|
console.error(
|
|
260
260
|
"api-client-generator %s Failed to parse existing package.json, creating new one",
|
|
261
261
|
e.yellow("warning"),
|
|
262
|
-
|
|
262
|
+
f
|
|
263
263
|
);
|
|
264
264
|
}
|
|
265
|
-
} catch (
|
|
266
|
-
console.error("api-client-generator %s Failed to read existing package.json", e.red("error"),
|
|
265
|
+
} catch (u) {
|
|
266
|
+
console.error("api-client-generator %s Failed to read existing package.json", e.red("error"), u);
|
|
267
267
|
}
|
|
268
268
|
else
|
|
269
269
|
console.log("api-client-generator %s Creating new package.json", e.greenBright("success"));
|
|
270
|
-
|
|
271
|
-
const h = Object.keys(
|
|
272
|
-
for (const
|
|
273
|
-
if (
|
|
274
|
-
const
|
|
275
|
-
|
|
270
|
+
l.exports = V(r, i, p, t);
|
|
271
|
+
const h = Object.keys(l.exports), c = /* @__PURE__ */ new Set();
|
|
272
|
+
for (const u of h) {
|
|
273
|
+
if (u === ".") continue;
|
|
274
|
+
const f = D(u);
|
|
275
|
+
f && c.add(f);
|
|
276
276
|
}
|
|
277
|
-
if (Array.from(
|
|
278
|
-
const
|
|
279
|
-
|
|
277
|
+
if (Array.from(c).length, l.exports && "." in l.exports) {
|
|
278
|
+
const u = l.exports["."];
|
|
279
|
+
u && u.import && (l.module = u.import, t && console.log(
|
|
280
280
|
"api-client-generator %s Set 'module' field from root export: %s",
|
|
281
281
|
e.blue("debug"),
|
|
282
|
-
e.whiteBright(
|
|
283
|
-
)),
|
|
282
|
+
e.whiteBright(u.import)
|
|
283
|
+
)), u && u.types && (l.types = u.types, t && console.log(
|
|
284
284
|
"api-client-generator %s Set 'types' field from root export: %s",
|
|
285
285
|
e.blue("debug"),
|
|
286
|
-
e.whiteBright(
|
|
286
|
+
e.whiteBright(u.types)
|
|
287
287
|
));
|
|
288
288
|
} else
|
|
289
|
-
"module" in
|
|
290
|
-
return
|
|
289
|
+
"module" in l && (delete l.module, t && console.log("api-client-generator %s Removed 'module' field (no clear root export).", e.blue("debug"))), "types" in l && (delete l.types, t && console.log("api-client-generator %s Removed 'types' field (no clear root export).", e.blue("debug")));
|
|
290
|
+
return l;
|
|
291
291
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
292
|
+
function K() {
|
|
293
|
+
const o = N(process.argv.slice(2)), r = process.env.APP_PLATFORM_URL ?? o.APP_PLATFORM_URL, n = r?.endsWith("/") ? r : r && `${r}/`, t = process.env.APP_PLATFORM_MODULES ?? o.APP_PLATFORM_MODULES, i = process.env.APP_API_CLIENT_DIRECTORY ?? o.APP_API_CLIENT_DIRECTORY, s = process.env.APP_PACKAGE_NAME ?? o.APP_PACKAGE_NAME, a = process.env.APP_PACKAGE_VERSION ?? o.APP_PACKAGE_VERSION, l = process.env.APP_OUT_DIR ?? o.APP_OUT_DIR ?? "./", p = process.env.APP_BUILD_DIR ?? o.APP_BUILD_DIR ?? "dist", d = process.env.RUNTIME ?? o.RUNTIME ?? "Net80", g = process.env.SKIP_BUILD === "true" || o.SKIP_BUILD === !0, h = process.env.VERBOSE === "true" || o.VERBOSE === !0, c = process.env.APP_TYPE_STYLE ?? o.APP_TYPE_STYLE ?? "Class", y = process.env.APP_PACKAGE_MODE === "true" || o.PACKAGE === !0, u = ["Net80", "Net90", "Net100"];
|
|
294
|
+
u.includes(d) || console.warn(
|
|
295
|
+
"api-client-generator %s Unknown RUNTIME value: %s. Known values: %s. Proceeding anyway — NSwag will report an error if the runtime is unsupported.",
|
|
296
|
+
e.yellow("warning"),
|
|
297
|
+
e.whiteBright(d),
|
|
298
|
+
e.whiteBright(u.join(", "))
|
|
299
|
+
), c !== "Class" && c !== "Interface" && (console.error(
|
|
300
|
+
"api-client-generator %s Invalid APP_TYPE_STYLE value: %s. Must be either 'Class' or 'Interface'",
|
|
301
|
+
e.red("error"),
|
|
302
|
+
e.whiteBright(c)
|
|
303
|
+
), process.exit(1)), h && console.log("api-client-generator %s Using APP_TYPE_STYLE: %s", e.blue("debug"), e.whiteBright(c)), n || (console.error(
|
|
304
|
+
"api-client-generator %s APP_PLATFORM_URL is required in .env config or as api-client-generator argument",
|
|
305
|
+
e.red("error")
|
|
306
|
+
), process.exit(1)), t || (console.error(
|
|
307
|
+
"api-client-generator %s APP_PLATFORM_MODULES is required in .env config or as api-client-generator argument",
|
|
308
|
+
e.red("error")
|
|
309
|
+
), process.exit(1)), i || (console.error(
|
|
310
|
+
"api-client-generator %s APP_API_CLIENT_DIRECTORY is required in .env config or as api-client-generator argument",
|
|
311
|
+
e.red("error")
|
|
312
|
+
), process.exit(1));
|
|
313
|
+
const f = m.join(m.resolve(process.cwd(), i), "package.json"), w = y || A(f);
|
|
314
|
+
return h && console.log(
|
|
315
|
+
"api-client-generator %s Package mode: %s (explicit flag: %s, existing package.json: %s)",
|
|
316
|
+
e.blue("debug"),
|
|
317
|
+
e.whiteBright(String(w)),
|
|
318
|
+
e.whiteBright(String(y)),
|
|
319
|
+
e.whiteBright(String(A(f)))
|
|
320
|
+
), {
|
|
321
|
+
platformUrl: n,
|
|
322
|
+
platformModules: t,
|
|
323
|
+
apiClientDirectory: i,
|
|
324
|
+
packageName: s,
|
|
325
|
+
packageVersion: a,
|
|
326
|
+
outDir: l,
|
|
327
|
+
buildDir: p,
|
|
328
|
+
runtime: d,
|
|
329
|
+
skipBuild: g,
|
|
330
|
+
verbose: h,
|
|
331
|
+
typeStyle: c,
|
|
332
|
+
packageMode: w,
|
|
333
|
+
parsedArgs: o
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
function Y(o) {
|
|
337
|
+
const r = new U(o.apiClientDirectory);
|
|
338
|
+
if (!A(o.apiClientDirectory))
|
|
339
|
+
try {
|
|
340
|
+
B(o.apiClientDirectory, { recursive: !0 }), console.log(
|
|
341
|
+
"api-client-generator %s Created directory %s",
|
|
342
|
+
e.greenBright("success"),
|
|
343
|
+
e.whiteBright(o.apiClientDirectory)
|
|
344
|
+
);
|
|
345
|
+
} catch (i) {
|
|
346
|
+
console.error(
|
|
347
|
+
"api-client-generator %s Failed to create directory %s",
|
|
348
|
+
e.red("error"),
|
|
349
|
+
e.whiteBright(o.apiClientDirectory)
|
|
350
|
+
), console.error(e.red("Error details:"), i), console.error("api-client-generator %s Directory creation troubleshooting:", e.blue("info")), console.error(e.blue(" - Check if you have write permissions in the parent directory")), console.error(e.blue(" - Ensure the path is valid and not too long")), console.error(e.blue(" - Try running with elevated permissions if needed")), process.exit(1);
|
|
351
|
+
}
|
|
352
|
+
const n = o.platformModules.replace(/[[\]]/g, "").split(",").map((i) => i.trim()).filter((i) => i.length > 0), t = [];
|
|
353
|
+
for (const i of n) {
|
|
354
|
+
const s = r.resolveApiClientPaths(i);
|
|
355
|
+
console.log(
|
|
356
|
+
"api-client-generator %s Generating API client for %s module on %s environment",
|
|
357
|
+
e.green("info"),
|
|
358
|
+
e.whiteBright(i),
|
|
359
|
+
e.whiteBright(o.platformUrl)
|
|
301
360
|
);
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
361
|
+
const a = [
|
|
362
|
+
`APP_PLATFORM_URL=${o.platformUrl}`,
|
|
363
|
+
`APP_PLATFORM_MODULE=${i}`,
|
|
364
|
+
`APP_AUTH_API_BASE_PATH=${r.nswagPaths.authApiBase}`,
|
|
365
|
+
`APP_TEMPLATE_DIRECTORY=${r.nswagPaths.templates}`,
|
|
366
|
+
`APP_API_CLIENT_PATH=${s.nswag}`,
|
|
367
|
+
`APP_TYPE_STYLE=${o.typeStyle}`,
|
|
368
|
+
`RUNTIME=${o.runtime}`
|
|
369
|
+
].join(","), l = ["run", r.nswagPaths.configuration, `/variables:${a}`];
|
|
370
|
+
o.verbose && (console.log("api-client-generator %s Running command: npx nswag %s", e.blue("debug"), l.join(" ")), console.log("api-client-generator %s Variables: %s", e.blue("debug"), a));
|
|
371
|
+
const p = k("npx nswag", l, {
|
|
372
|
+
stdio: ["ignore", o.verbose ? "inherit" : "pipe", "inherit"],
|
|
373
|
+
shell: !0
|
|
374
|
+
});
|
|
375
|
+
p.status === 0 ? (console.log(
|
|
376
|
+
"api-client-generator %s Successfully generated %s",
|
|
377
|
+
e.greenBright("success"),
|
|
378
|
+
e.whiteBright(s.console)
|
|
379
|
+
), t.push(`${i.toLowerCase()}.ts`)) : (console.error(
|
|
380
|
+
"api-client-generator %s Failed to generate %s",
|
|
305
381
|
e.red("error"),
|
|
306
|
-
e.whiteBright(
|
|
307
|
-
),
|
|
308
|
-
"api-client-generator %s
|
|
309
|
-
e.
|
|
310
|
-
|
|
311
|
-
),
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
const c = new J(n);
|
|
322
|
-
if (!T(n))
|
|
323
|
-
try {
|
|
324
|
-
O(n, { recursive: !0 }), console.log(
|
|
325
|
-
"api-client-generator %s Created directory %s",
|
|
326
|
-
e.greenBright("success"),
|
|
327
|
-
e.whiteBright(n)
|
|
328
|
-
);
|
|
329
|
-
} catch (f) {
|
|
330
|
-
console.error(
|
|
331
|
-
"api-client-generator %s Failed to create directory %s",
|
|
332
|
-
e.red("error"),
|
|
333
|
-
e.whiteBright(n)
|
|
334
|
-
), console.error(e.red("Error details:"), f), console.error("api-client-generator %s Directory creation troubleshooting:", e.blue("info")), console.error(e.blue(" - Check if you have write permissions in the parent directory")), console.error(e.blue(" - Ensure the path is valid and not too long")), console.error(e.blue(" - Try running with elevated permissions if needed")), process.exit(1);
|
|
335
|
-
}
|
|
336
|
-
const g = y.join(n, P);
|
|
337
|
-
if (!T(g))
|
|
338
|
-
try {
|
|
339
|
-
O(g, { recursive: !0 }), console.log(
|
|
340
|
-
"api-client-generator %s Created build directory %s",
|
|
341
|
-
e.greenBright("success"),
|
|
342
|
-
e.whiteBright(g)
|
|
343
|
-
);
|
|
344
|
-
} catch (f) {
|
|
345
|
-
console.error(
|
|
346
|
-
"api-client-generator %s Failed to create build directory %s",
|
|
347
|
-
e.red("error"),
|
|
348
|
-
e.whiteBright(g)
|
|
349
|
-
), console.error(e.red("Error details:"), f), console.error("api-client-generator %s Build directory creation troubleshooting:", e.blue("info")), console.error(e.blue(" - Check if you have write permissions in the API client directory")), console.error(e.blue(" - Ensure the build directory path is valid")), console.error(
|
|
350
|
-
e.blue(" - The TypeScript compiler will attempt to create the directory during compilation")
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
|
-
const b = o.replace(/[[\]]/g, "").split(",").map((f) => f.trim()).filter((f) => f.length > 0), I = [];
|
|
354
|
-
for (const f of b) {
|
|
355
|
-
const _ = c.resolveApiClientPaths(f);
|
|
356
|
-
console.log(
|
|
357
|
-
"api-client-generator %s Generating API client for %s module on %s environment",
|
|
358
|
-
e.green("info"),
|
|
359
|
-
e.whiteBright(f),
|
|
360
|
-
e.whiteBright(i)
|
|
361
|
-
);
|
|
362
|
-
const w = [
|
|
363
|
-
`APP_PLATFORM_URL=${i}`,
|
|
364
|
-
`APP_PLATFORM_MODULE=${f}`,
|
|
365
|
-
`APP_AUTH_API_BASE_PATH=${c.nswagPaths.authApiBase}`,
|
|
366
|
-
`APP_TEMPLATE_DIRECTORY=${c.nswagPaths.templates}`,
|
|
367
|
-
`APP_API_CLIENT_PATH=${_.nswag}`,
|
|
368
|
-
`APP_TYPE_STYLE=${m}`,
|
|
369
|
-
`RUNTIME=${u}`
|
|
370
|
-
].join(","), x = ["run", c.nswagPaths.configuration, `/variables:${w}`];
|
|
371
|
-
l && (console.log(
|
|
372
|
-
"api-client-generator %s Running command: npx nswag %s",
|
|
373
|
-
e.blue("debug"),
|
|
374
|
-
x.join(" ")
|
|
375
|
-
), console.log("api-client-generator %s Variables: %s", e.blue("debug"), w));
|
|
376
|
-
const A = v("npx nswag", x, {
|
|
377
|
-
stdio: ["ignore", l ? "inherit" : "pipe", "inherit"],
|
|
378
|
-
shell: !0
|
|
379
|
-
});
|
|
380
|
-
A.status === 0 ? (console.log(
|
|
381
|
-
"api-client-generator %s Successfully generated %s",
|
|
382
|
+
e.whiteBright(s.console)
|
|
383
|
+
), console.error(
|
|
384
|
+
"api-client-generator %s NSwag command failed with exit code: %s",
|
|
385
|
+
e.red("error"),
|
|
386
|
+
p.status
|
|
387
|
+
), p.stderr && p.stderr.toString().trim() && (console.error("api-client-generator %s NSwag error output:", e.red("error")), console.error(e.red(p.stderr.toString()))), p.stdout && p.stdout.toString().trim() && (console.error("api-client-generator %s NSwag output:", e.yellow("warning")), console.error(e.yellow(p.stdout.toString()))), console.error("api-client-generator %s Troubleshooting tips:", e.blue("info")), console.error(e.blue(" - Check if the platform URL is accessible: %s"), o.platformUrl), console.error(e.blue(" - Verify the module name '%s' exists on the platform"), i), console.error(e.blue(` - Ensure .NET Core ${o.runtime} is installed`)), console.error(e.blue(" - Try running with --VERBOSE=true for more details")), process.exit(1));
|
|
388
|
+
}
|
|
389
|
+
return t;
|
|
390
|
+
}
|
|
391
|
+
function J(o, r) {
|
|
392
|
+
const n = m.join(o.apiClientDirectory, o.buildDir);
|
|
393
|
+
if (!A(n))
|
|
394
|
+
try {
|
|
395
|
+
B(n, { recursive: !0 }), console.log(
|
|
396
|
+
"api-client-generator %s Created build directory %s",
|
|
382
397
|
e.greenBright("success"),
|
|
383
|
-
e.whiteBright(
|
|
384
|
-
)
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
), console.error(
|
|
389
|
-
"api-client-generator %s NSwag command failed with exit code: %s",
|
|
398
|
+
e.whiteBright(n)
|
|
399
|
+
);
|
|
400
|
+
} catch (p) {
|
|
401
|
+
console.error(
|
|
402
|
+
"api-client-generator %s Failed to create build directory %s",
|
|
390
403
|
e.red("error"),
|
|
391
|
-
|
|
392
|
-
),
|
|
404
|
+
e.whiteBright(n)
|
|
405
|
+
), console.error(e.red("Error details:"), p), console.error("api-client-generator %s Build directory creation troubleshooting:", e.blue("info")), console.error(e.blue(" - Check if you have write permissions in the API client directory")), console.error(e.blue(" - Ensure the build directory path is valid")), console.error(e.blue(" - The TypeScript compiler will attempt to create the directory during compilation"));
|
|
393
406
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
407
|
+
const t = m.join(o.apiClientDirectory, "tsconfig.json"), i = $(t, r, o.outDir, o.buildDir);
|
|
408
|
+
try {
|
|
409
|
+
x(t, JSON.stringify(i, null, 2)), o.verbose && console.log("api-client-generator %s Updated tsconfig.json", e.greenBright("success"));
|
|
410
|
+
} catch (p) {
|
|
411
|
+
console.error("api-client-generator %s Failed to write tsconfig.json", e.red("error")), console.error(e.red("Error details:"), p), console.error("api-client-generator %s File writing troubleshooting:", e.blue("info")), console.error(e.blue(" - Check if you have write permissions in the API client directory")), console.error(e.blue(" - Ensure the file path is valid and not locked by another process")), console.error(e.blue(" - Try running with elevated permissions if needed")), process.exit(1);
|
|
412
|
+
}
|
|
413
|
+
console.log("api-client-generator %s Compiling TypeScript files to JavaScript", e.green("info"));
|
|
414
|
+
const s = k("npx tsc", ["--project", t], {
|
|
415
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
416
|
+
shell: !0
|
|
417
|
+
});
|
|
418
|
+
s.status === 0 ? console.log("api-client-generator %s Successfully compiled TypeScript files", e.greenBright("success")) : (console.error("api-client-generator %s Failed to compile TypeScript files", e.red("error")), s.stderr && s.stderr.toString().trim() && (console.error("api-client-generator %s TypeScript compilation errors:", e.red("error")), console.error(e.red(s.stderr.toString()))), s.stdout && s.stdout.toString().trim() && (console.error("api-client-generator %s TypeScript output:", e.yellow("warning")), console.error(e.yellow(s.stdout.toString()))), console.error("api-client-generator %s TypeScript compilation troubleshooting:", e.blue("info")), console.error(e.blue(" - Check if all required dependencies are installed")), console.error(e.blue(" - Verify TypeScript configuration in tsconfig.json")), console.error(e.blue(" - Ensure generated API files are valid TypeScript")), console.error(e.blue(" - Try running with --VERBOSE=true for more details")), process.exit(1));
|
|
419
|
+
const a = m.join(o.apiClientDirectory, "package.json"), l = G(a, r, {
|
|
420
|
+
...o.parsedArgs,
|
|
421
|
+
APP_PACKAGE_NAME: o.packageName,
|
|
422
|
+
APP_PACKAGE_VERSION: o.packageVersion,
|
|
423
|
+
APP_BUILD_DIR: o.buildDir,
|
|
424
|
+
VERBOSE: o.verbose
|
|
425
|
+
});
|
|
426
|
+
try {
|
|
427
|
+
x(a, JSON.stringify(l, null, 2)), console.log("api-client-generator %s Generated package.json", e.greenBright("success"));
|
|
428
|
+
} catch (p) {
|
|
429
|
+
console.error("api-client-generator %s Failed to write package.json", e.red("error")), console.error(e.red("Error details:"), p), console.error("api-client-generator %s Package.json writing troubleshooting:", e.blue("info")), console.error(e.blue(" - Check if you have write permissions in the API client directory")), console.error(e.blue(" - Ensure the file path is valid and not locked by another process")), console.error(e.blue(" - Try running with elevated permissions if needed")), process.exit(1);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
async function q() {
|
|
433
|
+
try {
|
|
434
|
+
await I({}, "build");
|
|
435
|
+
const o = K(), r = Y(o);
|
|
436
|
+
o.packageMode && !o.skipBuild && r.length > 0 ? J(o, r) : o.packageMode || console.log(
|
|
437
|
+
"api-client-generator %s Generated %d API client file(s) in simple mode (no package build)",
|
|
438
|
+
e.greenBright("success"),
|
|
439
|
+
r.length
|
|
440
|
+
);
|
|
441
|
+
} catch (o) {
|
|
442
|
+
console.error("api-client-generator %s Unexpected error occurred during API client generation", e.red("error")), console.error(e.red("Error details:"), o), console.error("api-client-generator %s General troubleshooting:", e.blue("info")), console.error(e.blue(" - Check if all required dependencies are installed")), console.error(e.blue(" - Ensure you have proper permissions")), console.error(e.blue(" - Try running with --VERBOSE=true for more details")), console.error(e.blue(" - Check the platform URL and module names")), process.exit(1);
|
|
422
443
|
}
|
|
423
444
|
}
|
|
424
|
-
|
|
445
|
+
q();
|