Created
February 13, 2012 21:20
-
-
Save davidpfahler/1820595 to your computer and use it in GitHub Desktop.
A grunt task that compiles coffee-script to js
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
/* | |
* 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