jonschlinkert / copy

Copy files using glob patterns. Sync, async, promise or streams. (node.js utility)
MIT License
94 stars 124 forks source link

Making it possible to return nested non existing directories with `rewrite` option #1

Closed joakimbeng closed 9 years ago

joakimbeng commented 9 years ago

Copying a complete directory including subdirectories does not work at the moment.

Example:

Directory structure:

/source/
└── src
    └── index.js

And a rewrite option like so:

var path = require('path');
var cp = require('copy');

cp.dir('/source', '/dest', {
  rewrite: function (f, d) {
    return path.resolve(d, path.relative(src, f));
  }
}, cb)

Will throw an ENOENT error for the /dest/src directory.

This PR addresses that by calling mkdirp for each file's destination folder, instead of only for the top most destination folder.

Note: I also think that a rewrite function like the one above would be a more logical default, instead of flattening like now, what do you think?

jonschlinkert commented 9 years ago

totally agree! I just mentioned something about that this week (e.g that I needed to go back to this and do a rename function instead of just flattening) crazy coincidence, thank you!

looking forward to reviewing and merging tomorrow!

joakimbeng commented 9 years ago

@jonschlinkert have you had any time looking at this?

jonschlinkert commented 9 years ago

not yet, I'll try today. Trying to get a deadline driven project completed. almost there!

jonschlinkert commented 9 years ago

sorry it's taking so long! This is on my priority list for today

joakimbeng commented 9 years ago

No worries! I know the feeling, take your time :)

jonschlinkert commented 9 years ago

latest is published to npm, thanks again, I really appreciate it!