This repository has been archived by the owner on Feb 19, 2024. It is now read-only.
/
dev.js
67 lines (61 loc) · 1.84 KB
/
dev.js
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
65
66
67
const path = require('path');
const nodemon = require('nodemon');
const utils = require('nodemon/lib/utils');
const {
flow,
get,
intersection,
isEqual,
} = require('lodash/fp');
// By default we want nodemon to ignore any files that contain isomorphic code,
// so that if a change in the file occurs the dev server doesn't restart. That
// would break HMR and force you to reload the page.
const ignore = [
'actions/*',
'client/*',
'components/*',
'config/*',
'reducers/*',
'sagas/*',
'selectors/*',
'server/serverRenderer.js',
'server/getAppTemplateVars.js',
'server/getErrorTemplateVars.js',
'services/*',
'utils/*',
'hooks/*',
'irving.config.js',
'irving.config.server.js',
'componentMap.js',
];
const script = path.join(__dirname, './start.js');
nodemon({ script, ignore });
const getIgnore = get('config.options.ignore');
const isIgnoreApplied = flow(getIgnore, intersection(ignore), isEqual(ignore));
nodemon.on('crash', () => {
// When an error has occurred on the server, wait for any change in the
// project to restart the app.
if (isIgnoreApplied(nodemon)) {
nodemon.config.load({ script }, () => {
utils.log.info('Nodemon is temporarily watching all directories for a' +
' file change to resolve the error.');
});
}
});
nodemon.on('restart', () => {
// If the app has successfully restarted, make sure that we are ignore the
// isomorphic code directories again.
if (! isIgnoreApplied(nodemon)) {
nodemon.config.load({ script, ignore }, () => {
utils.log.info('Nodemon has continued to ignore directories where front' +
' end changes may occur.');
});
}
});
nodemon.on('log', (message) => {
if (message.error) {
console.error(message.colour); // eslint-disable-line no-console
} else {
console.log(message.colour); // eslint-disable-line no-console
}
});