Merge in @refaelos excludeHidden && excludeHiddenUnix patch
This commit is contained in:
commit
6c90fc6e67
9 changed files with 75 additions and 2 deletions
|
|
@ -187,9 +187,9 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) {
|
|||
if(!opts.whitelist && opts.filter && files[i].match(opts.filter)) continue;
|
||||
// if opts.whitelist is true every file or directory which doesn't match opts.filter will be ignored
|
||||
if(opts.whitelist && opts.filter && !files[i].match(opts.filter)) continue;
|
||||
if (opts.excludeHiddenUnix && /^\./.test(files[i])) continue;
|
||||
|
||||
var currFile = fs.lstatSync(sourceDir + "/" + files[i]);
|
||||
|
||||
if(currFile.isDirectory()) {
|
||||
/* recursion this thing right on back. */
|
||||
exports.copyDirSyncRecursive(sourceDir + "/" + files[i], newDirLocation + "/" + files[i], opts);
|
||||
|
|
|
|||
72
tests/copydirsync_unix.js
Normal file
72
tests/copydirsync_unix.js
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
var testCase = require('nodeunit').testCase;
|
||||
var fs = require('fs');
|
||||
var wrench = require('../lib/wrench');
|
||||
var path = require('path');
|
||||
|
||||
function checkResultHidden(test, files) {
|
||||
var check = [
|
||||
'.hidden',
|
||||
'.hidden.txt',
|
||||
'bar.txt',
|
||||
'foo',
|
||||
path.join('.hidden', 'dolor.md'),
|
||||
path.join('foo', 'bar'),
|
||||
path.join('foo', 'dolor.md'),
|
||||
path.join('foo', 'lorem.txt'),
|
||||
path.join('foo', 'bar', 'ipsum.js')
|
||||
];
|
||||
|
||||
test.deepEqual(files, check);
|
||||
}
|
||||
|
||||
function checkResultShown(test, files) {
|
||||
var check = [
|
||||
'bar.txt',
|
||||
'foo',
|
||||
path.join('foo', 'bar'),
|
||||
path.join('foo', 'dolor.md'),
|
||||
path.join('foo', 'lorem.txt'),
|
||||
path.join('foo', 'bar', 'ipsum.js')
|
||||
];
|
||||
|
||||
test.deepEqual(files, check);
|
||||
}
|
||||
|
||||
module.exports = testCase({
|
||||
test_copyDirSyncRecursiveHidden: function(test) {
|
||||
var dir = path.join(__dirname, 'shown');
|
||||
var testdir = path.join(__dirname, 'testdir');
|
||||
|
||||
test.ok(path.existsSync(dir), 'Folders should exist');
|
||||
|
||||
wrench.mkdirSyncRecursive(testdir, 0777);
|
||||
wrench.copyDirSyncRecursive(dir, testdir, { excludeHiddenUnix: false });
|
||||
|
||||
var files = wrench.readdirSyncRecursive(testdir);
|
||||
|
||||
checkResultHidden(test, files);
|
||||
|
||||
wrench.rmdirSyncRecursive(testdir);
|
||||
|
||||
test.done();
|
||||
},
|
||||
test_copyDirSyncRecursiveShown: function(test) {
|
||||
var dir = path.join(__dirname, 'shown');
|
||||
var testdir = path.join(__dirname, 'testdir');
|
||||
|
||||
test.ok(path.existsSync(dir), 'Folders should exist');
|
||||
|
||||
wrench.mkdirSyncRecursive(testdir, 0777);
|
||||
wrench.copyDirSyncRecursive(dir, testdir, { excludeHiddenUnix: true });
|
||||
|
||||
var files = wrench.readdirSyncRecursive(testdir);
|
||||
|
||||
checkResultShown(test, files);
|
||||
|
||||
wrench.rmdirSyncRecursive(testdir);
|
||||
|
||||
test.done();
|
||||
}
|
||||
});
|
||||
|
||||
// vim: et ts=4 sw=4
|
||||
|
|
@ -3,5 +3,6 @@
|
|||
|
||||
module.exports = {
|
||||
group_mkdir: require('./mkdir'),
|
||||
group_readdir: require('./readdir')
|
||||
group_readdir: require('./readdir'),
|
||||
group_copydir: require('./copydirsync_unix')
|
||||
};
|
||||
|
|
|
|||
0
tests/shown/.hidden.txt
Normal file
0
tests/shown/.hidden.txt
Normal file
0
tests/shown/.hidden/dolor.md
Normal file
0
tests/shown/.hidden/dolor.md
Normal file
0
tests/shown/bar.txt
Normal file
0
tests/shown/bar.txt
Normal file
0
tests/shown/foo/bar/ipsum.js
Normal file
0
tests/shown/foo/bar/ipsum.js
Normal file
0
tests/shown/foo/dolor.md
Normal file
0
tests/shown/foo/dolor.md
Normal file
0
tests/shown/foo/lorem.txt
Normal file
0
tests/shown/foo/lorem.txt
Normal file
Reference in a new issue