-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·54 lines (49 loc) · 1.43 KB
/
index.js
File metadata and controls
executable file
·54 lines (49 loc) · 1.43 KB
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
#!/usr/local/bin/node
var config = require(`${process.cwd()}/pantheon-config.js`).default;
var watch = require('watch');
var Rsync = require('rsync');
//config.watch_dir
//config.target
if( config.watch_dir && config.target) {
start_sync(config.watch_dir, config.target, config);
}
if( config.watch.length ) {
config.watch.forEach( (watch) => {
start_sync(watch.watch_dir, watch.target, config);
})
}
function start_sync(source, target, config) {
const rsync = get_sync(source, target, config);
const sync = () => {
rsync.execute(function(error, code, cmd) {
console.log(`synced ${source}`);
});
}
create_watch(source, sync);
sync();
}
function get_sync(source, target, config) {
return new Rsync()
.shell(`ssh -p ${config.port || 22}`)
.flags('rlvz')
.set('stats')
.source(source)
.destination(`${config.user}@${config.host}:${target}`);
}
function create_watch(watch_dir, sync) {
watch.createMonitor(watch_dir, (monitor) => {
console.log(`Watching ${watch_dir} for changes.`)
monitor.on("created", function (f, stat) {
console.log(`Detected addition of ${f}`);
sync();
});
monitor.on("changed", function (f, curr, prev) {
console.log(`Detected change in ${f}`);
sync();
});
monitor.on("removed", function (f, stat) {
console.log(`Detected ${f} deletion`);
sync();
});
});
}