@vc-shell/api-client-generator 2.0.7-pr236.b5ecb25 → 2.0.7-pr237.2bccbc6
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/README.md +7 -10
- package/dist/api-client-generator.js +209 -247
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -56,13 +56,13 @@ Add the dependencies to your project's **package.json**:
|
|
|
56
56
|
|
|
57
57
|
The options are listed in the table below:
|
|
58
58
|
|
|
59
|
-
| Options | Description
|
|
60
|
-
| ---------------------------- |
|
|
61
|
-
| `--APP_PLATFORM_MODULES` | Platform modules to generate API client.<br>{==string[]==} <br>
|
|
62
|
-
| `--APP_API_CLIENT_DIRECTORY` | Output directory for generated API clients. <br>{==string==}
|
|
63
|
-
| `--APP_PLATFORM_URL` | Platform URL to obtain client API configs. <br>{==string==}
|
|
64
|
-
| `--APP_TYPE_STYLE` | Sets the type style for generated DTOs. Can be 'Class' or 'Interface'.<br>{==string==}
|
|
65
|
-
| `--VERBOSE` | Enable verbose logging. <br>{==boolean==}
|
|
59
|
+
| Options | Description | Example |
|
|
60
|
+
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------ |
|
|
61
|
+
| `--APP_PLATFORM_MODULES` | Platform modules to generate API client.<br>{==string[]==} <br> Supports spaces in module lists: `[Module1, Module2]` or `[Module1,Module2]`<br>Customize the `--APP_PLATFORM_MODULES` list<br>to match your project's requirements. | `--APP_PLATFORM_MODULES='[VirtoCommerce.Catalog, VirtoCommerce.Orders]'` |
|
|
62
|
+
| `--APP_API_CLIENT_DIRECTORY` | Output directory for generated API clients. <br>{==string==} | `--APP_API_CLIENT_DIRECTORY=./src/api_client/` |
|
|
63
|
+
| `--APP_PLATFORM_URL` | Platform URL to obtain client API configs. <br>{==string==} | `--APP_PLATFORM_URL=https://vcmp-dev.govirto.com/` |
|
|
64
|
+
| `--APP_TYPE_STYLE` | Sets the type style for generated DTOs. Can be 'Class' or 'Interface'.<br>{==string==} | `--APP_TYPE_STYLE=Interface` |
|
|
65
|
+
| `--VERBOSE` | Enable verbose logging. <br>{==boolean==} | `--VERBOSE=true` |
|
|
66
66
|
|
|
67
67
|
!!! note
|
|
68
68
|
For the `--APP_TYPE_STYLE` parameter, use **exactly** `"Class"` or `"Interface"` (case-sensitive). Any other value will cause an error.
|
|
@@ -70,9 +70,6 @@ Add the dependencies to your project's **package.json**:
|
|
|
70
70
|
!!! tip
|
|
71
71
|
Use `--APP_TYPE_STYLE=Interface` for better TypeScript integration and smaller bundle sizes. Use `--APP_TYPE_STYLE=Class` when you need runtime type checking or class-specific features.
|
|
72
72
|
|
|
73
|
-
!!! warning
|
|
74
|
-
When passing `--APP_PLATFORM_MODULES` on the command line, wrap the value in quotes. Without quotes, the shell splits `[A, B]` on the space and only the first module is seen — the generator now detects this and exits with an error instead of silently generating a partial client.
|
|
75
|
-
|
|
76
73
|
3. Configure Platform URL and other settings in your project's **.env** file:
|
|
77
74
|
|
|
78
75
|
```title="vc-app-extend/.env"
|
|
@@ -1,74 +1,74 @@
|
|
|
1
1
|
import e from "chalk";
|
|
2
|
-
import { sync as
|
|
3
|
-
import { resolveConfig as
|
|
4
|
-
import { existsSync as w, mkdirSync as
|
|
5
|
-
import
|
|
6
|
-
import { fileURLToPath as
|
|
7
|
-
import { cwd as
|
|
8
|
-
import
|
|
9
|
-
const
|
|
10
|
-
class
|
|
2
|
+
import { sync as v } from "cross-spawn";
|
|
3
|
+
import { resolveConfig as j } from "vite";
|
|
4
|
+
import { existsSync as w, mkdirSync as I, writeFileSync as T, readdirSync as O, readFileSync as x } from "node:fs";
|
|
5
|
+
import m, { dirname as N, resolve as B, join as b, relative as S } from "node:path";
|
|
6
|
+
import { fileURLToPath as L } from "node:url";
|
|
7
|
+
import { cwd as M } from "node:process";
|
|
8
|
+
import U from "mri";
|
|
9
|
+
const $ = L(import.meta.url), F = N($);
|
|
10
|
+
class V {
|
|
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 = M(), this.generatorDirectory = B(F, ".."), this.assetsDirectory = b(this.generatorDirectory, "public", "assets"), this.apiClientDirectory = B(this.workingDirectory, r), this.nswagPaths = {
|
|
18
|
+
configuration: b(S(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(S(this.assetsDirectory, this.apiClientDirectory), n),
|
|
28
|
+
console: b(S(this.workingDirectory, this.apiClientDirectory), n)
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function D(o, r, n = []) {
|
|
33
33
|
const t = { ...o };
|
|
34
|
-
for (const
|
|
35
|
-
|
|
36
|
-
for (const [
|
|
37
|
-
const a =
|
|
38
|
-
|
|
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
40
|
return t;
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
const
|
|
42
|
+
function G(o, r, n, t) {
|
|
43
|
+
const i = {
|
|
44
44
|
extends: "@vc-shell/ts-config/tsconfig.json",
|
|
45
45
|
compilerOptions: {
|
|
46
46
|
baseUrl: ".",
|
|
47
|
-
declarationDir:
|
|
47
|
+
declarationDir: m.join(n, "types"),
|
|
48
48
|
outDir: t,
|
|
49
49
|
rootDir: "./"
|
|
50
50
|
},
|
|
51
51
|
files: [],
|
|
52
52
|
include: ["*.ts"]
|
|
53
53
|
};
|
|
54
|
-
let s = { ...
|
|
54
|
+
let s = { ...i };
|
|
55
55
|
if (w(o))
|
|
56
56
|
try {
|
|
57
|
-
const a =
|
|
57
|
+
const a = x(o, "utf-8");
|
|
58
58
|
try {
|
|
59
59
|
const l = JSON.parse(a);
|
|
60
|
-
s =
|
|
61
|
-
...
|
|
60
|
+
s = D(i, l), l.compilerOptions && typeof l.compilerOptions == "object" && (s.compilerOptions = {
|
|
61
|
+
...i.compilerOptions,
|
|
62
62
|
...l.compilerOptions
|
|
63
|
-
}, s.compilerOptions.outDir = t, s.compilerOptions.declarationDir =
|
|
64
|
-
const
|
|
65
|
-
s.files = Array.from(/* @__PURE__ */ new Set([...r, ...
|
|
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
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
70
|
l
|
|
71
|
-
), s = { ...
|
|
71
|
+
), s = { ...i }, s.files = r;
|
|
72
72
|
}
|
|
73
73
|
} catch (a) {
|
|
74
74
|
console.error("api-client-generator %s Failed to read existing tsconfig.json", e.red("error"), a);
|
|
@@ -77,158 +77,158 @@ function q(o, r, i, t) {
|
|
|
77
77
|
s.files = r, console.log("api-client-generator %s Created new tsconfig.json", e.greenBright("success"));
|
|
78
78
|
return s;
|
|
79
79
|
}
|
|
80
|
-
function
|
|
80
|
+
function E(o) {
|
|
81
81
|
let r = o;
|
|
82
|
-
const
|
|
82
|
+
const n = [".d.ts", ".ts", ".js"];
|
|
83
83
|
let t;
|
|
84
84
|
do {
|
|
85
85
|
t = !1;
|
|
86
|
-
for (const
|
|
87
|
-
if (r.toLowerCase().endsWith(
|
|
88
|
-
r = r.substring(0, r.length -
|
|
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
91
|
} while (t);
|
|
92
|
-
return r = r.replace(/\/\.\//g, "/"), r = r.replace(/\/+/g, "/"), r = r.replace(/\.\.\//g, ""), r !== "." && !r.startsWith("./") && !r.startsWith("/") && !
|
|
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
|
|
94
|
+
function _(o) {
|
|
95
|
+
let r = E(o);
|
|
96
|
+
r = m.basename(r);
|
|
97
|
+
const n = r.toLowerCase(), t = n.indexOf(".");
|
|
98
98
|
if (t > 0) {
|
|
99
|
-
const
|
|
99
|
+
const i = n.substring(0, t), s = n.substring(t + 1);
|
|
100
100
|
return {
|
|
101
|
-
prefix:
|
|
101
|
+
prefix: i,
|
|
102
102
|
coreName: s,
|
|
103
|
-
fullName:
|
|
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 R(o) {
|
|
113
|
+
return _(o).coreName;
|
|
114
114
|
}
|
|
115
|
-
function
|
|
115
|
+
function K(o, r) {
|
|
116
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
121
|
function P(o) {
|
|
122
122
|
return o.replace(/\\/g, "/");
|
|
123
123
|
}
|
|
124
|
-
function
|
|
125
|
-
const
|
|
126
|
-
for (const
|
|
127
|
-
const
|
|
128
|
-
if (!
|
|
129
|
-
const
|
|
130
|
-
for (const A of
|
|
131
|
-
|
|
124
|
+
function Y(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 y = g.fullName, c = P(`./${m.join(r, `${y}.js`)}`), h = P(`./${m.join(r, "types", `${y}.d.ts`)}`), u = { import: c, types: h }, f = K(g.coreName, g.prefix);
|
|
130
|
+
for (const A of f)
|
|
131
|
+
i[A] = u, t && console.log(
|
|
132
132
|
"api-client-generator %s Generated standard export: %s -> { import: %s, types: %s }",
|
|
133
133
|
e.blue("debug"),
|
|
134
134
|
e.whiteBright(A),
|
|
135
|
-
e.whiteBright(
|
|
136
|
-
e.whiteBright(
|
|
135
|
+
e.whiteBright(c),
|
|
136
|
+
e.whiteBright(h)
|
|
137
137
|
);
|
|
138
|
-
s.add(
|
|
138
|
+
s.add(g.coreName);
|
|
139
139
|
}
|
|
140
|
-
const a = { ...
|
|
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
|
|
145
|
+
if (typeof g != "object" || g === null) {
|
|
146
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
|
|
154
|
-
if (!
|
|
153
|
+
const y = g;
|
|
154
|
+
if (!y.import || !y.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 (
|
|
162
|
+
const c = E(d);
|
|
163
|
+
if (!(!c || c === "."))
|
|
164
|
+
if (R(c), c in i)
|
|
165
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
|
-
a[
|
|
173
|
-
import: P(`${
|
|
174
|
-
types: P(`${
|
|
171
|
+
const h = E(y.import), u = E(y.types);
|
|
172
|
+
a[c] = {
|
|
173
|
+
import: P(`${h}.js`),
|
|
174
|
+
types: P(`${u}.d.ts`)
|
|
175
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(`${h}.js`),
|
|
180
|
+
e.whiteBright(`${u}.d.ts`)
|
|
181
181
|
);
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
const l = /* @__PURE__ */ new Map();
|
|
185
|
-
for (const
|
|
186
|
-
if (
|
|
187
|
-
const
|
|
188
|
-
|
|
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
|
|
190
|
+
const p = Array.from(l.keys());
|
|
191
|
+
if (p.length === 1) {
|
|
192
|
+
const d = p[0], g = l.get(d), y = P(`./${m.join(r, `${g}.js`)}`), c = P(`./${m.join(r, "types", `${g}.d.ts`)}`);
|
|
193
193
|
a["."] = {
|
|
194
|
-
import:
|
|
195
|
-
types:
|
|
194
|
+
import: y,
|
|
195
|
+
types: c
|
|
196
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(g),
|
|
200
|
+
e.whiteBright(y),
|
|
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
|
-
a["."] = { import:
|
|
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 h = l.get(c), u = P(`./${m.join(r, `${h}.js`)}`), f = P(`./${m.join(r, "types", `${h}.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(h)
|
|
215
215
|
);
|
|
216
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
221
|
} else t && console.log("api-client-generator %s Removed malformed existing root export.", e.yellow("warning"));
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
224
|
return a;
|
|
225
225
|
}
|
|
226
|
-
function
|
|
227
|
-
const t =
|
|
228
|
-
|
|
226
|
+
function J(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
229
|
const a = {
|
|
230
|
-
name:
|
|
231
|
-
version:
|
|
230
|
+
name: n.APP_PACKAGE_NAME || "api-client",
|
|
231
|
+
version: n.APP_PACKAGE_VERSION || "1.0.0",
|
|
232
232
|
files: s,
|
|
233
233
|
exports: {},
|
|
234
234
|
// Add metadata to track generated content
|
|
@@ -237,13 +237,13 @@ function H(o, r, i) {
|
|
|
237
237
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
238
238
|
}
|
|
239
239
|
};
|
|
240
|
-
let l = { ...a },
|
|
240
|
+
let l = { ...a }, p, d, g;
|
|
241
241
|
if (w(o))
|
|
242
242
|
try {
|
|
243
|
-
const
|
|
243
|
+
const u = x(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 = D(a, f, [
|
|
247
247
|
"name",
|
|
248
248
|
"version",
|
|
249
249
|
"description",
|
|
@@ -254,56 +254,56 @@ function H(o, r, i) {
|
|
|
254
254
|
"scripts",
|
|
255
255
|
"devDependencies",
|
|
256
256
|
"dependencies"
|
|
257
|
-
]), l.apiClientGenerator = a.apiClientGenerator,
|
|
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
|
-
l.exports =
|
|
271
|
-
const
|
|
272
|
-
for (const
|
|
273
|
-
if (
|
|
274
|
-
const
|
|
275
|
-
|
|
270
|
+
l.exports = Y(r, i, p, t);
|
|
271
|
+
const y = Object.keys(l.exports), c = /* @__PURE__ */ new Set();
|
|
272
|
+
for (const u of y) {
|
|
273
|
+
if (u === ".") continue;
|
|
274
|
+
const f = R(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
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
290
|
return l;
|
|
291
291
|
}
|
|
292
|
-
function
|
|
293
|
-
const r =
|
|
292
|
+
function W(o) {
|
|
293
|
+
const r = m.resolve(process.cwd(), o);
|
|
294
294
|
if (!w(r))
|
|
295
295
|
return;
|
|
296
|
-
let
|
|
296
|
+
let n;
|
|
297
297
|
try {
|
|
298
|
-
|
|
298
|
+
n = O(r).filter((t) => t.endsWith(".ts") && t !== "index.ts");
|
|
299
299
|
} catch {
|
|
300
300
|
return;
|
|
301
301
|
}
|
|
302
|
-
if (
|
|
303
|
-
for (const t of
|
|
304
|
-
const
|
|
302
|
+
if (n.length !== 0) {
|
|
303
|
+
for (const t of n.slice(0, 5)) {
|
|
304
|
+
const i = m.join(r, t);
|
|
305
305
|
try {
|
|
306
|
-
const s =
|
|
306
|
+
const s = x(i, "utf-8");
|
|
307
307
|
if (/export class \w+ implements I\w+/.test(s))
|
|
308
308
|
return "Class";
|
|
309
309
|
} catch {
|
|
@@ -313,132 +313,94 @@ function Q(o) {
|
|
|
313
313
|
return "Interface";
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
|
-
function
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
return {
|
|
321
|
-
ok: !1,
|
|
322
|
-
message: `APP_PLATFORM_MODULES looks truncated — unexpected extra arguments were received: ${r.join(
|
|
323
|
-
", "
|
|
324
|
-
)}`,
|
|
325
|
-
hint: `This usually means the value was not quoted and the shell split it on spaces.
|
|
326
|
-
Wrap the whole value in quotes, e.g.
|
|
327
|
-
--APP_PLATFORM_MODULES='${u}'`
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
if (a)
|
|
331
|
-
return {
|
|
332
|
-
ok: !1,
|
|
333
|
-
message: `APP_PLATFORM_MODULES has unbalanced brackets: ${t}`,
|
|
334
|
-
hint: `The value appears truncated. Wrap it in quotes, e.g.
|
|
335
|
-
--APP_PLATFORM_MODULES='[VirtoCommerce.Catalog, VirtoCommerce.Orders]'`
|
|
336
|
-
};
|
|
337
|
-
const c = t.replace(/[[\]]/g, "").split(",").map((u) => u.trim()).filter((u) => u.length > 0);
|
|
338
|
-
return c.length === 0 ? {
|
|
339
|
-
ok: !1,
|
|
340
|
-
message: `APP_PLATFORM_MODULES did not contain any module names: ${t}`,
|
|
341
|
-
hint: `Provide at least one module, e.g.
|
|
342
|
-
--APP_PLATFORM_MODULES='[VirtoCommerce.Catalog]'`
|
|
343
|
-
} : { ok: !0, modules: c };
|
|
344
|
-
}
|
|
345
|
-
function Z() {
|
|
346
|
-
const o = G(process.argv.slice(2)), r = process.env.APP_PLATFORM_URL ?? o.APP_PLATFORM_URL, i = r?.endsWith("/") ? r : r && `${r}/`, t = process.env.APP_PLATFORM_MODULES !== void 0, n = t ? process.env.APP_PLATFORM_MODULES : o.APP_PLATFORM_MODULES, s = (o._ ?? []).map(String), a = process.env.APP_API_CLIENT_DIRECTORY ?? o.APP_API_CLIENT_DIRECTORY, l = process.env.APP_PACKAGE_NAME ?? o.APP_PACKAGE_NAME, c = process.env.APP_PACKAGE_VERSION ?? o.APP_PACKAGE_VERSION, u = process.env.APP_OUT_DIR ?? o.APP_OUT_DIR ?? "./", d = process.env.APP_BUILD_DIR ?? o.APP_BUILD_DIR ?? "dist", m = process.env.RUNTIME ?? o.RUNTIME ?? "Net80", f = process.env.SKIP_BUILD === "true" || o.SKIP_BUILD === !0, y = process.env.VERBOSE === "true" || o.VERBOSE === !0, g = process.env.APP_TYPE_STYLE ?? o.APP_TYPE_STYLE;
|
|
347
|
-
let p;
|
|
348
|
-
g ? p = g : a ? p = Q(a) ?? "Interface" : p = "Interface", g || console.log(
|
|
316
|
+
function q() {
|
|
317
|
+
const o = U(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, y = process.env.VERBOSE === "true" || o.VERBOSE === !0, c = process.env.APP_TYPE_STYLE ?? o.APP_TYPE_STYLE;
|
|
318
|
+
let h;
|
|
319
|
+
c ? h = c : i ? h = W(i) ?? "Interface" : h = "Interface", c || console.log(
|
|
349
320
|
"api-client-generator %s APP_TYPE_STYLE not specified, using %s (set APP_TYPE_STYLE=Class to generate class-based DTOs)",
|
|
350
321
|
e.blue("info"),
|
|
351
|
-
e.whiteBright(
|
|
322
|
+
e.whiteBright(h)
|
|
352
323
|
);
|
|
353
|
-
const
|
|
354
|
-
if (
|
|
324
|
+
const u = process.env.APP_PACKAGE_MODE === "true" || o.PACKAGE === !0, f = ["Net80", "Net90", "Net100"];
|
|
325
|
+
if (f.includes(d) || console.warn(
|
|
355
326
|
"api-client-generator %s Unknown RUNTIME value: %s. Known values: %s. Proceeding anyway — NSwag will report an error if the runtime is unsupported.",
|
|
356
327
|
e.yellow("warning"),
|
|
357
|
-
e.whiteBright(
|
|
358
|
-
e.whiteBright(
|
|
359
|
-
),
|
|
328
|
+
e.whiteBright(d),
|
|
329
|
+
e.whiteBright(f.join(", "))
|
|
330
|
+
), h !== "Class" && h !== "Interface" && (console.error(
|
|
360
331
|
"api-client-generator %s Invalid APP_TYPE_STYLE value: %s. Must be either 'Class' or 'Interface'",
|
|
361
332
|
e.red("error"),
|
|
362
|
-
e.whiteBright(
|
|
333
|
+
e.whiteBright(h)
|
|
363
334
|
), process.exit(1)), y) {
|
|
364
|
-
const
|
|
335
|
+
const k = c ? "explicit" : i ? "auto-detected" : "default";
|
|
365
336
|
console.log(
|
|
366
337
|
"api-client-generator %s Using APP_TYPE_STYLE: %s (%s)",
|
|
367
338
|
e.blue("debug"),
|
|
368
|
-
e.whiteBright(
|
|
369
|
-
e.gray(
|
|
339
|
+
e.whiteBright(h),
|
|
340
|
+
e.gray(k)
|
|
370
341
|
);
|
|
371
342
|
}
|
|
372
|
-
|
|
343
|
+
n || (console.error(
|
|
373
344
|
"api-client-generator %s APP_PLATFORM_URL is required in .env config or as api-client-generator argument",
|
|
374
345
|
e.red("error")
|
|
375
|
-
), process.exit(1)),
|
|
346
|
+
), process.exit(1)), t || (console.error(
|
|
376
347
|
"api-client-generator %s APP_PLATFORM_MODULES is required in .env config or as api-client-generator argument",
|
|
377
348
|
e.red("error")
|
|
378
|
-
), process.exit(1))
|
|
379
|
-
const _ = X(n, s, t);
|
|
380
|
-
_.ok || (console.error("api-client-generator %s %s", e.red("error"), _.message), _.hint && console.error(e.blue(_.hint)), process.exit(1));
|
|
381
|
-
const C = _.modules;
|
|
382
|
-
console.log(
|
|
383
|
-
"api-client-generator %s Parsed %d module(s): %s",
|
|
384
|
-
e.blue("info"),
|
|
385
|
-
C.length,
|
|
386
|
-
e.whiteBright(C.join(", "))
|
|
387
|
-
), a || (console.error(
|
|
349
|
+
), process.exit(1)), i || (console.error(
|
|
388
350
|
"api-client-generator %s APP_API_CLIENT_DIRECTORY is required in .env config or as api-client-generator argument",
|
|
389
351
|
e.red("error")
|
|
390
352
|
), process.exit(1));
|
|
391
|
-
const
|
|
353
|
+
const A = m.join(m.resolve(process.cwd(), i), "package.json"), C = u || w(A);
|
|
392
354
|
return y && console.log(
|
|
393
355
|
"api-client-generator %s Package mode: %s (explicit flag: %s, existing package.json: %s)",
|
|
394
356
|
e.blue("debug"),
|
|
395
|
-
e.whiteBright(String(
|
|
396
|
-
e.whiteBright(String(
|
|
397
|
-
e.whiteBright(String(w(
|
|
357
|
+
e.whiteBright(String(C)),
|
|
358
|
+
e.whiteBright(String(u)),
|
|
359
|
+
e.whiteBright(String(w(A)))
|
|
398
360
|
), {
|
|
399
|
-
platformUrl:
|
|
400
|
-
|
|
401
|
-
apiClientDirectory:
|
|
402
|
-
packageName:
|
|
403
|
-
packageVersion:
|
|
404
|
-
outDir:
|
|
405
|
-
buildDir:
|
|
406
|
-
runtime:
|
|
407
|
-
skipBuild:
|
|
361
|
+
platformUrl: n,
|
|
362
|
+
platformModules: t,
|
|
363
|
+
apiClientDirectory: i,
|
|
364
|
+
packageName: s,
|
|
365
|
+
packageVersion: a,
|
|
366
|
+
outDir: l,
|
|
367
|
+
buildDir: p,
|
|
368
|
+
runtime: d,
|
|
369
|
+
skipBuild: g,
|
|
408
370
|
verbose: y,
|
|
409
|
-
typeStyle:
|
|
410
|
-
packageMode:
|
|
371
|
+
typeStyle: h,
|
|
372
|
+
packageMode: C,
|
|
411
373
|
parsedArgs: o
|
|
412
374
|
};
|
|
413
375
|
}
|
|
414
|
-
function
|
|
415
|
-
const r = new
|
|
376
|
+
function z(o) {
|
|
377
|
+
const r = new V(o.apiClientDirectory);
|
|
416
378
|
if (!w(o.apiClientDirectory))
|
|
417
379
|
try {
|
|
418
|
-
|
|
380
|
+
I(o.apiClientDirectory, { recursive: !0 }), console.log(
|
|
419
381
|
"api-client-generator %s Created directory %s",
|
|
420
382
|
e.greenBright("success"),
|
|
421
383
|
e.whiteBright(o.apiClientDirectory)
|
|
422
384
|
);
|
|
423
|
-
} catch (
|
|
385
|
+
} catch (i) {
|
|
424
386
|
console.error(
|
|
425
387
|
"api-client-generator %s Failed to create directory %s",
|
|
426
388
|
e.red("error"),
|
|
427
389
|
e.whiteBright(o.apiClientDirectory)
|
|
428
|
-
), console.error(e.red("Error details:"),
|
|
390
|
+
), 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);
|
|
429
391
|
}
|
|
430
|
-
const
|
|
431
|
-
for (const
|
|
432
|
-
const s = r.resolveApiClientPaths(
|
|
392
|
+
const n = o.platformModules.replace(/[[\]]/g, "").split(",").map((i) => i.trim()).filter((i) => i.length > 0), t = [];
|
|
393
|
+
for (const i of n) {
|
|
394
|
+
const s = r.resolveApiClientPaths(i);
|
|
433
395
|
console.log(
|
|
434
396
|
"api-client-generator %s Generating API client for %s module on %s environment",
|
|
435
397
|
e.green("info"),
|
|
436
|
-
e.whiteBright(
|
|
398
|
+
e.whiteBright(i),
|
|
437
399
|
e.whiteBright(o.platformUrl)
|
|
438
400
|
);
|
|
439
401
|
const a = [
|
|
440
402
|
`APP_PLATFORM_URL=${o.platformUrl}`,
|
|
441
|
-
`APP_PLATFORM_MODULE=${
|
|
403
|
+
`APP_PLATFORM_MODULE=${i}`,
|
|
442
404
|
`APP_AUTH_API_BASE_PATH=${r.nswagPaths.authApiBase}`,
|
|
443
405
|
`APP_TEMPLATE_DIRECTORY=${r.nswagPaths.templates}`,
|
|
444
406
|
`APP_API_CLIENT_PATH=${s.nswag}`,
|
|
@@ -446,55 +408,55 @@ function ee(o) {
|
|
|
446
408
|
`RUNTIME=${o.runtime}`
|
|
447
409
|
].join(","), l = ["run", r.nswagPaths.configuration, `/variables:${a}`];
|
|
448
410
|
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));
|
|
449
|
-
const
|
|
411
|
+
const p = v("npx nswag", l, {
|
|
450
412
|
stdio: ["ignore", o.verbose ? "inherit" : "pipe", "inherit"],
|
|
451
413
|
shell: !0
|
|
452
414
|
});
|
|
453
|
-
|
|
415
|
+
p.status === 0 ? (console.log(
|
|
454
416
|
"api-client-generator %s Successfully generated %s",
|
|
455
417
|
e.greenBright("success"),
|
|
456
418
|
e.whiteBright(s.console)
|
|
457
|
-
), t.push(`${
|
|
419
|
+
), t.push(`${i.toLowerCase()}.ts`)) : (console.error(
|
|
458
420
|
"api-client-generator %s Failed to generate %s",
|
|
459
421
|
e.red("error"),
|
|
460
422
|
e.whiteBright(s.console)
|
|
461
423
|
), console.error(
|
|
462
424
|
"api-client-generator %s NSwag command failed with exit code: %s",
|
|
463
425
|
e.red("error"),
|
|
464
|
-
|
|
465
|
-
),
|
|
426
|
+
p.status
|
|
427
|
+
), 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));
|
|
466
428
|
}
|
|
467
429
|
return t;
|
|
468
430
|
}
|
|
469
|
-
function
|
|
470
|
-
const
|
|
471
|
-
if (!w(
|
|
431
|
+
function H(o, r) {
|
|
432
|
+
const n = m.join(o.apiClientDirectory, o.buildDir);
|
|
433
|
+
if (!w(n))
|
|
472
434
|
try {
|
|
473
|
-
|
|
435
|
+
I(n, { recursive: !0 }), console.log(
|
|
474
436
|
"api-client-generator %s Created build directory %s",
|
|
475
437
|
e.greenBright("success"),
|
|
476
|
-
e.whiteBright(
|
|
438
|
+
e.whiteBright(n)
|
|
477
439
|
);
|
|
478
|
-
} catch (
|
|
440
|
+
} catch (p) {
|
|
479
441
|
console.error(
|
|
480
442
|
"api-client-generator %s Failed to create build directory %s",
|
|
481
443
|
e.red("error"),
|
|
482
|
-
e.whiteBright(
|
|
483
|
-
), console.error(e.red("Error details:"),
|
|
444
|
+
e.whiteBright(n)
|
|
445
|
+
), 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"));
|
|
484
446
|
}
|
|
485
|
-
const t =
|
|
447
|
+
const t = m.join(o.apiClientDirectory, "tsconfig.json"), i = G(t, r, o.outDir, o.buildDir);
|
|
486
448
|
try {
|
|
487
|
-
|
|
488
|
-
} catch (
|
|
489
|
-
console.error("api-client-generator %s Failed to write tsconfig.json", e.red("error")), console.error(e.red("Error details:"),
|
|
449
|
+
T(t, JSON.stringify(i, null, 2)), o.verbose && console.log("api-client-generator %s Updated tsconfig.json", e.greenBright("success"));
|
|
450
|
+
} catch (p) {
|
|
451
|
+
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);
|
|
490
452
|
}
|
|
491
453
|
console.log("api-client-generator %s Compiling TypeScript files to JavaScript", e.green("info"));
|
|
492
|
-
const s =
|
|
454
|
+
const s = v("npx tsc", ["--project", t], {
|
|
493
455
|
stdio: ["ignore", "pipe", "pipe"],
|
|
494
456
|
shell: !0
|
|
495
457
|
});
|
|
496
458
|
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));
|
|
497
|
-
const a =
|
|
459
|
+
const a = m.join(o.apiClientDirectory, "package.json"), l = J(a, r, {
|
|
498
460
|
...o.parsedArgs,
|
|
499
461
|
APP_PACKAGE_NAME: o.packageName,
|
|
500
462
|
APP_PACKAGE_VERSION: o.packageVersion,
|
|
@@ -502,16 +464,16 @@ function re(o, r) {
|
|
|
502
464
|
VERBOSE: o.verbose
|
|
503
465
|
});
|
|
504
466
|
try {
|
|
505
|
-
|
|
506
|
-
} catch (
|
|
507
|
-
console.error("api-client-generator %s Failed to write package.json", e.red("error")), console.error(e.red("Error details:"),
|
|
467
|
+
T(a, JSON.stringify(l, null, 2)), console.log("api-client-generator %s Generated package.json", e.greenBright("success"));
|
|
468
|
+
} catch (p) {
|
|
469
|
+
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);
|
|
508
470
|
}
|
|
509
471
|
}
|
|
510
|
-
async function
|
|
472
|
+
async function Q() {
|
|
511
473
|
try {
|
|
512
|
-
await
|
|
513
|
-
const o =
|
|
514
|
-
o.packageMode && !o.skipBuild && r.length > 0 ?
|
|
474
|
+
await j({}, "build");
|
|
475
|
+
const o = q(), r = z(o);
|
|
476
|
+
o.packageMode && !o.skipBuild && r.length > 0 ? H(o, r) : o.packageMode || console.log(
|
|
515
477
|
"api-client-generator %s Generated %d API client file(s) in simple mode (no package build)",
|
|
516
478
|
e.greenBright("success"),
|
|
517
479
|
r.length
|
|
@@ -520,4 +482,4 @@ async function oe() {
|
|
|
520
482
|
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);
|
|
521
483
|
}
|
|
522
484
|
}
|
|
523
|
-
|
|
485
|
+
Q();
|
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": "2.0.7-
|
|
4
|
+
"version": "2.0.7-pr237.2bccbc6",
|
|
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": "2.0.7-
|
|
16
|
+
"@vc-shell/ts-config": "2.0.7-pr237.2bccbc6",
|
|
17
17
|
"typescript": "^5.8.3"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|