Skip to content

Instantly share code, notes, and snippets.

@francisl
Created October 25, 2013 02:50
Show Gist options
  • Save francisl/7148756 to your computer and use it in GitHub Desktop.
Save francisl/7148756 to your computer and use it in GitHub Desktop.
Updated version of a grunt compile script for livescript. 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');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment