@vc-shell/api-client-generator 1.1.88 → 1.1.90
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 +23 -0
- package/README.md +19 -5
- package/dist/api-client-generator.js +271 -245
- 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,26 @@
|
|
|
1
|
+
## [1.1.90](https://github.com/VirtoCommerce/vc-shell/compare/v1.1.89...v1.1.90) (2025-10-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **api-client:** update error message to reflect dynamic .NET Core version requirement ([bbfbaa0](https://github.com/VirtoCommerce/vc-shell/commit/bbfbaa0df92a91e56b36ca48d449d258c90c88bc))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **generate-api-client:** enhance configuration options with environment variable support and improved module list parsing ([30c00f9](https://github.com/VirtoCommerce/vc-shell/commit/30c00f9f963b0fdba5cf64e3ac3769f09f1ddf0b))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## [1.1.89](https://github.com/VirtoCommerce/vc-shell/compare/v1.1.88...v1.1.89) (2025-10-08)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **api-client:** update runtime configuration and enhance error handling in API client generation process ([c9a762a](https://github.com/VirtoCommerce/vc-shell/commit/c9a762ac4e4d120d66b0ab3a16ebfe9078f33fdd))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
1
24
|
## [1.1.88](https://github.com/VirtoCommerce/vc-shell/compare/v1.1.87...v1.1.88) (2025-10-07)
|
|
2
25
|
|
|
3
26
|
|
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ Add the dependencies to your project's **package.json**:
|
|
|
57
57
|
|
|
58
58
|
| Options | Description | Example |
|
|
59
59
|
|----------------------------- |---------------------------------------------------------------- |------------------------------------------------------------ |
|
|
60
|
-
| `--APP_PLATFORM_MODULES` | Platform modules to generate API client.<br>{==string[]==} <br> Customize the `--APP_PLATFORM_MODULES` list<br>to match your project's requirements. | `--APP_PLATFORM_MODULES='[Virtocommerce.MarketplaceVendor,Virtocommerce.Orders,Virtocommerce.Catalog]'` |
|
|
60
|
+
| `--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.MarketplaceVendor, Virtocommerce.Orders, Virtocommerce.Catalog]'` |
|
|
61
61
|
| `--APP_API_CLIENT_DIRECTORY` | Output directory for generated API clients. <br>{==string==} | `--APP_API_CLIENT_DIRECTORY=./src/api_client/` |
|
|
62
62
|
| `--APP_PLATFORM_URL` | Platform URL to obtain client API configs. <br>{==string==} | `--APP_PLATFORM_URL=https://vcmp-dev.govirto.com/` |
|
|
63
63
|
| `--APP_PACKAGE_NAME` | Package name for generated API clients. <br>{==string==} | `--APP_PACKAGE_NAME=@api-client` |
|
|
@@ -74,14 +74,21 @@ Add the dependencies to your project's **package.json**:
|
|
|
74
74
|
!!! tip
|
|
75
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
76
|
|
|
77
|
-
3. Configure Platform URL
|
|
77
|
+
3. Configure Platform URL and other settings in your project's **.env** file:
|
|
78
78
|
|
|
79
79
|
```title="vc-app-extend/.env"
|
|
80
80
|
APP_PLATFORM_URL=https://vcmp-dev.govirto.com/
|
|
81
|
+
APP_PLATFORM_MODULES=[Virtocommerce.MarketplaceVendor,Virtocommerce.Catalog,Virtocommerce.Orders]
|
|
82
|
+
APP_API_CLIENT_DIRECTORY=./src/api_client/
|
|
83
|
+
APP_PACKAGE_NAME=@my-app/api-client
|
|
84
|
+
APP_PACKAGE_VERSION=1.0.0
|
|
85
|
+
APP_BUILD_DIR=dist
|
|
86
|
+
VERBOSE=true
|
|
87
|
+
SKIP_BUILD=false
|
|
81
88
|
```
|
|
82
89
|
|
|
83
90
|
!!! note
|
|
84
|
-
|
|
91
|
+
All configuration options can be set via environment variables in `.env` file or passed as command line arguments. Environment variables take precedence over CLI arguments.
|
|
85
92
|
|
|
86
93
|
4. Generate the API clients using the following command:
|
|
87
94
|
|
|
@@ -168,7 +175,14 @@ By default, the build directory is "dist".
|
|
|
168
175
|
|
|
169
176
|
Better error handling and reporting make it easier to diagnose issues during client generation.
|
|
170
177
|
|
|
171
|
-
## Recent Improvements (v1.1.
|
|
178
|
+
## Recent Improvements (v1.1.9)
|
|
179
|
+
|
|
180
|
+
### New Features
|
|
181
|
+
|
|
182
|
+
- **Environment Variables Support**: All configuration options can now be set via environment variables in `.env` file
|
|
183
|
+
- **Improved Module List Parsing**: Enhanced support for spaces in module lists (e.g., `[Module1, Module2]` or `[Module1,Module2]`)
|
|
184
|
+
- **Better Boolean Handling**: Improved handling of boolean environment variables (`true`/`false` strings)
|
|
185
|
+
- **Enhanced Error Messages**: More descriptive error messages for missing required parameters
|
|
172
186
|
|
|
173
187
|
### Fixed Issues
|
|
174
188
|
|
|
@@ -181,7 +195,7 @@ Better error handling and reporting make it easier to diagnose issues during cli
|
|
|
181
195
|
- **Error Handling**: Improved JSON parsing error handling with better fallback strategies
|
|
182
196
|
- **Root Export Handling**: Fixed issue with root exports being ignored or improperly handled
|
|
183
197
|
|
|
184
|
-
###
|
|
198
|
+
### Previous Features
|
|
185
199
|
|
|
186
200
|
- **Intelligent Config Merging**: Complete rewrite of configuration merging logic to better preserve user settings
|
|
187
201
|
- **Export Path Standardization**: New system for standardizing export paths to improve consistency
|
|
@@ -1,105 +1,105 @@
|
|
|
1
1
|
import e from "chalk";
|
|
2
|
-
import { sync as
|
|
3
|
-
import { resolveConfig as
|
|
4
|
-
import { existsSync as
|
|
5
|
-
import
|
|
6
|
-
import { fileURLToPath as
|
|
7
|
-
import { cwd as
|
|
8
|
-
import
|
|
9
|
-
const
|
|
10
|
-
class
|
|
2
|
+
import { sync as k } from "cross-spawn";
|
|
3
|
+
import { resolveConfig as L } from "vite";
|
|
4
|
+
import { existsSync as T, mkdirSync as R, writeFileSync as v, readFileSync as j } from "node:fs";
|
|
5
|
+
import y, { dirname as M, resolve as O, join as x, relative as I } from "node:path";
|
|
6
|
+
import { fileURLToPath as U } from "node:url";
|
|
7
|
+
import { cwd as F } from "node:process";
|
|
8
|
+
import $ from "mri";
|
|
9
|
+
const V = U(import.meta.url), G = M(V);
|
|
10
|
+
class K {
|
|
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 = F(), this.generatorDirectory = O(G, ".."), this.assetsDirectory = x(this.generatorDirectory, "public", "assets"), this.apiClientDirectory = O(this.workingDirectory, r), this.nswagPaths = {
|
|
18
|
+
configuration: x(I(this.workingDirectory, this.assetsDirectory), "config.nswag"),
|
|
19
19
|
authApiBase: "authApiBase.ts",
|
|
20
20
|
templates: "templates"
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
resolveApiClientPaths(
|
|
24
|
-
const i = `${
|
|
23
|
+
resolveApiClientPaths(r) {
|
|
24
|
+
const i = `${r.toLowerCase()}.ts`;
|
|
25
25
|
return {
|
|
26
26
|
fileName: i,
|
|
27
|
-
nswag:
|
|
28
|
-
console:
|
|
27
|
+
nswag: x(I(this.assetsDirectory, this.apiClientDirectory), i),
|
|
28
|
+
console: x(I(this.workingDirectory, this.apiClientDirectory), i)
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
function D(
|
|
33
|
-
const
|
|
34
|
-
for (const
|
|
35
|
-
|
|
36
|
-
for (const [
|
|
37
|
-
const
|
|
38
|
-
|
|
32
|
+
function D(t, r, i = []) {
|
|
33
|
+
const o = { ...t };
|
|
34
|
+
for (const l of i)
|
|
35
|
+
l in r && (o[l] = r[l]);
|
|
36
|
+
for (const [l, c] of Object.entries(r)) {
|
|
37
|
+
const u = l;
|
|
38
|
+
l in o && typeof o[u] == "object" && !Array.isArray(o[u]) && typeof c == "object" && !Array.isArray(c) && c !== null ? o[u] = { ...o[u], ...c } : i.includes(l) || (o[u] = c);
|
|
39
39
|
}
|
|
40
|
-
return
|
|
40
|
+
return o;
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
const
|
|
42
|
+
function Y(t, r, i, o) {
|
|
43
|
+
const l = {
|
|
44
44
|
extends: "@vc-shell/ts-config/tsconfig.json",
|
|
45
45
|
compilerOptions: {
|
|
46
46
|
baseUrl: ".",
|
|
47
|
-
declarationDir:
|
|
48
|
-
outDir:
|
|
47
|
+
declarationDir: y.join(i, "types"),
|
|
48
|
+
outDir: o,
|
|
49
49
|
rootDir: "./"
|
|
50
50
|
},
|
|
51
51
|
files: [],
|
|
52
52
|
include: ["*.ts"]
|
|
53
53
|
};
|
|
54
|
-
let
|
|
55
|
-
if (
|
|
54
|
+
let c = { ...l };
|
|
55
|
+
if (T(t))
|
|
56
56
|
try {
|
|
57
|
-
const
|
|
57
|
+
const u = j(t, "utf-8");
|
|
58
58
|
try {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
...
|
|
62
|
-
...
|
|
63
|
-
},
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
} catch (
|
|
59
|
+
const n = JSON.parse(u);
|
|
60
|
+
c = D(l, n), n.compilerOptions && typeof n.compilerOptions == "object" && (c.compilerOptions = {
|
|
61
|
+
...l.compilerOptions,
|
|
62
|
+
...n.compilerOptions
|
|
63
|
+
}, c.compilerOptions.outDir = o, c.compilerOptions.declarationDir = y.join(o, "types"));
|
|
64
|
+
const P = Array.isArray(n.files) ? n.files : [];
|
|
65
|
+
c.files = Array.from(/* @__PURE__ */ new Set([...r, ...P])), console.log("api-client-generator %s Updated existing tsconfig.json", e.greenBright("success"));
|
|
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
|
-
|
|
71
|
-
),
|
|
70
|
+
n
|
|
71
|
+
), c = { ...l }, c.files = r;
|
|
72
72
|
}
|
|
73
|
-
} catch (
|
|
74
|
-
console.error("api-client-generator %s Failed to read existing tsconfig.json", e.red("error"),
|
|
73
|
+
} catch (u) {
|
|
74
|
+
console.error("api-client-generator %s Failed to read existing tsconfig.json", e.red("error"), u);
|
|
75
75
|
}
|
|
76
76
|
else
|
|
77
|
-
|
|
78
|
-
return
|
|
77
|
+
c.files = r, console.log("api-client-generator %s Created new tsconfig.json", e.greenBright("success"));
|
|
78
|
+
return c;
|
|
79
79
|
}
|
|
80
|
-
function
|
|
81
|
-
let
|
|
80
|
+
function S(t) {
|
|
81
|
+
let r = t;
|
|
82
82
|
const i = [".d.ts", ".ts", ".js"];
|
|
83
|
-
let
|
|
83
|
+
let o;
|
|
84
84
|
do {
|
|
85
|
-
|
|
86
|
-
for (const
|
|
87
|
-
if (
|
|
88
|
-
|
|
85
|
+
o = !1;
|
|
86
|
+
for (const l of i)
|
|
87
|
+
if (r.toLowerCase().endsWith(l.toLowerCase())) {
|
|
88
|
+
r = r.substring(0, r.length - l.length), o = !0;
|
|
89
89
|
break;
|
|
90
90
|
}
|
|
91
|
-
} while (
|
|
92
|
-
return
|
|
91
|
+
} while (o);
|
|
92
|
+
return r = r.replace(/\/\.\//g, "/"), r = r.replace(/\/+/g, "/"), r = r.replace(/\.\.\//g, ""), r !== "." && !r.startsWith("./") && !r.startsWith("/") && !y.isAbsolute(r) && (r = "./" + r), r.startsWith("//") && (r = "./" + r.substring(2)), r !== "." && r.startsWith("/") && !r.startsWith("./") && !y.isAbsolute(r) && (r = "." + r), r !== "." && r.startsWith("././") && (r = "./" + r.substring(3)), r;
|
|
93
93
|
}
|
|
94
|
-
function
|
|
95
|
-
let
|
|
96
|
-
|
|
97
|
-
const i =
|
|
98
|
-
if (
|
|
99
|
-
const
|
|
94
|
+
function C(t) {
|
|
95
|
+
let r = S(t);
|
|
96
|
+
r = y.basename(r);
|
|
97
|
+
const i = r.toLowerCase(), o = i.indexOf(".");
|
|
98
|
+
if (o > 0) {
|
|
99
|
+
const l = i.substring(0, o), c = i.substring(o + 1);
|
|
100
100
|
return {
|
|
101
|
-
prefix:
|
|
102
|
-
coreName:
|
|
101
|
+
prefix: l,
|
|
102
|
+
coreName: c,
|
|
103
103
|
fullName: i
|
|
104
104
|
};
|
|
105
105
|
}
|
|
@@ -109,127 +109,127 @@ function _(o) {
|
|
|
109
109
|
fullName: i
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
|
-
function
|
|
113
|
-
return
|
|
112
|
+
function N(t) {
|
|
113
|
+
return C(t).coreName;
|
|
114
114
|
}
|
|
115
|
-
function
|
|
116
|
-
if (!
|
|
115
|
+
function J(t, r) {
|
|
116
|
+
if (!t)
|
|
117
117
|
return [];
|
|
118
|
-
const i = [`./${
|
|
119
|
-
return
|
|
118
|
+
const i = [`./${t}`];
|
|
119
|
+
return r && i.push(`./${r}.${t}`), i;
|
|
120
120
|
}
|
|
121
|
-
function
|
|
122
|
-
return
|
|
121
|
+
function E(t) {
|
|
122
|
+
return t.replace(/\\/g, "/");
|
|
123
123
|
}
|
|
124
|
-
function
|
|
125
|
-
const
|
|
126
|
-
for (const f of
|
|
127
|
-
const
|
|
128
|
-
if (!
|
|
129
|
-
const
|
|
130
|
-
for (const
|
|
131
|
-
|
|
124
|
+
function q(t, r, i, o) {
|
|
125
|
+
const l = {}, c = /* @__PURE__ */ new Set();
|
|
126
|
+
for (const f of t) {
|
|
127
|
+
const s = C(f);
|
|
128
|
+
if (!s.coreName) continue;
|
|
129
|
+
const h = s.fullName, a = E(`./${y.join(r, `${h}.js`)}`), m = E(`./${y.join(r, "types", `${h}.d.ts`)}`), p = { import: a, types: m }, g = J(s.coreName, s.prefix);
|
|
130
|
+
for (const d of g)
|
|
131
|
+
l[d] = p, o && 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(
|
|
134
|
+
e.whiteBright(d),
|
|
135
|
+
e.whiteBright(a),
|
|
136
136
|
e.whiteBright(m)
|
|
137
137
|
);
|
|
138
|
-
|
|
138
|
+
c.add(s.coreName);
|
|
139
139
|
}
|
|
140
|
-
const
|
|
140
|
+
const u = { ...l };
|
|
141
141
|
if (i)
|
|
142
|
-
for (const [f,
|
|
142
|
+
for (const [f, s] of Object.entries(i)) {
|
|
143
143
|
if (f === ".")
|
|
144
144
|
continue;
|
|
145
|
-
if (typeof
|
|
146
|
-
|
|
145
|
+
if (typeof s != "object" || s === null) {
|
|
146
|
+
o && console.log(
|
|
147
147
|
"api-client-generator %s Skipping malformed existing export value for key: %s",
|
|
148
148
|
e.yellow("warning"),
|
|
149
149
|
f
|
|
150
150
|
);
|
|
151
151
|
continue;
|
|
152
152
|
}
|
|
153
|
-
const
|
|
154
|
-
if (!
|
|
155
|
-
|
|
153
|
+
const h = s;
|
|
154
|
+
if (!h.import || !h.types) {
|
|
155
|
+
o && 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
|
f
|
|
159
159
|
);
|
|
160
160
|
continue;
|
|
161
161
|
}
|
|
162
|
-
const
|
|
163
|
-
if (!(!
|
|
164
|
-
if (
|
|
165
|
-
|
|
162
|
+
const a = S(f);
|
|
163
|
+
if (!(!a || a === "."))
|
|
164
|
+
if (N(a), a in l)
|
|
165
|
+
o && 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(a)
|
|
169
169
|
);
|
|
170
170
|
else {
|
|
171
|
-
const m =
|
|
172
|
-
|
|
173
|
-
import:
|
|
174
|
-
types:
|
|
175
|
-
},
|
|
171
|
+
const m = S(h.import), p = S(h.types);
|
|
172
|
+
u[a] = {
|
|
173
|
+
import: E(`${m}.js`),
|
|
174
|
+
types: E(`${p}.d.ts`)
|
|
175
|
+
}, o && console.log(
|
|
176
176
|
"api-client-generator %s Preserved existing export: %s -> { import: %s, types: %s }",
|
|
177
177
|
e.blue("debug"),
|
|
178
|
-
e.whiteBright(
|
|
178
|
+
e.whiteBright(a),
|
|
179
179
|
e.whiteBright(`${m}.js`),
|
|
180
|
-
e.whiteBright(`${
|
|
180
|
+
e.whiteBright(`${p}.d.ts`)
|
|
181
181
|
);
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
|
-
const
|
|
185
|
-
for (const f in
|
|
184
|
+
const n = /* @__PURE__ */ new Map();
|
|
185
|
+
for (const f in u) {
|
|
186
186
|
if (f === ".") continue;
|
|
187
|
-
const
|
|
188
|
-
|
|
187
|
+
const s = C(f);
|
|
188
|
+
s.coreName && n.set(s.coreName, s.fullName);
|
|
189
189
|
}
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
192
|
-
const f =
|
|
193
|
-
|
|
194
|
-
import:
|
|
195
|
-
types:
|
|
196
|
-
},
|
|
190
|
+
const P = Array.from(n.keys());
|
|
191
|
+
if (P.length === 1) {
|
|
192
|
+
const f = P[0], s = n.get(f), h = E(`./${y.join(r, `${s}.js`)}`), a = E(`./${y.join(r, "types", `${s}.d.ts`)}`);
|
|
193
|
+
u["."] = {
|
|
194
|
+
import: h,
|
|
195
|
+
types: a
|
|
196
|
+
}, o && 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(s),
|
|
200
|
+
e.whiteBright(h),
|
|
201
|
+
e.whiteBright(a)
|
|
202
202
|
);
|
|
203
203
|
} else if (i && "." in i) {
|
|
204
204
|
const f = i["."];
|
|
205
205
|
if (typeof f == "object" && f !== null) {
|
|
206
|
-
const
|
|
207
|
-
if (
|
|
208
|
-
const
|
|
209
|
-
if (
|
|
210
|
-
const m =
|
|
211
|
-
|
|
206
|
+
const s = f;
|
|
207
|
+
if (s.import && s.types) {
|
|
208
|
+
const a = C(s.import).coreName;
|
|
209
|
+
if (a && P.includes(a)) {
|
|
210
|
+
const m = n.get(a), p = E(`./${y.join(r, `${m}.js`)}`), g = E(`./${y.join(r, "types", `${m}.d.ts`)}`);
|
|
211
|
+
u["."] = { import: p, types: g }, o && console.log(
|
|
212
212
|
"api-client-generator %s Preserved and standardized existing root export pointing to module '%s'",
|
|
213
213
|
e.blue("debug"),
|
|
214
214
|
e.whiteBright(m)
|
|
215
215
|
);
|
|
216
|
-
} else
|
|
216
|
+
} else o && 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
|
+
a || "unknown"
|
|
220
220
|
);
|
|
221
|
-
} else
|
|
221
|
+
} else o && console.log("api-client-generator %s Removed malformed existing root export.", e.yellow("warning"));
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
|
-
return
|
|
224
|
+
return u;
|
|
225
225
|
}
|
|
226
|
-
function
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
const
|
|
226
|
+
function W(t, r, i) {
|
|
227
|
+
const o = i.VERBOSE ?? !1, l = i.APP_BUILD_DIR ?? "dist", c = [];
|
|
228
|
+
l && c.push(l), c.push("package.json");
|
|
229
|
+
const u = {
|
|
230
230
|
name: i.APP_PACKAGE_NAME || "api-client",
|
|
231
231
|
version: i.APP_PACKAGE_VERSION || "1.0.0",
|
|
232
|
-
files:
|
|
232
|
+
files: c,
|
|
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 n = { ...u }, P, f, s;
|
|
241
|
+
if (T(t))
|
|
242
242
|
try {
|
|
243
|
-
const
|
|
243
|
+
const p = j(t, "utf-8");
|
|
244
244
|
try {
|
|
245
|
-
const
|
|
246
|
-
typeof
|
|
245
|
+
const g = JSON.parse(p);
|
|
246
|
+
typeof g.module == "string" && (f = g.module), typeof g.types == "string" && (s = g.types), n = D(u, g, [
|
|
247
247
|
"name",
|
|
248
248
|
"version",
|
|
249
249
|
"description",
|
|
@@ -254,138 +254,164 @@ function J(o, t, i) {
|
|
|
254
254
|
"scripts",
|
|
255
255
|
"devDependencies",
|
|
256
256
|
"dependencies"
|
|
257
|
-
]),
|
|
258
|
-
} catch (
|
|
257
|
+
]), n.apiClientGenerator = u.apiClientGenerator, g.files && Array.isArray(g.files) && (n.files = Array.from(/* @__PURE__ */ new Set([...c, ...g.files]))), P = g.exports, console.log("api-client-generator %s Updated existing package.json", e.greenBright("success"));
|
|
258
|
+
} catch (g) {
|
|
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
|
+
g
|
|
263
263
|
);
|
|
264
264
|
}
|
|
265
|
-
} catch (
|
|
266
|
-
console.error("api-client-generator %s Failed to read existing package.json", e.red("error"),
|
|
265
|
+
} catch (p) {
|
|
266
|
+
console.error("api-client-generator %s Failed to read existing package.json", e.red("error"), p);
|
|
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
|
+
n.exports = q(r, l, P, o);
|
|
271
|
+
const h = Object.keys(n.exports), a = /* @__PURE__ */ new Set();
|
|
272
|
+
for (const p of h) {
|
|
273
|
+
if (p === ".") continue;
|
|
274
|
+
const g = N(p);
|
|
275
|
+
g && a.add(g);
|
|
276
276
|
}
|
|
277
|
-
if (Array.from(
|
|
278
|
-
const
|
|
279
|
-
|
|
277
|
+
if (Array.from(a).length, n.exports && "." in n.exports) {
|
|
278
|
+
const p = n.exports["."];
|
|
279
|
+
p && p.import && (n.module = p.import, o && 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(p.import)
|
|
283
|
+
)), p && p.types && (n.types = p.types, o && 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(p.types)
|
|
287
287
|
));
|
|
288
288
|
} else
|
|
289
|
-
"module" in
|
|
290
|
-
return
|
|
289
|
+
"module" in n && (delete n.module, o && console.log("api-client-generator %s Removed 'module' field (no clear root export).", e.blue("debug"))), "types" in n && (delete n.types, o && console.log("api-client-generator %s Removed 'types' field (no clear root export).", e.blue("debug")));
|
|
290
|
+
return n;
|
|
291
291
|
}
|
|
292
|
-
async function
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
console.error(
|
|
292
|
+
async function z() {
|
|
293
|
+
try {
|
|
294
|
+
await L({}, "build");
|
|
295
|
+
const t = $(process.argv.slice(2)), r = process.env.APP_PLATFORM_URL ?? t.APP_PLATFORM_URL, i = process.env.APP_PLATFORM_MODULES ?? t.APP_PLATFORM_MODULES, o = process.env.APP_API_CLIENT_DIRECTORY ?? t.APP_API_CLIENT_DIRECTORY, l = process.env.APP_PACKAGE_NAME ?? t.APP_PACKAGE_NAME, c = process.env.APP_PACKAGE_VERSION ?? t.APP_PACKAGE_VERSION, u = process.env.APP_OUT_DIR ?? t.APP_OUT_DIR ?? "./", n = process.env.APP_BUILD_DIR ?? t.APP_BUILD_DIR ?? "dist", P = process.env.RUNTIME ?? t.RUNTIME ?? "Net80", f = process.env.SKIP_BUILD === "true" || t.SKIP_BUILD === !0, s = process.env.VERBOSE === "true" || t.VERBOSE === !0, h = process.env.APP_TYPE_STYLE ?? t.APP_TYPE_STYLE ?? "Class";
|
|
296
|
+
h !== "Class" && h !== "Interface" && (console.error(
|
|
297
297
|
"api-client-generator %s Invalid APP_TYPE_STYLE value: %s. Must be either 'Class' or 'Interface'",
|
|
298
298
|
e.red("error"),
|
|
299
|
-
e.whiteBright(
|
|
300
|
-
)
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
)
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
299
|
+
e.whiteBright(h)
|
|
300
|
+
), process.exit(1)), s && console.log(
|
|
301
|
+
"api-client-generator %s Using APP_TYPE_STYLE: %s",
|
|
302
|
+
e.blue("debug"),
|
|
303
|
+
e.whiteBright(h)
|
|
304
|
+
), r || (console.error(
|
|
305
|
+
"api-client-generator %s APP_PLATFORM_URL is required in .env config or as api-client-generator argument",
|
|
306
|
+
e.red("error")
|
|
307
|
+
), process.exit(1)), i || (console.error(
|
|
308
|
+
"api-client-generator %s APP_PLATFORM_MODULES is required in .env config or as api-client-generator argument",
|
|
309
|
+
e.red("error")
|
|
310
|
+
), process.exit(1)), o || (console.error(
|
|
311
|
+
"api-client-generator %s APP_API_CLIENT_DIRECTORY is required in .env config or as api-client-generator argument",
|
|
312
|
+
e.red("error")
|
|
313
|
+
), process.exit(1));
|
|
314
|
+
const a = new K(o);
|
|
315
|
+
if (!T(o))
|
|
316
|
+
try {
|
|
317
|
+
R(o, { recursive: !0 }), console.log(
|
|
318
|
+
"api-client-generator %s Created directory %s",
|
|
319
|
+
e.greenBright("success"),
|
|
320
|
+
e.whiteBright(o)
|
|
321
|
+
);
|
|
322
|
+
} catch (d) {
|
|
323
|
+
console.error(
|
|
324
|
+
"api-client-generator %s Failed to create directory %s",
|
|
325
|
+
e.red("error"),
|
|
326
|
+
e.whiteBright(o)
|
|
327
|
+
), console.error(e.red("Error details:"), d), 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);
|
|
328
|
+
}
|
|
329
|
+
const m = y.join(o, n);
|
|
330
|
+
if (!T(m))
|
|
331
|
+
try {
|
|
332
|
+
R(m, { recursive: !0 }), console.log(
|
|
333
|
+
"api-client-generator %s Created build directory %s",
|
|
334
|
+
e.greenBright("success"),
|
|
335
|
+
e.whiteBright(m)
|
|
336
|
+
);
|
|
337
|
+
} catch (d) {
|
|
338
|
+
console.error(
|
|
339
|
+
"api-client-generator %s Failed to create build directory %s",
|
|
340
|
+
e.red("error"),
|
|
341
|
+
e.whiteBright(m)
|
|
342
|
+
), console.error(e.red("Error details:"), d), 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(
|
|
343
|
+
e.blue(" - The TypeScript compiler will attempt to create the directory during compilation")
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
const p = i.replace(/[[\]]/g, "").split(",").map((d) => d.trim()).filter((d) => d.length > 0), g = [];
|
|
347
|
+
for (const d of p) {
|
|
348
|
+
const b = a.resolveApiClientPaths(d);
|
|
349
|
+
console.log(
|
|
350
|
+
"api-client-generator %s Generating API client for %s module on %s environment",
|
|
351
|
+
e.green("info"),
|
|
352
|
+
e.whiteBright(d),
|
|
353
|
+
e.whiteBright(r)
|
|
326
354
|
);
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
355
|
+
const w = [
|
|
356
|
+
`APP_PLATFORM_URL=${r}`,
|
|
357
|
+
`APP_PLATFORM_MODULE=${d}`,
|
|
358
|
+
`APP_AUTH_API_BASE_PATH=${a.nswagPaths.authApiBase}`,
|
|
359
|
+
`APP_TEMPLATE_DIRECTORY=${a.nswagPaths.templates}`,
|
|
360
|
+
`APP_API_CLIENT_PATH=${b.nswag}`,
|
|
361
|
+
`APP_TYPE_STYLE=${h}`,
|
|
362
|
+
`RUNTIME=${P}`
|
|
363
|
+
].join(","), _ = ["run", a.nswagPaths.configuration, `/variables:${w}`];
|
|
364
|
+
s && (console.log(
|
|
365
|
+
"api-client-generator %s Running command: npx nswag %s",
|
|
366
|
+
e.blue("debug"),
|
|
367
|
+
_.join(" ")
|
|
368
|
+
), console.log("api-client-generator %s Variables: %s", e.blue("debug"), w));
|
|
369
|
+
const A = k("npx nswag", _, {
|
|
370
|
+
stdio: ["ignore", s ? "inherit" : "pipe", "inherit"],
|
|
371
|
+
shell: !0
|
|
372
|
+
});
|
|
373
|
+
A.status === 0 ? (console.log(
|
|
374
|
+
"api-client-generator %s Successfully generated %s",
|
|
334
375
|
e.greenBright("success"),
|
|
335
|
-
e.whiteBright(
|
|
336
|
-
)
|
|
337
|
-
|
|
338
|
-
console.error(
|
|
339
|
-
"api-client-generator %s Failed to create build directory %s",
|
|
376
|
+
e.whiteBright(b.console)
|
|
377
|
+
), f || g.push(`${d.toLowerCase()}.ts`)) : (console.error(
|
|
378
|
+
"api-client-generator %s Failed to generate %s",
|
|
340
379
|
e.red("error"),
|
|
341
|
-
e.whiteBright(
|
|
342
|
-
|
|
343
|
-
|
|
380
|
+
e.whiteBright(b.console)
|
|
381
|
+
), console.error(
|
|
382
|
+
"api-client-generator %s NSwag command failed with exit code: %s",
|
|
383
|
+
e.red("error"),
|
|
384
|
+
A.status
|
|
385
|
+
), A.stderr && A.stderr.toString().trim() && (console.error("api-client-generator %s NSwag error output:", e.red("error")), console.error(e.red(A.stderr.toString()))), A.stdout && A.stdout.toString().trim() && (console.error("api-client-generator %s NSwag output:", e.yellow("warning")), console.error(e.yellow(A.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"), d), console.error(e.blue(` - Ensure .NET Core ${P} is installed`)), console.error(e.blue(" - Try running with --VERBOSE=true for more details")), process.exit(1));
|
|
344
386
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
e.
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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"));
|
|
387
|
+
if (!f) {
|
|
388
|
+
const d = y.join(o, "tsconfig.json"), b = Y(d, g, u, n);
|
|
389
|
+
try {
|
|
390
|
+
v(d, JSON.stringify(b, null, 2)), s && console.log("api-client-generator %s Updated tsconfig.json", e.greenBright("success"));
|
|
391
|
+
} catch (B) {
|
|
392
|
+
console.error("api-client-generator %s Failed to write tsconfig.json", e.red("error")), console.error(e.red("Error details:"), B), 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);
|
|
393
|
+
}
|
|
394
|
+
console.log("api-client-generator %s Compiling TypeScript files to JavaScript", e.green("info"));
|
|
395
|
+
const w = k("npx tsc", ["--project", d], {
|
|
396
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
397
|
+
shell: !0
|
|
398
|
+
});
|
|
399
|
+
w.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")), w.stderr && w.stderr.toString().trim() && (console.error("api-client-generator %s TypeScript compilation errors:", e.red("error")), console.error(e.red(w.stderr.toString()))), w.stdout && w.stdout.toString().trim() && (console.error("api-client-generator %s TypeScript output:", e.yellow("warning")), console.error(e.yellow(w.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));
|
|
400
|
+
const _ = y.join(o, "package.json"), A = W(_, g, {
|
|
401
|
+
...t,
|
|
402
|
+
APP_PACKAGE_NAME: l,
|
|
403
|
+
APP_PACKAGE_VERSION: c,
|
|
404
|
+
APP_BUILD_DIR: n,
|
|
405
|
+
VERBOSE: s
|
|
406
|
+
});
|
|
407
|
+
try {
|
|
408
|
+
v(_, JSON.stringify(A, null, 2)), console.log("api-client-generator %s Generated package.json", e.greenBright("success"));
|
|
409
|
+
} catch (B) {
|
|
410
|
+
console.error("api-client-generator %s Failed to write package.json", e.red("error")), console.error(e.red("Error details:"), B), 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);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
} catch (t) {
|
|
414
|
+
console.error("api-client-generator %s Unexpected error occurred during API client generation", e.red("error")), console.error(e.red("Error details:"), t), 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
415
|
}
|
|
390
416
|
}
|
|
391
|
-
|
|
417
|
+
z();
|
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.90",
|
|
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.90",
|
|
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
|
},
|