@vc-shell/api-client-generator 1.0.243 → 1.0.245

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