Code Monkey home page Code Monkey logo

grunt-contrib-coffee's Introduction

grunt-contrib-coffee v2.1.0 Build Status: Linux Build Status: Windows

Compile CoffeeScript files to JavaScript

Getting Started

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-contrib-coffee --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-contrib-coffee');

This plugin was designed to work with Grunt >= 0.4.x. If you're still using grunt v0.3.x it's strongly recommended that you upgrade, but in case you can't please use v0.3.2.

Coffee task

Run this task with the grunt coffee command.

Task targets, files and options may be specified according to the grunt Configuring tasks guide.

Options

separator

Type: String
Default: linefeed

Concatenated files will be joined on this string.

bare

Type: Boolean

Compile the JavaScript without the top-level function safety wrapper.

join

Type: Boolean
Default: false

When compiling multiple .coffee files into a single .js file, concatenate first.

sourceMap

Type: Boolean
Default: false

Compile JavaScript and create a .map file linking it to the CoffeeScript source. When compiling multiple .coffee files to a single .js file, concatenation occurs as though the 'join' option is enabled

sourceMapDir

Type: String
Default: (same path as your compiled js files)

Generated source map files will be created here.

joinExt

Type: String
Default: '.src.coffee'

Resulting extension when joining multiple CoffeeScript files.

Usage Examples

coffee: {
  compile: {
    files: {
      'path/to/result.js': 'path/to/source.coffee', // 1:1 compile
      'path/to/another.js': ['path/to/sources/*.coffee', 'path/to/more/*.coffee'] // compile and concat into single file
    }
  },

  compileBare: {
    options: {
      bare: true
    },
    files: {
      'path/to/result.js': 'path/to/source.coffee', // 1:1 compile
      'path/to/another.js': ['path/to/sources/*.coffee', 'path/to/more/*.coffee'] // compile and concat into single file
    }
  },

  compileJoined: {
    options: {
      join: true
    },
    files: {
      'path/to/result.js': 'path/to/source.coffee', // 1:1 compile, identical output to join = false
      'path/to/another.js': ['path/to/sources/*.coffee', 'path/to/more/*.coffee'] // concat then compile into single file
    }
  },

  compileWithMaps: {
    options: {
      sourceMap: true
    },
    files: {
      'path/to/result.js': 'path/to/source.coffee', // 1:1 compile
      'path/to/another.js': ['path/to/sources/*.coffee', 'path/to/more/*.coffee'] // concat then compile into single file
    }
  },

  compileWithMapsDir: {
    options: {
      sourceMap: true,
      sourceMapDir: 'path/to/maps/' // source map files will be created here
    },
    files: {
      'path/to/result.js': 'path/to/source.coffee'
    }
  },

  glob_to_multiple: {
    expand: true,
    flatten: true,
    cwd: 'path/to',
    src: ['*.coffee'],
    dest: 'path/to/dest/',
    ext: '.js'
  }

}

For more examples on how to use the expand API to manipulate the default dynamic path construction in the glob_to_multiple examples, see "Building the files object dynamically" in the grunt wiki entry Configuring Tasks.

Release History

  • 2019-03-18   v2.1.0   Updates to CoffeeScript 2.3.2.
  • 2017-09-27   v2.0.0   Updates to CoffeeScript 2.0.1.
  • 2016-02-15   v1.0.0   Updates to CoffeeScript 1.10.0. Update other dependencies. Use options.sourceMapDir when creating sourceRoot. Logs information if no valid files were matched.
  • 2015-02-20   v0.13.0   Updates to CoffeeScript 1.9.1.
  • 2014-10-04   v0.12.0   Fixes litcoffee sourcemaps. Updates to CoffeeScript 1.8.0.
  • 2014-08-15   v0.11.1   Fixes summary logging.
  • 2014-08-06   v0.11.0   Adds summary containing number of files created. Move file creation logging to grunt.verbose. Updates chalk to 0.5.
  • 2014-02-07   v0.10.0   sourceMappingURL calculated correctly.
  • 2014-01-29   v0.9.0   Source mapping fixes. Update CoffeeScript to 1.7.0. Use lodash directly instead of deprecated grunt.util._.
  • 2014-01-17   v0.8.2   Force CoffeeScript 1.6.3. Use new sourceMappingUrl syntax.
  • 2014-01-17   v0.8.1   Fix sourcemap regression.
  • 2013-12-24   v0.8.0   Support sourceMapDir.
  • 2013-04-19   v0.7.0   Place source maps at bottom of file. Change extension for source maps from .maps to .js.map.
  • 2013-04-18   v0.6.7   Improved error reporting.
  • 2013-04-08   v0.6.6   Fix regression with single-file compilation.
  • 2013-04-05   v0.6.5   Improved error reporting.
  • 2013-03-22   v0.6.4   Sourcemap support.
  • 2013-03-19   v0.6.3   Increase error logging verbosity.
  • 2013-03-18   v0.6.2   Bump to CoffeeScript 1.6.2.
  • 2013-03-18   v0.6.1   Support join option.
  • 2013-03-06   v0.6.0   Bump to CoffeeScript 1.6. Support literate CoffeeScript extension coffee.md.
  • 2013-02-25   v0.5.0   Bump to CoffeeScript 1.5. Support literate CoffeeScript (.litcoffee).
  • 2013-02-15   v0.4.0   First official release for Grunt 0.4.0.
  • 2013-01-23   v0.4.0rc7   Updating grunt/gruntplugin dependencies to rc7. Changing in-development grunt/gruntplugin dependency versions from tilde version ranges to specific versions. Bump coffeescript dependency to 1.4.
  • 2013-01-09   v0.4.0rc5   Updating to work with grunt v0.4.0rc5. Switching to this.filesSrc API.
  • 2012-12-15   v0.4.0a   Conversion to grunt v0.4 conventions. Remove experimental destination wildcards.
  • 2012-10-12   v0.3.2   Rename grunt-contrib-lib dep to grunt-lib-contrib.
  • 2012-09-25   v0.3.1   Don't fail when there are no files.
  • 2012-09-24   v0.3.0   Global options depreciated.
  • 2012-09-10   v0.2.0   Refactored from grunt-contrib into individual repo.

Task submitted by Eric Woroshow

This file was generated on Mon Mar 18 2019 14:04:56.

grunt-contrib-coffee's People

Contributors

adrianlee44 avatar aleclarson avatar amitport avatar boennemann avatar ctalkington avatar danne931 avatar dependabot[bot] avatar hildjj avatar ichernev avatar ipy avatar jamesplease avatar jfrux avatar johnnyfreeman avatar kevinsawicki avatar kylezeeuwen avatar leny avatar loginx avatar marcmenn avatar matthewwithanm avatar page- avatar pdehaan avatar radkodinev avatar rcrichton avatar scottydawg avatar shama avatar sindresorhus avatar tborg avatar vladikoff avatar xhmikosr avatar zaius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-contrib-coffee's Issues

Error when using dynamic building of files list

I am using grunt v0.4.0rc7 with grunt-contrib-coffee v0.4.0rc7. I try to config the task in my Gruntfile.coffee like this:

coffee:
   client:
      files:
        expand: true
        cwd: 'public/coffee/'
        dest: 'public/js/'
        ext: '.js'
        src: ['*.coffee'] 

There's one file in the 'public/coffee' directory - main.coffee. When I try to run grunt coffee I get the following output:

Running "coffee:client" (coffee) task
Warning: Object true has no method 'indexOf' Use --force to continue.

Aborted due to warnings.

I tried to use different combos with trailing slashes in cwd and dest parameters, but that didn't help.

Update: My mistake. Solved the problem. I think there should be some place in documentation, which explains dynamic files object building in more detail, because I figured out that the following two snippets work without warnings in the same way (and that brings some confusion between grunt and contrib-coffee docs):

coffee:
   client:
      files: [
        expand: true
        cwd: 'public/coffee/'
        dest: 'public/js/'
        ext: '.js'
        src: ['*.coffee'] 
      ]
coffee:
   client:
        expand: true
        cwd: 'public/coffee/'
        dest: 'public/js/'
        ext: '.js'
        src: ['*.coffee'] 

Issue when compiling multiple .litcoffee files with source maps

When compining in the following way:

    services: {
            options: {
              sourceMap : true,
              seperator : "/*! Grunt file concatination */"
            },
            files: {
              'app/js/services.js': ['components/application/**/*.service.litcoffee']
            }
          },...

It seems that source maps are created for all the litcoffee files that match, but only the first ends up in the final services.js file.

Compile entire folders 1-to-1

Hey guys,

I'm probably missing something painfully obvious, but I want all subfolders of my /assets/coffee folder to compile to respective subfolders in /assets/js. So /assets/coffee/entities/post.coffee should compile to /assets/js/entities/post.js. Could you point me in the right direction?

Thanks!

  • Steven

Destination of file cannot being evaluated.

I have this example which builds dynamically the paths from our src and dest file.
This returns an error Unexpected '{'
coffee:
compile:
files:
"#{BUILD_JS_DIR}/app.js": "#{STAGE_APP_DIR}/app_concat.coffee"

If though I hard type the path of BUILD_JS_DIR like
files:
"my_beloved_path/js/app/app.js": "#{STAGE_APP_DIR}/app_concat.coffee"

it compiles properly.

Update sourceMap declaration syntax

Chrome recent update deprecated old sourceMaps syntax:

"//@ sourceMappingURL=" source mapping URL declaration is deprecated, "//# sourceMappingURL=" declaration should be used instead.

Minify Option

It would be really great if there was an uglify option!

CommonJS wrapper

I need a way to compile CoffeeScript files to CommonJS modules.
At the moment I am using a separate grunt task to add the CommonJS wrapper to each of the resulting js files.
This could be done with the CoffeScript task if there was a process function to add the wrapping code either in CoffeScript before compile or in the resulting JS after compilation.

Support the process option

This + join will get rid of a concat task in my case.
This is particularly useful because coffee will, for example escape quotes correctly in codes such as:

text = """<%= icontainquotes %>"""

This should of course work with the join option both enabled or disabled.

setup/access environment variable?

i'm not sure it is the right place to ask this, but I've been looking around and cannot find anything. I'm using "grunt-env", and I have NODE_ENV setup in my Gruntfile, but I don't know how to let my coffee script file able to access the variable. Since it is compiled by grunt-contrib-coffee, perhaps there's some way that I can pass the variables into the file?

bare option not working

I tried using your (very helpful) module, but cannot get the bare option to work.

I added it to the compile object but it does not seem to have any effect. Is it supported ?

coffee: {
  compile: {        
    bare: true,
    files: [
      {
        expand: true,
        cwd: 'src',
        src: ['*.coffee'],
        dest: 'lib',
        ext: '.js'
      }
    ]
   }      
  }

0.8.0 breaks sourcemaps in certain configurations

This is my configuration, which worked fine with 0.7.0

coffee:
    compile:
        options:
            bare: true
            sourceMap: true
        files: [
            expand: true
            cwd: '<%= build_dir %>'
            src: [ '**/*.coffee' ]
            dest: '<%= build_dir %>'
            ext: '.js'
        ]

This created a .js and a .js.map file for every .coffee file in my build directory, placing both next to the .coffee source.

Running "coffee:compile" (coffee) task
    File build_dev/controllers/base/controller.js created.
    File build_dev/controllers/base/controller.js.map created.
    File build_dev/models/base/collection.js created.
    File build_dev/models/base/collection.js.map created.
    File build_dev/models/base/model.js created.
    File build_dev/models/base/model.js.map created.
    File build_dev/views/base/collection_view.js created.
    File build_dev/views/base/collection_view.js.map created.
    File build_dev/views/base/view.js created.
    File build_dev/views/base/view.js.map created.

The sourceMappingURL in each generated .js file is relative:

/*
//@ sourceMappingURL=model.js.map
*/

After switching to 0.8.0, the same configuration leads to this console.log

Running "coffee:compile" (coffee) task
    File build_dev/editor/composer/controllers/base/controller.js created.
    File build_dev/controllers/base/controller.js.map created.
    File build_dev/controllers/composer_controller.js created.
    File build_dev/models/base/collection.js created.
    File build_dev/controllers/base/collection.js.map created.
    File build_dev/models/base/model.js created.
    File build_dev/controllers/base/model.js.map created.
    File build_dev/views/base/collection_view.js created.
    File build_dev/controllers/base/collection_view.js.map created.
    File build_dev/views/base/view.js created.
    File build_dev/controllers/base/view.js.map created.

The sourceMappingURL in the generated .js files is now fubar:

/*
//# sourceMappingURL=../../../../../build_dev/controllers/base/model.js.map
*/

All .js.map files are generated into the same folder, without me making use of the new sourceMapDir option. Why?

I'd like the exact same results as before. What do i have to do to achieve them?

Comment option

It would be nice to have an option where I could define a custom comment like This file was generated with CoffeeScript to have a simpler distinction between compiled and hand-written javascript files in projects where both types could occur.

set sourceMappingURL root

My coffee task looks like this:

coffee:
     dev:
       options:
         bare: yes
         sourceMap: yes
       expand: yes
       cwd: '<%= srcDir %>/js'
       dest: '<%= srcDir %>/js'
       src: '**/*.coffee'
       ext: '.js'

For a js file in my src/js directory, for example app.js, it gets compiled with the following sourceMappingURL: //# sourceMappingURL=../../src/js/app.js.map but it should be //# sourceMappingURL=app.js.map. Is there a way to specify this Url's root?

0.7.0: coffeescript compilation failure is causing process exit, even with --force option

I'm using grunt --watch --force to compile coffeescript. When the compilation fails it will abort the watch and exit grunt. Example:

$ grunt --watch --force
....
Running "watch" task

Completed in 0.985s at Thu Aug 08 2013 14:06:46 GMT-0700 (PDT) - Waiting...OK
>> File "app/assets/src/coffee/data.coffee" changed.

Running "coffee:dev" (coffee) task
...
File app/assets/js/data.js.map created.
>> SyntaxError: unexpected THEN
>> In file: app/assets/src/coffee/qsr/serverDataLayer.coffee
>> On line: 305
>>               when 'file' then
>>                           ^ 
Warning: CoffeeScript failed to compile. Use --force to continue.

Aborted due to warnings.

$

Watch config for coffee:

  grunt.initConfig
    watch:
      coffee:
        files: ['app/assets/src/coffee/**/*.coffee', 'app/assets/src/coffee/*.coffee', 'app/webserver.coffee']
        tasks: ['coffee:dev', 'replace', 'mochaTest']
        options:
          nospawn: true

... 

    coffee: 
      dev:
        options:
          sourceMap: true
          force: true
        expand: true
        cwd: "app/assets/src/coffee"
        src: "**/*.coffee"
        dest: "app/assets/js/"
        ext: ".js"

I've never tried debugging grunt, I'll give it a shot. Anything else you need? My understanding is that grunt shouldn't be dying if it hits an error. Is this a grunt error instead of an error in this project?

Source maps

Any plans on integrating CoffeeScriptRedux and source maps?
Is there interest in a PR?

Multiple coffees are not joined

The following:

coffee: {
  all: {
    src: ['script1.coffee', 'script2.coffee'],
    dest: 'script.js'
  }
}

gives the following:

(function(){
  // script1.coffee compiled
}).call(this);

(function(){
  // script2.coffee compiled
}).call(this);

instead of --joined coffees into:

(function(){
  // script1.coffee compiled
  // script2.coffee compiled
}).call(this);

Right now I have to concat my coffee files before compiling.
I'd rather skip that step.

Off-topic: is it possible to use concat directives such as <file_template:...> in some way?

Is it possible to keep the same source folder structure in the destination folder?

Source:

src/app
│
├── app.coffee
├── router.coffee
├── utils
│   ├── csrf.coffee
│   └── tastypie.coffee
└── views
    ├── alert_view.coffee
    ├── dialog_view.coffee
    ├── editable_view.coffee
    ├── libraries_view.coffee
    ├── library_view.coffee
    ├── navigation_view.coffee
    └── profile_view.coffee

Destination (the same dirs structure):

dest/app
│
├── app.js
├── router.js
├── utils
│   ├── csrf.js
│   └── tastypie.js
└── views
    ├── alert_view.js
    ├── dialog_view.js
    ├── editable_view.js
    ├── libraries_view.js
    ├── library_view.js
    ├── navigation_view.js
    └── profile_view.js

To make it possible before I had this in my Grunt 0.3.x config file:

coffee:
  compile:
    files:
      'dest/app/*.js': 'src/app/**/*.coffee'

    options:
      basePath: 'src/app'

The question is how I can get the same result using the new grunt-contrib-coffee (0.4.x) version?

more flexibility for sourcemaps

It would be nice to be able have some control over which directory the source map is generated in. For example, I have a directory structure like this:

ProjectRoot/
    |-coffee/
        |-my_library.coffee
    |-js/
    |-source-maps/

It would be great if I could get the generated js to go in the js/ directory (which I know is already possible) and the generated source map to go in the source-maps/ directory.

Concatenate coffee files before compiling

As described in this so-question: http://stackoverflow.com/questions/15165017/how-to-avoid-multiple-helper-implementations-like-indexof-with-grunt-contrib grunt-contrib-coffee does generate mulitiple helper imlpementations if they are needed in different source files, because the compiled result gets concatenated after compiling.

The source files should be concatenated before compiling to ensure that all those helper implementations like __indexOf are only generated once.

So for example in a setup like

compile:
    files:
        'public/assets/application.js': [
            'coffee/file1.coffee',
            'coffee/file2.coffee'
        ]

file1.coffee and file2.coffee should be concatenated before compiling.

Expand strips periods in filename

I'm using the following expand configuration:
glob_to_multiple:
expand: true
cwd: 'coffee/'
src: ['*/.coffee']
dest: 'js/'
ext: '.js'

But any filenames which have a period (i.e. "file.name.coffee") are being renamed as just "file.js" instead of "file.name.js".

My understanding is that the "*" pattern should only ignore "/", but it's also ignoring/stripping content delimited with periods. Is there a way to retain the full filenames with another pattern? Or is this a bug?

Thanks!

Loyal

handling errors from require('coffee').compile(code, options)

on 'tasks/coffee.js' row 176:

try {
      return require('coffee-script').compile(code, options);
} catch (e) {

      var firstColumn = e.location.first_column; //176

e can be a string
in which case this crashes on "Cannot read property 'first_column' of undefined"

0.4.1 is a MAJOR update, not a minor one

I should not upgrade from 0.4.0 to 0.4.1 and have my app completely break. The update includes a MAJOR update on the Coffeescript side (1.4.0 to 1.5.0). Why is this only considered a minor update on the Grunt side?

I'm specifically referring to this Coffeescript update jashkenas/coffeescript#2715 which has broken so many apps.

bare option works unpredictably

I have a config like this:

specs: ["*.spec.coffee"],
coffee: {
  tests: {
    options: {
      bare: false,
      sourceMap: true,
      join: true
    },
    files: [{
      src: ["<%= specs %>"],
      dest: "specs.js"
    }]
  }
}

And the result is that the files are concatenated first, then put into a big closure.

However, if I had just

specs: ["*.spec.coffee"],
coffee: {
  tests: {
    options: {
      bare: false
    },
    files: {
      "specs.js": "<%= specs %>"
    }
  }
}

It would first wrap each of the files into a closure and then concat them, which is what I want, but it doesn't have a source map, which I want. If I add the sourceMap: true, it again wraps it all in one closure. Also using that syntax for the files seems to be not advocated.

It would be nice if there's a good way of getting closure-wrapping before concat with source maps.

nested directories not supported

With this plugin it is very hard if not impossible to compile an unknown number of coffee files in a deeply nested directory structure on the spot.

Example (from Gruntfile):

coffee:
  test: 
    files: '*.js': ['test/**/*.coffee']

What I would like to do is to compile all coffee script files in the test folder or one of its subfolder (or one of their subfolders...) to a JavaScript file, but not change the directory of the file.
So, path/to/file.coffee should compile to path/to/file.js, but instead compiles to ./file.js.

Extra '/' in sourceMap coffee file lookup?

I added the sourceMap: true option to my Gruntfile.js. I use coffescript 1.6.2. What it produces looks about right. However, from hello.coffee, I still only get hello.js in my Chrome sources. If I set a breakpoint, I get this this error:
Cannot GET /app/scripts//hello.coffee

When I run grunt server:
My coffeescript file is:
app/scripts/hello.coffee
the generated js and js.map files are:
.tmp/scripts/hello.js
.tmp/scripts/hello.js.map

The bottom of .tmp/scripts/hello.js reads:
/* //@ sourceMappingURL=hello.js.map */

.tmp/scripts/hello.js.map is:
{ "version": 3, "file": "hello.js", "sourceRoot": "../../app/scripts/", "sources": [ "hello.coffee" ], "names": [], "mappings": "AAAA;CAAA,CAAA,CAAA,IAAO,mBAAP;CAAA" }

Thanks,
Matt

Compression

Add a compression option which compresses the compiled javascript (like grunt-contrib-less)

"Extension" options breaks files with dots in name

Hey, just a quick bug: it seems that the ext option breaks the name of files with a dot.

E.g.: file-v0.1.0.coffee is compiled to file-v0.js.

Seems like a typical naïve replace() without a lastIndexOf().

I'm kinda out of time right now but maybe I can track down the bug myself later.

Thanks for the task 👍

Any way to pick the order of a dynamic glob?

I have several .coffee files inside many folders, that is a angularjs application. Sometimes, I'm currently using:

  grunt.initConfig({
    src: {
      coffee: ["javascripts/app/common.coffee"]
    },
    coffee: {
      front: {
        options: {
          join: true
        },
        src: ["<%= src.coffee %>", "javascripts/app/front/**/*.coffee"],
        dest: 'javascripts/app.js' 
      },
      back: {
        options: {
          join: true
        },
        src: ["<%= src.coffee %>", "javascripts/app/back/**/*.coffee"],
        dest: 'javascripts/backapp.js'
      }
    },

Whenever I create a new file, the order of the joined files are alphabetic. Is there any way I can give some priority to some filenames, instead of renaming them? (like 01plan, 02stuff, etc)

Add compile all files without concat

It would be great to have possibility to compile all files by pattern, like this:

coffee: {
    compile: {
        files: {
          'lib/*.js': ['src/*.coffee']
        }
    }
}

Actually this is like coffee command:

coffee --compile --output lib src

Coffee compilation repeating on Windows

Please forgive me if I'm just making a stupid mistake...but I haven't been able to find it so far.

Environment:

  • Windows 8 64-bit
  • node 0.8.14
  • grunt 0.4.0rc4
  • grunt-contrib-coffee 0.3.2

Symptom:
Count the number of files in config ("files:"), and that is how many times that every file is compiled. For instance, in my app I have 36 .coffee files, so all 36 files are compiled 36 times - 1296 total compilations.

Example Config:
I'm reasonably sure my config is correct, but not positive. I know that the path convention and escaping is fine, since all files are compiled....just too many times. I did not include all files in config below for the sake of relative brevity.

coffee: {
    app: {
        files: { 'C:\\Forks\\Project\\generated\\js\\app.js': 'C:\\Forks\\Project\\app\\js\\app.coffee',  'C:\\Forks\\Project\\generated\\js\\appFake.js': 'C:\\Forks\\Project\\app\\js\\appFake.coffee',  'C:\\Forks\\Project\\generated\\js\\controllers\\auth.js': 'C:\\Forks\\Project\\app\\js\\controllers\\auth.coffee'}
    },
    spec: {
        files: { 'C:\\Forks\\Project\\generated\\test\\chai-adapter.js': 'C:\\Forks\\Project\\test\\chai-adapter.coffee',  'C:\\Forks\\Project\\generated\\test\\e2e\\scenarios.js': 'C:\\Forks\\Project\\test\\e2e\\scenarios.coffee',  'C:\\Forks\\Project\\generated\\test\\spec\\controllersSpec.js': 'C:\\Forks\\Project\\test\\spec\\controllersSpec.coffee'}
    }
  }

map filenames inconsistent with coffee-script

If I compile my sources with coffee -s -m ..., it generates myfile.js and myfile.map. If i compile it using this grunt task, it creates myfile.js and myfile.js.map. It's trivial to change to be consistent on line 62 of coffee.js:

mapFileName: fileName + '.js.map'

Add support for grunt event emitting on compilation error

Can you add something like that:

 if (grunt.event.listeners('coffee').length > 0) {
    grunt.event.emit('coffee', 'error', 'CoffeeScript failed to compile.', e, filepath, firstLine, firstColumn);
 }

just before logging compilation error in coffee.js in function compileCoffee.

With that change, you can post notifications with grunt-notify dependency as following:

var notify = require('./node_modules/grunt-notify/lib/notify-lib');
grunt.event.on('coffee', function(status, type, message, exception, filepath, firstLine, firstColumn) {
    notify({
        title: type + " - " + message,
        message: exception + " - [" +firstLine + ":" + firstColumn + "] filepath" 
    });
});

It is very useful for development workflow, as you can see notification only on compilation errors, and on the end of each task without having info about results.

Regards,

Alexis

Not compiling in the correct dir?

I'm using grunt-contrib-coffee as set up by yeoman's angular generator. It is supposed to watch .coffee files and compile them into .tmp/scripts but instead it compiles them in both .tmp/scripts at first and in scripts/ on save.

Here's the relevant bit of Gruntfile, as far as I can tell:

grunt.initConfig({
  yeoman: yeomanConfig,
  watch: {
    coffee: {
      files: ['<%= yeoman.app %>/scripts/{,*/}*.coffee'],
      tasks: ['coffee:dist']
    },
    coffeeTest: {
      files: ['test/spec/{,*/}*.coffee'],
      tasks: ['coffee:test']
    },
 [...]
  coffee: {
    dist: {
      files: [{
        expand: true,
        cwd: '<%= yeoman.app %>/scripts',
        src: '{,*/}*.coffee',
        dest: '.tmp/scripts',
        ext: '.js'
      }]
    },
    test: {
      files: [{
        expand: true,
        cwd: 'test/spec',
        src: '{,*/}*.coffee',
        dest: '.tmp/spec',
        ext: '.js'
      }]
    }
  },

Any idea what could be going on?

Conditionally compile targets

It would be useful to only compile targets when they are out of date, compared to their respective sources (as with make, etc.). One benefit it brings, is when using grunt watch to conditionally compile changed coffee sources, reducing compile times. A common case would be in a TDD cycle, monitoring a test suite and sources, then compiling and running tests on modifications.

A simple mtime check on all sources vs. the mtime of the target should suffice. Perhaps it's something that should be opt-in/-out.

Improve example: glob to multiple

I've found that the given example

glob_to_multiple: {
  files: grunt.file.expandMapping(['path/to/*.coffee'], 'path/to/dest/', {
    rename: function(destBase, destPath) {
      return destBase + destPath.replace(/\.coffee$/, '.js');
    }
  })
}

was not working correctly for me. The problem was that it resulted in output files like this:

# Actual
path/to/path/to/dest/file.js
# Expected
path/to/dest/file.js

This is an improved version (working with [email protected]) that should fix this problem.

var path = require('path');

glob_to_multiple: {
  files: grunt.file.expandMapping(['*.coffee'], 'path/to/dest', {
    cwd: 'path/to',
    rename: function(destBase, destPath) {
      return path.join(destBase, destPath.replace(/\.coffee$/, '.js'));
    }
  })
}

Possible to run multiple coffee tasks/configs?

I would like to define multiple coffee compilation instructions: for example, I want to glob a few folders one way, and manually concatenate other files a different way.

Searching generically for a way to do this, it seems like this is possible if the task is defined as a multiTask.

It does not seem that this module is built as a multiTask, however.
Is there another way to accomplish the same goal? Or can this be made a multiTask? Thank you.

Update for compatibility with grunt 0.4.0rc5

I need someone to help update this plugin to work with grunt 0.4.0rc5.

I had to revert the whole file src-dest mappings implicit iteration abstraction per gruntjs/grunt#606, and once again, multi tasks have to iterate over this.files manually. In addition, there's a new this.filesSrc array that contains a reduced, uniqued set of all matched src files in case the task is read-only and only cares about source files.

See:

Notes:

  • A user may specify a new option nonull in addition to src to tell grunt to keep patterns or filepaths that don't actually match files. Because of this, the task shouldn't explode if a nonexistent src filepath is encountered. I handle this in the grunt-contrib-concat by warning if not grunt.file.exists but not failing the task.

Guidelines for updating / publishing this plugin:

  • Change this project's version number to one ending in "rc5" so that it's clearer that it works with grunt 0.4.0rc5. If the existing version number doesn't end in an "a" or "rc" increment the patch version. Eg, jshint went from 0.1.0 -> 0.1.1rc5
  • Ensure grunt 0.4.0rc5-compatible plugins are specified in package.json devDependencies like this (grunt-contrib-internal can be "*")
  • Update the CHANGELOG like this
  • Regenerate the README.md file via grunt.
  • Delete node_modules, run npm cache clean and re-run npm install to test.
  • Publish to npm using --tag=master (not latest)

expandMapping

☁ main [develop] ⚡ grunt coffee
Loading "grunt.js" tasks and helpers...ERROR

TypeError: Object # has no method 'expandMapping'
Task "coffee" not found. Use --force to continue.

I'm getting this error with any version of grunt and any version of grunt-contrib-coffee combinations. I need 0.3.x branch, 'cause grunt-contrib-jasmine 0.4.x is VERY unstable. Can you help me?

Concat (not compile) *.js files

I have mixed files that I've not written, part JS and part CoffeeScript that I would like all to compile into one file.

coffee: {
  compile: {
    files: { 
      'js/all.js': [...],
      'js/vendor.js': [
        'app/scripts/vendor/*.coffee',
        'app/scripts/vendor/*.js'
      ],
    },
  }

It seems like 'grunt-contrib-coffee' doesn't need to care about JS files, I can concat them myself right?

Well..

  1. Compiling the result of CS -> JS with other JS stuff would result in much less clean Gruntfile. (1 extra task to concat result with JS, 1 extra file that is meaningless tempfile, extra lines in Gruntfile)

  2. If I needed to include files in the correct order A.coffee B.js C.coffee, I would need to convert B.js into coffe and in some cases thats not a good idea (if its a minified JS lib or something)

Btw the sass gem already does that with css/sass, pretty neat.

PS: thanks for the awesome plugin, love the uniform config with sass, very easy to work with!

Feature Request: Smart Compile

Keep a /tmp/grunt-contrib-coffee/cache.json file which would map the string src.fullpath + ';' + dest.fullpath to src file modified date unix times. Then only compile again if current modified date is greater than stored date.

Instead of modified dates, we could also use an SHA of the file contents.

Would do it myself though no time at the moment.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.