mock-service-cli 2.4.1 → 2.4.2
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/manageMockFiles.js +1 -1
- package/lib/mockServer.js +6 -4
- package/lib/utils.js +9 -0
- package/package.json +1 -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.2](https://github.com/chandq/mock-service-cli/compare/v2.4.1...v2.4.2) (2022-01-07)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* 缓存mock统计信息 ([1ee87cd](https://github.com/chandq/mock-service-cli/commit/1ee87cd041e68b9f17b64e9e3cb906681cb855fc))
|
|
11
|
+
|
|
5
12
|
### [2.4.1](https://github.com/chandq/mock-service-cli/compare/v2.4.0...v2.4.1) (2022-01-06)
|
|
6
13
|
|
|
7
14
|
|
package/lib/manageMockFiles.js
CHANGED
package/lib/mockServer.js
CHANGED
|
@@ -7,7 +7,7 @@ const express = require('express'), // 引入express
|
|
|
7
7
|
chalk = require('chalk');
|
|
8
8
|
const ifaces = os.networkInterfaces();
|
|
9
9
|
const { Server } = require('socket.io');
|
|
10
|
-
const { dateFormat, logger, SupportMethods, getFileLatestContent, filePath2ApiUrl } = require('./utils');
|
|
10
|
+
const { dateFormat, logger, SupportMethods, getFileLatestContent, filePath2ApiUrl, isEmptyObj } = require('./utils');
|
|
11
11
|
const { genMockFiles, getMockStatFromDir, getMockStatFromFile } = require('./manageMockFiles');
|
|
12
12
|
|
|
13
13
|
const methodRegExp = new RegExp(`(${SupportMethods.join('|')}) +(.*)`, 'i');
|
|
@@ -20,7 +20,9 @@ const AsyncTaskQueue = require('./asyncTaskQueue');
|
|
|
20
20
|
const saveDataAsyncTask = new AsyncTaskQueue();
|
|
21
21
|
|
|
22
22
|
let count = 0,
|
|
23
|
-
fileCount = 0
|
|
23
|
+
fileCount = 0, // 记录mock api个数,mock file个数
|
|
24
|
+
mockDirStat = {}, // 缓存mock目录的统计信息
|
|
25
|
+
mockFileStat = {}; // 缓存mock文件的统计信息
|
|
24
26
|
let done = false;
|
|
25
27
|
if (!process.env.PORT) {
|
|
26
28
|
portfinder.basePort = 8090;
|
|
@@ -147,10 +149,10 @@ if (process.env.SOCKET_SERVER) {
|
|
|
147
149
|
colors.green(`Socket client ${clientIp} has connected. --- ${dateFormat('YYYY-mm-dd HH:MM:SS', new Date())}`)
|
|
148
150
|
);
|
|
149
151
|
socket.on('mock-dir-stat', function (dir) {
|
|
150
|
-
socket.emit('mock-dir-stat', getMockStatFromDir(dir));
|
|
152
|
+
socket.emit('mock-dir-stat', isEmptyObj(mockDirStat) ? mockDirStat = getMockStatFromDir(dir) : mockDirStat);
|
|
151
153
|
});
|
|
152
154
|
socket.on('mock-file-stat', function (filePath) {
|
|
153
|
-
socket.emit('mock-file-stat', getMockStatFromFile(filePath));
|
|
155
|
+
socket.emit('mock-file-stat', isEmptyObj(mockFileStat) ? mockFileStat = getMockStatFromFile(filePath) : mockFileStat);
|
|
154
156
|
});
|
|
155
157
|
const async = args => {
|
|
156
158
|
return async next => {
|
package/lib/utils.js
CHANGED
|
@@ -120,6 +120,14 @@ const filePath2ApiUrl = function (filePath) {
|
|
|
120
120
|
const getDataType = function (data) {
|
|
121
121
|
return Object.prototype.toString.call(data).slice(8, -1).toLowerCase();
|
|
122
122
|
};
|
|
123
|
+
/**
|
|
124
|
+
* @description: 判断对象是否为空
|
|
125
|
+
* @param {object} obj
|
|
126
|
+
* @return {boolean}
|
|
127
|
+
*/
|
|
128
|
+
const isEmptyObj = function (obj) {
|
|
129
|
+
return getDataType(obj) === 'object' && Object.keys(obj).length === 0;
|
|
130
|
+
};
|
|
123
131
|
/**
|
|
124
132
|
* @description: 流方式写文件(适合写超大文件)
|
|
125
133
|
* @param {string} filePath
|
|
@@ -275,6 +283,7 @@ module.exports = {
|
|
|
275
283
|
getFileLatestContent,
|
|
276
284
|
filePath2ApiUrl,
|
|
277
285
|
getDataType,
|
|
286
|
+
isEmptyObj,
|
|
278
287
|
writeStream,
|
|
279
288
|
readStream,
|
|
280
289
|
debounce,
|