-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnodemon.js
58 lines (49 loc) · 1.36 KB
/
nodemon.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
//
// Configure nodemon to restart the server when a server source file changes.
//
// When restarting, use the list of files that changed to determine
// how to intelligently remove cache files.
//
// src/server/sources/agenda.js => remove /work/cache/board_agenda_*
// src/server/sources/agenda/* => remove /work/cache/board_agenda_*
// src/server/sources/other.js => remove /work/cache/other.js* (which matches json)
//
const fs = require('fs');
const nodemon = require('nodemon');
nodemon({
script: 'src/server.js',
watch: [
'src/client/events/shared-worker.js',
'src/server',
'src/server.js'
]
});
nodemon.on('start', function () {
});
nodemon.on('quit', function () {
process.exit();
})
nodemon.on('restart', function (files) {
console.log('restarting...');
let sources = process.cwd() + '/src/server/sources/';
let cache = fs.readdirSync('./work/cache');
let trash = new Set();
for (let file of files) {
if (file.startsWith(sources)) {
file = file.slice(sources.length);
let prefix;
if (file.startsWith('agenda')) {
prefix = 'board_agenda_';
} else {
prefix = file;
}
for (let cfile of cache) {
if (cfile.startsWith(prefix)) trash.add(cfile);
}
}
}
for (let file of trash) {
console.log('decaching ', file);
fs.unlinkSync(`./work/cache/${file}`);
}
});