forked from whatwg/streams
-
Notifications
You must be signed in to change notification settings - Fork 0
/
local-watch.js
44 lines (37 loc) · 1.05 KB
/
local-watch.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
'use strict';
const fs = require('fs');
const childProcess = require('child_process');
const promiseDebounce = require('promise-debounce');
const emuAlgify = require('emu-algify');
const build = promiseDebounce(() => {
log('Building...');
try {
childProcess.execSync(
'bikeshed spec index.bs index.html --md-Text-Macro="SNAPSHOT-LINK <local watch copy>"',
{ encoding: 'utf-8', stdio: 'inherit' }
);
log('(bikeshed done)');
} catch (e) {
error('Error executing bikeshed:\n');
console.error(e.stdout);
}
const input = fs.readFileSync('index.html', { encoding: 'utf-8' });
return emuAlgify(input, { throwingIndicators: true })
.then(output => {
fs.writeFileSync('index.html', output);
log('Build complete');
})
.catch(err => {
error('Error executing ecmarkupify:\n');
console.error(err);
}
);
});
fs.watch('index.bs', build);
build();
function log(s) {
console.log(`[${(new Date()).toISOString()}] ${s}`);
}
function error(s) {
console.error(`[${(new Date()).toISOString()}] ${s}`);
}