Skip to content

Instantly share code, notes, and snippets.

@nibblebot
Created December 5, 2012 17:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nibblebot/4217755 to your computer and use it in GitHub Desktop.
Save nibblebot/4217755 to your computer and use it in GitHub Desktop.
Handlebars and Coffeescript Watcher
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'})
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment