Skip to content

Commit

Permalink
Fix for expand-less copies with multiple files
Browse files Browse the repository at this point in the history
Introduces a new test that uses a cwd- and expand-less target with
multiple input files being copied to a single destination directory. In
the task itself, the loop that operates on the list of `src` paths no
longer persists the `dest` from loop-to-loop, allowing the `src`
filename to actually show up in the full `dest` for successive files.

Fixes #220.
Partially reverts a15feec.
  • Loading branch information
corpulentcoffee committed Feb 28, 2015
1 parent 52f07be commit c22e722
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ module.exports = function(grunt) {
]
},

noexpandWild: {
files: [
{src: 'test/fixtures/*.js', dest: 'tmp/copy_test_noexpandWild/'}
]
},

flatten: {
files: [
{expand: true, flatten: true, filter: 'isFile', src: ['test/fixtures/**', '!**/*.wav'], dest: 'tmp/copy_test_flatten/'}
Expand Down
3 changes: 1 addition & 2 deletions tasks/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ module.exports = function(grunt) {
};

this.files.forEach(function(filePair) {
var dest = filePair.dest;
isExpandedPair = filePair.orig.expand || false;

filePair.src.forEach(function(src) {
src = unixifyPath(src);
dest = unixifyPath(dest);
var dest = unixifyPath(filePair.dest);

if (detectDestType(dest) === 'directory') {
dest = (isExpandedPair) ? dest : path.join(dest, src);
Expand Down
14 changes: 14 additions & 0 deletions test/copy_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ exports.copy = {
test.done();
},

noexpandWild: function(test) {
'use strict';

test.expect(3);

['/', '/test/', '/test/fixtures/'].forEach(function(subpath, i) {
var actual = fs.readdirSync('tmp/copy_test_noexpandWild' + subpath).sort();
var expected = fs.readdirSync('test/expected/copy_test_noexpandWild' + subpath).sort();
test.deepEqual(expected, actual, 'should copy file structure at level ' + i);
});

test.done();
},

flatten: function(test) {
'use strict';

Expand Down
1 change: 1 addition & 0 deletions test/expected/copy_test_noexpandWild/test/fixtures/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$(document).ready(function(){});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('hello');

0 comments on commit c22e722

Please sign in to comment.