@vc-shell/api-client-generator 1.0.282 → 1.0.283
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 +4 -0
- package/dist/api-client-generator.js +47 -44
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import g from "chalk";
|
|
2
|
-
import {
|
|
2
|
+
import { sync as C } from "cross-spawn";
|
|
3
3
|
import { resolveConfig as L } from "vite";
|
|
4
4
|
import { existsSync as D, readFileSync as T, writeFileSync as x } from "node:fs";
|
|
5
5
|
import m, { dirname as R, resolve as b, join as _, relative as w } from "node:path";
|
|
6
6
|
import { fileURLToPath as k } from "node:url";
|
|
7
|
-
import { cwd as
|
|
8
|
-
const
|
|
7
|
+
import { cwd as j } from "node:process";
|
|
8
|
+
const E = k(import.meta.url), S = R(E);
|
|
9
9
|
class I {
|
|
10
10
|
workingDirectory;
|
|
11
11
|
generatorDirectory;
|
|
@@ -13,7 +13,7 @@ class I {
|
|
|
13
13
|
apiClientDirectory;
|
|
14
14
|
nswagPaths;
|
|
15
15
|
constructor(e) {
|
|
16
|
-
this.workingDirectory =
|
|
16
|
+
this.workingDirectory = j(), this.generatorDirectory = b(S, ".."), this.assetsDirectory = _(this.generatorDirectory, "public", "assets"), this.apiClientDirectory = b(this.workingDirectory, e), this.nswagPaths = {
|
|
17
17
|
configuration: _(w(this.workingDirectory, this.assetsDirectory), "config.nswag"),
|
|
18
18
|
authApiBase: "authApiBase.ts",
|
|
19
19
|
templates: "templates"
|
|
@@ -37,53 +37,53 @@ function $(r, e, i, n) {
|
|
|
37
37
|
}
|
|
38
38
|
function M(r, e) {
|
|
39
39
|
r = r || [], e = e || {};
|
|
40
|
-
var i, n, c, t, h,
|
|
41
|
-
const
|
|
42
|
-
if (e.alias = e.alias || {}, e.string = O(e.string), e.boolean = O(e.boolean),
|
|
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)
|
|
43
43
|
for (i in e.alias)
|
|
44
|
-
for (n = e.alias[i] = O(e.alias[i]),
|
|
45
|
-
(e.alias[n[
|
|
46
|
-
for (
|
|
47
|
-
for (n = e.alias[e.boolean[
|
|
48
|
-
for (
|
|
49
|
-
for (n = e.alias[e.string[
|
|
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
50
|
if (u) {
|
|
51
51
|
for (i in e.default)
|
|
52
52
|
if (t = typeof e.default[i], n = e.alias[i] = e.alias[i] || [], e[t] !== void 0)
|
|
53
|
-
for (e[t].push(i),
|
|
54
|
-
e[t].push(n[
|
|
53
|
+
for (e[t].push(i), o = 0; o < n.length; o++)
|
|
54
|
+
e[t].push(n[o]);
|
|
55
55
|
}
|
|
56
|
-
const d =
|
|
57
|
-
for (
|
|
58
|
-
if (c = r[
|
|
59
|
-
|
|
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));
|
|
60
60
|
break;
|
|
61
61
|
}
|
|
62
62
|
for (l = 0; l < c.length && c.charCodeAt(l) === 45; l++)
|
|
63
63
|
;
|
|
64
64
|
if (l === 0)
|
|
65
|
-
|
|
65
|
+
s._.push(c);
|
|
66
66
|
else if (c.substring(l, l + 3) === "no-") {
|
|
67
|
-
if (t = c.substring(l + 3),
|
|
67
|
+
if (t = c.substring(l + 3), p && !~d.indexOf(t))
|
|
68
68
|
return e.unknown(c);
|
|
69
|
-
|
|
69
|
+
s[t] = !1;
|
|
70
70
|
} else {
|
|
71
71
|
for (a = l + 1; a < c.length && c.charCodeAt(a) !== 61; a++)
|
|
72
72
|
;
|
|
73
|
-
for (t = c.substring(l, a), h = c.substring(++a) ||
|
|
74
|
-
if (t = n[a],
|
|
75
|
-
$(
|
|
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);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
if (u)
|
|
80
80
|
for (i in e.default)
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
for (i in
|
|
81
|
+
s[i] === void 0 && (s[i] = e.default[i]);
|
|
82
|
+
if (P)
|
|
83
|
+
for (i in s)
|
|
84
84
|
for (n = e.alias[i] || []; n.length > 0; )
|
|
85
|
-
|
|
86
|
-
return
|
|
85
|
+
s[n.shift()] = s[i];
|
|
86
|
+
return s;
|
|
87
87
|
}
|
|
88
88
|
async function N() {
|
|
89
89
|
await L({}, "build");
|
|
@@ -98,7 +98,7 @@ async function N() {
|
|
|
98
98
|
if (!r.APP_API_CLIENT_DIRECTORY)
|
|
99
99
|
return console.log(g.red("error"), "api-client-generator outDir command is required");
|
|
100
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
|
|
101
|
+
let s = {
|
|
102
102
|
extends: "@vc-shell/ts-config/tsconfig.json",
|
|
103
103
|
compilerOptions: {
|
|
104
104
|
baseUrl: ".",
|
|
@@ -111,36 +111,38 @@ async function N() {
|
|
|
111
111
|
};
|
|
112
112
|
if (D(h)) {
|
|
113
113
|
const f = JSON.parse(T(h, "utf-8"));
|
|
114
|
-
|
|
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
115
|
}
|
|
116
116
|
console.log("api-client-generator %s Generated tsconfig.json", g.greenBright("success"));
|
|
117
117
|
for (const f of c) {
|
|
118
|
-
const
|
|
119
|
-
|
|
118
|
+
const P = n.resolveApiClientPaths(f);
|
|
119
|
+
console.log(
|
|
120
120
|
"api-client-generator %s Generating API client for %s module on %s environment",
|
|
121
121
|
g.green("info"),
|
|
122
122
|
g.whiteBright(f),
|
|
123
123
|
g.whiteBright(e)
|
|
124
|
-
)
|
|
124
|
+
);
|
|
125
|
+
const p = C(
|
|
125
126
|
"npx nswag",
|
|
126
127
|
[
|
|
127
128
|
"run",
|
|
128
129
|
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=${
|
|
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}`,
|
|
130
131
|
"/runtime:Net60"
|
|
131
132
|
],
|
|
132
133
|
{
|
|
133
134
|
stdio: ["ignore", "inherit", "ignore"],
|
|
134
135
|
shell: !0
|
|
135
136
|
}
|
|
136
|
-
)
|
|
137
|
+
);
|
|
138
|
+
if (p.status === 0) {
|
|
137
139
|
console.log(
|
|
138
140
|
"api-client-generator %s Successfully generated %s",
|
|
139
141
|
g.greenBright("success"),
|
|
140
|
-
g.whiteBright(
|
|
142
|
+
g.whiteBright(P.console)
|
|
141
143
|
);
|
|
142
144
|
const u = f.toLowerCase();
|
|
143
|
-
|
|
145
|
+
s.files.includes(`${u}.ts`) || s.files.push(`${u}.ts`);
|
|
144
146
|
const d = {
|
|
145
147
|
import: i !== "./" ? `./${i}/${u}.js` : `./${u}.js`,
|
|
146
148
|
types: i !== "./" ? `./${i}/types/${u}.d.ts` : `./types/${u}.js`
|
|
@@ -152,10 +154,11 @@ async function N() {
|
|
|
152
154
|
console.error(
|
|
153
155
|
"api-client-generator %s Failed to generate %s",
|
|
154
156
|
g.red("error"),
|
|
155
|
-
g.whiteBright(
|
|
157
|
+
g.whiteBright(P.console),
|
|
158
|
+
p
|
|
156
159
|
);
|
|
157
160
|
}
|
|
158
|
-
x(h, JSON.stringify(
|
|
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], {
|
|
159
162
|
stdio: ["ignore", "inherit", "ignore"],
|
|
160
163
|
shell: !0
|
|
161
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"));
|
|
@@ -169,11 +172,11 @@ async function N() {
|
|
|
169
172
|
if (D(l)) {
|
|
170
173
|
const f = JSON.parse(T(l, "utf-8"));
|
|
171
174
|
a = { ...a, ...f }, a.files = Array.from(new Set(a.files.concat(f.files || []))), a.exports = { ...f.exports, ...a.exports };
|
|
172
|
-
for (const [
|
|
173
|
-
const u =
|
|
175
|
+
for (const [P, p] of Object.entries(t)) {
|
|
176
|
+
const u = p.import, d = m.basename(u), A = Object.keys(a.exports).find(
|
|
174
177
|
(y) => a.exports[y].import.includes(d)
|
|
175
178
|
);
|
|
176
|
-
A ? a.exports[A] =
|
|
179
|
+
A ? a.exports[A] = p : a.exports[P] = p;
|
|
177
180
|
}
|
|
178
181
|
}
|
|
179
182
|
x(l, JSON.stringify(a, null, 2)), console.log("api-client-generator %s Generated package.json", g.greenBright("success"));
|
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.
|
|
4
|
+
"version": "1.0.283",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": "./dist/api-client-generator.js",
|
|
7
7
|
"files": [
|
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
"build": "vite build"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@vc-shell/ts-config": "^1.0.
|
|
15
|
+
"@vc-shell/ts-config": "^1.0.283",
|
|
16
16
|
"typescript": "~5.3.3"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"chalk": "^2.4.2",
|
|
20
|
+
"cross-spawn": "^7.0.3",
|
|
20
21
|
"nswag": "^13.20.0",
|
|
21
22
|
"vite": "^5.0.11",
|
|
22
23
|
"vite-plugin-dts": "^3.6.4"
|