From 1480b38ce83cff88f18c996a88125d9185304dad Mon Sep 17 00:00:00 2001
From: Chris Cowan <chriscowan@plus3network.com>
Date: Tue, 9 Jul 2013 16:40:01 -0700
Subject: [PATCH] Folders should maintian the directory structure for
 src/**/*.coffee

---
 lib/createFolderStream.js                                   | 3 ++-
 .../{out-fixtures/test.coffee => fixtures/copy/example.txt} | 0
 test/folder.js                                              | 6 +++---
 test/out-fixtures/copy/example.txt                          | 1 +
 4 files changed, 6 insertions(+), 4 deletions(-)
 rename test/{out-fixtures/test.coffee => fixtures/copy/example.txt} (100%)
 create mode 100644 test/out-fixtures/copy/example.txt

diff --git a/lib/createFolderStream.js b/lib/createFolderStream.js
index 647d0e4b2..fc580b6b9 100644
--- a/lib/createFolderStream.js
+++ b/lib/createFolderStream.js
@@ -10,8 +10,9 @@ module.exports = function(folder, opt) {
 
   function saveFile (file, cb) {
     var writePath = path.join(folder, file.shortened);
+    var writeFolder = path.dirname(writePath);
 
-    mkdirp(folder, function(err){
+    mkdirp(writeFolder, function(err){
       if (err) return cb(err);
       fs.writeFile(writePath, file.contents, function(err){
         if (err) return cb(err);
diff --git a/test/out-fixtures/test.coffee b/test/fixtures/copy/example.txt
similarity index 100%
rename from test/out-fixtures/test.coffee
rename to test/fixtures/copy/example.txt
diff --git a/test/folder.js b/test/folder.js
index b3ea81389..4a81cd2ba 100644
--- a/test/folder.js
+++ b/test/folder.js
@@ -18,7 +18,7 @@ describe('gulp file collection', function() {
       var outpath = join(__dirname, "./out-fixtures");
       rimraf(outpath, function(err){
         should.not.exist(err);
-        var instream = gulp.files(join(__dirname, "./fixtures/*.coffee"));
+        var instream = gulp.files(join(__dirname, "./fixtures/**/*.txt"));
         var outstream = gulp.folder(outpath);
         instream.pipe(outstream);
 
@@ -28,11 +28,11 @@ describe('gulp file collection', function() {
           should.exist(file);
           should.exist(file.path);
           should.exist(file.contents);
-          file.path.should.equal(join(__dirname, "./fixtures/test.coffee"));
+          file.path.should.equal(join(__dirname, "./fixtures/copy/example.txt"));
           String(file.contents).should.equal("this is a test");
         });
         outstream.on('end', function() {
-          fs.readFile(join(outpath, "test.coffee"), function(err, contents){
+          fs.readFile(join(outpath, "copy", "example.txt"), function(err, contents){
             should.not.exist(err);
             should.exist(contents);
             String(contents).should.equal("this is a test");
diff --git a/test/out-fixtures/copy/example.txt b/test/out-fixtures/copy/example.txt
new file mode 100644
index 000000000..a8a940627
--- /dev/null
+++ b/test/out-fixtures/copy/example.txt
@@ -0,0 +1 @@
+this is a test
\ No newline at end of file