Skip to content

Instantly share code, notes, and snippets.

@kristjanmik
Created September 14, 2013 17:20
Show Gist options
  • Save kristjanmik/6563816 to your computer and use it in GitHub Desktop.
Save kristjanmik/6563816 to your computer and use it in GitHub Desktop.
Restart titanium build on file change
var chokidar = require('chokidar'),
spawn = require('child_process').spawn,
utils = require('util');
var watcher = chokidar.watch('./', {ignored: /^build/, persistent: true});
var lastUpdate = new Date().getTime();
function update(path){
if(typeof path === 'object' || path.indexOf('Resources') !== -1 || path.indexOf('build') !== -1 || path.indexOf('monitor.js') !== -1){
return;
}
var now = new Date().getTime();
if(now-lastUpdate > 3000){
lastUpdate = new Date().getTime();
console.log('File is: ', path);
var titanium = spawn('titanium', ['build','-p','ios']);
titanium.stdout.on('data', function (data) {
utils.log(data);
});
titanium.stderr.on('data', function (data) {
utils.log(data);
});
titanium.on('close', function (code) {
utils.log('TITANIUM KILLED, EXIT CODE: ' + code);
});
}
}
watcher
.on('add', update)
.on('change', update)
.on('unlink', update);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment