@@ -7,8 +7,7 @@ import { exec } from 'child-process-promise';
7
7
portfinder.basePort = 4000;
8
8
9
9
const SIGINT = 'SIGINT';
10
- let webpackDevServer;
11
- let docsServer;
10
+ let processMap = {};
12
11
13
12
function output(prefix, message) {
14
13
let formattedMessage = message.trim().split('\n')
@@ -23,22 +22,37 @@ function listen({stdout, stderr}, name) {
23
22
}
24
23
25
24
function shutdown() {
26
- if (webpackDevServer) {
27
- webpackDevServer.kill(SIGINT);
28
- }
29
- if (docsServer) {
30
- docsServer.kill(SIGINT);
25
+ for (let key in processMap) {
26
+ processMap[key].kill(SIGINT);
31
27
}
32
28
}
33
29
34
30
function catchExec(name, err) {
35
31
if (err.killed) {
36
32
console.log('Shutdown: '.cyan + name.green);
37
- } else {
38
- console.log(`${name} -- Failed`.red);
39
- console.log(err.toString().red);
33
+ shutdown();
34
+ return false;
40
35
}
41
- shutdown();
36
+
37
+ console.log(`${name} -- Failed`.red);
38
+ console.log(err.toString().red);
39
+ return true;
40
+ }
41
+
42
+ function runCmd(name, cmd, options) {
43
+ exec(cmd, options)
44
+ .progress(childProcess => {
45
+ listen(childProcess, name);
46
+ processMap[name] = childProcess;
47
+ return;
48
+ })
49
+ .then(() => console.log('Shutdown: '.cyan + name.green))
50
+ .catch(err => {
51
+ if (catchExec(name, err)) {
52
+ // Restart if not explicitly shutdown
53
+ runCmd(name, cmd, options);
54
+ }
55
+ });
42
56
}
43
57
44
58
console.log('Starting docs in Development mode'.cyan);
@@ -51,28 +65,14 @@ portfinder.getPorts(2, {}, (portFinderErr, [docsPort, webpackPort]) => {
51
65
process.exit(1);
52
66
}
53
67
54
- exec(`webpack-dev-server --quiet --config webpack.docs.js --color --port ${webpackPort}`)
55
- .progress(childProcess => {
56
- listen(childProcess, 'webpack-dev-server');
57
- webpackDevServer = childProcess;
58
- return;
59
- })
60
- .then(() => console.log('Shutdown: '.cyan + 'webpack-dev-server'.green))
61
- .catch(err => catchExec('webpack-dev-server', err));
68
+ runCmd('webpack-dev-server', `nodemon --watch webpack --watch webpack.config.js --watch node_modules --exec webpack-dev-server -- --config webpack.docs.js --color --port ${webpackPort} --debug --hot`);
62
69
63
- exec('nodemon --exec babel-node docs/server.js', {
64
- env: {
65
- PORT: docsPort,
66
- WEBPACK_DEV_PORT: webpackPort,
67
- ...process.env
68
- }
69
- })
70
- .progress(childProcess => {
71
- listen(childProcess, 'docs-server');
72
- docsServer = childProcess;
73
- return;
74
- })
75
- .then(() => console.log('Shutdown: '.cyan + 'docs-server'.green))
76
- .catch(err => catchExec('docs-server', err));
70
+ runCmd('docs-server', 'nodemon --watch docs --watch src --watch node_modules --exec babel-node docs/server.js', {
71
+ env: {
72
+ PORT: docsPort,
73
+ WEBPACK_DEV_PORT: webpackPort,
74
+ ...process.env
75
+ }
76
+ });
77
77
});
78
78
0 commit comments