-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
64 lines (58 loc) · 1.73 KB
/
main.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const shell = require('shelljs');
const net = require('net')
function log(str: string, color = 'FgRed') {
const colorMap = {
FgRed: '\x1b[31m',
FgGreen: '\x1b[32m',
FgYellow: '\x1b[33m',
FgBlue: '\x1b[34m',
FgMagenta: '\x1b[35m',
FgCyan: '\x1b[36m',
};
return console.log(colorMap[color], `\n \t\t${str} \n`);
}
const development = process.argv[2];
shell.cd('spiderServices')
shell.exec('ts-node ./src/main.ts', async (code: number) => {
if (code !== 0) {
log('启动spider service 失败');
return;
} else {
log('启动spider service 成功', 'FgGreen');
}
});
const server = net.createServer().listen(4000);
server.on('listening', function () { // 执行这块代码说明端口未被占用
server.close() // 关闭服务
setTimeout(() => {
shell.cd('../servicesController');
shell.exec('ts-node ./src/main.ts', async(code: number) => {
if (code !== 0) {
log('启动service Controller 失败');
return;
} else {
log('启动service Controller 成功', 'FgGreen');
}
});
}, 500)
});
server.on('error', function (err) {
shell.cd('../servicesController');
shell.exec('ts-node ./src/main.ts', async(code: number) => {
if (code !== 0) {
log('启动service Controller 失败');
return;
} else {
log('启动service Controller 成功', 'FgGreen');
}
});
});
shell.cd('../dakeBook');
shell.exec('npm run start', async(code: number) => {
if (code !== 0) {
log('启动dakeBook 失败');
return;
} else {
log('启动dakeBook 成功', 'FgGreen');
}
});