-
Notifications
You must be signed in to change notification settings - Fork 4
/
watch.js
37 lines (34 loc) · 1.51 KB
/
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
var buildConfig = require('./tools/buildConfig.js');
var readDirectory = require('./tools/readDirectory.js');
var refresh = require('./refresh.js');
var findRootDirectory = require('./tools/findRootDirectory.js');
module.exports = () => {
var fs = require('fs');
console.log('koji-tools watching');
// const props = JSON.parse(refresh());
// output what the server wants us to in order to start the preview window
// console.log(props.config.develop.frontend.events.built);
// NOTE: figure out what to do about this one, because we cant output this before the server is ready...
// make sure that its in there to start, postinstall has been doing so weird stuff
refresh();
// watch the .koji directory from a node_modules directory...
let root = findRootDirectory();
readDirectory(root)
.filter(path => (path.endsWith('koji.json') || path.includes('.koji')) && !path.includes('.koji-resources'))
.forEach((path) => {
console.log('Watching', path);
let fsWait = false;
fs.access(path, fs.F_OK, (err) => {
if (!err) {
fs.watch(path, (eventType, filename) => {
if (fsWait) return;
fsWait = setTimeout(() => {
fsWait = false;
}, 1000);
console.log(eventType, filename);
refresh();
});
}
});
});
}