Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
default: mock.EggMock;
app: (option?: MidwayApplicationOptions) => MidwayMockApplication;
cluster: (option?: MidwayApplicationOptions) => MidwayMockApplication;
// [prop: string]: any
}
/**
* 只初始化app级别的container
* agent相关的逻辑使用mm2.app
* @param options 参数
*/
function mockContainer(options: MidwayApplicationOptions): MockContainer {
return new MockContainer(options);
}
const defaultFramework: string = resolveModule('midway') || resolveModule('midway-mirror');
export const mm = Object.assign({}, mock, {
container: mockContainer,
}) as MidwayMock;
mm.app = (options): MidwayMockApplication => {
if (process.env.MIDWAY_BASE_DIR && !options.baseDir) { options.baseDir = process.env.MIDWAY_BASE_DIR; }
if (process.env.MIDWAY_FRAMEWORK_PATH && !options.framework) { options.framework = process.env.MIDWAY_FRAMEWORK_PATH; }
// @ts-ignore
return mock.app(Object.assign({
framework: options.framework || defaultFramework,
typescript: !!require.extensions['.ts'],
}, options));
};
mm.cluster = (options) => {
'package:midway-compileFunctions': async () => { // 构建midway faas
this.serverless.cli.log('Building Midway FaaS directory files...');
if (!this.isTsDir) {
this.serverless.cli.log(' - Not found tsconfig.json and skip build');
return;
}
const timeTick = this.tick();
if (this.options.ncc) {
this.serverless.cli.log(' - Using single file build mode');
// await buildByNcc();
} else {
this.serverless.cli.log(' - Using tradition build mode');
const spinner = ora(' - Compiling Functions').start();
const builder = new BuildCommand();
const servicePath: string = this.midwayBuildPath;
await co(function* () {
yield builder.run({
cwd: servicePath,
argv: {
clean: true,
project: 'tsconfig.json',
srcDir: 'src'
}
});
});
await remove(join(this.midwayBuildPath, 'src'));
spinner.stop();
}
this.serverless.cli.log(` - Build Midway FaaS complete (${timeTick()}ms)`);
},