forked from mdbarr/enmeshed
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserve.js
executable file
·43 lines (37 loc) · 959 Bytes
/
serve.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
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const child_process = require('child_process');
try {
child_process.execSync('./build.js', {
stdio: 'inherit'
});
console.log();
} catch (error) {
console.log(error);
process.exit(0);
}
process.argv.push('./dist/');
require('http-server/bin/http-server');
const last = {};
const options = {
interval: 2500
};
function rebuild(which, curr) {
if (!last[which] || last[which].mtime !== curr.mtime) {
last.which = curr;
console.log();
console.log('-'.repeat(80));
console.log(`\n${ which } changed, rebuilding...`);
try {
child_process.execSync('./build.js', {
stdio: 'inherit'
});
console.log();
} catch (error) {
console.log(error);
}
}
}
fs.watchFile('./index.html', options, (curr, prev) => rebuild('index.html', curr, prev));
fs.watchFile('./build.js', options, (curr, prev) => rebuild('build.js', curr, prev));