@dazhicheng/openapi 1.1.12 → 1.1.14
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 +12 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/cli.d.ts +2 -0
- package/src/cli.ts +28 -28
- package/src/index.d.ts +141 -0
- package/src/index.ts +276 -274
- package/src/log.d.ts +2 -0
- package/src/log.ts +0 -1
- package/src/mockGenerator.d.ts +8 -0
- package/src/mockGenerator.ts +239 -239
- package/src/openAPIParserMock/index.d.ts +7 -0
- package/src/openAPIParserMock/index.ts +0 -3
- package/src/openAPIParserMock/primitives.d.ts +31 -0
- package/src/openAPIParserMock/primitives.ts +30 -30
- package/src/openAPIParserMock/utils.d.ts +8 -0
- package/src/openAPIParserMock/utils.ts +54 -54
- package/src/serviceGenerator.d.ts +460 -0
- package/src/serviceGenerator.ts +1095 -1093
- package/src/util.d.ts +35 -0
- package/src/util.ts +0 -4
- package/templates/interface.njk +54 -54
- package/templates/serviceController.njk +76 -76
- package/templates/serviceIndex.njk +14 -14
package/src/mockGenerator.ts
CHANGED
|
@@ -1,239 +1,239 @@
|
|
|
1
|
-
import Mock from "mockjs";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import { prettierFile, writeFile } from "./util";
|
|
4
|
-
import { dirname, join } from "path";
|
|
5
|
-
import OpenAPIParserMock from "./openAPIParserMock/index";
|
|
6
|
-
import Log from "./log";
|
|
7
|
-
import pinyin from "tiny-pinyin";
|
|
8
|
-
import { GenerateServiceProps } from "./index";
|
|
9
|
-
Mock.Random.extend({
|
|
10
|
-
country() {
|
|
11
|
-
const data = [
|
|
12
|
-
"阿根廷",
|
|
13
|
-
"澳大利亚",
|
|
14
|
-
"巴西",
|
|
15
|
-
"加拿大",
|
|
16
|
-
"中国",
|
|
17
|
-
"法国",
|
|
18
|
-
"德国",
|
|
19
|
-
"印度",
|
|
20
|
-
"印度尼西亚",
|
|
21
|
-
"意大利",
|
|
22
|
-
"日本",
|
|
23
|
-
"韩国",
|
|
24
|
-
"墨西哥",
|
|
25
|
-
"俄罗斯",
|
|
26
|
-
"沙特阿拉伯",
|
|
27
|
-
"南非",
|
|
28
|
-
"土耳其",
|
|
29
|
-
"英国",
|
|
30
|
-
"美国",
|
|
31
|
-
];
|
|
32
|
-
const id = (Math.random() * data.length).toFixed();
|
|
33
|
-
return data[id];
|
|
34
|
-
},
|
|
35
|
-
phone() {
|
|
36
|
-
const phonepreFix = ["111", "112", "114"]; // 自己写前缀哈
|
|
37
|
-
return this.pick(phonepreFix) + Mock.mock(/\d{8}/); // Number()
|
|
38
|
-
},
|
|
39
|
-
status() {
|
|
40
|
-
const status = ["success", "error", "default", "processing", "warning"];
|
|
41
|
-
return status[(Math.random() * 4).toFixed(0)];
|
|
42
|
-
},
|
|
43
|
-
authority() {
|
|
44
|
-
const status = ["admin", "user", "guest"];
|
|
45
|
-
return status[(Math.random() * status.length).toFixed(0)];
|
|
46
|
-
},
|
|
47
|
-
avatar() {
|
|
48
|
-
const avatar = [
|
|
49
|
-
"https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg",
|
|
50
|
-
"https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png",
|
|
51
|
-
"https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png",
|
|
52
|
-
"https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png",
|
|
53
|
-
"https://gw.alipayobjects.com/zos/rmsportal/OKJXDXrmkNshAMvwtvhu.png",
|
|
54
|
-
"https://avatars0.githubusercontent.com/u/507615?s=40&v=4",
|
|
55
|
-
"https://avatars1.githubusercontent.com/u/8186664?s=40&v=4",
|
|
56
|
-
];
|
|
57
|
-
const id = (Math.random() * avatar.length).toFixed();
|
|
58
|
-
return avatar[id];
|
|
59
|
-
},
|
|
60
|
-
group() {
|
|
61
|
-
const data = ["体验技术部", "创新科技组", "前端 6 组", "区块链平台部", "服务技术部"];
|
|
62
|
-
const id = (Math.random() * data.length).toFixed();
|
|
63
|
-
return data[id];
|
|
64
|
-
},
|
|
65
|
-
label() {
|
|
66
|
-
const label = [
|
|
67
|
-
"很有想法的",
|
|
68
|
-
"小清新",
|
|
69
|
-
"傻白甜",
|
|
70
|
-
"阳光少年",
|
|
71
|
-
"大咖",
|
|
72
|
-
"健身达人",
|
|
73
|
-
"程序员",
|
|
74
|
-
"算法工程师",
|
|
75
|
-
"川妹子",
|
|
76
|
-
"名望程序员",
|
|
77
|
-
"大长腿",
|
|
78
|
-
"海纳百川",
|
|
79
|
-
"专注设计",
|
|
80
|
-
"爱好广泛",
|
|
81
|
-
"IT 互联网",
|
|
82
|
-
];
|
|
83
|
-
const id = (Math.random() * label.length).toFixed();
|
|
84
|
-
return label[id];
|
|
85
|
-
},
|
|
86
|
-
href() {
|
|
87
|
-
const href = [
|
|
88
|
-
"https://preview.pro.ant.design/dashboard/analysis",
|
|
89
|
-
"https://ant.design",
|
|
90
|
-
"https://procomponents.ant.design/",
|
|
91
|
-
"https://umijs.org/",
|
|
92
|
-
"https://github.com/umijs/dumi",
|
|
93
|
-
];
|
|
94
|
-
const id = (Math.random() * href.length).toFixed();
|
|
95
|
-
return href[id];
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
const genMockData = (example: string) => {
|
|
100
|
-
if (!example) {
|
|
101
|
-
return {};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (typeof example === "string") {
|
|
105
|
-
return Mock.mock(example);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (Array.isArray(example)) {
|
|
109
|
-
return Mock.mock(example);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return Object.keys(example)
|
|
113
|
-
.map(name => {
|
|
114
|
-
return {
|
|
115
|
-
[name]: Mock.mock(example[name]),
|
|
116
|
-
};
|
|
117
|
-
})
|
|
118
|
-
.reduce((pre, next) => {
|
|
119
|
-
return {
|
|
120
|
-
...pre,
|
|
121
|
-
...next,
|
|
122
|
-
};
|
|
123
|
-
}, {});
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const genByTemp = ({
|
|
127
|
-
method,
|
|
128
|
-
path,
|
|
129
|
-
parameters,
|
|
130
|
-
status,
|
|
131
|
-
data,
|
|
132
|
-
mockConfig,
|
|
133
|
-
}: {
|
|
134
|
-
method: string;
|
|
135
|
-
path: string;
|
|
136
|
-
parameters: {
|
|
137
|
-
name: string;
|
|
138
|
-
in: string;
|
|
139
|
-
description: string;
|
|
140
|
-
required: boolean;
|
|
141
|
-
schema: { type: string };
|
|
142
|
-
example: string;
|
|
143
|
-
}[];
|
|
144
|
-
status: string;
|
|
145
|
-
data: string;
|
|
146
|
-
mockConfig: GenerateServiceProps["mockConfig"];
|
|
147
|
-
}) => {
|
|
148
|
-
if (!["get", "put", "post", "delete", "patch"].includes(method.toLocaleLowerCase())) {
|
|
149
|
-
return "";
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
let securityPath = path;
|
|
153
|
-
parameters?.forEach(item => {
|
|
154
|
-
if (item.in === "path") {
|
|
155
|
-
securityPath = securityPath.replace(`{${item.name}}`, `:${item.name}`);
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
if (mockConfig.msw) {
|
|
160
|
-
return `'${method.toUpperCase()} ${securityPath}': ${data}`;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return `'${method.toUpperCase()} ${securityPath}': (req: Request, res: Response) => {
|
|
164
|
-
res.status(${status}).send(${data});
|
|
165
|
-
}`;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const genMockFiles = (mockFunction: string[], mockConfig: GenerateServiceProps["mockConfig"]) => {
|
|
169
|
-
return prettierFile(`
|
|
170
|
-
// @ts-ignore
|
|
171
|
-
${mockConfig.msw ? "" : "import { Request, Response } from 'express'"}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
export default {
|
|
175
|
-
${mockFunction.join("\n,")}
|
|
176
|
-
}`)[0];
|
|
177
|
-
};
|
|
178
|
-
export type genMockDataServerConfig = {
|
|
179
|
-
openAPI: any;
|
|
180
|
-
mockFolder: string;
|
|
181
|
-
mockConfig: GenerateServiceProps["mockConfig"];
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
const mockGenerator = async ({ openAPI, mockFolder, mockConfig }: genMockDataServerConfig) => {
|
|
185
|
-
const openAPParse = new OpenAPIParserMock(openAPI);
|
|
186
|
-
const docs = openAPParse.parser();
|
|
187
|
-
const pathList = Object.keys(docs.paths);
|
|
188
|
-
const { paths } = docs;
|
|
189
|
-
const mockActionsObj = {};
|
|
190
|
-
pathList.forEach(path => {
|
|
191
|
-
const pathConfig = paths[path];
|
|
192
|
-
Object.keys(pathConfig).forEach(method => {
|
|
193
|
-
const methodConfig = pathConfig[method];
|
|
194
|
-
if (methodConfig) {
|
|
195
|
-
let conte = (
|
|
196
|
-
methodConfig.operationId ||
|
|
197
|
-
methodConfig?.tags?.join("/") ||
|
|
198
|
-
path.replace("/", "").split("/")[1]
|
|
199
|
-
)?.replace(/[^\w^\s^\u4e00-\u9fa5]/gi, "");
|
|
200
|
-
if (/[\u3220-\uFA29]/.test(conte)) {
|
|
201
|
-
conte = pinyin.convertToPinyin(conte, "", true);
|
|
202
|
-
}
|
|
203
|
-
if (!conte) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
const data = genMockData(methodConfig.responses?.["200"]?.example);
|
|
207
|
-
if (!mockActionsObj[conte]) {
|
|
208
|
-
mockActionsObj[conte] = [];
|
|
209
|
-
}
|
|
210
|
-
const tempFile = genByTemp({
|
|
211
|
-
method,
|
|
212
|
-
path,
|
|
213
|
-
parameters: methodConfig.parameters,
|
|
214
|
-
status: "200",
|
|
215
|
-
data: JSON.stringify(data),
|
|
216
|
-
mockConfig,
|
|
217
|
-
});
|
|
218
|
-
if (tempFile) {
|
|
219
|
-
mockActionsObj[conte].push(tempFile);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
Object.keys(mockActionsObj).forEach(file => {
|
|
225
|
-
if (!file || file === "undefined") {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
if (file.includes("/")) {
|
|
229
|
-
const dirName = dirname(join(mockFolder, `${file}.ts`));
|
|
230
|
-
if (!fs.existsSync(dirName)) {
|
|
231
|
-
fs.mkdirSync(dirName);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
writeFile(mockFolder, `${file}.ts`, genMockFiles(mockActionsObj[file], mockConfig));
|
|
235
|
-
});
|
|
236
|
-
Log("✅ 生成 mock 文件成功");
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
export { mockGenerator };
|
|
1
|
+
import Mock from "mockjs";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import { prettierFile, writeFile } from "./util";
|
|
4
|
+
import { dirname, join } from "path";
|
|
5
|
+
import OpenAPIParserMock from "./openAPIParserMock/index";
|
|
6
|
+
import Log from "./log";
|
|
7
|
+
import pinyin from "tiny-pinyin";
|
|
8
|
+
import { GenerateServiceProps } from "./index";
|
|
9
|
+
Mock.Random.extend({
|
|
10
|
+
country() {
|
|
11
|
+
const data = [
|
|
12
|
+
"阿根廷",
|
|
13
|
+
"澳大利亚",
|
|
14
|
+
"巴西",
|
|
15
|
+
"加拿大",
|
|
16
|
+
"中国",
|
|
17
|
+
"法国",
|
|
18
|
+
"德国",
|
|
19
|
+
"印度",
|
|
20
|
+
"印度尼西亚",
|
|
21
|
+
"意大利",
|
|
22
|
+
"日本",
|
|
23
|
+
"韩国",
|
|
24
|
+
"墨西哥",
|
|
25
|
+
"俄罗斯",
|
|
26
|
+
"沙特阿拉伯",
|
|
27
|
+
"南非",
|
|
28
|
+
"土耳其",
|
|
29
|
+
"英国",
|
|
30
|
+
"美国",
|
|
31
|
+
];
|
|
32
|
+
const id = (Math.random() * data.length).toFixed();
|
|
33
|
+
return data[id];
|
|
34
|
+
},
|
|
35
|
+
phone() {
|
|
36
|
+
const phonepreFix = ["111", "112", "114"]; // 自己写前缀哈
|
|
37
|
+
return this.pick(phonepreFix) + Mock.mock(/\d{8}/); // Number()
|
|
38
|
+
},
|
|
39
|
+
status() {
|
|
40
|
+
const status = ["success", "error", "default", "processing", "warning"];
|
|
41
|
+
return status[(Math.random() * 4).toFixed(0)];
|
|
42
|
+
},
|
|
43
|
+
authority() {
|
|
44
|
+
const status = ["admin", "user", "guest"];
|
|
45
|
+
return status[(Math.random() * status.length).toFixed(0)];
|
|
46
|
+
},
|
|
47
|
+
avatar() {
|
|
48
|
+
const avatar = [
|
|
49
|
+
"https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg",
|
|
50
|
+
"https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png",
|
|
51
|
+
"https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png",
|
|
52
|
+
"https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png",
|
|
53
|
+
"https://gw.alipayobjects.com/zos/rmsportal/OKJXDXrmkNshAMvwtvhu.png",
|
|
54
|
+
"https://avatars0.githubusercontent.com/u/507615?s=40&v=4",
|
|
55
|
+
"https://avatars1.githubusercontent.com/u/8186664?s=40&v=4",
|
|
56
|
+
];
|
|
57
|
+
const id = (Math.random() * avatar.length).toFixed();
|
|
58
|
+
return avatar[id];
|
|
59
|
+
},
|
|
60
|
+
group() {
|
|
61
|
+
const data = ["体验技术部", "创新科技组", "前端 6 组", "区块链平台部", "服务技术部"];
|
|
62
|
+
const id = (Math.random() * data.length).toFixed();
|
|
63
|
+
return data[id];
|
|
64
|
+
},
|
|
65
|
+
label() {
|
|
66
|
+
const label = [
|
|
67
|
+
"很有想法的",
|
|
68
|
+
"小清新",
|
|
69
|
+
"傻白甜",
|
|
70
|
+
"阳光少年",
|
|
71
|
+
"大咖",
|
|
72
|
+
"健身达人",
|
|
73
|
+
"程序员",
|
|
74
|
+
"算法工程师",
|
|
75
|
+
"川妹子",
|
|
76
|
+
"名望程序员",
|
|
77
|
+
"大长腿",
|
|
78
|
+
"海纳百川",
|
|
79
|
+
"专注设计",
|
|
80
|
+
"爱好广泛",
|
|
81
|
+
"IT 互联网",
|
|
82
|
+
];
|
|
83
|
+
const id = (Math.random() * label.length).toFixed();
|
|
84
|
+
return label[id];
|
|
85
|
+
},
|
|
86
|
+
href() {
|
|
87
|
+
const href = [
|
|
88
|
+
"https://preview.pro.ant.design/dashboard/analysis",
|
|
89
|
+
"https://ant.design",
|
|
90
|
+
"https://procomponents.ant.design/",
|
|
91
|
+
"https://umijs.org/",
|
|
92
|
+
"https://github.com/umijs/dumi",
|
|
93
|
+
];
|
|
94
|
+
const id = (Math.random() * href.length).toFixed();
|
|
95
|
+
return href[id];
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const genMockData = (example: string) => {
|
|
100
|
+
if (!example) {
|
|
101
|
+
return {};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (typeof example === "string") {
|
|
105
|
+
return Mock.mock(example);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (Array.isArray(example)) {
|
|
109
|
+
return Mock.mock(example);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return Object.keys(example)
|
|
113
|
+
.map(name => {
|
|
114
|
+
return {
|
|
115
|
+
[name]: Mock.mock(example[name]),
|
|
116
|
+
};
|
|
117
|
+
})
|
|
118
|
+
.reduce((pre, next) => {
|
|
119
|
+
return {
|
|
120
|
+
...pre,
|
|
121
|
+
...next,
|
|
122
|
+
};
|
|
123
|
+
}, {});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const genByTemp = ({
|
|
127
|
+
method,
|
|
128
|
+
path,
|
|
129
|
+
parameters,
|
|
130
|
+
status,
|
|
131
|
+
data,
|
|
132
|
+
mockConfig,
|
|
133
|
+
}: {
|
|
134
|
+
method: string;
|
|
135
|
+
path: string;
|
|
136
|
+
parameters: {
|
|
137
|
+
name: string;
|
|
138
|
+
in: string;
|
|
139
|
+
description: string;
|
|
140
|
+
required: boolean;
|
|
141
|
+
schema: { type: string };
|
|
142
|
+
example: string;
|
|
143
|
+
}[];
|
|
144
|
+
status: string;
|
|
145
|
+
data: string;
|
|
146
|
+
mockConfig: GenerateServiceProps["mockConfig"];
|
|
147
|
+
}) => {
|
|
148
|
+
if (!["get", "put", "post", "delete", "patch"].includes(method.toLocaleLowerCase())) {
|
|
149
|
+
return "";
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let securityPath = path;
|
|
153
|
+
parameters?.forEach(item => {
|
|
154
|
+
if (item.in === "path") {
|
|
155
|
+
securityPath = securityPath.replace(`{${item.name}}`, `:${item.name}`);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
if (mockConfig.msw) {
|
|
160
|
+
return `'${method.toUpperCase()} ${securityPath}': ${data}`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return `'${method.toUpperCase()} ${securityPath}': (req: Request, res: Response) => {
|
|
164
|
+
res.status(${status}).send(${data});
|
|
165
|
+
}`;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const genMockFiles = (mockFunction: string[], mockConfig: GenerateServiceProps["mockConfig"]) => {
|
|
169
|
+
return prettierFile(`
|
|
170
|
+
// @ts-ignore
|
|
171
|
+
${mockConfig.msw ? "" : "import { Request, Response } from 'express'"}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
export default {
|
|
175
|
+
${mockFunction.join("\n,")}
|
|
176
|
+
}`)[0];
|
|
177
|
+
};
|
|
178
|
+
export type genMockDataServerConfig = {
|
|
179
|
+
openAPI: any;
|
|
180
|
+
mockFolder: string;
|
|
181
|
+
mockConfig: GenerateServiceProps["mockConfig"];
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const mockGenerator = async ({ openAPI, mockFolder, mockConfig }: genMockDataServerConfig) => {
|
|
185
|
+
const openAPParse = new OpenAPIParserMock(openAPI);
|
|
186
|
+
const docs = openAPParse.parser();
|
|
187
|
+
const pathList = Object.keys(docs.paths);
|
|
188
|
+
const { paths } = docs;
|
|
189
|
+
const mockActionsObj = {};
|
|
190
|
+
pathList.forEach(path => {
|
|
191
|
+
const pathConfig = paths[path];
|
|
192
|
+
Object.keys(pathConfig).forEach(method => {
|
|
193
|
+
const methodConfig = pathConfig[method];
|
|
194
|
+
if (methodConfig) {
|
|
195
|
+
let conte = (
|
|
196
|
+
methodConfig.operationId ||
|
|
197
|
+
methodConfig?.tags?.join("/") ||
|
|
198
|
+
path.replace("/", "").split("/")[1]
|
|
199
|
+
)?.replace(/[^\w^\s^\u4e00-\u9fa5]/gi, "");
|
|
200
|
+
if (/[\u3220-\uFA29]/.test(conte)) {
|
|
201
|
+
conte = pinyin.convertToPinyin(conte, "", true);
|
|
202
|
+
}
|
|
203
|
+
if (!conte) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const data = genMockData(methodConfig.responses?.["200"]?.example);
|
|
207
|
+
if (!mockActionsObj[conte]) {
|
|
208
|
+
mockActionsObj[conte] = [];
|
|
209
|
+
}
|
|
210
|
+
const tempFile = genByTemp({
|
|
211
|
+
method,
|
|
212
|
+
path,
|
|
213
|
+
parameters: methodConfig.parameters,
|
|
214
|
+
status: "200",
|
|
215
|
+
data: JSON.stringify(data),
|
|
216
|
+
mockConfig,
|
|
217
|
+
});
|
|
218
|
+
if (tempFile) {
|
|
219
|
+
mockActionsObj[conte].push(tempFile);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
Object.keys(mockActionsObj).forEach(file => {
|
|
225
|
+
if (!file || file === "undefined") {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (file.includes("/")) {
|
|
229
|
+
const dirName = dirname(join(mockFolder, `${file}.ts`));
|
|
230
|
+
if (!fs.existsSync(dirName)) {
|
|
231
|
+
fs.mkdirSync(dirName);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
writeFile(mockFolder, `${file}.ts`, genMockFiles(mockActionsObj[file], mockConfig));
|
|
235
|
+
});
|
|
236
|
+
Log("✅ 生成 mock 文件成功");
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
export { mockGenerator };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
string: string;
|
|
3
|
+
string_email: string;
|
|
4
|
+
string_phone: string;
|
|
5
|
+
string_username: string;
|
|
6
|
+
string_url: string;
|
|
7
|
+
string_uuid: string;
|
|
8
|
+
string_id: string;
|
|
9
|
+
string_status: string;
|
|
10
|
+
string_authority: string;
|
|
11
|
+
string_label: string;
|
|
12
|
+
string_group: string;
|
|
13
|
+
string_csentence: string;
|
|
14
|
+
string_cname: string;
|
|
15
|
+
string_name: string;
|
|
16
|
+
string_errorCode: string;
|
|
17
|
+
string_country: string;
|
|
18
|
+
string_county: string;
|
|
19
|
+
string_province: string;
|
|
20
|
+
string_city: string;
|
|
21
|
+
string_avatar: string;
|
|
22
|
+
string_href: string;
|
|
23
|
+
"string_string(16)": string;
|
|
24
|
+
"string_date-time": string;
|
|
25
|
+
string_date: string;
|
|
26
|
+
number: string;
|
|
27
|
+
number_float: string;
|
|
28
|
+
integer: string;
|
|
29
|
+
boolean: string;
|
|
30
|
+
};
|
|
31
|
+
export default _default;
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
string: "@string",
|
|
3
|
-
string_email: "@email",
|
|
4
|
-
string_phone: "@phone",
|
|
5
|
-
string_username: "@cname",
|
|
6
|
-
string_url: "@url",
|
|
7
|
-
string_uuid: "@guid",
|
|
8
|
-
string_id: "@increment",
|
|
9
|
-
string_status: "@status",
|
|
10
|
-
string_authority: "@authority",
|
|
11
|
-
string_label: "@label",
|
|
12
|
-
string_group: "@group",
|
|
13
|
-
string_csentence: "@csentence",
|
|
14
|
-
string_cname: "@cname",
|
|
15
|
-
string_name: "@last",
|
|
16
|
-
string_errorCode: "@increment",
|
|
17
|
-
string_country: "@country",
|
|
18
|
-
string_county: "@county(true)",
|
|
19
|
-
string_province: "@province",
|
|
20
|
-
string_city: "@city",
|
|
21
|
-
string_avatar: "@avatar",
|
|
22
|
-
string_href: "@href",
|
|
23
|
-
"string_string(16)": "@string(16)",
|
|
24
|
-
"string_date-time": "@datetime",
|
|
25
|
-
string_date: "@date",
|
|
26
|
-
number: "@integer(60, 100)",
|
|
27
|
-
number_float: "@float(60, 100, 3, 5)",
|
|
28
|
-
integer: "@integer(60, 100)",
|
|
29
|
-
boolean: "@boolean",
|
|
30
|
-
};
|
|
1
|
+
export default {
|
|
2
|
+
string: "@string",
|
|
3
|
+
string_email: "@email",
|
|
4
|
+
string_phone: "@phone",
|
|
5
|
+
string_username: "@cname",
|
|
6
|
+
string_url: "@url",
|
|
7
|
+
string_uuid: "@guid",
|
|
8
|
+
string_id: "@increment",
|
|
9
|
+
string_status: "@status",
|
|
10
|
+
string_authority: "@authority",
|
|
11
|
+
string_label: "@label",
|
|
12
|
+
string_group: "@group",
|
|
13
|
+
string_csentence: "@csentence",
|
|
14
|
+
string_cname: "@cname",
|
|
15
|
+
string_name: "@last",
|
|
16
|
+
string_errorCode: "@increment",
|
|
17
|
+
string_country: "@country",
|
|
18
|
+
string_county: "@county(true)",
|
|
19
|
+
string_province: "@province",
|
|
20
|
+
string_city: "@city",
|
|
21
|
+
string_avatar: "@avatar",
|
|
22
|
+
string_href: "@href",
|
|
23
|
+
"string_string(16)": "@string(16)",
|
|
24
|
+
"string_date-time": "@datetime",
|
|
25
|
+
string_date: "@date",
|
|
26
|
+
number: "@integer(60, 100)",
|
|
27
|
+
number_float: "@float(60, 100, 3, 5)",
|
|
28
|
+
integer: "@integer(60, 100)",
|
|
29
|
+
boolean: "@boolean",
|
|
30
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare function isObject(obj: any): boolean;
|
|
2
|
+
declare function objectify(thing: any): any;
|
|
3
|
+
declare function get(entity: any, path: (string | number)[]): any;
|
|
4
|
+
declare function normalizeArray(arr: any): any[];
|
|
5
|
+
declare function isFunc(thing: any): boolean;
|
|
6
|
+
declare function inferSchema(thing: any): any;
|
|
7
|
+
declare function getRandomInt(min: any, max: any): number;
|
|
8
|
+
export { isObject, get, objectify, isFunc, inferSchema, normalizeArray, getRandomInt };
|