From 5c0831ef43d98bfdfbeb6b3f3f9dee54c24211b0 Mon Sep 17 00:00:00 2001 From: "monk.add" Date: Thu, 18 Apr 2013 11:33:25 +0800 Subject: [PATCH] Add option to ignore files Add one more attribute to param 'opts' to ignore the files when run directory copy synchronously. --- lib/wrench.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/wrench.js b/lib/wrench.js index cc5c18b..ab39bbe 100644 --- a/lib/wrench.js +++ b/lib/wrench.js @@ -183,10 +183,10 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) { for(var i = 0; i < files.length; i++) { // ignores all files or directories which match the RegExp in opts.filter - if(typeof opts !== 'undefined') { + if(typeof opts !== 'undefined') { 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.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; } @@ -194,6 +194,8 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) { var fCopyFile = function(srcFile, destFile) { if(typeof opts !== 'undefined' && opts.preserveFiles && fs.existsSync(destFile)) return; + // if opts.ignoreFiles is true every file will be ignored + if(typeof opts !== 'undefined' && opts.ignoreFiles) return; var contents = fs.readFileSync(srcFile); fs.writeFileSync(destFile, contents);