Permalink
Browse files

Add a `dirs` options to preserve directory structure in destPath

  • Loading branch information...
rockwood committed Aug 5, 2012
1 parent cd03804 commit a9f08c8b17a6d1ca684e176285a4f5e26ffa65b9
Showing with 36 additions and 3 deletions.
  1. +6 −0 README.md
  2. +9 −3 tasks/coffee.js
  3. +21 −0 test/coffee_test.js
View
@@ -49,6 +49,12 @@ you set your options to:
bare: false
}
+If you have `dest` path and want to preserve the directory structure of your coffee files, pass the `dirs` option".
+
+ options: {
+ dirs: true
+ }
+
## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt][grunt].
View
@@ -38,11 +38,17 @@ module.exports = function(grunt) {
var coffee = require('coffee-script'),
js = '';
- destPath = destPath ? destPath : path.dirname(src);
+ options = options || {};
extension = extension ? extension : '.js';
- var dest = path.join(destPath, path.basename(src, '.coffee') + extension);
- options = options || {};
+ if( destPath && options.dirs ){
+ destPath = path.join(destPath, path.dirname(src));
+ } else if( !destPath ){
+ destPath = path.dirname(src);
+ }
+
+ var dest = path.join(destPath, path.basename(src, '.coffee') + extension);
+
if( options.bare !== false ) {
options.bare = true;
}
View
@@ -28,6 +28,7 @@ var src = 'test/fixtures/hello_world.coffee';
var destFolder = 'tmp/js';
var dest1 = 'test/fixtures/hello_world.js';
var dest2 = 'test/fixtures/hello_world.coffee.js';
+var dest3 = path.join(destFolder, dest1);
exports['coffee'] = {
setUp: function(done) {
@@ -39,6 +40,11 @@ exports['coffee'] = {
if ( fs.existsSync(destFolder + '/hello_world.js') ) {
fs.unlinkSync(destFolder + '/hello_world.js');
}
+ if ( fs.existsSync(dest3)) {
+ fs.unlinkSync(dest3);
+ fs.rmdirSync(destFolder + '/test/fixtures');
+ fs.rmdirSync(destFolder + '/test');
+ }
fs.rmdirSync(destFolder);
}
@@ -48,6 +54,12 @@ exports['coffee'] = {
if (fs.existsSync(dest2)) {
fs.unlinkSync(dest2);
}
+ if (fs.existsSync(dest2)) {
+ fs.unlinkSync(dest2);
+ }
+ if (fs.existsSync(dest3)) {
+ fs.unlinkSync(dest3);
+ }
done();
},
@@ -76,6 +88,15 @@ exports['coffee'] = {
test.done();
},
+ 'helper-dirs': function(test) {
+ test.expect(1);
+ grunt.helper('coffee', [src], destFolder, { dirs:true });
+ test.equal(grunt.file.read(dest3),
+ '\nconsole.log("Hello CoffeeScript!");\n',
+ 'it should compile the coffee');
+ test.done();
+ },
+
'helper-extension': function(test) {
test.expect(1);
grunt.helper('coffee', [src], null, {}, '.coffee.js');

0 comments on commit a9f08c8

Please sign in to comment.