Skip to content

Instantly share code, notes, and snippets.

@michsch
Forked from davidpfahler/Grunt Coffee Task
Created July 11, 2012 01:18

Revisions

  1. @davidnpma davidnpma revised this gist Feb 13, 2012. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions Grunt Coffee Task
    Original file line number Diff line number Diff line change
    @@ -21,13 +21,11 @@ task.registerBasicTask("coffee", "Compile coffee files to js", function(data, na

    task.registerHelper('coffee', function(filepath /* String */, callback /* [Function] */) {

    var coffee = require('coffee-script'),
    fileName = filepath.match(/\/[a-z|A-Z|_]*\.coffee$/)[0].slice(1),
    jsPath = filepath.replace(/\.coffee$/, '.js');
    var coffee = require('coffee-script');

    try {
    var js = coffee.compile(file.read(filepath));
    if (js) file.write(jsPath, js);
    if (js) file.write(filepath.replace(/\.coffee$/, '.js'), js);
    }
    catch (e) {
    log.error(e.message);
  2. @davidnpma davidnpma revised this gist Feb 13, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Grunt Coffee Task
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ task.registerHelper('coffee', function(filepath /* String */, callback /* [Funct

    var coffee = require('coffee-script'),
    fileName = filepath.match(/\/[a-z|A-Z|_]*\.coffee$/)[0].slice(1),
    jsPath = 'modules/'+fileName.replace('coffee', 'js');
    jsPath = filepath.replace(/\.coffee$/, '.js');

    try {
    var js = coffee.compile(file.read(filepath));
  3. @davidnpma davidnpma created this gist Feb 13, 2012.
    35 changes: 35 additions & 0 deletions Grunt Coffee Task
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    /*
    * 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'),
    fileName = filepath.match(/\/[a-z|A-Z|_]*\.coffee$/)[0].slice(1),
    jsPath = 'modules/'+fileName.replace('coffee', 'js');

    try {
    var js = coffee.compile(file.read(filepath));
    if (js) file.write(jsPath, js);
    }
    catch (e) {
    log.error(e.message);
    }
    });