Skip to content

Instantly share code, notes, and snippets.

@richthegeek
Created March 6, 2013 12:40
Show Gist options
  • Save richthegeek/5099033 to your computer and use it in GitHub Desktop.
Save richthegeek/5099033 to your computer and use it in GitHub Desktop.
Modified builder-coffee which takes .coffee files directly from teh "scripts" directive of a component.json file.
fs = require( 'fs' )
CoffeeScript = require( 'coffee-script' )
module.exports = ( builder )->
builder.hook 'before scripts', ( pkg )->
if scripts = pkg.conf.scripts
ret_scripts = []
scripts.forEach (file) ->
name = file.match /^(.+)\.coffee$/i
if name
source = fs.readFileSync file, 'utf8'
compiled = CoffeeScript.compile source, bare: yes
file = name[1] + '.js'
fs.writeFileSync file, compiled, 'utf-8'
ret_scripts.push file
pkg.conf.scripts = ret_scripts
return pkg
// Generated by CoffeeScript 1.5.0
(function() {
var CoffeeScript, fs;
fs = require('fs');
CoffeeScript = require('coffee-script');
module.exports = function(builder) {
return builder.hook('before scripts', function(pkg) {
var ret_scripts, scripts;
if (scripts = pkg.conf.scripts) {
ret_scripts = [];
scripts.forEach(function(file) {
var compiled, name, source;
name = file.match(/^(.+)\.coffee$/i);
if (name) {
source = fs.readFileSync(file, 'utf8');
compiled = CoffeeScript.compile(source, {
bare: true
});
file = name[1] + '.js';
fs.writeFileSync(file, compiled, 'utf-8');
}
return ret_scripts.push(file);
});
}
pkg.conf.scripts = ret_scripts;
return pkg;
});
};
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment