Created
December 5, 2012 17:35
-
-
Save nibblebot/4217755 to your computer and use it in GitHub Desktop.
Handlebars and Coffeescript Watcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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