forked from umijs/umi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartDevServers.js
More file actions
51 lines (45 loc) · 1.24 KB
/
startDevServers.js
File metadata and controls
51 lines (45 loc) · 1.24 KB
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
const { fork } = require('child_process');
const { join, dirname } = require('path');
const DEV_SCRIPT = join(__dirname, '../packages/umi/bin/umi.js');
function startDevServer(opts = {}) {
const { port, cwd } = opts;
return new Promise(resolve => {
const child = fork(DEV_SCRIPT, ['dev', '--port', port, '--cwd', cwd], {
env: {
...process.env,
CLEAR_CONSOLE: 'none',
BROWSER: 'none',
UMI_DIR: dirname(require.resolve('../packages/umi/package')),
},
});
child.on('message', args => {
if (args.type === 'DONE') {
resolve(child);
}
});
});
}
function start() {
const devServers = [
[12341, '../packages/umi/test/normal'],
[12342, '../packages/umi/test/hashHistory'],
[12351, '../packages/umi-plugin-react/test/normal'],
[12352, '../packages/umi-plugin-react/test/with-dva'],
[12353, '../packages/umi-plugin-react/test/pwa'],
];
return Promise.all(
devServers.map(([port, cwd]) => {
return startDevServer({ port, cwd: join(__dirname, cwd) });
}),
);
}
module.exports = start;
if (require.main === module) {
start()
.then(() => {
console.log('All dev servers are started.');
})
.catch(e => {
console.log(e);
});
}