-
Notifications
You must be signed in to change notification settings - Fork 4
/
watcher.js
43 lines (37 loc) · 1.13 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
var watch = require('watch'),
exec = require("child_process").exec;
console.log("MONITORING");
var syncInProgress = false;
setInterval(function() {
if (syncInProgress) return;
syncInProgress = true;
exec('rsync -avz --exclude "node_modules" . pi@192.168.2.6:/media/pi/projects/Jeffrey/', function(err,stdout,stderr) {
if (err)
console.log(err,stdout,stderr);
syncInProgress = false;
});
},500);
/*
var syncTimer = false, syncInProgress = false;
var sync = function sync() {
console.log("SYNC?", syncInProgress);
syncTimer = clearTimeout(syncTimer);
if (syncInProgress) {
syncTimer = setTimeout(sync,100);
return;
}
syncInProgress = true;
syncTimer = setTimeout(function() {
console.log("SYNCING");
exec('rsync -avz --exlclude "node_modules" . pi@192.168.2.6:/media/pi/project/Jeffrey/', function(err,stdout,stderr) {
console.log(err,stdout,stderr);
syncInProgress = false;
})
},100);
};
watch.createMonitor('.', function (monitor) {
monitor.on("created",sync);
monitor.on("changed",sync);
monitor.on("removed",sync);
})
*/