@gopowerteam/request-generate 0.1.19 → 0.1.21
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/{chunk-LBEPSBX6.mjs → chunk-4OXX5WFT.mjs} +1 -1
- package/dist/index.d.ts +11 -2
- package/dist/index.js +29 -7
- package/dist/index.mjs +30 -8
- package/dist/templates/partials/export-service-class.hbs +1 -1
- package/dist/vite-plugin/index.js +4 -4
- package/dist/vite-plugin/index.mjs +2 -2
- package/package.json +3 -3
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
|
}
|
|
@@ -5,7 +5,7 @@ var __publicField = (obj, key, value) => {
|
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
// ../../node_modules/.pnpm/tsup@6.6.
|
|
8
|
+
// ../../node_modules/.pnpm/tsup@6.6.3_ts-node@10.9.1_typescript@4.9.5/node_modules/tsup/assets/esm_shims.js
|
|
9
9
|
import { fileURLToPath } from "url";
|
|
10
10
|
import path from "path";
|
|
11
11
|
var getFilename = () => fileURLToPath(import.meta.url);
|
package/dist/index.d.ts
CHANGED
|
@@ -31,11 +31,18 @@ type GenerateOptions = {
|
|
|
31
31
|
responseType?: 'promise' | 'observable'
|
|
32
32
|
}
|
|
33
33
|
// 多应用列表
|
|
34
|
-
applications?: Record<string,
|
|
34
|
+
applications?: Record<string, ApplicationConfig>
|
|
35
35
|
// 追加service
|
|
36
36
|
appendService?: boolean
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
type ApplicationConfig =
|
|
40
|
+
| {
|
|
41
|
+
key: string
|
|
42
|
+
openapi: string
|
|
43
|
+
}
|
|
44
|
+
| string
|
|
45
|
+
|
|
39
46
|
/**
|
|
40
47
|
* 生成应用选项
|
|
41
48
|
*/
|
|
@@ -143,6 +150,8 @@ declare class Generate {
|
|
|
143
150
|
static writeClient(client: GenerateClient, options: GenerateApplicationOptions): void;
|
|
144
151
|
}
|
|
145
152
|
|
|
153
|
+
declare function defineConfig(config: GenerateOptions): GenerateOptions;
|
|
154
|
+
|
|
146
155
|
declare const _default: typeof Generate.startup;
|
|
147
156
|
|
|
148
|
-
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
|
};
|
|
@@ -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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__dirname,
|
|
3
3
|
__publicField
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-4OXX5WFT.mjs";
|
|
5
5
|
|
|
6
6
|
// src/utils/get-openapi-document.ts
|
|
7
7
|
import swaggerParse from "@apidevtools/swagger-parser";
|
|
@@ -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
|
};
|
|
@@ -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
|
};
|
|
@@ -5,7 +5,7 @@ export class {{{name}}}Service {
|
|
|
5
5
|
|
|
6
6
|
private generateRequest(
|
|
7
7
|
requestSendOptions: RequestSendOptions,
|
|
8
|
-
requestPlugins: RequestPlugin[] = [],
|
|
8
|
+
requestPlugins: (RequestPlugin | undefined)[] = [],
|
|
9
9
|
requestGenerateOptions?: RequestGenerateOptions
|
|
10
10
|
){
|
|
11
11
|
switch(true){
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }require('../chunk-XXPGZHWZ.js');
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }require('../chunk-XXPGZHWZ.js');
|
|
2
2
|
|
|
3
3
|
// src/vite-plugin/index.ts
|
|
4
4
|
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
5
5
|
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
6
|
-
var _handlebars = require('handlebars'); var
|
|
6
|
+
var _handlebars = require('handlebars'); var _handlebars2 = _interopRequireDefault(_handlebars);
|
|
7
7
|
|
|
8
8
|
// src/vite-plugin/templates.ts
|
|
9
9
|
var useRequestFunctionCodeTemplate = `
|
|
@@ -190,14 +190,14 @@ function getServiceGroups(services) {
|
|
|
190
190
|
}, []);
|
|
191
191
|
}
|
|
192
192
|
function generateCode(services, groups) {
|
|
193
|
-
const template =
|
|
193
|
+
const template = _handlebars2.default.compile(generateCodeTemplate);
|
|
194
194
|
return template({
|
|
195
195
|
groups: groups.length ? groups : void 0,
|
|
196
196
|
services
|
|
197
197
|
});
|
|
198
198
|
}
|
|
199
199
|
function generateDeclare(services, groups, options) {
|
|
200
|
-
const template =
|
|
200
|
+
const template = _handlebars2.default.compile(generateDeclareTemplate);
|
|
201
201
|
const content = template({
|
|
202
202
|
groups: groups.length ? groups : void 0,
|
|
203
203
|
services,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-4OXX5WFT.mjs";
|
|
2
2
|
|
|
3
3
|
// src/vite-plugin/index.ts
|
|
4
4
|
import * as fs from "fs";
|
|
5
5
|
import * as path from "path";
|
|
6
|
-
import
|
|
6
|
+
import Handlebars from "handlebars";
|
|
7
7
|
|
|
8
8
|
// src/vite-plugin/templates.ts
|
|
9
9
|
var useRequestFunctionCodeTemplate = `
|
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.21",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -48,11 +48,11 @@
|
|
|
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.18"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
55
|
-
"handlebars": "^4.7.
|
|
55
|
+
"handlebars": "^4.7.8",
|
|
56
56
|
"qs": "^6.11.0",
|
|
57
57
|
"rimraf": "^4.1.2",
|
|
58
58
|
"rxjs": "^7.8.0",
|