-
Notifications
You must be signed in to change notification settings - Fork 0
/
watcher.js
32 lines (29 loc) · 966 Bytes
/
watcher.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
// Example of a more typical implementation structure:
import {Actions} from './actions';
import {sendFile} from './connection.js';
import {requestFile} from './connection.js';
import {config} from './config';
// Initialize watcher.
var watch = require('watch');
export function startWatch(){
watch.createMonitor('./root', function (monitor) {
monitor.files['./root/*'] // Stat object for my zshrc.
monitor.on("created", function (f, stat) {
// Handle new files
console.log(f, " created");
Actions.initializeFileTable();
})
monitor.on("changed", function (f, curr, prev) {
// Handle file changes
console.log(f, " changed");
for(var i=0; i<config.server_addr.length; i++){
sendFile(config.server_addr[i], './'+f);
}
})
monitor.on("removed", function (f, stat) {
// Handle removed files
console.log(f, " removed");
})
// monitor.stop(); // Stop watching
});
}