@wx-sab/renkei 1.0.0-alpha.0 → 1.0.0
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/README.md +1 -1
- package/lib/commands/api.js +5 -2
- package/lib/core/generate.d.ts +1 -1
- package/lib/core/generate.js +18 -11
- package/package.json +3 -3
package/README.md
CHANGED
package/lib/commands/api.js
CHANGED
|
@@ -23,12 +23,15 @@ const readProjectConfigFile = () => {
|
|
|
23
23
|
}
|
|
24
24
|
return null;
|
|
25
25
|
};
|
|
26
|
-
const parse = new commander_1.default.Command('api').action(() => {
|
|
26
|
+
const parse = new commander_1.default.Command('api').option('-s, --service <service>', '只获取指定的服务,多个服务用","分隔', ',').action((param, options) => {
|
|
27
|
+
var _a;
|
|
28
|
+
// 只生成指定服务
|
|
29
|
+
const services = ((_a = param.service) === null || _a === void 0 ? void 0 : _a.split(',')) || [];
|
|
27
30
|
const config = readProjectConfigFile();
|
|
28
31
|
if (!config) {
|
|
29
32
|
console.warn('未找到配置文件');
|
|
30
33
|
return;
|
|
31
34
|
}
|
|
32
|
-
(0, generate_1.generateApis)(config);
|
|
35
|
+
(0, generate_1.generateApis)(config, services);
|
|
33
36
|
});
|
|
34
37
|
exports.default = parse;
|
package/lib/core/generate.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ import { GenerateConfig } from "./interface";
|
|
|
6
6
|
* 单个配置生成
|
|
7
7
|
*/
|
|
8
8
|
export declare const generate: (conf: GenerateConfig) => Promise<import("swagger-typescript-api").GenerateApiOutput>;
|
|
9
|
-
export declare const generateApis: (config: GenerateConfig | GenerateConfig[]) => Promise<void>;
|
|
9
|
+
export declare const generateApis: (config: GenerateConfig | GenerateConfig[], services: string[]) => Promise<void>;
|
package/lib/core/generate.js
CHANGED
|
@@ -61,8 +61,8 @@ const generate = (conf) => {
|
|
|
61
61
|
extraTemplates: [
|
|
62
62
|
{
|
|
63
63
|
name: "index.ts",
|
|
64
|
-
path: path_1.default.resolve(__dirname, "../../templates/service.ejs")
|
|
65
|
-
}
|
|
64
|
+
path: path_1.default.resolve(__dirname, "../../templates/service.ejs")
|
|
65
|
+
}
|
|
66
66
|
],
|
|
67
67
|
hooks: {
|
|
68
68
|
onCreateRouteName(routeNameInfo, rawRouteInfo) {
|
|
@@ -83,7 +83,7 @@ const generate = (conf) => {
|
|
|
83
83
|
return {
|
|
84
84
|
duplicate: duplicate,
|
|
85
85
|
original: methodName,
|
|
86
|
-
usage: methodName
|
|
86
|
+
usage: methodName
|
|
87
87
|
};
|
|
88
88
|
},
|
|
89
89
|
onPrepareConfig(currentConfiguration) {
|
|
@@ -104,18 +104,19 @@ const generate = (conf) => {
|
|
|
104
104
|
// 将 /api/v1/order-mains/{orderId} 转成 /api/v1/order-mains/${orderId}
|
|
105
105
|
// routeData.raw.route 是进过 customRequestUrl 转换过的
|
|
106
106
|
// @ts-ignore
|
|
107
|
-
routeData.request.path = (_a = routeData.raw.route) === null || _a === void 0 ? void 0 : _a.replace(/\{([^}]+)\}/g,
|
|
107
|
+
routeData.request.path = (_a = routeData.raw.route) === null || _a === void 0 ? void 0 : _a.replace(/\{([^}]+)\}/g, "${$1}");
|
|
108
108
|
return routeData;
|
|
109
109
|
},
|
|
110
110
|
onInit(configuration) {
|
|
111
111
|
return Object.assign(Object.assign({}, configuration), { serviceName: config.serviceName, apifoxProjectId: config.apifoxProjectId, customResponseType: config.customResponseType, customMockService: config.customMockService });
|
|
112
|
-
}
|
|
113
|
-
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
114
|
});
|
|
115
115
|
};
|
|
116
116
|
exports.generate = generate;
|
|
117
117
|
// 批量生成接口
|
|
118
|
-
const generateApis = (config
|
|
118
|
+
const generateApis = (config, services // 指定服务
|
|
119
|
+
) => __awaiter(void 0, void 0, void 0, function* () {
|
|
119
120
|
var _a, e_1, _b, _c;
|
|
120
121
|
// 递归收集config下可能有的 projects ,也当做新的config
|
|
121
122
|
const collectConfig = (conf, collects = []) => {
|
|
@@ -125,14 +126,20 @@ const generateApis = (config) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
125
126
|
conf.forEach((con) => collectConfig(con, collects));
|
|
126
127
|
}
|
|
127
128
|
else {
|
|
128
|
-
collects.push(lodash_1.default.omit(conf,
|
|
129
|
+
collects.push(lodash_1.default.omit(conf, "projects"));
|
|
129
130
|
if (Array.isArray(conf.projects)) {
|
|
130
|
-
conf.projects.forEach((project) => collectConfig(Object.assign(Object.assign({}, lodash_1.default.omit(conf,
|
|
131
|
+
conf.projects.forEach((project) => collectConfig(Object.assign(Object.assign({}, lodash_1.default.omit(conf, "projects")), project), collects));
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
134
|
return collects;
|
|
134
135
|
};
|
|
135
|
-
const _configs = collectConfig(config)
|
|
136
|
+
const _configs = collectConfig(config).filter((conf) => {
|
|
137
|
+
// 只筛选指定的服务
|
|
138
|
+
if (services.length > 0) {
|
|
139
|
+
return services.includes(conf.serviceName);
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
142
|
+
});
|
|
136
143
|
// 进度条控制
|
|
137
144
|
const progress = new cli_progress_1.default.SingleBar({});
|
|
138
145
|
progress.start(_configs.length, 0);
|
|
@@ -153,6 +160,6 @@ const generateApis = (config) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
153
160
|
finally { if (e_1) throw e_1.error; }
|
|
154
161
|
}
|
|
155
162
|
progress.stop();
|
|
156
|
-
console.info(
|
|
163
|
+
console.info("✅ 执行完毕");
|
|
157
164
|
});
|
|
158
165
|
exports.generateApis = generateApis;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wx-sab/renkei",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "解析swagger转为ts代码,日本动漫《游戏王》中的‘Renkei’,意为连携或协作。",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"dev": "ts-node ./src/index.ts",
|
|
11
|
-
"demo": "ts-node --transpile-only ./demo.ts",
|
|
12
11
|
"clean": "rm -rf lib",
|
|
13
12
|
"build": "npm run clean & tsc --outDir lib",
|
|
14
|
-
"version:alpha": "npm version premajor --preid alpha"
|
|
13
|
+
"version:alpha": "npm version premajor --preid alpha",
|
|
14
|
+
"api": "ts-node --transpile-only ./src/cli.ts api"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|