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