@midwayjs/mock 3.13.8 → 3.13.9

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/app.js CHANGED
@@ -1,12 +1,11 @@
1
- const { createApp, close } = require('./dist');
1
+ const { createApp, close, processArgsParser } = require('./dist');
2
2
  const { join } = require('path');
3
3
 
4
4
  (async () => {
5
5
  process.env.MIDWAY_TS_MODE = 'false';
6
- // 查找 process.argv 中的 --port 参数
7
- const portIndex = process.argv.findIndex((item) => item === '--port');
8
- if (portIndex !== -1) {
9
- process.env.MIDWAY_HTTP_PORT = process.argv[portIndex + 1];
6
+ const args = processArgsParser(process.argv);
7
+ if (args.port) {
8
+ process.env.MIDWAY_HTTP_PORT = args.port;
10
9
  }
11
10
 
12
11
  process.once('SIGINT', onSignal);
@@ -18,11 +17,13 @@ const { join } = require('path');
18
17
  const app = await createApp({
19
18
  appDir: process.cwd(),
20
19
  baseDir: join(process.cwd(), 'dist'),
20
+ ...args,
21
21
  });
22
22
 
23
23
  process.send({
24
24
  title: 'server-ready',
25
25
  port: process.env.MIDWAY_HTTP_PORT,
26
+ ssl: args.ssl,
26
27
  });
27
28
 
28
29
  function onSignal() {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { create, close, createApp, createFunctionApp, createLightApp, createBootstrap, } from './creator';
2
2
  export * from './client/index';
3
- export { transformFrameworkToConfiguration } from './utils';
3
+ export { transformFrameworkToConfiguration, processArgsParser } from './utils';
4
4
  export * from './mock';
5
5
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.transformFrameworkToConfiguration = exports.createBootstrap = exports.createLightApp = exports.createFunctionApp = exports.createApp = exports.close = exports.create = void 0;
17
+ exports.processArgsParser = exports.transformFrameworkToConfiguration = exports.createBootstrap = exports.createLightApp = exports.createFunctionApp = exports.createApp = exports.close = exports.create = void 0;
18
18
  var creator_1 = require("./creator");
19
19
  Object.defineProperty(exports, "create", { enumerable: true, get: function () { return creator_1.create; } });
20
20
  Object.defineProperty(exports, "close", { enumerable: true, get: function () { return creator_1.close; } });
@@ -25,5 +25,6 @@ Object.defineProperty(exports, "createBootstrap", { enumerable: true, get: funct
25
25
  __exportStar(require("./client/index"), exports);
26
26
  var utils_1 = require("./utils");
27
27
  Object.defineProperty(exports, "transformFrameworkToConfiguration", { enumerable: true, get: function () { return utils_1.transformFrameworkToConfiguration; } });
28
+ Object.defineProperty(exports, "processArgsParser", { enumerable: true, get: function () { return utils_1.processArgsParser; } });
28
29
  __exportStar(require("./mock"), exports);
29
30
  //# sourceMappingURL=index.js.map
package/dist/utils.d.ts CHANGED
@@ -13,4 +13,13 @@ export declare function transformFrameworkToConfiguration<T extends IMidwayFrame
13
13
  }>;
14
14
  export declare function removeFile(file: string): Promise<void>;
15
15
  export declare function mergeGlobalConfig(globalConfig: any, newConfigObject: Record<string, any>): any;
16
+ /**
17
+ * 解析命令行参数的函数。
18
+ * 它接受一个字符串数组作为输入,然后解析这个数组,
19
+ * 将形如 `--key value` 或 `--key=value` 的参数转换为对象的键值对,
20
+ * 形如 `--key` 的参数转换为 `{ key: true }`。
21
+ * @param argv 命令行参数数组
22
+ * @returns 解析后的参数对象
23
+ */
24
+ export declare function processArgsParser(argv: string[]): {};
16
25
  //# sourceMappingURL=utils.d.ts.map
package/dist/utils.js CHANGED
@@ -6,7 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.mergeGlobalConfig = exports.removeFile = exports.transformFrameworkToConfiguration = exports.findFirstExistModule = exports.isWin32 = exports.isTestEnvironment = void 0;
9
+ exports.processArgsParser = exports.mergeGlobalConfig = exports.removeFile = exports.transformFrameworkToConfiguration = exports.findFirstExistModule = exports.isWin32 = exports.isTestEnvironment = void 0;
10
10
  const core_1 = require("@midwayjs/core");
11
11
  const os = require("os");
12
12
  const assert = require("assert");
@@ -108,4 +108,34 @@ function mergeGlobalConfig(globalConfig, newConfigObject) {
108
108
  return globalConfig;
109
109
  }
110
110
  exports.mergeGlobalConfig = mergeGlobalConfig;
111
+ /**
112
+ * 解析命令行参数的函数。
113
+ * 它接受一个字符串数组作为输入,然后解析这个数组,
114
+ * 将形如 `--key value` 或 `--key=value` 的参数转换为对象的键值对,
115
+ * 形如 `--key` 的参数转换为 `{ key: true }`。
116
+ * @param argv 命令行参数数组
117
+ * @returns 解析后的参数对象
118
+ */
119
+ function processArgsParser(argv) {
120
+ const args = argv.slice(2);
121
+ const result = {};
122
+ args.forEach((arg, index) => {
123
+ if (arg.startsWith('--')) {
124
+ let value;
125
+ let key = arg.slice(2);
126
+ if (key.includes('=')) {
127
+ [key, value] = key.split('=');
128
+ }
129
+ else if (args[index + 1] && !args[index + 1].startsWith('--')) {
130
+ value = args[index + 1];
131
+ }
132
+ else {
133
+ value = true;
134
+ }
135
+ result[key] = value;
136
+ }
137
+ });
138
+ return result;
139
+ }
140
+ exports.processArgsParser = processArgsParser;
111
141
  //# sourceMappingURL=utils.js.map
package/function.js CHANGED
@@ -1,12 +1,11 @@
1
- const { createFunctionApp, close } = require('./dist');
1
+ const { createFunctionApp, close, processArgsParser } = require('./dist');
2
2
  const { join } = require('path');
3
3
 
4
4
  (async () => {
5
5
  process.env.MIDWAY_TS_MODE = 'false';
6
- // 查找 process.argv 中的 --port 参数
7
- const portIndex = process.argv.findIndex(item => item === '--port');
8
- if (portIndex !== -1) {
9
- process.env.MIDWAY_HTTP_PORT = process.argv[portIndex + 1];
6
+ const args = processArgsParser(process.argv);
7
+ if (args.port) {
8
+ process.env.MIDWAY_HTTP_PORT = args.port;
10
9
  }
11
10
 
12
11
  process.once('SIGINT', onSignal);
@@ -18,11 +17,13 @@ const { join } = require('path');
18
17
  const app = await createFunctionApp({
19
18
  appDir: process.cwd(),
20
19
  baseDir: join(process.cwd(), 'dist'),
20
+ ...args,
21
21
  });
22
22
 
23
23
  process.send({
24
24
  title: 'server-ready',
25
25
  port: process.env.MIDWAY_HTTP_PORT,
26
+ ssl: args.ssl,
26
27
  });
27
28
 
28
29
  function onSignal() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/mock",
3
- "version": "3.13.8",
3
+ "version": "3.13.9",
4
4
  "description": "create your test app from midway framework",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -51,5 +51,5 @@
51
51
  "type": "git",
52
52
  "url": "https://github.com/midwayjs/midway.git"
53
53
  },
54
- "gitHead": "a0b8dc4d1627a3108f9f3c1f77edc9d2e7b328dd"
54
+ "gitHead": "00750219506f4e3ad0e1dbb167d295610005b328"
55
55
  }