@vc-shell/api-client-generator 1.0.320 → 1.0.322

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,16 @@
1
+ ## [1.0.322](https://github.com/VirtoCommerce/vc-shell/compare/v1.0.321...v1.0.322) (2024-11-05)
2
+
3
+
4
+ ### Features
5
+
6
+ * **api-client:** skip build arg ([f67a69f](https://github.com/VirtoCommerce/vc-shell/commit/f67a69fc0b09129a5b2e7ec51039bcc2ba435ea1))
7
+
8
+
9
+
10
+ ## [1.0.321](https://github.com/VirtoCommerce/vc-shell/compare/v1.0.320...v1.0.321) (2024-10-23)
11
+
12
+
13
+
1
14
  ## [1.0.320](https://github.com/VirtoCommerce/vc-shell/compare/v1.0.319...v1.0.320) (2024-10-21)
2
15
 
3
16
 
package/README.md CHANGED
@@ -60,6 +60,10 @@ Add the dependencies to your project's **package.json**:
60
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='[MarketplaceVendor,Orders,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
+ | `--APP_PACKAGE_NAME` | Package name for generated API clients. <br>{==string==} | `--APP_PACKAGE_NAME=vc-app-extend` |
64
+ | `--APP_PACKAGE_VERSION` | Package version for generated API clients. <br>{==string==} | `--APP_PACKAGE_VERSION=1.0.0` |
65
+ | `--APP_OUT_DIR` | Output directory for generated API clients. <br>{==string==} | `--APP_OUT_DIR=./src/api_client/` |
66
+ | `--SKIP_BUILD` | Skip build step. <br>{==boolean==} | `--SKIP_BUILD=true` |
63
67
 
64
68
  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:
65
69
 
@@ -1,20 +1,20 @@
1
1
  import g from "chalk";
2
- import { sync as C } from "cross-spawn";
3
- import { resolveConfig as L } from "vite";
4
- import { existsSync as D, readFileSync as T, writeFileSync as x } from "node:fs";
5
- import m, { dirname as R, resolve as b, join as _, relative as w } from "node:path";
6
- import { fileURLToPath as k } from "node:url";
7
- import { cwd as j } from "node:process";
8
- const E = k(import.meta.url), S = R(E);
9
- class I {
2
+ import { sync as O } from "cross-spawn";
3
+ import { resolveConfig as I } from "vite";
4
+ import { existsSync as D, readFileSync as C, writeFileSync as T } from "node:fs";
5
+ import A, { dirname as b, resolve as L, join as m, relative as _ } from "node:path";
6
+ import { fileURLToPath as R } from "node:url";
7
+ import { cwd as S } from "node:process";
8
+ const k = R(import.meta.url), j = b(k);
9
+ class E {
10
10
  workingDirectory;
11
11
  generatorDirectory;
12
12
  assetsDirectory;
13
13
  apiClientDirectory;
14
14
  nswagPaths;
15
15
  constructor(e) {
16
- this.workingDirectory = j(), this.generatorDirectory = b(S, ".."), this.assetsDirectory = _(this.generatorDirectory, "public", "assets"), this.apiClientDirectory = b(this.workingDirectory, e), this.nswagPaths = {
17
- configuration: _(w(this.workingDirectory, this.assetsDirectory), "config.nswag"),
16
+ this.workingDirectory = S(), this.generatorDirectory = L(j, ".."), this.assetsDirectory = m(this.generatorDirectory, "public", "assets"), this.apiClientDirectory = L(this.workingDirectory, e), this.nswagPaths = {
17
+ configuration: m(_(this.workingDirectory, this.assetsDirectory), "config.nswag"),
18
18
  authApiBase: "authApiBase.ts",
19
19
  templates: "templates"
20
20
  };
@@ -23,111 +23,110 @@ class I {
23
23
  const i = `${e.toLowerCase()}.ts`;
24
24
  return {
25
25
  fileName: i,
26
- nswag: _(w(this.assetsDirectory, this.apiClientDirectory), i),
27
- console: _(w(this.workingDirectory, this.apiClientDirectory), i)
26
+ nswag: m(_(this.assetsDirectory, this.apiClientDirectory), i),
27
+ console: m(_(this.workingDirectory, this.apiClientDirectory), i)
28
28
  };
29
29
  }
30
30
  }
31
- function O(r) {
32
- return r == null ? [] : Array.isArray(r) ? r : [r];
31
+ function y(n) {
32
+ return n == null ? [] : Array.isArray(n) ? n : [n];
33
33
  }
34
- function $(r, e, i, n) {
35
- var c, t = r[e], h = ~n.string.indexOf(e) ? i == null || i === !0 ? "" : String(i) : typeof i == "boolean" ? i : ~n.boolean.indexOf(e) ? i === "false" ? !1 : i === "true" || (r._.push((c = +i, c * 0 === 0 ? c : i)), !!i) : (c = +i, c * 0 === 0 ? c : i);
36
- r[e] = t == null ? h : Array.isArray(t) ? t.concat(h) : [t, h];
34
+ function $(n, e, i, t) {
35
+ var c, s = n[e], u = ~t.string.indexOf(e) ? i == null || i === !0 ? "" : String(i) : typeof i == "boolean" ? i : ~t.boolean.indexOf(e) ? i === "false" ? !1 : i === "true" || (n._.push((c = +i, c * 0 === 0 ? c : i)), !!i) : (c = +i, c * 0 === 0 ? c : i);
36
+ n[e] = s == null ? u : Array.isArray(s) ? s.concat(u) : [s, u];
37
37
  }
38
- function M(r, e) {
39
- r = r || [], e = e || {};
40
- var i, n, c, t, h, s = { _: [] }, o = 0, l = 0, a = 0, f = r.length;
41
- const P = e.alias !== void 0, p = e.unknown !== void 0, u = e.default !== void 0;
42
- if (e.alias = e.alias || {}, e.string = O(e.string), e.boolean = O(e.boolean), P)
38
+ function B(n, e) {
39
+ n = n || [], e = e || {};
40
+ var i, t, c, s, u, o = { _: [] }, r = 0, a = 0, l = 0, f = n.length;
41
+ const P = e.alias !== void 0, h = e.unknown !== void 0, p = e.default !== void 0;
42
+ if (e.alias = e.alias || {}, e.string = y(e.string), e.boolean = y(e.boolean), P)
43
43
  for (i in e.alias)
44
- for (n = e.alias[i] = O(e.alias[i]), o = 0; o < n.length; o++)
45
- (e.alias[n[o]] = n.concat(i)).splice(o, 1);
46
- for (o = e.boolean.length; o-- > 0; )
47
- for (n = e.alias[e.boolean[o]] || [], l = n.length; l-- > 0; ) e.boolean.push(n[l]);
48
- for (o = e.string.length; o-- > 0; )
49
- for (n = e.alias[e.string[o]] || [], l = n.length; l-- > 0; ) e.string.push(n[l]);
50
- if (u) {
44
+ for (t = e.alias[i] = y(e.alias[i]), r = 0; r < t.length; r++)
45
+ (e.alias[t[r]] = t.concat(i)).splice(r, 1);
46
+ for (r = e.boolean.length; r-- > 0; )
47
+ for (t = e.alias[e.boolean[r]] || [], a = t.length; a-- > 0; ) e.boolean.push(t[a]);
48
+ for (r = e.string.length; r-- > 0; )
49
+ for (t = e.alias[e.string[r]] || [], a = t.length; a-- > 0; ) e.string.push(t[a]);
50
+ if (p) {
51
51
  for (i in e.default)
52
- if (t = typeof e.default[i], n = e.alias[i] = e.alias[i] || [], e[t] !== void 0)
53
- for (e[t].push(i), o = 0; o < n.length; o++)
54
- e[t].push(n[o]);
52
+ if (s = typeof e.default[i], t = e.alias[i] = e.alias[i] || [], e[s] !== void 0)
53
+ for (e[s].push(i), r = 0; r < t.length; r++)
54
+ e[s].push(t[r]);
55
55
  }
56
- const d = p ? Object.keys(e.alias) : [];
57
- for (o = 0; o < f; o++) {
58
- if (c = r[o], c === "--") {
59
- s._ = s._.concat(r.slice(++o));
56
+ const d = h ? Object.keys(e.alias) : [];
57
+ for (r = 0; r < f; r++) {
58
+ if (c = n[r], c === "--") {
59
+ o._ = o._.concat(n.slice(++r));
60
60
  break;
61
61
  }
62
- for (l = 0; l < c.length && c.charCodeAt(l) === 45; l++)
62
+ for (a = 0; a < c.length && c.charCodeAt(a) === 45; a++)
63
63
  ;
64
- if (l === 0)
65
- s._.push(c);
66
- else if (c.substring(l, l + 3) === "no-") {
67
- if (t = c.substring(l + 3), p && !~d.indexOf(t))
64
+ if (a === 0)
65
+ o._.push(c);
66
+ else if (c.substring(a, a + 3) === "no-") {
67
+ if (s = c.substring(a + 3), h && !~d.indexOf(s))
68
68
  return e.unknown(c);
69
- s[t] = !1;
69
+ o[s] = !1;
70
70
  } else {
71
- for (a = l + 1; a < c.length && c.charCodeAt(a) !== 61; a++)
71
+ for (l = a + 1; l < c.length && c.charCodeAt(l) !== 61; l++)
72
72
  ;
73
- for (t = c.substring(l, a), h = c.substring(++a) || o + 1 === f || ("" + r[o + 1]).charCodeAt(0) === 45 || r[++o], n = l === 2 ? [t] : t, a = 0; a < n.length; a++) {
74
- if (t = n[a], p && !~d.indexOf(t)) return e.unknown("-".repeat(l) + t);
75
- $(s, t, a + 1 < n.length || h, e);
73
+ for (s = c.substring(a, l), u = c.substring(++l) || r + 1 === f || ("" + n[r + 1]).charCodeAt(0) === 45 || n[++r], t = a === 2 ? [s] : s, l = 0; l < t.length; l++) {
74
+ if (s = t[l], h && !~d.indexOf(s)) return e.unknown("-".repeat(a) + s);
75
+ $(o, s, l + 1 < t.length || u, e);
76
76
  }
77
77
  }
78
78
  }
79
- if (u)
79
+ if (p)
80
80
  for (i in e.default)
81
- s[i] === void 0 && (s[i] = e.default[i]);
81
+ o[i] === void 0 && (o[i] = e.default[i]);
82
82
  if (P)
83
- for (i in s)
84
- for (n = e.alias[i] || []; n.length > 0; )
85
- s[n.shift()] = s[i];
86
- return s;
83
+ for (i in o)
84
+ for (t = e.alias[i] || []; t.length > 0; )
85
+ o[t.shift()] = o[i];
86
+ return o;
87
87
  }
88
- async function N() {
89
- await L({}, "build");
90
- const r = M(process.argv.slice(2)), e = process.env.APP_PLATFORM_URL ?? r.APP_PLATFORM_URL;
88
+ async function M() {
89
+ await I({}, "build");
90
+ const n = B(process.argv.slice(2)), e = process.env.APP_PLATFORM_URL ?? n.APP_PLATFORM_URL;
91
91
  if (!e)
92
92
  return console.log(
93
93
  g.red("error"),
94
94
  "api-client-generator APP_PLATFORM_URL is required in .env config or as api-client-generator argument"
95
95
  );
96
- if (!r.APP_PLATFORM_MODULES)
96
+ if (!n.APP_PLATFORM_MODULES)
97
97
  return console.log(g.red("error"), "api-client-generator modules command is required");
98
- if (!r.APP_API_CLIENT_DIRECTORY)
98
+ if (!n.APP_API_CLIENT_DIRECTORY)
99
99
  return console.log(g.red("error"), "api-client-generator outDir command is required");
100
- const i = r.APP_OUT_DIR ?? "./", n = new I(r.APP_API_CLIENT_DIRECTORY), c = r.APP_PLATFORM_MODULES.replace(/[[\]]/g, "").split(","), t = {}, h = m.join(r.APP_API_CLIENT_DIRECTORY, "tsconfig.json");
101
- let s = {
100
+ const i = n.APP_OUT_DIR ?? "./", t = new E(n.APP_API_CLIENT_DIRECTORY), c = n.APP_PLATFORM_MODULES.replace(/[[\]]/g, "").split(","), s = {};
101
+ let u, o;
102
+ if (!n.SKIP_BUILD && (u = A.join(n.APP_API_CLIENT_DIRECTORY, "tsconfig.json"), o = {
102
103
  extends: "@vc-shell/ts-config/tsconfig.json",
103
104
  compilerOptions: {
104
105
  baseUrl: ".",
105
- declarationDir: m.join(i, "types"),
106
+ declarationDir: A.join(i, "types"),
106
107
  outDir: i,
107
108
  rootDir: "./"
108
109
  },
109
110
  files: [],
110
111
  include: ["*.ts"]
111
- };
112
- if (D(h)) {
113
- const f = JSON.parse(T(h, "utf-8"));
114
- s = { ...s, ...f }, s.compilerOptions = { ...s.compilerOptions, ...f.compilerOptions }, s.files = Array.from(new Set(s.files.concat(f.files || []))), s.include = Array.from(new Set(s.include.concat(f.include || [])));
112
+ }, D(u))) {
113
+ const r = JSON.parse(C(u, "utf-8"));
114
+ o = { ...o, ...r }, o && (o.compilerOptions = { ...o.compilerOptions, ...r.compilerOptions }, o.files = Array.from(new Set(o.files.concat(r.files || []))), o.include = Array.from(new Set(o.include.concat(r.include || [])))), console.log("api-client-generator %s Generated tsconfig.json", g.greenBright("success"));
115
115
  }
116
- console.log("api-client-generator %s Generated tsconfig.json", g.greenBright("success"));
117
- for (const f of c) {
118
- const P = n.resolveApiClientPaths(f);
116
+ for (const r of c) {
117
+ const a = t.resolveApiClientPaths(r);
119
118
  console.log(
120
119
  "api-client-generator %s Generating API client for %s module on %s environment",
121
120
  g.green("info"),
122
- g.whiteBright(f),
121
+ g.whiteBright(r),
123
122
  g.whiteBright(e)
124
123
  );
125
- const p = C(
124
+ const l = O(
126
125
  "npx nswag",
127
126
  [
128
127
  "run",
129
- n.nswagPaths.configuration,
130
- `/variables:APP_PLATFORM_URL=${e},APP_PLATFORM_MODULE=${f},APP_AUTH_API_BASE_PATH=${n.nswagPaths.authApiBase},APP_TEMPLATE_DIRECTORY=${n.nswagPaths.templates},APP_API_CLIENT_PATH=${P.nswag}`,
128
+ t.nswagPaths.configuration,
129
+ `/variables:APP_PLATFORM_URL=${e},APP_PLATFORM_MODULE=${r},APP_AUTH_API_BASE_PATH=${t.nswagPaths.authApiBase},APP_TEMPLATE_DIRECTORY=${t.nswagPaths.templates},APP_API_CLIENT_PATH=${a.nswag}`,
131
130
  "/runtime:Net60"
132
131
  ],
133
132
  {
@@ -135,50 +134,53 @@ async function N() {
135
134
  shell: !0
136
135
  }
137
136
  );
138
- if (p.status === 0) {
139
- console.log(
137
+ if (l.status === 0) {
138
+ if (console.log(
140
139
  "api-client-generator %s Successfully generated %s",
141
140
  g.greenBright("success"),
142
- g.whiteBright(P.console)
143
- );
144
- const u = f.toLowerCase();
145
- s.files.includes(`${u}.ts`) || s.files.push(`${u}.ts`);
146
- const d = {
147
- import: i !== "./" ? `./${i}/${u}.js` : `./${u}.js`,
148
- types: i !== "./" ? `./${i}/types/${u}.d.ts` : `./types/${u}.js`
149
- }, A = Object.keys(t).find(
150
- (y) => t[y].import.includes(`${u}.js`)
151
- );
152
- A ? t[A] = d : t[`./${u}`] = d;
141
+ g.whiteBright(a.console)
142
+ ), !n.SKIP_BUILD && o) {
143
+ const f = r.toLowerCase();
144
+ o.files.includes(`${f}.ts`) || o.files.push(`${f}.ts`);
145
+ const P = {
146
+ import: i !== "./" ? `./${i}/${f}.js` : `./${f}.js`,
147
+ types: i !== "./" ? `./${i}/types/${f}.d.ts` : `./types/${f}.js`
148
+ }, h = Object.keys(s).find(
149
+ (p) => s[p].import.includes(`${f}.js`)
150
+ );
151
+ h ? s[h] = P : s[`./${f}`] = P;
152
+ }
153
153
  } else
154
154
  console.error(
155
155
  "api-client-generator %s Failed to generate %s",
156
156
  g.red("error"),
157
- g.whiteBright(P.console),
158
- p
157
+ g.whiteBright(a.console),
158
+ l
159
159
  );
160
160
  }
161
- x(h, JSON.stringify(s, null, 2)), console.log("api-client-generator %s Compiling TypeScript files to JavaScript", g.green("info")), C("npx tsc", ["--project", h], {
162
- stdio: ["ignore", "inherit", "ignore"],
163
- shell: !0
164
- }).status === 0 ? console.log("api-client-generator %s Successfully compiled TypeScript files", g.greenBright("success")) : console.error("api-client-generator %s Failed to compile TypeScript files", g.red("error"));
165
- const l = m.join(r.APP_API_CLIENT_DIRECTORY, "package.json");
166
- let a = {
167
- name: r.APP_PACKAGE_NAME || "api-client",
168
- version: r.APP_PACKAGE_VERSION || "1.0.0",
169
- files: i !== "./" ? [i, "package.json"] : ["package.json"],
170
- exports: t
171
- };
172
- if (D(l)) {
173
- const f = JSON.parse(T(l, "utf-8"));
174
- a = { ...a, ...f }, a.files = Array.from(new Set(a.files.concat(f.files || []))), a.exports = { ...f.exports, ...a.exports };
175
- for (const [P, p] of Object.entries(t)) {
176
- const u = p.import, d = m.basename(u), A = Object.keys(a.exports).find(
177
- (y) => a.exports[y].import.includes(d)
178
- );
179
- A ? a.exports[A] = p : a.exports[P] = p;
161
+ if (!n.SKIP_BUILD && u && o) {
162
+ T(u, JSON.stringify(o, null, 2)), console.log("api-client-generator %s Compiling TypeScript files to JavaScript", g.green("info")), O("npx tsc", ["--project", u], {
163
+ stdio: ["ignore", "inherit", "ignore"],
164
+ shell: !0
165
+ }).status === 0 ? console.log("api-client-generator %s Successfully compiled TypeScript files", g.greenBright("success")) : console.error("api-client-generator %s Failed to compile TypeScript files", g.red("error"));
166
+ const a = A.join(n.APP_API_CLIENT_DIRECTORY, "package.json");
167
+ let l = {
168
+ name: n.APP_PACKAGE_NAME || "api-client",
169
+ version: n.APP_PACKAGE_VERSION || "1.0.0",
170
+ files: i !== "./" ? [i, "package.json"] : ["package.json"],
171
+ exports: s
172
+ };
173
+ if (D(a)) {
174
+ const f = JSON.parse(C(a, "utf-8"));
175
+ l = { ...l, ...f }, l.files = Array.from(new Set(l.files.concat(f.files || []))), l.exports = { ...f.exports, ...l.exports };
176
+ for (const [P, h] of Object.entries(s)) {
177
+ const p = h.import, d = A.basename(p), w = Object.keys(l.exports).find(
178
+ (x) => l.exports[x].import.includes(d)
179
+ );
180
+ w ? l.exports[w] = h : l.exports[P] = h;
181
+ }
180
182
  }
183
+ T(a, JSON.stringify(l, null, 2)), console.log("api-client-generator %s Generated package.json", g.greenBright("success"));
181
184
  }
182
- x(l, JSON.stringify(a, null, 2)), console.log("api-client-generator %s Generated package.json", g.greenBright("success"));
183
185
  }
184
- N();
186
+ M();
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.0.320",
4
+ "version": "1.0.322",
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.0.320",
16
+ "@vc-shell/ts-config": "^1.0.322",
17
17
  "typescript": "~5.3.3"
18
18
  },
19
19
  "dependencies": {