@gopowerteam/request-generate 0.1.18 → 0.1.20
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/bin/index.js +5 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.js +30 -8
- package/dist/index.mjs +30 -8
- package/package.json +2 -2
package/bin/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict'
|
|
3
|
+
require('ts-node').register()
|
|
3
4
|
|
|
4
5
|
const path = require('node:path')
|
|
5
6
|
const fs = require('node:fs')
|
|
@@ -20,6 +21,7 @@ const params = program
|
|
|
20
21
|
.opts()
|
|
21
22
|
|
|
22
23
|
const configFilePaths = [
|
|
24
|
+
'request.config.ts',
|
|
23
25
|
'request-generate.config.cjs',
|
|
24
26
|
'request-generate.config.js'
|
|
25
27
|
]
|
|
@@ -38,8 +40,10 @@ function loadConfigFile(filePath) {
|
|
|
38
40
|
fs.existsSync(path.resolve(process.cwd(), file))
|
|
39
41
|
)
|
|
40
42
|
|
|
41
|
-
if (configFilePath) {
|
|
43
|
+
if (configFilePath.endsWith('js')) {
|
|
42
44
|
return require(path.resolve(process.cwd(), configFilePath))
|
|
45
|
+
} else if (configFilePath.endsWith('ts')) {
|
|
46
|
+
return require(path.resolve(process.cwd(), configFilePath)).default
|
|
43
47
|
} else {
|
|
44
48
|
throw new Error('无法找到RequestGenerate配置文件')
|
|
45
49
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -31,9 +31,18 @@ type GenerateOptions = {
|
|
|
31
31
|
responseType?: 'promise' | 'observable'
|
|
32
32
|
}
|
|
33
33
|
// 多应用列表
|
|
34
|
-
applications?: Record<string,
|
|
34
|
+
applications?: Record<string, ApplicationConfig>
|
|
35
|
+
// 追加service
|
|
36
|
+
appendService?: boolean
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
type ApplicationConfig =
|
|
40
|
+
| {
|
|
41
|
+
key: string
|
|
42
|
+
openapi: string
|
|
43
|
+
}
|
|
44
|
+
| string
|
|
45
|
+
|
|
37
46
|
/**
|
|
38
47
|
* 生成应用选项
|
|
39
48
|
*/
|
|
@@ -141,6 +150,8 @@ declare class Generate {
|
|
|
141
150
|
static writeClient(client: GenerateClient, options: GenerateApplicationOptions): void;
|
|
142
151
|
}
|
|
143
152
|
|
|
153
|
+
declare function defineConfig(config: GenerateOptions): GenerateOptions;
|
|
154
|
+
|
|
144
155
|
declare const _default: typeof Generate.startup;
|
|
145
156
|
|
|
146
|
-
export { GenerateOptions, _default as default };
|
|
157
|
+
export { GenerateOptions, _default as default, defineConfig };
|
package/dist/index.js
CHANGED
|
@@ -29,14 +29,30 @@ function getOpenAPIVersion(document) {
|
|
|
29
29
|
|
|
30
30
|
// src/utils/get-services-options.ts
|
|
31
31
|
var _path = require('path'); var path2 = _interopRequireWildcard(_path); var path3 = _interopRequireWildcard(_path); var path4 = _interopRequireWildcard(_path);
|
|
32
|
-
function createOptions(options, name, application
|
|
32
|
+
function createOptions(options, name, application) {
|
|
33
|
+
const { service, openapi } = (() => {
|
|
34
|
+
if (!application) {
|
|
35
|
+
return {
|
|
36
|
+
service: "",
|
|
37
|
+
openapi: options.openapi
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (typeof application === "string") {
|
|
41
|
+
return {
|
|
42
|
+
service: application,
|
|
43
|
+
openapi: options.openapi
|
|
44
|
+
};
|
|
45
|
+
} else {
|
|
46
|
+
return {
|
|
47
|
+
service: application.key,
|
|
48
|
+
openapi: application.openapi
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
})();
|
|
33
52
|
return {
|
|
34
53
|
name,
|
|
35
|
-
application,
|
|
36
|
-
input: `${options.gateway}/${
|
|
37
|
-
/\/{2,3}/g,
|
|
38
|
-
"/"
|
|
39
|
-
),
|
|
54
|
+
application: service,
|
|
55
|
+
input: `${options.gateway}/${service}/${openapi}`.replace(/\/{2,3}/g, "/"),
|
|
40
56
|
output: name ? path2.default.join(options.output, name) : options.output,
|
|
41
57
|
exportModels: options.exportModels
|
|
42
58
|
};
|
|
@@ -923,7 +939,7 @@ function writeServices(client, options) {
|
|
|
923
939
|
fs4.mkdirSync(output, { recursive: true });
|
|
924
940
|
client.services.forEach((service) => {
|
|
925
941
|
const filename = `${service.name}Service.ts`;
|
|
926
|
-
service.application = options.application;
|
|
942
|
+
service.application = Generate.options.appendService === false ? "" : options.application;
|
|
927
943
|
writeService(service, path4.join(output, filename));
|
|
928
944
|
});
|
|
929
945
|
}
|
|
@@ -983,8 +999,14 @@ var _Generate = class {
|
|
|
983
999
|
var Generate = _Generate;
|
|
984
1000
|
_chunkXXPGZHWZjs.__publicField.call(void 0, Generate, "options");
|
|
985
1001
|
|
|
1002
|
+
// src/deine-config.ts
|
|
1003
|
+
function defineConfig(config) {
|
|
1004
|
+
return config;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
986
1007
|
// src/index.ts
|
|
987
1008
|
var src_default = Generate.startup;
|
|
988
1009
|
|
|
989
1010
|
|
|
990
|
-
|
|
1011
|
+
|
|
1012
|
+
exports.default = src_default; exports.defineConfig = defineConfig;
|
package/dist/index.mjs
CHANGED
|
@@ -30,14 +30,30 @@ function getOpenAPIVersion(document) {
|
|
|
30
30
|
|
|
31
31
|
// src/utils/get-services-options.ts
|
|
32
32
|
import path from "node:path";
|
|
33
|
-
function createOptions(options, name, application
|
|
33
|
+
function createOptions(options, name, application) {
|
|
34
|
+
const { service, openapi } = (() => {
|
|
35
|
+
if (!application) {
|
|
36
|
+
return {
|
|
37
|
+
service: "",
|
|
38
|
+
openapi: options.openapi
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (typeof application === "string") {
|
|
42
|
+
return {
|
|
43
|
+
service: application,
|
|
44
|
+
openapi: options.openapi
|
|
45
|
+
};
|
|
46
|
+
} else {
|
|
47
|
+
return {
|
|
48
|
+
service: application.key,
|
|
49
|
+
openapi: application.openapi
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
})();
|
|
34
53
|
return {
|
|
35
54
|
name,
|
|
36
|
-
application,
|
|
37
|
-
input: `${options.gateway}/${
|
|
38
|
-
/\/{2,3}/g,
|
|
39
|
-
"/"
|
|
40
|
-
),
|
|
55
|
+
application: service,
|
|
56
|
+
input: `${options.gateway}/${service}/${openapi}`.replace(/\/{2,3}/g, "/"),
|
|
41
57
|
output: name ? path.join(options.output, name) : options.output,
|
|
42
58
|
exportModels: options.exportModels
|
|
43
59
|
};
|
|
@@ -924,7 +940,7 @@ function writeServices(client, options) {
|
|
|
924
940
|
fs4.mkdirSync(output, { recursive: true });
|
|
925
941
|
client.services.forEach((service) => {
|
|
926
942
|
const filename = `${service.name}Service.ts`;
|
|
927
|
-
service.application = options.application;
|
|
943
|
+
service.application = Generate.options.appendService === false ? "" : options.application;
|
|
928
944
|
writeService(service, path4.join(output, filename));
|
|
929
945
|
});
|
|
930
946
|
}
|
|
@@ -984,8 +1000,14 @@ var _Generate = class {
|
|
|
984
1000
|
var Generate = _Generate;
|
|
985
1001
|
__publicField(Generate, "options");
|
|
986
1002
|
|
|
1003
|
+
// src/deine-config.ts
|
|
1004
|
+
function defineConfig(config) {
|
|
1005
|
+
return config;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
987
1008
|
// src/index.ts
|
|
988
1009
|
var src_default = Generate.startup;
|
|
989
1010
|
export {
|
|
990
|
-
src_default as default
|
|
1011
|
+
src_default as default,
|
|
1012
|
+
defineConfig
|
|
991
1013
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gopowerteam/request-generate",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.20",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"tsup": "^6.6.3",
|
|
49
49
|
"typescript": "^4.9.5",
|
|
50
50
|
"vite": "^4.1.4",
|
|
51
|
-
"@gopowerteam/request": "0.1.
|
|
51
|
+
"@gopowerteam/request": "0.1.17"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@apidevtools/swagger-parser": "^10.1.0",
|