Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

check for blank extension & rolled extension into options #14

Closed
wants to merge 1 commit into from

2 participants

@brewster1134

i was having the issue of scripts with extension .js.coffee compiling to .js.js. Passing a blank string in as the extension was ignored and revert to the default. There is now a check to allow the extension to be ''.

It also seemed like the options object would be a good place for the extension option. tests added :)

@avalade avalade referenced this pull request from a commit
@avalade Addressed duplicate .js.js extensions
This fixes the issues:

* avalade/grunt-coffee#16
* avalade/grunt-coffee#14

I've also added in a check where, if you're 
compiling a .js file, it just copies it into
the appropriate directory based upon the 
output directory setting and the preserve 
directories setting.
5b5f1cc
@avalade
Owner

Thanks for the pull request and apologies about the delay as I've been away traveling without access to my repos.

I've addressed this concern of yours in commit 5b5f1cc. Please let me know if this will work for you and if I can add you to the contributors and then I'll do a release.

@brewster1134

excellent! looks good to me. and you are welcome to add me but im not sure i contributed enough!

also... im curious why extension isn't a part of the options object?

@avalade
Owner

The options was originally just supposed to be options for the coffee-script compiler. However, I let the preserve_dirs argument leak into the options args by accident. If I was doing a bigger change to the plugin, I'd move the extension into the options as well and make the options contain a coffee-script-options element, but since this change is a small one, I don't want to do much more than do a patch release which requires me to keep everything backwards compatible.

But in the future, when I do a minor version increment, I'll collapse the extension into the options argument.

@avalade avalade closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
6 tasks/coffee.js
@@ -36,12 +36,12 @@ module.exports = function(grunt) {
// HELPERS
// ==========================================================================
- grunt.registerHelper('coffee', function(src, destPath, options, extension) {
+ grunt.registerHelper('coffee', function(src, destPath, options) {
var coffee = require('coffee-script'),
js = '';
options = options || {};
- extension = extension ? extension : '.js';
+ extension = options.extension || options.extension == '' ? options.extension : '.js';
if( destPath && options.preserve_dirs ){
var dirname = path.dirname(src);
@@ -54,7 +54,7 @@ module.exports = function(grunt) {
}
var dest = path.join(destPath, path.basename(src, '.coffee') + extension);
-
+
if( options.bare !== false ) {
options.bare = true;
}
View
23 test/coffee_test.js
@@ -56,7 +56,7 @@ exports['coffee'] = {
}
helper(filesToDelete);
}
-
+
helper(filesToDelete);
};
@@ -107,12 +107,12 @@ exports['coffee'] = {
'helper-dirs-base': function(test) {
var base = 'test';
test.expect(1);
- grunt.helper('coffee',
- [src],
- outputFolder,
- {
- preserve_dirs:true,
- base_path:base
+ grunt.helper('coffee',
+ [src],
+ outputFolder,
+ {
+ preserve_dirs:true,
+ base_path:base
});
test.equal(
grunt.file.read(
@@ -124,9 +124,14 @@ exports['coffee'] = {
},
'helper-extension': function(test) {
- test.expect(1);
- grunt.helper('coffee', [src], outputFolder, {}, '.coffee.js');
+ test.expect(2);
+
+ grunt.helper('coffee', [src], outputFolder, { extension: '.coffee.js' });
test.ok(fs.existsSync(path.join(outputFolder, "hello_world.coffee.js")));
+
+ grunt.helper('coffee', ['test/fixtures/hello_world.js.coffee'], outputFolder, { extension: '' });
+ test.ok(fs.existsSync(path.join(outputFolder, "hello_world.js")));
+
test.done();
}
};
View
1  test/fixtures/hello_world.js.coffee
@@ -0,0 +1 @@
+console.log "Hello CoffeeScript!"
Something went wrong with that request. Please try again.