mock-service-cli 3.1.4 → 3.1.5

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.
Files changed (2) hide show
  1. package/lib/mockServer.js +17 -2
  2. package/package.json +1 -1
package/lib/mockServer.js CHANGED
@@ -104,7 +104,13 @@ const composeRouteFromJsFile = function (file) {
104
104
  reqMethod = method.toLowerCase();
105
105
  reqUrl = url;
106
106
  }
107
- argv.a && log.info(colors.yellow(`path ${++count}: `), item, colors.blue(typeof fileObject[item]));
107
+ argv.a &&
108
+ log.info(
109
+ colors.grey(`path ${String(++count).padStart(3, ' ')}: `),
110
+ colors.cyan(reqMethod.padEnd(8, ' ')),
111
+ colors.cyan(reqUrl),
112
+ colors.blue(typeof fileObject[item])
113
+ );
108
114
  log.assert(typeof app[reqMethod] === 'function', colors.red(`${file}, ${reqMethod}`));
109
115
  if (typeof fileObject[item] === 'function') {
110
116
  app[reqMethod](reqUrl, fileObject[item]);
@@ -136,11 +142,20 @@ const parseMockFiles = function (specialDir = '../mock') {
136
142
  argv.a &&
137
143
  log.info(colors.green(`Mockfile ${++fileCount}: `), filePath, colors.yellow('all API URL is follows: '));
138
144
  const fileObject = getFileLatestContent(filePath);
145
+ if (!fileObject) {
146
+ console.error(colors.red(`[warning] "${filePath}" 文件解析失败,请检查并确保文件中的js语法正确`));
147
+ continue;
148
+ }
139
149
  // eslint-disable-next-line no-loop-func
140
150
  Object.keys(fileObject).forEach(method => {
141
151
  const apiUrl = filePath2ApiUrl(decodeURIComponent(el.name.split('.')[0]));
142
152
  argv.a &&
143
- log.info(colors.yellow(`path ${++count}: `), `${method} ${apiUrl}`, colors.blue(typeof fileObject[method]));
153
+ log.info(
154
+ colors.grey(`path ${String(++count).padStart(3, ' ')}: `),
155
+ colors.cyan(method.padEnd(8, ' ')),
156
+ colors.cyan(apiUrl),
157
+ colors.blue(typeof fileObject[method])
158
+ );
144
159
  log.assert(typeof app[method] === 'function', colors.red(`${filePath}, ${method}`));
145
160
  app[method](apiUrl, function (req, res) {
146
161
  res.json(fileObject[method]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mock-service-cli",
3
- "version": "3.1.4",
3
+ "version": "3.1.5",
4
4
  "description": "🦅 Local mock server",
5
5
  "main": "./lib/mockServer.js",
6
6
  "bin": {