public
Last active

Handlebars and Coffeescript Watcher

  • Download Gist
multiwatch.js
JavaScript
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
function addSlashes( str ) {
return (str+'').replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0");
}
var spawn = require('child_process').spawn;
var growl = require('growl');
var coffee = './node_modules/.bin/coffee';
var coffee_tasks = [];
var handlebars_tasks = [];
coffee_tasks.push(spawn(coffee, ['-cwo', 'static/js', 'static/coffee']));
coffee_tasks.push(spawn(coffee, ['-cwo', 'test', 'test/src']));
handlebars_tasks.push(spawn('node', ['./scripts/watch_handlebars.js']));
 
coffee_tasks.forEach(function(cmd) {
cmd.stdout.on('data', function (data) {
process.stdout.write(data)
// hack since coffee watcher doesn't output errors to STDERR
if (/^In /.test(data)) {
console.log('ERROR')
growl(data, { title: 'Coffeescript Error'})
}
})
cmd.stderr.on('data', function (data) {
console.log('ERROR')
process.stderr.write(data)
})
});
 
handlebars_tasks.forEach(function(cmd) {
cmd.stdout.on('data', function (data) {
process.stdout.write(data)
})
cmd.stderr.on('data', function (data) {
process.stderr.write('Handlebars Error:')
var err = data.toString().match(/\nError: .+\n(.*\n){3}/)
if (err && err[0]) {
data = err[0]
}
process.stderr.write(data)
data = addSlashes(data);
growl(data, { title: 'Handlebars Error'})
})
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.