mock-service-cli 2.4.0 → 2.4.1
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 +7 -0
- package/lib/asyncTaskQueue.js +6 -2
- package/lib/manageMockFiles.js +17 -5
- package/lib/utils.js +3 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [2.4.1](https://github.com/chandq/mock-service-cli/compare/v2.4.0...v2.4.1) (2022-01-06)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* 修复无法同时保留相同url不同请求类型的响应数据 ([90326dc](https://github.com/chandq/mock-service-cli/commit/90326dc556760eb81efadd76b031366452c95d2b))
|
|
11
|
+
|
|
5
12
|
## [2.4.0](https://github.com/chandq/mock-service-cli/compare/v2.3.2...v2.4.0) (2022-01-05)
|
|
6
13
|
|
|
7
14
|
|
package/lib/asyncTaskQueue.js
CHANGED
|
@@ -2,21 +2,25 @@
|
|
|
2
2
|
* @description: 异步任务队列
|
|
3
3
|
* @Date: 2022-01-04 10:46:20
|
|
4
4
|
* @LastEditors: chendq
|
|
5
|
-
* @LastEditTime: 2022-01-
|
|
5
|
+
* @LastEditTime: 2022-01-06 13:17:21
|
|
6
6
|
* @Author: chendq
|
|
7
7
|
*/
|
|
8
8
|
// const { getDataType } = require('./utils');
|
|
9
9
|
class AsyncTaskQueue {
|
|
10
|
-
constructor() {
|
|
10
|
+
constructor(isSaveItem = false) {
|
|
11
11
|
this.list = [];
|
|
12
12
|
this.index = 0;
|
|
13
13
|
this.isStop = false;
|
|
14
14
|
this.isParallel = false;
|
|
15
|
+
this.isSaveItem = isSaveItem; // 执行完成后的数据是否保留
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
next() {
|
|
18
19
|
// 加限制
|
|
19
20
|
if (this.index >= this.list.length - 1 || this.isStop) return;
|
|
21
|
+
if (!this.isSaveItem) {
|
|
22
|
+
this.list.splice(this.index, 1, '');
|
|
23
|
+
}
|
|
20
24
|
const cur = this.list[++this.index];
|
|
21
25
|
cur(this.next.bind(this));
|
|
22
26
|
}
|
package/lib/manageMockFiles.js
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
* @description: 生成Mock文件、获取mock数据统计
|
|
3
3
|
* @Date: 2021-12-22 16:57:08
|
|
4
4
|
* @LastEditors: chendq
|
|
5
|
-
* @LastEditTime: 2022-01-
|
|
5
|
+
* @LastEditTime: 2022-01-06 13:09:42
|
|
6
6
|
* @Author: chendq
|
|
7
7
|
*/
|
|
8
8
|
const fsa = require('fs-extra'),
|
|
9
9
|
fs = require('fs'),
|
|
10
10
|
path = require('path'),
|
|
11
|
+
_ = require('lodash'),
|
|
11
12
|
colors = require('colors/safe');
|
|
12
13
|
const {
|
|
13
14
|
getFileLatestContent,
|
|
@@ -93,7 +94,15 @@ const genMockFiles = async function ({ url: apiUrl, method, data: resJsonData, d
|
|
|
93
94
|
|
|
94
95
|
// mock文件存在
|
|
95
96
|
if (fsa.pathExistsSync(mockFilePath)) {
|
|
96
|
-
const mockFileContent =
|
|
97
|
+
const mockFileContent = getFileLatestContent(mockFilePath);
|
|
98
|
+
// 内容一样不作修改
|
|
99
|
+
if (mockFileContent.hasOwnProperty(method) && _.isEqual(mockFileContent[method], resJsonData)) {
|
|
100
|
+
// log.assert(
|
|
101
|
+
// !_.isEqual(mockFileContent[method], resJsonData),
|
|
102
|
+
// colors.bgYellow(`${method} ${apiUrl}, Mock data is same`)
|
|
103
|
+
// );
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
97
106
|
mockFileContent[method] = resJsonData;
|
|
98
107
|
try {
|
|
99
108
|
await writeStream(mockFilePath, JSON.stringify(mockFileContent, null, 2));
|
|
@@ -178,7 +187,8 @@ const deepCollectMockData = function (mockDataMap, specialDir = '../mock') {
|
|
|
178
187
|
*/
|
|
179
188
|
const getMockStatFromDir = dirPath => {
|
|
180
189
|
if (!fsa.pathExistsSync(dirPath)) {
|
|
181
|
-
|
|
190
|
+
getLogger(path.resolve(process.cwd())).error(`入参无效,${dirPath} 目录不存在`);
|
|
191
|
+
return;
|
|
182
192
|
}
|
|
183
193
|
const mockDataMap = {};
|
|
184
194
|
deepCollectMockData(mockDataMap, dirPath);
|
|
@@ -212,7 +222,8 @@ const getMockStatFromDir = dirPath => {
|
|
|
212
222
|
*/
|
|
213
223
|
const getMockStatFromFile = filePath => {
|
|
214
224
|
if (!fsa.pathExistsSync(filePath)) {
|
|
215
|
-
|
|
225
|
+
getLogger(path.resolve(process.cwd())).error(`入参无效,${filePath} 文件不存在`);
|
|
226
|
+
return;
|
|
216
227
|
}
|
|
217
228
|
const mockDataMap = {};
|
|
218
229
|
collectMockDataFromJsFile(mockDataMap, filePath);
|
|
@@ -227,7 +238,8 @@ const getMockStatFromFile = filePath => {
|
|
|
227
238
|
*/
|
|
228
239
|
const hasMockApi = function (mockDataMap, apiUrl, method) {
|
|
229
240
|
if (!apiUrl || !method || !mockDataMap || !(mockDataMap instanceof Object)) {
|
|
230
|
-
|
|
241
|
+
getLogger(path.resolve(process.cwd())).error(`入参无效,${mockDataMap} 必须是 mock数据的Object对象`);
|
|
242
|
+
return;
|
|
231
243
|
}
|
|
232
244
|
return mockDataMap.hasOwnProperty(`${method.toLocaleLowerCase()} ${path.normalize(apiUrl)}`);
|
|
233
245
|
};
|
package/lib/utils.js
CHANGED
|
@@ -136,7 +136,9 @@ const writeStream = function (filePath, data) {
|
|
|
136
136
|
writerStream.end();
|
|
137
137
|
writerStream.on('finish', () => {});
|
|
138
138
|
writerStream.on('close', () => {
|
|
139
|
-
|
|
139
|
+
setTimeout(() => {
|
|
140
|
+
resolve(data);
|
|
141
|
+
});
|
|
140
142
|
});
|
|
141
143
|
|
|
142
144
|
writerStream.on('error', err => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mock-service-cli",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "🦅 Local mock server",
|
|
5
5
|
"main": "./lib/mockServer.js",
|
|
6
6
|
"bin": {
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"deasync": "^0.1.23",
|
|
50
50
|
"express": "^4.17.1",
|
|
51
51
|
"fs-extra": "^10.0.0",
|
|
52
|
+
"lodash": "^4.17.21",
|
|
52
53
|
"minimist": "^1.2.5",
|
|
53
54
|
"nodemon": "^2.0.14",
|
|
54
55
|
"portfinder": "^1.0.28",
|