forked from Tencent/TSW
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
32 lines (29 loc) · 1.03 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import * as path from "path";
import { consoleHack } from "./core/runtime/console.hack";
import { httpCreateServerHack } from "./core/runtime/create-server.hack";
import { dnsHack } from "./core/runtime/dns.hack";
import { requestHack } from "./core/runtime/capture/index";
import { eventBus } from "./core/bus";
import { winstonHack } from "./core/winston";
export default async (
basePath: string,
mainPath: string,
configPath: string
): Promise<void> => {
const configAbsolutePath = path.resolve(basePath, configPath);
global.tswConfig = await import(configAbsolutePath);
// eslint-disable-next-line no-restricted-syntax
for (const plugin of global.tswConfig.plugins) {
// eslint-disable-next-line no-await-in-loop
await plugin.init(eventBus, global.tswConfig).catch((e) => {
console.error(`${plugin.name} 插件初始化失败: ${e.message}`);
process.exit(-1);
});
}
httpCreateServerHack();
dnsHack();
consoleHack();
requestHack();
winstonHack();
await import(path.resolve(basePath, mainPath));
};