@midwayjs/mock 3.13.7 → 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 +6 -5
- package/dist/creator.js +32 -20
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +31 -1
- package/function.js +6 -5
- package/package.json +2 -2
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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/creator.js
CHANGED
|
@@ -314,27 +314,39 @@ async function createFunctionApp(baseDir, options = {}, customFrameworkModule) {
|
|
|
314
314
|
var _a;
|
|
315
315
|
return ((_a = options.starter) === null || _a === void 0 ? void 0 : _a.createDefaultMockContext()) || {};
|
|
316
316
|
};
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
res.statusCode
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
317
|
+
try {
|
|
318
|
+
const ctx = await framework.wrapHttpRequest(req);
|
|
319
|
+
// create event and invoke
|
|
320
|
+
const result = await framework.invokeTriggerFunction(ctx, url.pathname, {
|
|
321
|
+
isHttpFunction: true,
|
|
322
|
+
});
|
|
323
|
+
const { statusCode, headers, body, isBase64Encoded } = result;
|
|
324
|
+
if (res.headersSent) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
for (const key in headers) {
|
|
328
|
+
res.setHeader(key, headers[key]);
|
|
329
|
+
}
|
|
330
|
+
if (res.statusCode !== statusCode) {
|
|
331
|
+
res.statusCode = statusCode;
|
|
332
|
+
}
|
|
333
|
+
// http trigger only support `Buffer` or a `string` or a `stream.Readable`
|
|
334
|
+
if (isBase64Encoded && typeof body === 'string') {
|
|
335
|
+
res.end(Buffer.from(body, 'base64'));
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
res.end(body);
|
|
339
|
+
}
|
|
335
340
|
}
|
|
336
|
-
|
|
337
|
-
|
|
341
|
+
catch (err) {
|
|
342
|
+
if (/favicon\.ico not found/.test(err.message)) {
|
|
343
|
+
res.statusCode = 404;
|
|
344
|
+
res.end();
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
console.error(err);
|
|
348
|
+
res.statusCode = err.status || 500;
|
|
349
|
+
res.end(err.message);
|
|
338
350
|
}
|
|
339
351
|
};
|
|
340
352
|
};
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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.
|
|
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": "
|
|
54
|
+
"gitHead": "00750219506f4e3ad0e1dbb167d295610005b328"
|
|
55
55
|
}
|