@vc-shell/api-client-generator 1.1.88 → 1.1.89
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 +9 -0
- package/dist/api-client-generator.js +279 -255
- package/dist/assets/config.nswag +1 -1
- package/package.json +3 -3
- package/public/assets/config.nswag +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## [1.1.89](https://github.com/VirtoCommerce/vc-shell/compare/v1.1.88...v1.1.89) (2025-10-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **api-client:** update runtime configuration and enhance error handling in API client generation process ([c9a762a](https://github.com/VirtoCommerce/vc-shell/commit/c9a762ac4e4d120d66b0ab3a16ebfe9078f33fdd))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
1
10
|
## [1.1.88](https://github.com/VirtoCommerce/vc-shell/compare/v1.1.87...v1.1.88) (2025-10-07)
|
|
2
11
|
|
|
3
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
|
|
2
|
+
import { sync as T } from "cross-spawn";
|
|
3
|
+
import { resolveConfig as j } from "vite";
|
|
4
|
+
import { existsSync as _, mkdirSync as I, writeFileSync as x, readFileSync as B } from "node:fs";
|
|
5
|
+
import m, { dirname as O, resolve as S, join as A, relative as C } from "node:path";
|
|
6
|
+
import { fileURLToPath as D } from "node:url";
|
|
7
|
+
import { cwd as L } from "node:process";
|
|
8
8
|
import N from "mri";
|
|
9
|
-
const
|
|
9
|
+
const v = D(import.meta.url), M = O(v);
|
|
10
10
|
class F {
|
|
11
11
|
workingDirectory;
|
|
12
12
|
generatorDirectory;
|
|
13
13
|
assetsDirectory;
|
|
14
14
|
apiClientDirectory;
|
|
15
15
|
nswagPaths;
|
|
16
|
-
constructor(
|
|
17
|
-
this.workingDirectory =
|
|
18
|
-
configuration:
|
|
16
|
+
constructor(r) {
|
|
17
|
+
this.workingDirectory = L(), this.generatorDirectory = S(M, ".."), this.assetsDirectory = A(this.generatorDirectory, "public", "assets"), this.apiClientDirectory = S(this.workingDirectory, r), this.nswagPaths = {
|
|
18
|
+
configuration: A(C(this.workingDirectory, this.assetsDirectory), "config.nswag"),
|
|
19
19
|
authApiBase: "authApiBase.ts",
|
|
20
20
|
templates: "templates"
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
resolveApiClientPaths(
|
|
24
|
-
const
|
|
23
|
+
resolveApiClientPaths(r) {
|
|
24
|
+
const n = `${r.toLowerCase()}.ts`;
|
|
25
25
|
return {
|
|
26
|
-
fileName:
|
|
27
|
-
nswag:
|
|
28
|
-
console:
|
|
26
|
+
fileName: n,
|
|
27
|
+
nswag: A(C(this.assetsDirectory, this.apiClientDirectory), n),
|
|
28
|
+
console: A(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 R(o, r, n = []) {
|
|
33
|
+
const t = { ...o };
|
|
34
|
+
for (const s of n)
|
|
35
|
+
s in r && (t[s] = r[s]);
|
|
36
|
+
for (const [s, u] of Object.entries(r)) {
|
|
37
|
+
const d = s;
|
|
38
|
+
s in t && typeof t[d] == "object" && !Array.isArray(t[d]) && typeof u == "object" && !Array.isArray(u) && u !== null ? t[d] = { ...t[d], ...u } : n.includes(s) || (t[d] = u);
|
|
39
39
|
}
|
|
40
|
-
return
|
|
40
|
+
return t;
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
const
|
|
42
|
+
function $(o, r, n, t) {
|
|
43
|
+
const s = {
|
|
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 u = { ...s };
|
|
55
|
+
if (_(o))
|
|
56
56
|
try {
|
|
57
|
-
const
|
|
57
|
+
const d = B(o, "utf-8");
|
|
58
58
|
try {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
...
|
|
62
|
-
...
|
|
63
|
-
},
|
|
64
|
-
const y = Array.isArray(
|
|
65
|
-
|
|
66
|
-
} catch (
|
|
59
|
+
const i = JSON.parse(d);
|
|
60
|
+
u = R(s, i), i.compilerOptions && typeof i.compilerOptions == "object" && (u.compilerOptions = {
|
|
61
|
+
...s.compilerOptions,
|
|
62
|
+
...i.compilerOptions
|
|
63
|
+
}, u.compilerOptions.outDir = t, u.compilerOptions.declarationDir = m.join(t, "types"));
|
|
64
|
+
const y = Array.isArray(i.files) ? i.files : [];
|
|
65
|
+
u.files = Array.from(/* @__PURE__ */ new Set([...r, ...y])), console.log("api-client-generator %s Updated existing tsconfig.json", e.greenBright("success"));
|
|
66
|
+
} catch (i) {
|
|
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
|
+
i
|
|
71
|
+
), u = { ...s }, u.files = r;
|
|
72
72
|
}
|
|
73
|
-
} catch (
|
|
74
|
-
console.error("api-client-generator %s Failed to read existing tsconfig.json", e.red("error"),
|
|
73
|
+
} catch (d) {
|
|
74
|
+
console.error("api-client-generator %s Failed to read existing tsconfig.json", e.red("error"), d);
|
|
75
75
|
}
|
|
76
76
|
else
|
|
77
|
-
|
|
78
|
-
return
|
|
77
|
+
u.files = r, console.log("api-client-generator %s Created new tsconfig.json", e.greenBright("success"));
|
|
78
|
+
return u;
|
|
79
79
|
}
|
|
80
|
-
function
|
|
81
|
-
let
|
|
82
|
-
const
|
|
83
|
-
let
|
|
80
|
+
function b(o) {
|
|
81
|
+
let r = o;
|
|
82
|
+
const n = [".d.ts", ".ts", ".js"];
|
|
83
|
+
let t;
|
|
84
84
|
do {
|
|
85
|
-
|
|
86
|
-
for (const
|
|
87
|
-
if (
|
|
88
|
-
|
|
85
|
+
t = !1;
|
|
86
|
+
for (const s of n)
|
|
87
|
+
if (r.toLowerCase().endsWith(s.toLowerCase())) {
|
|
88
|
+
r = r.substring(0, r.length - s.length), t = !0;
|
|
89
89
|
break;
|
|
90
90
|
}
|
|
91
|
-
} while (
|
|
92
|
-
return
|
|
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
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
99
|
-
const
|
|
94
|
+
function E(o) {
|
|
95
|
+
let r = b(o);
|
|
96
|
+
r = m.basename(r);
|
|
97
|
+
const n = r.toLowerCase(), t = n.indexOf(".");
|
|
98
|
+
if (t > 0) {
|
|
99
|
+
const s = n.substring(0, t), u = n.substring(t + 1);
|
|
100
100
|
return {
|
|
101
|
-
prefix:
|
|
102
|
-
coreName:
|
|
103
|
-
fullName:
|
|
101
|
+
prefix: s,
|
|
102
|
+
coreName: u,
|
|
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 k(o) {
|
|
113
|
+
return E(o).coreName;
|
|
114
114
|
}
|
|
115
|
-
function U(o,
|
|
115
|
+
function U(o, r) {
|
|
116
116
|
if (!o)
|
|
117
117
|
return [];
|
|
118
|
-
const
|
|
119
|
-
return
|
|
118
|
+
const n = [`./${o}`];
|
|
119
|
+
return r && n.push(`./${r}.${o}`), n;
|
|
120
120
|
}
|
|
121
121
|
function P(o) {
|
|
122
122
|
return o.replace(/\\/g, "/");
|
|
123
123
|
}
|
|
124
|
-
function Y(o,
|
|
125
|
-
const
|
|
126
|
-
for (const
|
|
127
|
-
const
|
|
128
|
-
if (!
|
|
129
|
-
const
|
|
130
|
-
for (const
|
|
131
|
-
|
|
124
|
+
function Y(o, r, n, t) {
|
|
125
|
+
const s = {}, u = /* @__PURE__ */ new Set();
|
|
126
|
+
for (const h of o) {
|
|
127
|
+
const c = E(h);
|
|
128
|
+
if (!c.coreName) continue;
|
|
129
|
+
const p = c.fullName, g = P(`./${m.join(r, `${p}.js`)}`), f = P(`./${m.join(r, "types", `${p}.d.ts`)}`), a = { import: g, types: f }, l = U(c.coreName, c.prefix);
|
|
130
|
+
for (const w of l)
|
|
131
|
+
s[w] = a, 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(g),
|
|
136
|
+
e.whiteBright(f)
|
|
137
137
|
);
|
|
138
|
-
|
|
138
|
+
u.add(c.coreName);
|
|
139
139
|
}
|
|
140
|
-
const
|
|
141
|
-
if (
|
|
142
|
-
for (const [
|
|
143
|
-
if (
|
|
140
|
+
const d = { ...s };
|
|
141
|
+
if (n)
|
|
142
|
+
for (const [h, c] of Object.entries(n)) {
|
|
143
|
+
if (h === ".")
|
|
144
144
|
continue;
|
|
145
|
-
if (typeof
|
|
146
|
-
|
|
145
|
+
if (typeof c != "object" || c === 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
|
+
h
|
|
150
150
|
);
|
|
151
151
|
continue;
|
|
152
152
|
}
|
|
153
|
-
const
|
|
154
|
-
if (!
|
|
155
|
-
|
|
153
|
+
const p = c;
|
|
154
|
+
if (!p.import || !p.types) {
|
|
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
|
+
h
|
|
159
159
|
);
|
|
160
160
|
continue;
|
|
161
161
|
}
|
|
162
|
-
const
|
|
163
|
-
if (!(!
|
|
164
|
-
if (
|
|
165
|
-
|
|
162
|
+
const g = b(h);
|
|
163
|
+
if (!(!g || g === "."))
|
|
164
|
+
if (k(g), g in s)
|
|
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(g)
|
|
169
169
|
);
|
|
170
170
|
else {
|
|
171
|
-
const
|
|
172
|
-
g
|
|
173
|
-
import: P(`${
|
|
174
|
-
types: P(`${
|
|
175
|
-
},
|
|
171
|
+
const f = b(p.import), a = b(p.types);
|
|
172
|
+
d[g] = {
|
|
173
|
+
import: P(`${f}.js`),
|
|
174
|
+
types: P(`${a}.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(g),
|
|
179
|
+
e.whiteBright(`${f}.js`),
|
|
180
|
+
e.whiteBright(`${a}.d.ts`)
|
|
181
181
|
);
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
|
-
const
|
|
185
|
-
for (const
|
|
186
|
-
if (
|
|
187
|
-
const
|
|
188
|
-
|
|
184
|
+
const i = /* @__PURE__ */ new Map();
|
|
185
|
+
for (const h in d) {
|
|
186
|
+
if (h === ".") continue;
|
|
187
|
+
const c = E(h);
|
|
188
|
+
c.coreName && i.set(c.coreName, c.fullName);
|
|
189
189
|
}
|
|
190
|
-
const y = Array.from(
|
|
190
|
+
const y = Array.from(i.keys());
|
|
191
191
|
if (y.length === 1) {
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
import:
|
|
195
|
-
types:
|
|
196
|
-
},
|
|
192
|
+
const h = y[0], c = i.get(h), p = P(`./${m.join(r, `${c}.js`)}`), g = P(`./${m.join(r, "types", `${c}.d.ts`)}`);
|
|
193
|
+
d["."] = {
|
|
194
|
+
import: p,
|
|
195
|
+
types: g
|
|
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(
|
|
200
|
-
e.whiteBright(
|
|
201
|
-
e.whiteBright(
|
|
199
|
+
e.whiteBright(c),
|
|
200
|
+
e.whiteBright(p),
|
|
201
|
+
e.whiteBright(g)
|
|
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 h = n["."];
|
|
205
|
+
if (typeof h == "object" && h !== null) {
|
|
206
|
+
const c = h;
|
|
207
|
+
if (c.import && c.types) {
|
|
208
|
+
const g = E(c.import).coreName;
|
|
209
|
+
if (g && y.includes(g)) {
|
|
210
|
+
const f = i.get(g), a = P(`./${m.join(r, `${f}.js`)}`), l = P(`./${m.join(r, "types", `${f}.d.ts`)}`);
|
|
211
|
+
d["."] = { import: a, types: l }, 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(f)
|
|
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
|
+
g || "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 d;
|
|
225
225
|
}
|
|
226
|
-
function
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
name:
|
|
231
|
-
version:
|
|
232
|
-
files:
|
|
226
|
+
function V(o, r, n) {
|
|
227
|
+
const t = n.VERBOSE ?? !1, s = n.APP_BUILD_DIR ?? "dist", u = [];
|
|
228
|
+
s && u.push(s), u.push("package.json");
|
|
229
|
+
const d = {
|
|
230
|
+
name: n.APP_PACKAGE_NAME || "api-client",
|
|
231
|
+
version: n.APP_PACKAGE_VERSION || "1.0.0",
|
|
232
|
+
files: u,
|
|
233
233
|
exports: {},
|
|
234
234
|
// Add metadata to track generated content
|
|
235
235
|
apiClientGenerator: {
|
|
@@ -237,13 +237,13 @@ function J(o, t, i) {
|
|
|
237
237
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
238
238
|
}
|
|
239
239
|
};
|
|
240
|
-
let
|
|
241
|
-
if (
|
|
240
|
+
let i = { ...d }, y, h, c;
|
|
241
|
+
if (_(o))
|
|
242
242
|
try {
|
|
243
|
-
const
|
|
243
|
+
const a = B(o, "utf-8");
|
|
244
244
|
try {
|
|
245
|
-
const
|
|
246
|
-
typeof
|
|
245
|
+
const l = JSON.parse(a);
|
|
246
|
+
typeof l.module == "string" && (h = l.module), typeof l.types == "string" && (c = l.types), i = R(d, l, [
|
|
247
247
|
"name",
|
|
248
248
|
"version",
|
|
249
249
|
"description",
|
|
@@ -254,138 +254,162 @@ function J(o, t, i) {
|
|
|
254
254
|
"scripts",
|
|
255
255
|
"devDependencies",
|
|
256
256
|
"dependencies"
|
|
257
|
-
]),
|
|
258
|
-
} catch (
|
|
257
|
+
]), i.apiClientGenerator = d.apiClientGenerator, l.files && Array.isArray(l.files) && (i.files = Array.from(/* @__PURE__ */ new Set([...u, ...l.files]))), y = l.exports, console.log("api-client-generator %s Updated existing package.json", e.greenBright("success"));
|
|
258
|
+
} catch (l) {
|
|
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
|
+
l
|
|
263
263
|
);
|
|
264
264
|
}
|
|
265
|
-
} catch (
|
|
266
|
-
console.error("api-client-generator %s Failed to read existing package.json", e.red("error"),
|
|
265
|
+
} catch (a) {
|
|
266
|
+
console.error("api-client-generator %s Failed to read existing package.json", e.red("error"), a);
|
|
267
267
|
}
|
|
268
268
|
else
|
|
269
269
|
console.log("api-client-generator %s Creating new package.json", e.greenBright("success"));
|
|
270
|
-
|
|
271
|
-
const
|
|
272
|
-
for (const
|
|
273
|
-
if (
|
|
274
|
-
const
|
|
275
|
-
|
|
270
|
+
i.exports = Y(r, s, y, t);
|
|
271
|
+
const p = Object.keys(i.exports), g = /* @__PURE__ */ new Set();
|
|
272
|
+
for (const a of p) {
|
|
273
|
+
if (a === ".") continue;
|
|
274
|
+
const l = k(a);
|
|
275
|
+
l && g.add(l);
|
|
276
276
|
}
|
|
277
|
-
if (Array.from(
|
|
278
|
-
const
|
|
279
|
-
|
|
277
|
+
if (Array.from(g).length, i.exports && "." in i.exports) {
|
|
278
|
+
const a = i.exports["."];
|
|
279
|
+
a && a.import && (i.module = a.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(a.import)
|
|
283
|
+
)), a && a.types && (i.types = a.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(a.types)
|
|
287
287
|
));
|
|
288
288
|
} else
|
|
289
|
-
"module" in
|
|
290
|
-
return
|
|
289
|
+
"module" in i && (delete i.module, t && console.log("api-client-generator %s Removed 'module' field (no clear root export).", e.blue("debug"))), "types" in i && (delete i.types, t && console.log("api-client-generator %s Removed 'types' field (no clear root export).", e.blue("debug")));
|
|
290
|
+
return i;
|
|
291
291
|
}
|
|
292
|
-
async function
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
"api-client-generator %s Invalid APP_TYPE_STYLE value: %s. Must be either 'Class' or 'Interface'",
|
|
298
|
-
e.red("error"),
|
|
299
|
-
e.whiteBright(r)
|
|
300
|
-
);
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
if (i && console.log("api-client-generator %s Using APP_TYPE_STYLE: %s", e.blue("debug"), e.whiteBright(r)), !t)
|
|
304
|
-
return console.log(
|
|
305
|
-
e.red("error"),
|
|
306
|
-
"api-client-generator APP_PLATFORM_URL is required in .env config or as api-client-generator argument"
|
|
307
|
-
);
|
|
308
|
-
if (!o.APP_PLATFORM_MODULES)
|
|
309
|
-
return console.log(e.red("error"), "api-client-generator modules command is required");
|
|
310
|
-
if (!o.APP_API_CLIENT_DIRECTORY)
|
|
311
|
-
return console.log(e.red("error"), "api-client-generator outDir command is required");
|
|
312
|
-
const a = o.APP_OUT_DIR ?? "./", l = o.APP_BUILD_DIR ?? "dist", g = new F(o.APP_API_CLIENT_DIRECTORY);
|
|
313
|
-
if (!C(o.APP_API_CLIENT_DIRECTORY))
|
|
314
|
-
try {
|
|
315
|
-
T(o.APP_API_CLIENT_DIRECTORY, { recursive: !0 }), console.log(
|
|
316
|
-
"api-client-generator %s Created directory %s",
|
|
317
|
-
e.greenBright("success"),
|
|
318
|
-
e.whiteBright(o.APP_API_CLIENT_DIRECTORY)
|
|
319
|
-
);
|
|
320
|
-
} catch (n) {
|
|
292
|
+
async function G() {
|
|
293
|
+
try {
|
|
294
|
+
await j({}, "build");
|
|
295
|
+
const o = N(process.argv.slice(2)), r = process.env.APP_PLATFORM_URL ?? o.APP_PLATFORM_URL, n = o.RUNTIME ?? "Net80", t = o.VERBOSE ?? !1, s = o.APP_TYPE_STYLE ?? "Class";
|
|
296
|
+
if (s !== "Class" && s !== "Interface") {
|
|
321
297
|
console.error(
|
|
322
|
-
"api-client-generator %s
|
|
298
|
+
"api-client-generator %s Invalid APP_TYPE_STYLE value: %s. Must be either 'Class' or 'Interface'",
|
|
323
299
|
e.red("error"),
|
|
324
|
-
e.whiteBright(
|
|
325
|
-
n
|
|
300
|
+
e.whiteBright(s)
|
|
326
301
|
);
|
|
327
302
|
return;
|
|
328
303
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
e.whiteBright(s)
|
|
336
|
-
);
|
|
337
|
-
} catch (n) {
|
|
338
|
-
console.error(
|
|
339
|
-
"api-client-generator %s Failed to create build directory %s",
|
|
304
|
+
if (t && console.log(
|
|
305
|
+
"api-client-generator %s Using APP_TYPE_STYLE: %s",
|
|
306
|
+
e.blue("debug"),
|
|
307
|
+
e.whiteBright(s)
|
|
308
|
+
), !r)
|
|
309
|
+
return console.log(
|
|
340
310
|
e.red("error"),
|
|
341
|
-
|
|
342
|
-
n
|
|
311
|
+
"api-client-generator APP_PLATFORM_URL is required in .env config or as api-client-generator argument"
|
|
343
312
|
);
|
|
313
|
+
if (!o.APP_PLATFORM_MODULES)
|
|
314
|
+
return console.log(e.red("error"), "api-client-generator modules command is required");
|
|
315
|
+
if (!o.APP_API_CLIENT_DIRECTORY)
|
|
316
|
+
return console.log(e.red("error"), "api-client-generator outDir command is required");
|
|
317
|
+
const u = o.APP_OUT_DIR ?? "./", d = o.APP_BUILD_DIR ?? "dist", i = new F(o.APP_API_CLIENT_DIRECTORY);
|
|
318
|
+
if (!_(o.APP_API_CLIENT_DIRECTORY))
|
|
319
|
+
try {
|
|
320
|
+
I(o.APP_API_CLIENT_DIRECTORY, { recursive: !0 }), console.log(
|
|
321
|
+
"api-client-generator %s Created directory %s",
|
|
322
|
+
e.greenBright("success"),
|
|
323
|
+
e.whiteBright(o.APP_API_CLIENT_DIRECTORY)
|
|
324
|
+
);
|
|
325
|
+
} catch (p) {
|
|
326
|
+
console.error(
|
|
327
|
+
"api-client-generator %s Failed to create directory %s",
|
|
328
|
+
e.red("error"),
|
|
329
|
+
e.whiteBright(o.APP_API_CLIENT_DIRECTORY)
|
|
330
|
+
), console.error(e.red("Error details:"), p), 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"));
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const y = m.join(o.APP_API_CLIENT_DIRECTORY, d);
|
|
334
|
+
if (!_(y))
|
|
335
|
+
try {
|
|
336
|
+
I(y, { recursive: !0 }), console.log(
|
|
337
|
+
"api-client-generator %s Created build directory %s",
|
|
338
|
+
e.greenBright("success"),
|
|
339
|
+
e.whiteBright(y)
|
|
340
|
+
);
|
|
341
|
+
} catch (p) {
|
|
342
|
+
console.error(
|
|
343
|
+
"api-client-generator %s Failed to create build directory %s",
|
|
344
|
+
e.red("error"),
|
|
345
|
+
e.whiteBright(y)
|
|
346
|
+
), 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(
|
|
347
|
+
e.blue(" - The TypeScript compiler will attempt to create the directory during compilation")
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
const h = o.APP_PLATFORM_MODULES.replace(/[[\]]/g, "").split(","), c = [];
|
|
351
|
+
for (const p of h) {
|
|
352
|
+
const g = i.resolveApiClientPaths(p);
|
|
353
|
+
console.log(
|
|
354
|
+
"api-client-generator %s Generating API client for %s module on %s environment",
|
|
355
|
+
e.green("info"),
|
|
356
|
+
e.whiteBright(p),
|
|
357
|
+
e.whiteBright(r)
|
|
358
|
+
);
|
|
359
|
+
const f = [
|
|
360
|
+
`APP_PLATFORM_URL=${r}`,
|
|
361
|
+
`APP_PLATFORM_MODULE=${p}`,
|
|
362
|
+
`APP_AUTH_API_BASE_PATH=${i.nswagPaths.authApiBase}`,
|
|
363
|
+
`APP_TEMPLATE_DIRECTORY=${i.nswagPaths.templates}`,
|
|
364
|
+
`APP_API_CLIENT_PATH=${g.nswag}`,
|
|
365
|
+
`APP_TYPE_STYLE=${s}`,
|
|
366
|
+
`RUNTIME=${n}`
|
|
367
|
+
].join(","), a = ["run", i.nswagPaths.configuration, `/variables:${f}`];
|
|
368
|
+
t && (console.log(
|
|
369
|
+
"api-client-generator %s Running command: npx nswag %s",
|
|
370
|
+
e.blue("debug"),
|
|
371
|
+
a.join(" ")
|
|
372
|
+
), console.log("api-client-generator %s Variables: %s", e.blue("debug"), f));
|
|
373
|
+
const l = T("npx nswag", a, {
|
|
374
|
+
stdio: ["ignore", t ? "inherit" : "pipe", "inherit"],
|
|
375
|
+
shell: !0
|
|
376
|
+
});
|
|
377
|
+
l.status === 0 ? (console.log(
|
|
378
|
+
"api-client-generator %s Successfully generated %s",
|
|
379
|
+
e.greenBright("success"),
|
|
380
|
+
e.whiteBright(g.console)
|
|
381
|
+
), o.SKIP_BUILD || c.push(`${p.toLowerCase()}.ts`)) : (console.error(
|
|
382
|
+
"api-client-generator %s Failed to generate %s",
|
|
383
|
+
e.red("error"),
|
|
384
|
+
e.whiteBright(g.console)
|
|
385
|
+
), console.error(
|
|
386
|
+
"api-client-generator %s NSwag command failed with exit code: %s",
|
|
387
|
+
e.red("error"),
|
|
388
|
+
l.status
|
|
389
|
+
), l.stderr && l.stderr.toString().trim() && (console.error("api-client-generator %s NSwag error output:", e.red("error")), console.error(e.red(l.stderr.toString()))), l.stdout && l.stdout.toString().trim() && (console.error("api-client-generator %s NSwag output:", e.yellow("warning")), console.error(e.yellow(l.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"), r), console.error(e.blue(" - Verify the module name '%s' exists on the platform"), p), console.error(e.blue(" - Ensure .NET Core 9.0+ is installed")), console.error(e.blue(" - Try running with --VERBOSE=true for more details")));
|
|
344
390
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
e.
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
c.status === 0 ? (console.log(
|
|
368
|
-
"api-client-generator %s Successfully generated %s",
|
|
369
|
-
e.greenBright("success"),
|
|
370
|
-
e.whiteBright(u.console)
|
|
371
|
-
), o.SKIP_BUILD || f.push(`${n.toLowerCase()}.ts`)) : (console.error(
|
|
372
|
-
"api-client-generator %s Failed to generate %s",
|
|
373
|
-
e.red("error"),
|
|
374
|
-
e.whiteBright(u.console)
|
|
375
|
-
), i && console.error(
|
|
376
|
-
"api-client-generator %s NSwag command failed with exit code: %s",
|
|
377
|
-
e.red("error"),
|
|
378
|
-
c.status
|
|
379
|
-
));
|
|
380
|
-
}
|
|
381
|
-
if (!o.SKIP_BUILD) {
|
|
382
|
-
const n = h.join(o.APP_API_CLIENT_DIRECTORY, "tsconfig.json"), u = v(n, f, a, l);
|
|
383
|
-
B(n, JSON.stringify(u, null, 2)), console.log("api-client-generator %s Compiling TypeScript files to JavaScript", e.green("info")), I("npx tsc", ["--project", n], {
|
|
384
|
-
stdio: ["ignore", "inherit", "ignore"],
|
|
385
|
-
shell: !0
|
|
386
|
-
}).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"));
|
|
387
|
-
const m = h.join(o.APP_API_CLIENT_DIRECTORY, "package.json"), c = J(m, f, o);
|
|
388
|
-
B(m, JSON.stringify(c, null, 2)), console.log("api-client-generator %s Generated package.json", e.greenBright("success"));
|
|
391
|
+
if (!o.SKIP_BUILD) {
|
|
392
|
+
const p = m.join(o.APP_API_CLIENT_DIRECTORY, "tsconfig.json"), g = $(p, c, u, d);
|
|
393
|
+
try {
|
|
394
|
+
x(p, JSON.stringify(g, null, 2)), t && console.log("api-client-generator %s Updated tsconfig.json", e.greenBright("success"));
|
|
395
|
+
} catch (w) {
|
|
396
|
+
console.error("api-client-generator %s Failed to write tsconfig.json", e.red("error")), console.error(e.red("Error details:"), w), 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"));
|
|
397
|
+
}
|
|
398
|
+
console.log("api-client-generator %s Compiling TypeScript files to JavaScript", e.green("info"));
|
|
399
|
+
const f = T("npx tsc", ["--project", p], {
|
|
400
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
401
|
+
shell: !0
|
|
402
|
+
});
|
|
403
|
+
f.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")), f.stderr && f.stderr.toString().trim() && (console.error("api-client-generator %s TypeScript compilation errors:", e.red("error")), console.error(e.red(f.stderr.toString()))), f.stdout && f.stdout.toString().trim() && (console.error("api-client-generator %s TypeScript output:", e.yellow("warning")), console.error(e.yellow(f.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")));
|
|
404
|
+
const a = m.join(o.APP_API_CLIENT_DIRECTORY, "package.json"), l = V(a, c, o);
|
|
405
|
+
try {
|
|
406
|
+
x(a, JSON.stringify(l, null, 2)), console.log("api-client-generator %s Generated package.json", e.greenBright("success"));
|
|
407
|
+
} catch (w) {
|
|
408
|
+
console.error("api-client-generator %s Failed to write package.json", e.red("error")), console.error(e.red("Error details:"), w), 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"));
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
} catch (o) {
|
|
412
|
+
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);
|
|
389
413
|
}
|
|
390
414
|
}
|
|
391
|
-
|
|
415
|
+
G();
|
package/dist/assets/config.nswag
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vc-shell/api-client-generator",
|
|
3
3
|
"description": "Tool for API clients generation",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.89",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": "./dist/api-client-generator.js",
|
|
7
7
|
"files": [
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@types/cross-spawn": "^6.0.6",
|
|
16
|
-
"@vc-shell/ts-config": "^1.1.
|
|
16
|
+
"@vc-shell/ts-config": "^1.1.89",
|
|
17
17
|
"typescript": "^5.8.3"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"chalk": "^2.4.2",
|
|
21
21
|
"cross-spawn": "^7.0.3",
|
|
22
22
|
"mri": "^1.2.0",
|
|
23
|
-
"nswag": "^
|
|
23
|
+
"nswag": "^14.5.0",
|
|
24
24
|
"vite": "^6.3.3",
|
|
25
25
|
"vite-plugin-dts": "^3.6.4"
|
|
26
26
|
},
|