Skip to content

Commit

Permalink
Merge pull request #17 from avalade/feature/duplicate-extensions
Browse files Browse the repository at this point in the history
Addressed duplicate .js.js extensions
  • Loading branch information
avalade committed Aug 30, 2012
2 parents 045d7f5 + 5b5f1cc commit 010eef3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tasks/coffee.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = function(grunt) {
js = '';

options = options || {};
extension = extension ? extension : '.js';
extension = typeof extension === "undefined" ? '.js' : extension;

if( destPath && options.preserve_dirs ){
var dirname = path.dirname(src);
Expand All @@ -54,7 +54,17 @@ module.exports = function(grunt) {
}

var dest = path.join(destPath, path.basename(src, '.coffee') + extension);


// De-dup dest if we have .js.js - see issue #16
if (dest.match(/\.js\.js/)) {
dest = dest.replace(/\.js\.js/, ".js");
}

if (path.extname(src) === '.js') {
grunt.file.copy(src, dest);
return true;
}

if( options.bare !== false ) {
options.bare = true;
}
Expand Down
21 changes: 21 additions & 0 deletions test/coffee_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ fs.existsSync = fs.existsSync ? fs.existsSync : path.existsSync;
*/

var src = 'test/fixtures/hello_world.coffee';
var dupExtSrc = 'test/fixtures/duplicate_extension.js.coffee';
var jsSrc = 'test/fixtures/js_hello_world.js';
var outputFolder = 'tmp/js';
var expectedJSFile = 'test/fixtures/hello_world.js';

Expand Down Expand Up @@ -128,5 +130,24 @@ exports['coffee'] = {
grunt.helper('coffee', [src], outputFolder, {}, '.coffee.js');
test.ok(fs.existsSync(path.join(outputFolder, "hello_world.coffee.js")));
test.done();
},

'helper-duplicate-extension': function(test) {
test.expect(1);
grunt.helper('coffee', [dupExtSrc], outputFolder, {});
test.ok(fs.existsSync(path.join(outputFolder, "duplicate_extension.js")));
test.done();
},

'helper-js-file-passthrough': function(test) {
test.expect(2);
grunt.helper('coffee', [jsSrc], outputFolder, {preserve_dirs: true});
test.ok(fs.existsSync(path.join(outputFolder, jsSrc)));
test.equal(
grunt.file.read(path.join(outputFolder, jsSrc)),
'console.log("Hello world!");\n',
'it should just copy javascript files'
);
test.done();
}
};
1 change: 1 addition & 0 deletions test/fixtures/duplicate_extension.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log "Hello CoffeeScript!"
1 change: 1 addition & 0 deletions test/fixtures/js_hello_world.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello world!");

0 comments on commit 010eef3

Please sign in to comment.