mock-service-cli 2.0.0 → 2.0.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/manageMockFiles.js +2 -2
- package/lib/mockServer.js +4 -1
- 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.0.1](https://github.com/chandq/mock-service-cli/compare/v2.0.0...v2.0.1) (2021-12-27)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* issue of executed failed under windows ([e160753](https://github.com/chandq/mock-service-cli/commit/e16075307e9fec8efcce464004b0881884f68ab8))
|
|
11
|
+
|
|
5
12
|
## [2.0.0](https://github.com/chandq/mock-service-cli/compare/v1.2.1...v2.0.0) (2021-12-25)
|
|
6
13
|
|
|
7
14
|
|
package/lib/manageMockFiles.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @description: 生成Mock文件、获取mock数据统计
|
|
3
3
|
* @Date: 2021-12-22 16:57:08
|
|
4
4
|
* @LastEditors: chendq
|
|
5
|
-
* @LastEditTime: 2021-12-
|
|
5
|
+
* @LastEditTime: 2021-12-27 10:15:01
|
|
6
6
|
* @Author: chendq
|
|
7
7
|
*/
|
|
8
8
|
const fsa = require('fs-extra'),
|
|
@@ -98,7 +98,7 @@ const collectMockDataFromJsFile = function (mockDataMap, filePath) {
|
|
|
98
98
|
* @return {*} void
|
|
99
99
|
*/
|
|
100
100
|
const deepCollectMockData = function (mockDataMap, specialDir = '../mock') {
|
|
101
|
-
const files = fs.readdirSync(path.resolve(
|
|
101
|
+
const files = fs.readdirSync(path.resolve(process.cwd(), specialDir), { withFileTypes: true });
|
|
102
102
|
const curFilesSize = files.length;
|
|
103
103
|
for (let index = 0; index < curFilesSize; index++) {
|
|
104
104
|
const el = files[index];
|
package/lib/mockServer.js
CHANGED
|
@@ -75,6 +75,7 @@ const composeRoute = function (file) {
|
|
|
75
75
|
reqUrl = url;
|
|
76
76
|
}
|
|
77
77
|
log.info(colors.yellow(`path ${++count}: `), item, colors.blue(typeof fileObject[item]));
|
|
78
|
+
log.assert(typeof app[reqMethod] === 'function', colors.red(`${file}, ${reqMethod}`));
|
|
78
79
|
if (typeof fileObject[item] === 'function') {
|
|
79
80
|
app[reqMethod](reqUrl, fileObject[item]);
|
|
80
81
|
} else if (typeof fileObject[item] === 'object') {
|
|
@@ -90,7 +91,7 @@ const composeRoute = function (file) {
|
|
|
90
91
|
* @return {void}
|
|
91
92
|
*/
|
|
92
93
|
const parseMockFiles = function (specialDir = '../mock') {
|
|
93
|
-
const files = fs.readdirSync(path.resolve(
|
|
94
|
+
const files = fs.readdirSync(path.resolve(process.cwd(), specialDir), { withFileTypes: true });
|
|
94
95
|
const curFilesSize = files.length;
|
|
95
96
|
for (let index = 0; index < curFilesSize; index++) {
|
|
96
97
|
const el = files[index];
|
|
@@ -104,9 +105,11 @@ const parseMockFiles = function (specialDir = '../mock') {
|
|
|
104
105
|
if (el.name.endsWith('.json') && el.name !== 'mock-list.json') {
|
|
105
106
|
log.info(colors.green(`Mockfile ${++fileCount}: `), filePath, colors.yellow('all API URL is follows: '));
|
|
106
107
|
const fileObject = getFileLatestContent(filePath);
|
|
108
|
+
// eslint-disable-next-line no-loop-func
|
|
107
109
|
Object.keys(fileObject).forEach(method => {
|
|
108
110
|
const apiUrl = decodeURIComponent(el.name.split('.')[0]);
|
|
109
111
|
log.info(colors.yellow(`path ${++count}: `), `${method} ${apiUrl}`, colors.blue(typeof fileObject[method]));
|
|
112
|
+
log.assert(typeof app[method] === 'function', colors.red(`${filePath}, ${method}`));
|
|
110
113
|
app[method](apiUrl, function (req, res) {
|
|
111
114
|
res.json(fileObject[method]);
|
|
112
115
|
});
|