Skip to content

Instantly share code, notes, and snippets.

@aaaristo
Last active March 23, 2017 14:44
Show Gist options
  • Save aaaristo/347eb7cdfb9b7e2980cc2c5faa2b5f00 to your computer and use it in GitHub Desktop.
Save aaaristo/347eb7cdfb9b7e2980cc2c5faa2b5f00 to your computer and use it in GitHub Desktop.
Synchronize a local development server with fswatch and rsync but transmitting multiple files at once instead of one-by-one
#!/bin/sh
ssh dev -t "bash -i -l -c '. ~/.nvm/nvm.sh; . ~/.bash_profile; cd $(pwd); git clean -f; git checkout .'"
fswatch -e .git/ . | node ${0}.js dev:$PWD
const readline = require('readline');
const spawn = require('child_process').spawn;
const dest = process.argv[2];
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var paths = {};
const cwd = process.cwd();
setInterval(() => {
const keys = Object.keys(paths);
if (keys.length) {
paths = {};
const args = ['-azPR', '--del'];
args.push.apply(args, keys);
args.push(dest);
args.push('--exclude-from');
args.push('.syncignore');
const rsync = spawn('rsync', args);
rsync.stdout.on('data', (data) => {
console.log(data.toString());
});
rsync.stderr.on('data', (data) => {
console.log(data.toString());
});
rsync.on('close', (code) => {
console.log('rsync exited', code);
if (code == 1) process.exit(1);
});
}
}, 1000);
function ask() {
rl.question('', (path) => {
paths[path.replace(cwd+'/', '')] = true;
ask();
});
}
ask();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment