-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch.mjs
83 lines (73 loc) · 3.24 KB
/
watch.mjs
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import chokidar from 'chokidar';
import { exec } from 'child_process';
let executing = [];
const execute=(command,index) => {
if (executing.length < index || !executing[index-1]) {
executing[index-1] = true;
return new Promise((a,r) => exec(command, function(error, stdout, stderr) {
executing[index-1] = false;
if (error) r(stderr);
else a(stdout);
})).catch(console.error);
}
};
execute("git ls-files -- src/*.html",1)
.then(stdout => stdout.split("\n").filter(s => s.length > 0))
.then(files => {
const watcher = chokidar.watch(files);
const log = console.log.bind(console);
watcher
.on('add', path => {
log(`File path ${path} has been added`);
execute("echo 'html\ndeploy' | xargs -I{} npm run {} --ignore-scripts",1);
})
.on('change', path => {
log(`File path ${path} has been changed`);
execute("echo 'html\ndeploy' | xargs -I{} npm run {} --ignore-scripts",1);
})
.on('unlink', path => log(`File ${path} has been removed`))
.on('error', error => log(`Watcher error: ${error}`))
.on('ready', _ => log('Initial scan complete. Ready for changes'))
;
process.on('SIGTERM', _ => watcher.close().then(_ => log('closed')));
});
execute("git ls-files -- assets/ts/*.ts",2)
.then(stdout => stdout.split("\n").filter(s => s.length > 0))
.then(files => {
const watcher = chokidar.watch(files);
const log = console.log.bind(console);
watcher
.on('add', file => {
log(`File path ${file} has been added`);
execute("echo 'prejs\njs\ndeploy' | xargs -I{} npm run {} --ignore-scripts",2);
})
.on('change', file => {
log(`File path ${file} has been changed`);
execute("echo 'prejs\njs\ndeploy' | xargs -I{} npm run {} --ignore-scripts",2);
})
.on('unlink', path => log(`File ${path} has been removed`))
.on('error', error => log(`Watcher error: ${error}`))
.on('ready', _ => log('Initial scan complete. Ready for changes'))
;
process.on('SIGTERM', _ => watcher.close().then(_ => log('closed')));
});
execute("git ls-files -- assets/sass/*.scss",3)
.then(stdout => stdout.split("\n").filter(s => s.length > 0))
.then(files => {
const watcher = chokidar.watch(files);
const log = console.log.bind(console);
watcher
.on('add', file => {
log(`File path ${file} has been added`);
execute("echo 'css\ndeploy' | xargs -I{} npm run {} --ignore-scripts",3);
})
.on('change', file => {
log(`File path ${file} has been changed`);
execute("echo 'css\ndeploy' | xargs -I{} npm run {} --ignore-scripts",3);
})
.on('unlink', path => log(`File ${path} has been removed`))
.on('error', error => log(`Watcher error: ${error}`))
.on('ready', _ => log('Initial scan complete. Ready for changes'))
;
process.on('SIGTERM', _ => watcher.close().then(_ => log('closed')));
});