Permalink
Browse files

Merge pull request #17 from avalade/feature/duplicate-extensions

Addressed duplicate .js.js extensions
  • Loading branch information...
2 parents 045d7f5 + 5b5f1cc commit 010eef39f0182c4aef266321afed79d9d56c1742 @avalade committed Aug 30, 2012
Showing with 35 additions and 2 deletions.
  1. +12 −2 tasks/coffee.js
  2. +21 −0 test/coffee_test.js
  3. +1 −0 test/fixtures/duplicate_extension.js.coffee
  4. +1 −0 test/fixtures/js_hello_world.js
View
@@ -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);
@@ -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;
}
View
@@ -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';
@@ -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();
}
};
@@ -0,0 +1 @@
+console.log "Hello CoffeeScript!"
@@ -0,0 +1 @@
+console.log("Hello world!");

0 comments on commit 010eef3

Please sign in to comment.