@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 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 to ensure your project can access the platform's API configurations. Add the platform URL to your project's **.env** file:
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
- Alternatively, you can specify the Platform URL as a command option in the previous step when running the `"generate-api-client"` command.
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.8)
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
- ### New Features
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 I } from "cross-spawn";
3
- import { resolveConfig as S } from "vite";
4
- import { existsSync as C, mkdirSync as T, writeFileSync as B, readFileSync as O } from "node:fs";
5
- import h, { dirname as b, resolve as R, join as w, relative as E } from "node:path";
6
- import { fileURLToPath as L } from "node:url";
7
- import { cwd as k } from "node:process";
8
- import N from "mri";
9
- const M = L(import.meta.url), $ = b(M);
10
- class F {
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(t) {
17
- this.workingDirectory = k(), this.generatorDirectory = R($, ".."), this.assetsDirectory = w(this.generatorDirectory, "public", "assets"), this.apiClientDirectory = R(this.workingDirectory, t), this.nswagPaths = {
18
- configuration: w(E(this.workingDirectory, this.assetsDirectory), "config.nswag"),
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(t) {
24
- const i = `${t.toLowerCase()}.ts`;
23
+ resolveApiClientPaths(r) {
24
+ const i = `${r.toLowerCase()}.ts`;
25
25
  return {
26
26
  fileName: i,
27
- nswag: w(E(this.assetsDirectory, this.apiClientDirectory), i),
28
- console: w(E(this.workingDirectory, this.apiClientDirectory), i)
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(o, t, i = []) {
33
- const r = { ...o };
34
- for (const a of i)
35
- a in t && (r[a] = t[a]);
36
- for (const [a, l] of Object.entries(t)) {
37
- const g = a;
38
- a in r && typeof r[g] == "object" && !Array.isArray(r[g]) && typeof l == "object" && !Array.isArray(l) && l !== null ? r[g] = { ...r[g], ...l } : i.includes(a) || (r[g] = l);
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 r;
40
+ return o;
41
41
  }
42
- function v(o, t, i, r) {
43
- const a = {
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: h.join(i, "types"),
48
- outDir: r,
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 l = { ...a };
55
- if (C(o))
54
+ let c = { ...l };
55
+ if (T(t))
56
56
  try {
57
- const g = O(o, "utf-8");
57
+ const u = j(t, "utf-8");
58
58
  try {
59
- const s = JSON.parse(g);
60
- l = D(a, s), s.compilerOptions && typeof s.compilerOptions == "object" && (l.compilerOptions = {
61
- ...a.compilerOptions,
62
- ...s.compilerOptions
63
- }, l.compilerOptions.outDir = r, l.compilerOptions.declarationDir = h.join(r, "types"));
64
- const y = Array.isArray(s.files) ? s.files : [];
65
- l.files = Array.from(/* @__PURE__ */ new Set([...t, ...y])), console.log("api-client-generator %s Updated existing tsconfig.json", e.greenBright("success"));
66
- } catch (s) {
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
- s
71
- ), l = { ...a }, l.files = t;
70
+ n
71
+ ), c = { ...l }, c.files = r;
72
72
  }
73
- } catch (g) {
74
- console.error("api-client-generator %s Failed to read existing tsconfig.json", e.red("error"), g);
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
- l.files = t, console.log("api-client-generator %s Created new tsconfig.json", e.greenBright("success"));
78
- return l;
77
+ c.files = r, console.log("api-client-generator %s Created new tsconfig.json", e.greenBright("success"));
78
+ return c;
79
79
  }
80
- function A(o) {
81
- let t = o;
80
+ function S(t) {
81
+ let r = t;
82
82
  const i = [".d.ts", ".ts", ".js"];
83
- let r;
83
+ let o;
84
84
  do {
85
- r = !1;
86
- for (const a of i)
87
- if (t.toLowerCase().endsWith(a.toLowerCase())) {
88
- t = t.substring(0, t.length - a.length), r = !0;
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 (r);
92
- return t = t.replace(/\/\.\//g, "/"), t = t.replace(/\/+/g, "/"), t = t.replace(/\.\.\//g, ""), t !== "." && !t.startsWith("./") && !t.startsWith("/") && !h.isAbsolute(t) && (t = "./" + t), t.startsWith("//") && (t = "./" + t.substring(2)), t !== "." && t.startsWith("/") && !t.startsWith("./") && !h.isAbsolute(t) && (t = "." + t), t !== "." && t.startsWith("././") && (t = "./" + t.substring(3)), t;
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 _(o) {
95
- let t = A(o);
96
- t = h.basename(t);
97
- const i = t.toLowerCase(), r = i.indexOf(".");
98
- if (r > 0) {
99
- const a = i.substring(0, r), l = i.substring(r + 1);
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: a,
102
- coreName: l,
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 j(o) {
113
- return _(o).coreName;
112
+ function N(t) {
113
+ return C(t).coreName;
114
114
  }
115
- function U(o, t) {
116
- if (!o)
115
+ function J(t, r) {
116
+ if (!t)
117
117
  return [];
118
- const i = [`./${o}`];
119
- return t && i.push(`./${t}.${o}`), i;
118
+ const i = [`./${t}`];
119
+ return r && i.push(`./${r}.${t}`), i;
120
120
  }
121
- function P(o) {
122
- return o.replace(/\\/g, "/");
121
+ function E(t) {
122
+ return t.replace(/\\/g, "/");
123
123
  }
124
- function Y(o, t, i, r) {
125
- const a = {}, l = /* @__PURE__ */ new Set();
126
- for (const f of o) {
127
- const n = _(f);
128
- if (!n.coreName) continue;
129
- const u = n.fullName, p = P(`./${h.join(t, `${u}.js`)}`), m = P(`./${h.join(t, "types", `${u}.d.ts`)}`), c = { import: p, types: m }, d = U(n.coreName, n.prefix);
130
- for (const x of d)
131
- a[x] = c, r && console.log(
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(x),
135
- e.whiteBright(p),
134
+ e.whiteBright(d),
135
+ e.whiteBright(a),
136
136
  e.whiteBright(m)
137
137
  );
138
- l.add(n.coreName);
138
+ c.add(s.coreName);
139
139
  }
140
- const g = { ...a };
140
+ const u = { ...l };
141
141
  if (i)
142
- for (const [f, n] of Object.entries(i)) {
142
+ for (const [f, s] of Object.entries(i)) {
143
143
  if (f === ".")
144
144
  continue;
145
- if (typeof n != "object" || n === null) {
146
- r && console.log(
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 u = n;
154
- if (!u.import || !u.types) {
155
- r && console.log(
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 p = A(f);
163
- if (!(!p || p === "."))
164
- if (j(p), p in a)
165
- r && console.log(
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(p)
168
+ e.whiteBright(a)
169
169
  );
170
170
  else {
171
- const m = A(u.import), c = A(u.types);
172
- g[p] = {
173
- import: P(`${m}.js`),
174
- types: P(`${c}.d.ts`)
175
- }, r && console.log(
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(p),
178
+ e.whiteBright(a),
179
179
  e.whiteBright(`${m}.js`),
180
- e.whiteBright(`${c}.d.ts`)
180
+ e.whiteBright(`${p}.d.ts`)
181
181
  );
182
182
  }
183
183
  }
184
- const s = /* @__PURE__ */ new Map();
185
- for (const f in g) {
184
+ const n = /* @__PURE__ */ new Map();
185
+ for (const f in u) {
186
186
  if (f === ".") continue;
187
- const n = _(f);
188
- n.coreName && s.set(n.coreName, n.fullName);
187
+ const s = C(f);
188
+ s.coreName && n.set(s.coreName, s.fullName);
189
189
  }
190
- const y = Array.from(s.keys());
191
- if (y.length === 1) {
192
- const f = y[0], n = s.get(f), u = P(`./${h.join(t, `${n}.js`)}`), p = P(`./${h.join(t, "types", `${n}.d.ts`)}`);
193
- g["."] = {
194
- import: u,
195
- types: p
196
- }, r && console.log(
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(n),
200
- e.whiteBright(u),
201
- e.whiteBright(p)
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 n = f;
207
- if (n.import && n.types) {
208
- const p = _(n.import).coreName;
209
- if (p && y.includes(p)) {
210
- const m = s.get(p), c = P(`./${h.join(t, `${m}.js`)}`), d = P(`./${h.join(t, "types", `${m}.d.ts`)}`);
211
- g["."] = { import: c, types: d }, r && console.log(
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 r && console.log(
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
- p || "unknown"
219
+ a || "unknown"
220
220
  );
221
- } else r && console.log("api-client-generator %s Removed malformed existing root export.", e.yellow("warning"));
221
+ } else o && console.log("api-client-generator %s Removed malformed existing root export.", e.yellow("warning"));
222
222
  }
223
223
  }
224
- return g;
224
+ return u;
225
225
  }
226
- function J(o, t, i) {
227
- const r = i.VERBOSE ?? !1, a = i.APP_BUILD_DIR ?? "dist", l = [];
228
- a && l.push(a), l.push("package.json");
229
- const g = {
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: l,
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 s = { ...g }, y, f, n;
241
- if (C(o))
240
+ let n = { ...u }, P, f, s;
241
+ if (T(t))
242
242
  try {
243
- const c = O(o, "utf-8");
243
+ const p = j(t, "utf-8");
244
244
  try {
245
- const d = JSON.parse(c);
246
- typeof d.module == "string" && (f = d.module), typeof d.types == "string" && (n = d.types), s = D(g, d, [
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
- ]), s.apiClientGenerator = g.apiClientGenerator, d.files && Array.isArray(d.files) && (s.files = Array.from(/* @__PURE__ */ new Set([...l, ...d.files]))), y = d.exports, console.log("api-client-generator %s Updated existing package.json", e.greenBright("success"));
258
- } catch (d) {
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
- d
262
+ g
263
263
  );
264
264
  }
265
- } catch (c) {
266
- console.error("api-client-generator %s Failed to read existing package.json", e.red("error"), c);
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
- s.exports = Y(t, a, y, r);
271
- const u = Object.keys(s.exports), p = /* @__PURE__ */ new Set();
272
- for (const c of u) {
273
- if (c === ".") continue;
274
- const d = j(c);
275
- d && p.add(d);
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(p).length, s.exports && "." in s.exports) {
278
- const c = s.exports["."];
279
- c && c.import && (s.module = c.import, r && console.log(
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(c.import)
283
- )), c && c.types && (s.types = c.types, r && console.log(
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(c.types)
286
+ e.whiteBright(p.types)
287
287
  ));
288
288
  } else
289
- "module" in s && (delete s.module, r && console.log("api-client-generator %s Removed 'module' field (no clear root export).", e.blue("debug"))), "types" in s && (delete s.types, r && console.log("api-client-generator %s Removed 'types' field (no clear root export).", e.blue("debug")));
290
- return s;
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 K() {
293
- await S({}, "build");
294
- const o = N(process.argv.slice(2)), t = process.env.APP_PLATFORM_URL ?? o.APP_PLATFORM_URL, i = o.VERBOSE ?? !1, r = o.APP_TYPE_STYLE ?? "Class";
295
- if (r !== "Class" && r !== "Interface") {
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(r)
300
- );
301
- return;
302
- }
303
- if (i && console.log("api-client-generator %s Using APP_TYPE_STYLE: %s", e.blue("debug"), e.whiteBright(r)), !t)
304
- return console.log(
305
- e.red("error"),
306
- "api-client-generator APP_PLATFORM_URL is required in .env config or as api-client-generator argument"
307
- );
308
- if (!o.APP_PLATFORM_MODULES)
309
- return console.log(e.red("error"), "api-client-generator modules command is required");
310
- if (!o.APP_API_CLIENT_DIRECTORY)
311
- return console.log(e.red("error"), "api-client-generator outDir command is required");
312
- const a = o.APP_OUT_DIR ?? "./", l = o.APP_BUILD_DIR ?? "dist", g = new F(o.APP_API_CLIENT_DIRECTORY);
313
- if (!C(o.APP_API_CLIENT_DIRECTORY))
314
- try {
315
- T(o.APP_API_CLIENT_DIRECTORY, { recursive: !0 }), console.log(
316
- "api-client-generator %s Created directory %s",
317
- e.greenBright("success"),
318
- e.whiteBright(o.APP_API_CLIENT_DIRECTORY)
319
- );
320
- } catch (n) {
321
- console.error(
322
- "api-client-generator %s Failed to create directory %s",
323
- e.red("error"),
324
- e.whiteBright(o.APP_API_CLIENT_DIRECTORY),
325
- n
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
- return;
328
- }
329
- const s = h.join(o.APP_API_CLIENT_DIRECTORY, l);
330
- if (!C(s))
331
- try {
332
- T(s, { recursive: !0 }), console.log(
333
- "api-client-generator %s Created build directory %s",
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(s)
336
- );
337
- } catch (n) {
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(s),
342
- n
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
- const y = o.APP_PLATFORM_MODULES.replace(/[[\]]/g, "").split(","), f = [];
346
- for (const n of y) {
347
- const u = g.resolveApiClientPaths(n);
348
- console.log(
349
- "api-client-generator %s Generating API client for %s module on %s environment",
350
- e.green("info"),
351
- e.whiteBright(n),
352
- e.whiteBright(t)
353
- );
354
- const p = [
355
- `APP_PLATFORM_URL=${t}`,
356
- `APP_PLATFORM_MODULE=${n}`,
357
- `APP_AUTH_API_BASE_PATH=${g.nswagPaths.authApiBase}`,
358
- `APP_TEMPLATE_DIRECTORY=${g.nswagPaths.templates}`,
359
- `APP_API_CLIENT_PATH=${u.nswag}`,
360
- `APP_TYPE_STYLE=${r}`
361
- ].join(","), m = ["run", g.nswagPaths.configuration, `/variables:${p}`, "/runtime:Net60"];
362
- i && (console.log("api-client-generator %s Running command: npx nswag %s", e.blue("debug"), m.join(" ")), console.log("api-client-generator %s Variables: %s", e.blue("debug"), p));
363
- const c = I("npx nswag", m, {
364
- stdio: ["ignore", i ? "inherit" : "pipe", "inherit"],
365
- shell: !0
366
- });
367
- c.status === 0 ? (console.log(
368
- "api-client-generator %s Successfully generated %s",
369
- e.greenBright("success"),
370
- e.whiteBright(u.console)
371
- ), o.SKIP_BUILD || f.push(`${n.toLowerCase()}.ts`)) : (console.error(
372
- "api-client-generator %s Failed to generate %s",
373
- e.red("error"),
374
- e.whiteBright(u.console)
375
- ), i && console.error(
376
- "api-client-generator %s NSwag command failed with exit code: %s",
377
- e.red("error"),
378
- c.status
379
- ));
380
- }
381
- if (!o.SKIP_BUILD) {
382
- const n = h.join(o.APP_API_CLIENT_DIRECTORY, "tsconfig.json"), u = v(n, f, a, l);
383
- B(n, JSON.stringify(u, null, 2)), console.log("api-client-generator %s Compiling TypeScript files to JavaScript", e.green("info")), I("npx tsc", ["--project", n], {
384
- stdio: ["ignore", "inherit", "ignore"],
385
- shell: !0
386
- }).status === 0 ? console.log("api-client-generator %s Successfully compiled TypeScript files", e.greenBright("success")) : console.error("api-client-generator %s Failed to compile TypeScript files", e.red("error"));
387
- const m = h.join(o.APP_API_CLIENT_DIRECTORY, "package.json"), c = J(m, f, o);
388
- B(m, JSON.stringify(c, null, 2)), console.log("api-client-generator %s Generated package.json", e.greenBright("success"));
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
- K();
417
+ z();
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtime": "Default",
2
+ "runtime": "$(RUNTIME)",
3
3
  "defaultVariables": null,
4
4
  "documentGenerator": {
5
5
  "fromDocument": {
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.88",
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.88",
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": "^13.20.0",
23
+ "nswag": "^14.5.0",
24
24
  "vite": "^6.3.3",
25
25
  "vite-plugin-dts": "^3.6.4"
26
26
  },
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtime": "Default",
2
+ "runtime": "$(RUNTIME)",
3
3
  "defaultVariables": null,
4
4
  "documentGenerator": {
5
5
  "fromDocument": {