@vc-shell/api-client-generator 1.0.251 → 1.0.252
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 +63 -63
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,10 +2,10 @@ import g from "chalk";
|
|
|
2
2
|
import { spawnSync as C } from "node:child_process";
|
|
3
3
|
import { resolveConfig as L } from "vite";
|
|
4
4
|
import { existsSync as D, readFileSync as T, writeFileSync as x } from "node:fs";
|
|
5
|
-
import
|
|
6
|
-
import { fileURLToPath as
|
|
7
|
-
import { cwd as
|
|
8
|
-
const
|
|
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 S } from "node:process";
|
|
8
|
+
const j = k(import.meta.url), E = R(j);
|
|
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 = S(), this.generatorDirectory = b(E, ".."), 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"
|
|
@@ -31,63 +31,63 @@ class I {
|
|
|
31
31
|
function O(r) {
|
|
32
32
|
return r == null ? [] : Array.isArray(r) ? r : [r];
|
|
33
33
|
}
|
|
34
|
-
function
|
|
35
|
-
var c, t = r[e],
|
|
36
|
-
r[e] = t == null ?
|
|
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];
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function M(r, e) {
|
|
39
39
|
r = r || [], e = e || {};
|
|
40
|
-
var i, n, c, t,
|
|
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, o = { _: [] }, s = 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[
|
|
50
|
-
if (
|
|
44
|
+
for (n = e.alias[i] = O(e.alias[i]), s = 0; s < n.length; s++)
|
|
45
|
+
(e.alias[n[s]] = n.concat(i)).splice(s, 1);
|
|
46
|
+
for (s = e.boolean.length; s-- > 0; )
|
|
47
|
+
for (n = e.alias[e.boolean[s]] || [], l = n.length; l-- > 0; ) e.boolean.push(n[l]);
|
|
48
|
+
for (s = e.string.length; s-- > 0; )
|
|
49
|
+
for (n = e.alias[e.string[s]] || [], l = n.length; l-- > 0; ) e.string.push(n[l]);
|
|
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), s = 0; s < n.length; s++)
|
|
54
|
+
e[t].push(n[s]);
|
|
55
55
|
}
|
|
56
|
-
const d =
|
|
57
|
-
for (
|
|
58
|
-
if (c = r[
|
|
59
|
-
|
|
56
|
+
const d = P ? Object.keys(e.alias) : [];
|
|
57
|
+
for (s = 0; s < f; s++) {
|
|
58
|
+
if (c = r[s], c === "--") {
|
|
59
|
+
o._ = o._.concat(r.slice(++s));
|
|
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
|
+
o._.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
|
+
o[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),
|
|
74
|
-
if (t = n[a],
|
|
75
|
-
|
|
73
|
+
for (t = c.substring(l, a), h = c.substring(++a) || s + 1 === f || ("" + r[s + 1]).charCodeAt(0) === 45 || r[++s], 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
|
+
$(o, t, a + 1 < n.length || h, e);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
if (
|
|
79
|
+
if (u)
|
|
80
80
|
for (i in e.default)
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
for (i in
|
|
81
|
+
o[i] === void 0 && (o[i] = e.default[i]);
|
|
82
|
+
if (p)
|
|
83
|
+
for (i in o)
|
|
84
84
|
for (n = e.alias[i] || []; n.length > 0; )
|
|
85
|
-
|
|
86
|
-
return
|
|
85
|
+
o[n.shift()] = o[i];
|
|
86
|
+
return o;
|
|
87
87
|
}
|
|
88
|
-
async function
|
|
88
|
+
async function N() {
|
|
89
89
|
await L({}, "build");
|
|
90
|
-
const r =
|
|
90
|
+
const r = M(process.argv.slice(2)), e = process.env.APP_PLATFORM_URL ?? r.APP_PLATFORM_URL;
|
|
91
91
|
if (!e)
|
|
92
92
|
return console.log(
|
|
93
93
|
g.red("error"),
|
|
@@ -97,25 +97,25 @@ async function v() {
|
|
|
97
97
|
return console.log(g.red("error"), "api-client-generator modules command is required");
|
|
98
98
|
if (!r.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 ?? "
|
|
101
|
-
let
|
|
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 o = {
|
|
102
102
|
extends: "@vc-shell/ts-config/tsconfig.json",
|
|
103
103
|
compilerOptions: {
|
|
104
104
|
baseUrl: ".",
|
|
105
|
-
declarationDir:
|
|
105
|
+
declarationDir: m.join(i, "types"),
|
|
106
106
|
outDir: i,
|
|
107
107
|
rootDir: "./"
|
|
108
108
|
},
|
|
109
109
|
files: [],
|
|
110
110
|
include: ["*.ts"]
|
|
111
111
|
};
|
|
112
|
-
if (D(
|
|
113
|
-
const f = JSON.parse(T(
|
|
114
|
-
|
|
112
|
+
if (D(h)) {
|
|
113
|
+
const f = JSON.parse(T(h, "utf-8"));
|
|
114
|
+
o = { ...o, ...f }, o.compilerOptions = { ...o.compilerOptions, ...f.compilerOptions }, o.files = Array.from(new Set(o.files.concat(f.files || []))), o.include = Array.from(new Set(o.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
|
|
118
|
+
const p = n.resolveApiClientPaths(f);
|
|
119
119
|
if (console.log(
|
|
120
120
|
"api-client-generator %s Generating API client for %s module on %s environment",
|
|
121
121
|
g.green("info"),
|
|
@@ -126,7 +126,7 @@ async function v() {
|
|
|
126
126
|
[
|
|
127
127
|
"run",
|
|
128
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=${
|
|
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}`,
|
|
130
130
|
"/runtime:Net60"
|
|
131
131
|
],
|
|
132
132
|
{
|
|
@@ -137,45 +137,45 @@ async function v() {
|
|
|
137
137
|
console.log(
|
|
138
138
|
"api-client-generator %s Successfully generated %s",
|
|
139
139
|
g.greenBright("success"),
|
|
140
|
-
g.whiteBright(
|
|
140
|
+
g.whiteBright(p.console)
|
|
141
141
|
);
|
|
142
|
-
const
|
|
143
|
-
|
|
142
|
+
const u = f.toLowerCase();
|
|
143
|
+
o.files.includes(`${u}.ts`) || o.files.push(`${u}.ts`);
|
|
144
144
|
const d = {
|
|
145
|
-
import:
|
|
146
|
-
types:
|
|
147
|
-
},
|
|
148
|
-
(y) => t[y].import.includes(`${
|
|
145
|
+
import: i !== "./" ? `./${i}/${u}.js` : `./${u}.js`,
|
|
146
|
+
types: i !== "./" ? `./${i}/types/${u}.d.ts` : `./types/${u}.js`
|
|
147
|
+
}, A = Object.keys(t).find(
|
|
148
|
+
(y) => t[y].import.includes(`${u}.js`)
|
|
149
149
|
);
|
|
150
|
-
|
|
150
|
+
A ? t[A] = d : t[`./${u}`] = d;
|
|
151
151
|
} else
|
|
152
152
|
console.error(
|
|
153
153
|
"api-client-generator %s Failed to generate %s",
|
|
154
154
|
g.red("error"),
|
|
155
|
-
g.whiteBright(
|
|
155
|
+
g.whiteBright(p.console)
|
|
156
156
|
);
|
|
157
157
|
}
|
|
158
|
-
x(
|
|
158
|
+
x(h, JSON.stringify(o, null, 2)), console.log("api-client-generator %s Compiling TypeScript files to JavaScript", g.green("info")), C("npx tsc", ["--project", h], {
|
|
159
159
|
stdio: ["ignore", "inherit", "ignore"],
|
|
160
160
|
shell: !0
|
|
161
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 =
|
|
162
|
+
const l = m.join(r.APP_API_CLIENT_DIRECTORY, "package.json");
|
|
163
163
|
let a = {
|
|
164
164
|
name: r.APP_PACKAGE_NAME || "api-client",
|
|
165
165
|
version: r.APP_PACKAGE_VERSION || "1.0.0",
|
|
166
|
-
files: [i, "package.json"],
|
|
166
|
+
files: i !== "./" ? [i, "package.json"] : ["package.json"],
|
|
167
167
|
exports: t
|
|
168
168
|
};
|
|
169
169
|
if (D(l)) {
|
|
170
170
|
const f = JSON.parse(T(l, "utf-8"));
|
|
171
171
|
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
|
|
172
|
+
for (const [p, P] of Object.entries(t)) {
|
|
173
|
+
const u = P.import, d = m.basename(u), A = Object.keys(a.exports).find(
|
|
174
174
|
(y) => a.exports[y].import.includes(d)
|
|
175
175
|
);
|
|
176
|
-
|
|
176
|
+
A ? a.exports[A] = P : a.exports[p] = P;
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
x(l, JSON.stringify(a, null, 2)), console.log("api-client-generator %s Generated package.json", g.greenBright("success"));
|
|
180
180
|
}
|
|
181
|
-
|
|
181
|
+
N();
|
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.252",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": "./dist/api-client-generator.js",
|
|
7
7
|
"files": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"build": "vite build"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@vc-shell/ts-config": "^1.0.
|
|
15
|
+
"@vc-shell/ts-config": "^1.0.252",
|
|
16
16
|
"typescript": "~5.3.3"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|