Skip to content

Instantly share code, notes, and snippets.

@michsch
Forked from davidpfahler/Grunt Coffee Task
Created July 11, 2012 01:18
Show Gist options
  • Save michsch/3087293 to your computer and use it in GitHub Desktop.
Save michsch/3087293 to your computer and use it in GitHub Desktop.
A grunt task that compiles coffee-script to js
/*
* Grunt Task File
* ---------------
*
* Task: coffee
* Description: Compile coffee files to js
* Dependencies: coffee-script
*
*/
task.registerBasicTask("coffee", "Compile coffee files to js", function(data, name) {
var files = file.expand(data); // files array contains filepath as strings
// compile each coffee-sciprt file to js
files.forEach(function(filepath) {
// compile and write to file
task.helper('coffee', filepath);
});
});
task.registerHelper('coffee', function(filepath /* String */, callback /* [Function] */) {
var coffee = require('coffee-script');
try {
var js = coffee.compile(file.read(filepath));
if (js) file.write(filepath.replace(/\.coffee$/, '.js'), js);
}
catch (e) {
log.error(e.message);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment