@vc-shell/api-client-generator 1.0.321 → 1.0.323
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 +13 -0
- package/README.md +4 -0
- package/dist/api-client-generator.js +109 -107
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
## [1.0.323](https://github.com/VirtoCommerce/vc-shell/compare/v1.0.322...v1.0.323) (2024-11-05)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## [1.0.322](https://github.com/VirtoCommerce/vc-shell/compare/v1.0.321...v1.0.322) (2024-11-05)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **api-client:** skip build arg ([f67a69f](https://github.com/VirtoCommerce/vc-shell/commit/f67a69fc0b09129a5b2e7ec51039bcc2ba435ea1))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
1
14
|
## [1.0.321](https://github.com/VirtoCommerce/vc-shell/compare/v1.0.320...v1.0.321) (2024-10-23)
|
|
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
|
|
3
|
-
import { resolveConfig as
|
|
4
|
-
import { existsSync as D, readFileSync as
|
|
5
|
-
import
|
|
6
|
-
import { fileURLToPath as
|
|
7
|
-
import { cwd as
|
|
8
|
-
const
|
|
9
|
-
class
|
|
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 =
|
|
17
|
-
configuration: _(
|
|
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: _(
|
|
27
|
-
console: _(
|
|
26
|
+
nswag: m(_(this.assetsDirectory, this.apiClientDirectory), i),
|
|
27
|
+
console: m(_(this.workingDirectory, this.apiClientDirectory), i)
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
return
|
|
31
|
+
function y(n) {
|
|
32
|
+
return n == null ? [] : Array.isArray(n) ? n : [n];
|
|
33
33
|
}
|
|
34
|
-
function $(
|
|
35
|
-
var c,
|
|
36
|
-
|
|
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
|
|
39
|
-
|
|
40
|
-
var i,
|
|
41
|
-
const P = e.alias !== void 0,
|
|
42
|
-
if (e.alias = e.alias || {}, e.string =
|
|
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 (
|
|
45
|
-
(e.alias[
|
|
46
|
-
for (
|
|
47
|
-
for (
|
|
48
|
-
for (
|
|
49
|
-
for (
|
|
50
|
-
if (
|
|
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 (
|
|
53
|
-
for (e[
|
|
54
|
-
e[
|
|
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 =
|
|
57
|
-
for (
|
|
58
|
-
if (c = r
|
|
59
|
-
|
|
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 (
|
|
62
|
+
for (a = 0; a < c.length && c.charCodeAt(a) === 45; a++)
|
|
63
63
|
;
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
else if (c.substring(
|
|
67
|
-
if (
|
|
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
|
|
69
|
+
o[s] = !1;
|
|
70
70
|
} else {
|
|
71
|
-
for (
|
|
71
|
+
for (l = a + 1; l < c.length && c.charCodeAt(l) !== 61; l++)
|
|
72
72
|
;
|
|
73
|
-
for (
|
|
74
|
-
if (
|
|
75
|
-
$(
|
|
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 (
|
|
79
|
+
if (p)
|
|
80
80
|
for (i in e.default)
|
|
81
|
-
|
|
81
|
+
o[i] === void 0 && (o[i] = e.default[i]);
|
|
82
82
|
if (P)
|
|
83
|
-
for (i in
|
|
84
|
-
for (
|
|
85
|
-
|
|
86
|
-
return
|
|
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
|
|
89
|
-
await
|
|
90
|
-
const
|
|
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 (!
|
|
96
|
+
if (!n.APP_PLATFORM_MODULES)
|
|
97
97
|
return console.log(g.red("error"), "api-client-generator modules command is required");
|
|
98
|
-
if (!
|
|
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 =
|
|
101
|
-
let
|
|
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:
|
|
106
|
+
declarationDir: A.join(i, "types"),
|
|
106
107
|
outDir: i,
|
|
107
108
|
rootDir: "./"
|
|
108
109
|
},
|
|
109
110
|
files: [],
|
|
110
111
|
include: ["*.ts"]
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
117
|
-
|
|
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(
|
|
121
|
+
g.whiteBright(r),
|
|
123
122
|
g.whiteBright(e)
|
|
124
123
|
);
|
|
125
|
-
const
|
|
124
|
+
const l = O(
|
|
126
125
|
"npx nswag",
|
|
127
126
|
[
|
|
128
127
|
"run",
|
|
129
|
-
|
|
130
|
-
`/variables:APP_PLATFORM_URL=${e},APP_PLATFORM_MODULE=${
|
|
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 (
|
|
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(
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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(
|
|
158
|
-
|
|
157
|
+
g.whiteBright(a.console),
|
|
158
|
+
l
|
|
159
159
|
);
|
|
160
160
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
(
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
|
|
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.
|
|
4
|
+
"version": "1.0.323",
|
|
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.
|
|
16
|
+
"@vc-shell/ts-config": "^1.0.323",
|
|
17
17
|
"typescript": "~5.3.3"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|