Livescript and Grunt

Updated version of a grunt compile script for livescript. (for newer version of grunt > 0.4.0)

Original from Micah Smith. http://www.allampersandall.com/2012/08/nodejs-gruntjs-livescript-mocha-example

module.exports = function(grunt) {
// LIVESCRIPT ----------------------------
var log = grunt.log;
var growl = require('growl')
function handleResult(from, dest, err, stdout, code, done) {
if(err){
growl('ERROR', stdout);
log.writeln(from + ': failed to compile to ' + dest + '.');
log.writeln(stdout);
done(false);
}else{
log.writeln(from + ': compiled to ' + dest + '.');
done(true);
}
};
var livescript_dir_to_dir = function(fromdir, dest, done) {
var args = {
cmd: 'livescript',
args: [ '--compile', '--output', dest, fromdir ]
};
runHelper(args, function(err, stdout, code){
handleResult(fromdir, dest, err, stdout, code, done);
});
}
grunt.registerMultiTask('livescript', 'compile livescripts', function() {
var done = this.async();
var files = this.data.files;
var dir = this.data.dir;
var dest = this.data.dest;
// ex: ./coffee -> ./js
if(dir) {
// if destination was not defined, compile to same dir
if(!dest) {
dest = dir;
}
livescript_dir_to_dir(dir, dest, done);
return;
}
// ex: [ '1.coffee', '2.coffee' ] -> foo.js
if(files) {
livescript_multi_to_one(files, dest, done);
return;
}
});
var exec = require('child_process').exec;
// child_process.exec bridge
var runHelper = function(opts, done) {
console.log("opts ", opts.args);
var command = opts.cmd + ' ' + opts.args.join(' ');
exec(command, opts.opts, function(code, stdout, stderr) {
if(!done){
return;
}
if(code === 0) {
done(null, stdout, code);
} else {
done(code, stderr, code);
}
});
}
grunt.initConfig({
watch: {
dist1: {
files:"app/src/**/*.ls",
tasks:"livescript"
},
dist2: {
files:"tests-src/**/*.ls",
tasks:"livescript"
},
},
livescript:{
dist1:{
dir:"tests-src/"
,dest:"tests/"
},
dist2:{
dir:"tests-src/"
,dest:"tests/"
}
}
});
grunt.registerTask('lsapp', ['watch', 'livescript']);
grunt.loadNpmTasks('grunt-contrib-watch');
};
view raw grunt-livescript.js hosted with ❤ by GitHub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s