@vc-shell/api-client-generator 1.1.86 → 1.1.88
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 +13 -0
- package/dist/api-client-generator.js +200 -177
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
## [1.1.88](https://github.com/VirtoCommerce/vc-shell/compare/v1.1.87...v1.1.88) (2025-10-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## [1.1.87](https://github.com/VirtoCommerce/vc-shell/compare/v1.1.86...v1.1.87) (2025-10-06)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **api-client:** enhance module name parsing and export generation for improved flexibility and compatibility ([37d3e20](https://github.com/VirtoCommerce/vc-shell/commit/37d3e20831e6931d4fcc93c7127a53b7af2d7540))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
1
14
|
## [1.1.86](https://github.com/VirtoCommerce/vc-shell/compare/v1.1.85...v1.1.86) (2025-10-06)
|
|
2
15
|
|
|
3
16
|
|
|
@@ -1,212 +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 I } from "cross-spawn";
|
|
3
|
+
import { resolveConfig as S } from "vite";
|
|
4
|
+
import { existsSync as C, mkdirSync as T, writeFileSync as B, readFileSync as O } from "node:fs";
|
|
5
|
+
import h, { dirname as b, resolve as R, join as w, relative as E } from "node:path";
|
|
6
|
+
import { fileURLToPath as L } from "node:url";
|
|
7
|
+
import { cwd as k } from "node:process";
|
|
8
|
+
import N from "mri";
|
|
9
|
+
const M = L(import.meta.url), $ = b(M);
|
|
10
|
+
class F {
|
|
11
11
|
workingDirectory;
|
|
12
12
|
generatorDirectory;
|
|
13
13
|
assetsDirectory;
|
|
14
14
|
apiClientDirectory;
|
|
15
15
|
nswagPaths;
|
|
16
16
|
constructor(t) {
|
|
17
|
-
this.workingDirectory =
|
|
17
|
+
this.workingDirectory = k(), this.generatorDirectory = R($, ".."), this.assetsDirectory = w(this.generatorDirectory, "public", "assets"), this.apiClientDirectory = R(this.workingDirectory, t), this.nswagPaths = {
|
|
18
18
|
configuration: w(E(this.workingDirectory, this.assetsDirectory), "config.nswag"),
|
|
19
19
|
authApiBase: "authApiBase.ts",
|
|
20
20
|
templates: "templates"
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
resolveApiClientPaths(t) {
|
|
24
|
-
const
|
|
24
|
+
const i = `${t.toLowerCase()}.ts`;
|
|
25
25
|
return {
|
|
26
|
-
fileName:
|
|
27
|
-
nswag: w(E(this.assetsDirectory, this.apiClientDirectory),
|
|
28
|
-
console: w(E(this.workingDirectory, this.apiClientDirectory),
|
|
26
|
+
fileName: i,
|
|
27
|
+
nswag: w(E(this.assetsDirectory, this.apiClientDirectory), i),
|
|
28
|
+
console: w(E(this.workingDirectory, this.apiClientDirectory), i)
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
function D(o, t,
|
|
32
|
+
function D(o, t, i = []) {
|
|
33
33
|
const r = { ...o };
|
|
34
|
-
for (const
|
|
35
|
-
|
|
36
|
-
for (const [
|
|
37
|
-
const
|
|
38
|
-
|
|
34
|
+
for (const a of i)
|
|
35
|
+
a in t && (r[a] = t[a]);
|
|
36
|
+
for (const [a, l] of Object.entries(t)) {
|
|
37
|
+
const g = a;
|
|
38
|
+
a in r && typeof r[g] == "object" && !Array.isArray(r[g]) && typeof l == "object" && !Array.isArray(l) && l !== null ? r[g] = { ...r[g], ...l } : i.includes(a) || (r[g] = l);
|
|
39
39
|
}
|
|
40
40
|
return r;
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
const
|
|
42
|
+
function v(o, t, i, r) {
|
|
43
|
+
const a = {
|
|
44
44
|
extends: "@vc-shell/ts-config/tsconfig.json",
|
|
45
45
|
compilerOptions: {
|
|
46
46
|
baseUrl: ".",
|
|
47
|
-
declarationDir:
|
|
47
|
+
declarationDir: h.join(i, "types"),
|
|
48
48
|
outDir: r,
|
|
49
49
|
rootDir: "./"
|
|
50
50
|
},
|
|
51
51
|
files: [],
|
|
52
52
|
include: ["*.ts"]
|
|
53
53
|
};
|
|
54
|
-
let
|
|
55
|
-
if (
|
|
54
|
+
let l = { ...a };
|
|
55
|
+
if (C(o))
|
|
56
56
|
try {
|
|
57
|
-
const
|
|
57
|
+
const g = O(o, "utf-8");
|
|
58
58
|
try {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
...
|
|
62
|
-
...
|
|
63
|
-
},
|
|
64
|
-
const y = Array.isArray(
|
|
65
|
-
|
|
66
|
-
} catch (
|
|
59
|
+
const s = JSON.parse(g);
|
|
60
|
+
l = D(a, s), s.compilerOptions && typeof s.compilerOptions == "object" && (l.compilerOptions = {
|
|
61
|
+
...a.compilerOptions,
|
|
62
|
+
...s.compilerOptions
|
|
63
|
+
}, l.compilerOptions.outDir = r, l.compilerOptions.declarationDir = h.join(r, "types"));
|
|
64
|
+
const y = Array.isArray(s.files) ? s.files : [];
|
|
65
|
+
l.files = Array.from(/* @__PURE__ */ new Set([...t, ...y])), console.log("api-client-generator %s Updated existing tsconfig.json", e.greenBright("success"));
|
|
66
|
+
} catch (s) {
|
|
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
|
+
s
|
|
71
|
+
), l = { ...a }, l.files = t;
|
|
72
72
|
}
|
|
73
|
-
} catch (
|
|
74
|
-
console.error("api-client-generator %s Failed to read existing tsconfig.json", e.red("error"),
|
|
73
|
+
} catch (g) {
|
|
74
|
+
console.error("api-client-generator %s Failed to read existing tsconfig.json", e.red("error"), g);
|
|
75
75
|
}
|
|
76
76
|
else
|
|
77
|
-
|
|
78
|
-
return
|
|
77
|
+
l.files = t, console.log("api-client-generator %s Created new tsconfig.json", e.greenBright("success"));
|
|
78
|
+
return l;
|
|
79
79
|
}
|
|
80
80
|
function A(o) {
|
|
81
81
|
let t = o;
|
|
82
|
-
const
|
|
82
|
+
const i = [".d.ts", ".ts", ".js"];
|
|
83
83
|
let r;
|
|
84
84
|
do {
|
|
85
85
|
r = !1;
|
|
86
|
-
for (const
|
|
87
|
-
if (t.toLowerCase().endsWith(
|
|
88
|
-
t = t.substring(0, t.length -
|
|
86
|
+
for (const a of i)
|
|
87
|
+
if (t.toLowerCase().endsWith(a.toLowerCase())) {
|
|
88
|
+
t = t.substring(0, t.length - a.length), r = !0;
|
|
89
89
|
break;
|
|
90
90
|
}
|
|
91
91
|
} while (r);
|
|
92
|
-
return t = t.replace(/\/\.\//g, "/"), t = t.replace(/\/+/g, "/"), t = t.replace(/\.\.\//g, ""), t !== "." && !t.startsWith("./") && !t.startsWith("/") && !
|
|
92
|
+
return t = t.replace(/\/\.\//g, "/"), t = t.replace(/\/+/g, "/"), t = t.replace(/\.\.\//g, ""), t !== "." && !t.startsWith("./") && !t.startsWith("/") && !h.isAbsolute(t) && (t = "./" + t), t.startsWith("//") && (t = "./" + t.substring(2)), t !== "." && t.startsWith("/") && !t.startsWith("./") && !h.isAbsolute(t) && (t = "." + t), t !== "." && t.startsWith("././") && (t = "./" + t.substring(3)), t;
|
|
93
93
|
}
|
|
94
|
-
function
|
|
94
|
+
function _(o) {
|
|
95
95
|
let t = A(o);
|
|
96
|
-
|
|
96
|
+
t = h.basename(t);
|
|
97
|
+
const i = t.toLowerCase(), r = i.indexOf(".");
|
|
98
|
+
if (r > 0) {
|
|
99
|
+
const a = i.substring(0, r), l = i.substring(r + 1);
|
|
100
|
+
return {
|
|
101
|
+
prefix: a,
|
|
102
|
+
coreName: l,
|
|
103
|
+
fullName: i
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
prefix: void 0,
|
|
108
|
+
coreName: i,
|
|
109
|
+
fullName: i
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function j(o) {
|
|
113
|
+
return _(o).coreName;
|
|
97
114
|
}
|
|
98
|
-
function
|
|
99
|
-
|
|
115
|
+
function U(o, t) {
|
|
116
|
+
if (!o)
|
|
117
|
+
return [];
|
|
118
|
+
const i = [`./${o}`];
|
|
119
|
+
return t && i.push(`./${t}.${o}`), i;
|
|
100
120
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
121
|
+
function P(o) {
|
|
122
|
+
return o.replace(/\\/g, "/");
|
|
123
|
+
}
|
|
124
|
+
function Y(o, t, i, r) {
|
|
125
|
+
const a = {}, l = /* @__PURE__ */ new Set();
|
|
126
|
+
for (const f of o) {
|
|
127
|
+
const n = _(f);
|
|
128
|
+
if (!n.coreName) continue;
|
|
129
|
+
const u = n.fullName, p = P(`./${h.join(t, `${u}.js`)}`), m = P(`./${h.join(t, "types", `${u}.d.ts`)}`), c = { import: p, types: m }, d = U(n.coreName, n.prefix);
|
|
130
|
+
for (const x of d)
|
|
131
|
+
a[x] = c, r && console.log(
|
|
109
132
|
"api-client-generator %s Generated standard export: %s -> { import: %s, types: %s }",
|
|
110
133
|
e.blue("debug"),
|
|
111
|
-
e.whiteBright(
|
|
112
|
-
e.whiteBright(
|
|
113
|
-
e.whiteBright(
|
|
134
|
+
e.whiteBright(x),
|
|
135
|
+
e.whiteBright(p),
|
|
136
|
+
e.whiteBright(m)
|
|
114
137
|
);
|
|
115
|
-
|
|
138
|
+
l.add(n.coreName);
|
|
116
139
|
}
|
|
117
|
-
const
|
|
118
|
-
if (
|
|
119
|
-
for (const [
|
|
120
|
-
if (
|
|
140
|
+
const g = { ...a };
|
|
141
|
+
if (i)
|
|
142
|
+
for (const [f, n] of Object.entries(i)) {
|
|
143
|
+
if (f === ".")
|
|
121
144
|
continue;
|
|
122
|
-
if (typeof
|
|
145
|
+
if (typeof n != "object" || n === null) {
|
|
123
146
|
r && console.log(
|
|
124
147
|
"api-client-generator %s Skipping malformed existing export value for key: %s",
|
|
125
148
|
e.yellow("warning"),
|
|
126
|
-
|
|
149
|
+
f
|
|
127
150
|
);
|
|
128
151
|
continue;
|
|
129
152
|
}
|
|
130
|
-
const
|
|
131
|
-
if (!
|
|
153
|
+
const u = n;
|
|
154
|
+
if (!u.import || !u.types) {
|
|
132
155
|
r && console.log(
|
|
133
156
|
"api-client-generator %s Skipping existing export with missing import/types for key: %s",
|
|
134
157
|
e.yellow("warning"),
|
|
135
|
-
|
|
158
|
+
f
|
|
136
159
|
);
|
|
137
160
|
continue;
|
|
138
161
|
}
|
|
139
|
-
const
|
|
140
|
-
if (!(!
|
|
141
|
-
if (
|
|
162
|
+
const p = A(f);
|
|
163
|
+
if (!(!p || p === "."))
|
|
164
|
+
if (j(p), p in a)
|
|
142
165
|
r && console.log(
|
|
143
166
|
"api-client-generator %s Existing export key '%s' was handled by new generation.",
|
|
144
167
|
e.blue("debug"),
|
|
145
|
-
e.whiteBright(
|
|
168
|
+
e.whiteBright(p)
|
|
146
169
|
);
|
|
147
170
|
else {
|
|
148
|
-
const
|
|
149
|
-
p
|
|
150
|
-
import: `${
|
|
151
|
-
types: `${
|
|
171
|
+
const m = A(u.import), c = A(u.types);
|
|
172
|
+
g[p] = {
|
|
173
|
+
import: P(`${m}.js`),
|
|
174
|
+
types: P(`${c}.d.ts`)
|
|
152
175
|
}, r && console.log(
|
|
153
176
|
"api-client-generator %s Preserved existing export: %s -> { import: %s, types: %s }",
|
|
154
177
|
e.blue("debug"),
|
|
155
|
-
e.whiteBright(
|
|
156
|
-
e.whiteBright(`${
|
|
157
|
-
e.whiteBright(`${
|
|
178
|
+
e.whiteBright(p),
|
|
179
|
+
e.whiteBright(`${m}.js`),
|
|
180
|
+
e.whiteBright(`${c}.d.ts`)
|
|
158
181
|
);
|
|
159
182
|
}
|
|
160
183
|
}
|
|
161
|
-
const
|
|
162
|
-
for (const
|
|
163
|
-
if (
|
|
164
|
-
const
|
|
165
|
-
|
|
184
|
+
const s = /* @__PURE__ */ new Map();
|
|
185
|
+
for (const f in g) {
|
|
186
|
+
if (f === ".") continue;
|
|
187
|
+
const n = _(f);
|
|
188
|
+
n.coreName && s.set(n.coreName, n.fullName);
|
|
166
189
|
}
|
|
167
|
-
const y = Array.from(
|
|
190
|
+
const y = Array.from(s.keys());
|
|
168
191
|
if (y.length === 1) {
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
import:
|
|
172
|
-
types:
|
|
192
|
+
const f = y[0], n = s.get(f), u = P(`./${h.join(t, `${n}.js`)}`), p = P(`./${h.join(t, "types", `${n}.d.ts`)}`);
|
|
193
|
+
g["."] = {
|
|
194
|
+
import: u,
|
|
195
|
+
types: p
|
|
173
196
|
}, r && console.log(
|
|
174
197
|
"api-client-generator %s Set root export for single module '%s': { import: %s, types: %s }",
|
|
175
198
|
e.blue("debug"),
|
|
176
|
-
e.whiteBright(
|
|
177
|
-
e.whiteBright(
|
|
178
|
-
e.whiteBright(
|
|
199
|
+
e.whiteBright(n),
|
|
200
|
+
e.whiteBright(u),
|
|
201
|
+
e.whiteBright(p)
|
|
179
202
|
);
|
|
180
|
-
} else if (
|
|
181
|
-
const
|
|
182
|
-
if (typeof
|
|
183
|
-
const
|
|
184
|
-
if (
|
|
185
|
-
const
|
|
186
|
-
if (
|
|
187
|
-
const
|
|
188
|
-
|
|
203
|
+
} else if (i && "." in i) {
|
|
204
|
+
const f = i["."];
|
|
205
|
+
if (typeof f == "object" && f !== null) {
|
|
206
|
+
const n = f;
|
|
207
|
+
if (n.import && n.types) {
|
|
208
|
+
const p = _(n.import).coreName;
|
|
209
|
+
if (p && y.includes(p)) {
|
|
210
|
+
const m = s.get(p), c = P(`./${h.join(t, `${m}.js`)}`), d = P(`./${h.join(t, "types", `${m}.d.ts`)}`);
|
|
211
|
+
g["."] = { import: c, types: d }, r && console.log(
|
|
189
212
|
"api-client-generator %s Preserved and standardized existing root export pointing to module '%s'",
|
|
190
213
|
e.blue("debug"),
|
|
191
|
-
e.whiteBright(
|
|
214
|
+
e.whiteBright(m)
|
|
192
215
|
);
|
|
193
216
|
} else r && console.log(
|
|
194
217
|
"api-client-generator %s Removed existing root export as it pointed to an unknown or unhandled module '%s'",
|
|
195
218
|
e.yellow("warning"),
|
|
196
|
-
|
|
219
|
+
p || "unknown"
|
|
197
220
|
);
|
|
198
221
|
} else r && console.log("api-client-generator %s Removed malformed existing root export.", e.yellow("warning"));
|
|
199
222
|
}
|
|
200
223
|
}
|
|
201
|
-
return
|
|
224
|
+
return g;
|
|
202
225
|
}
|
|
203
|
-
function
|
|
204
|
-
const r =
|
|
205
|
-
|
|
206
|
-
const
|
|
207
|
-
name:
|
|
208
|
-
version:
|
|
209
|
-
files:
|
|
226
|
+
function J(o, t, i) {
|
|
227
|
+
const r = i.VERBOSE ?? !1, a = i.APP_BUILD_DIR ?? "dist", l = [];
|
|
228
|
+
a && l.push(a), l.push("package.json");
|
|
229
|
+
const g = {
|
|
230
|
+
name: i.APP_PACKAGE_NAME || "api-client",
|
|
231
|
+
version: i.APP_PACKAGE_VERSION || "1.0.0",
|
|
232
|
+
files: l,
|
|
210
233
|
exports: {},
|
|
211
234
|
// Add metadata to track generated content
|
|
212
235
|
apiClientGenerator: {
|
|
@@ -214,13 +237,13 @@ function U(o, t, a) {
|
|
|
214
237
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
215
238
|
}
|
|
216
239
|
};
|
|
217
|
-
let
|
|
218
|
-
if (
|
|
240
|
+
let s = { ...g }, y, f, n;
|
|
241
|
+
if (C(o))
|
|
219
242
|
try {
|
|
220
|
-
const
|
|
243
|
+
const c = O(o, "utf-8");
|
|
221
244
|
try {
|
|
222
|
-
const
|
|
223
|
-
typeof
|
|
245
|
+
const d = JSON.parse(c);
|
|
246
|
+
typeof d.module == "string" && (f = d.module), typeof d.types == "string" && (n = d.types), s = D(g, d, [
|
|
224
247
|
"name",
|
|
225
248
|
"version",
|
|
226
249
|
"description",
|
|
@@ -231,44 +254,44 @@ function U(o, t, a) {
|
|
|
231
254
|
"scripts",
|
|
232
255
|
"devDependencies",
|
|
233
256
|
"dependencies"
|
|
234
|
-
]),
|
|
235
|
-
} catch (
|
|
257
|
+
]), s.apiClientGenerator = g.apiClientGenerator, d.files && Array.isArray(d.files) && (s.files = Array.from(/* @__PURE__ */ new Set([...l, ...d.files]))), y = d.exports, console.log("api-client-generator %s Updated existing package.json", e.greenBright("success"));
|
|
258
|
+
} catch (d) {
|
|
236
259
|
console.error(
|
|
237
260
|
"api-client-generator %s Failed to parse existing package.json, creating new one",
|
|
238
261
|
e.yellow("warning"),
|
|
239
|
-
|
|
262
|
+
d
|
|
240
263
|
);
|
|
241
264
|
}
|
|
242
|
-
} catch (
|
|
243
|
-
console.error("api-client-generator %s Failed to read existing package.json", e.red("error"),
|
|
265
|
+
} catch (c) {
|
|
266
|
+
console.error("api-client-generator %s Failed to read existing package.json", e.red("error"), c);
|
|
244
267
|
}
|
|
245
268
|
else
|
|
246
269
|
console.log("api-client-generator %s Creating new package.json", e.greenBright("success"));
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
for (const
|
|
250
|
-
if (
|
|
251
|
-
const
|
|
252
|
-
|
|
270
|
+
s.exports = Y(t, a, y, r);
|
|
271
|
+
const u = Object.keys(s.exports), p = /* @__PURE__ */ new Set();
|
|
272
|
+
for (const c of u) {
|
|
273
|
+
if (c === ".") continue;
|
|
274
|
+
const d = j(c);
|
|
275
|
+
d && p.add(d);
|
|
253
276
|
}
|
|
254
|
-
if (Array.from(
|
|
255
|
-
const
|
|
256
|
-
|
|
277
|
+
if (Array.from(p).length, s.exports && "." in s.exports) {
|
|
278
|
+
const c = s.exports["."];
|
|
279
|
+
c && c.import && (s.module = c.import, r && console.log(
|
|
257
280
|
"api-client-generator %s Set 'module' field from root export: %s",
|
|
258
281
|
e.blue("debug"),
|
|
259
|
-
e.whiteBright(
|
|
260
|
-
)),
|
|
282
|
+
e.whiteBright(c.import)
|
|
283
|
+
)), c && c.types && (s.types = c.types, r && console.log(
|
|
261
284
|
"api-client-generator %s Set 'types' field from root export: %s",
|
|
262
285
|
e.blue("debug"),
|
|
263
|
-
e.whiteBright(
|
|
286
|
+
e.whiteBright(c.types)
|
|
264
287
|
));
|
|
265
288
|
} else
|
|
266
|
-
"module" in
|
|
267
|
-
return
|
|
289
|
+
"module" in s && (delete s.module, r && console.log("api-client-generator %s Removed 'module' field (no clear root export).", e.blue("debug"))), "types" in s && (delete s.types, r && console.log("api-client-generator %s Removed 'types' field (no clear root export).", e.blue("debug")));
|
|
290
|
+
return s;
|
|
268
291
|
}
|
|
269
|
-
async function
|
|
270
|
-
await
|
|
271
|
-
const o =
|
|
292
|
+
async function K() {
|
|
293
|
+
await S({}, "build");
|
|
294
|
+
const o = N(process.argv.slice(2)), t = process.env.APP_PLATFORM_URL ?? o.APP_PLATFORM_URL, i = o.VERBOSE ?? !1, r = o.APP_TYPE_STYLE ?? "Class";
|
|
272
295
|
if (r !== "Class" && r !== "Interface") {
|
|
273
296
|
console.error(
|
|
274
297
|
"api-client-generator %s Invalid APP_TYPE_STYLE value: %s. Must be either 'Class' or 'Interface'",
|
|
@@ -277,7 +300,7 @@ async function Y() {
|
|
|
277
300
|
);
|
|
278
301
|
return;
|
|
279
302
|
}
|
|
280
|
-
if (
|
|
303
|
+
if (i && console.log("api-client-generator %s Using APP_TYPE_STYLE: %s", e.blue("debug"), e.whiteBright(r)), !t)
|
|
281
304
|
return console.log(
|
|
282
305
|
e.red("error"),
|
|
283
306
|
"api-client-generator APP_PLATFORM_URL is required in .env config or as api-client-generator argument"
|
|
@@ -286,83 +309,83 @@ async function Y() {
|
|
|
286
309
|
return console.log(e.red("error"), "api-client-generator modules command is required");
|
|
287
310
|
if (!o.APP_API_CLIENT_DIRECTORY)
|
|
288
311
|
return console.log(e.red("error"), "api-client-generator outDir command is required");
|
|
289
|
-
const
|
|
290
|
-
if (!
|
|
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))
|
|
291
314
|
try {
|
|
292
|
-
|
|
315
|
+
T(o.APP_API_CLIENT_DIRECTORY, { recursive: !0 }), console.log(
|
|
293
316
|
"api-client-generator %s Created directory %s",
|
|
294
317
|
e.greenBright("success"),
|
|
295
318
|
e.whiteBright(o.APP_API_CLIENT_DIRECTORY)
|
|
296
319
|
);
|
|
297
|
-
} catch (
|
|
320
|
+
} catch (n) {
|
|
298
321
|
console.error(
|
|
299
322
|
"api-client-generator %s Failed to create directory %s",
|
|
300
323
|
e.red("error"),
|
|
301
324
|
e.whiteBright(o.APP_API_CLIENT_DIRECTORY),
|
|
302
|
-
|
|
325
|
+
n
|
|
303
326
|
);
|
|
304
327
|
return;
|
|
305
328
|
}
|
|
306
|
-
const
|
|
307
|
-
if (!
|
|
329
|
+
const s = h.join(o.APP_API_CLIENT_DIRECTORY, l);
|
|
330
|
+
if (!C(s))
|
|
308
331
|
try {
|
|
309
|
-
|
|
332
|
+
T(s, { recursive: !0 }), console.log(
|
|
310
333
|
"api-client-generator %s Created build directory %s",
|
|
311
334
|
e.greenBright("success"),
|
|
312
|
-
e.whiteBright(
|
|
335
|
+
e.whiteBright(s)
|
|
313
336
|
);
|
|
314
|
-
} catch (
|
|
337
|
+
} catch (n) {
|
|
315
338
|
console.error(
|
|
316
339
|
"api-client-generator %s Failed to create build directory %s",
|
|
317
340
|
e.red("error"),
|
|
318
|
-
e.whiteBright(
|
|
319
|
-
|
|
341
|
+
e.whiteBright(s),
|
|
342
|
+
n
|
|
320
343
|
);
|
|
321
344
|
}
|
|
322
|
-
const y = o.APP_PLATFORM_MODULES.replace(/[[\]]/g, "").split(","),
|
|
323
|
-
for (const
|
|
324
|
-
const
|
|
345
|
+
const y = o.APP_PLATFORM_MODULES.replace(/[[\]]/g, "").split(","), f = [];
|
|
346
|
+
for (const n of y) {
|
|
347
|
+
const u = g.resolveApiClientPaths(n);
|
|
325
348
|
console.log(
|
|
326
349
|
"api-client-generator %s Generating API client for %s module on %s environment",
|
|
327
350
|
e.green("info"),
|
|
328
|
-
e.whiteBright(
|
|
351
|
+
e.whiteBright(n),
|
|
329
352
|
e.whiteBright(t)
|
|
330
353
|
);
|
|
331
|
-
const
|
|
354
|
+
const p = [
|
|
332
355
|
`APP_PLATFORM_URL=${t}`,
|
|
333
|
-
`APP_PLATFORM_MODULE=${
|
|
334
|
-
`APP_AUTH_API_BASE_PATH=${
|
|
335
|
-
`APP_TEMPLATE_DIRECTORY=${
|
|
336
|
-
`APP_API_CLIENT_PATH=${
|
|
356
|
+
`APP_PLATFORM_MODULE=${n}`,
|
|
357
|
+
`APP_AUTH_API_BASE_PATH=${g.nswagPaths.authApiBase}`,
|
|
358
|
+
`APP_TEMPLATE_DIRECTORY=${g.nswagPaths.templates}`,
|
|
359
|
+
`APP_API_CLIENT_PATH=${u.nswag}`,
|
|
337
360
|
`APP_TYPE_STYLE=${r}`
|
|
338
|
-
].join(","),
|
|
339
|
-
|
|
340
|
-
const
|
|
341
|
-
stdio: ["ignore",
|
|
361
|
+
].join(","), m = ["run", g.nswagPaths.configuration, `/variables:${p}`, "/runtime:Net60"];
|
|
362
|
+
i && (console.log("api-client-generator %s Running command: npx nswag %s", e.blue("debug"), m.join(" ")), console.log("api-client-generator %s Variables: %s", e.blue("debug"), p));
|
|
363
|
+
const c = I("npx nswag", m, {
|
|
364
|
+
stdio: ["ignore", i ? "inherit" : "pipe", "inherit"],
|
|
342
365
|
shell: !0
|
|
343
366
|
});
|
|
344
|
-
|
|
367
|
+
c.status === 0 ? (console.log(
|
|
345
368
|
"api-client-generator %s Successfully generated %s",
|
|
346
369
|
e.greenBright("success"),
|
|
347
|
-
e.whiteBright(
|
|
348
|
-
), o.SKIP_BUILD ||
|
|
370
|
+
e.whiteBright(u.console)
|
|
371
|
+
), o.SKIP_BUILD || f.push(`${n.toLowerCase()}.ts`)) : (console.error(
|
|
349
372
|
"api-client-generator %s Failed to generate %s",
|
|
350
373
|
e.red("error"),
|
|
351
|
-
e.whiteBright(
|
|
352
|
-
),
|
|
374
|
+
e.whiteBright(u.console)
|
|
375
|
+
), i && console.error(
|
|
353
376
|
"api-client-generator %s NSwag command failed with exit code: %s",
|
|
354
377
|
e.red("error"),
|
|
355
|
-
|
|
378
|
+
c.status
|
|
356
379
|
));
|
|
357
380
|
}
|
|
358
381
|
if (!o.SKIP_BUILD) {
|
|
359
|
-
const
|
|
360
|
-
|
|
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], {
|
|
361
384
|
stdio: ["ignore", "inherit", "ignore"],
|
|
362
385
|
shell: !0
|
|
363
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"));
|
|
364
|
-
const
|
|
365
|
-
|
|
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"));
|
|
366
389
|
}
|
|
367
390
|
}
|
|
368
|
-
|
|
391
|
+
K();
|
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.88",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": "./dist/api-client-generator.js",
|
|
7
7
|
"files": [
|
|
@@ -13,7 +13,7 @@
|
|
|
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.88",
|
|
17
17
|
"typescript": "^5.8.3"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|