From 07d0da6725035164f184e1393ad1828da58b2465 Mon Sep 17 00:00:00 2001 From: Nick Van den Bleeken Date: Thu, 6 Oct 2016 15:45:35 +0200 Subject: [PATCH] Apply filter also on directories and symlinks for copySync() --- lib/copy-sync/copy-sync.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/copy-sync/copy-sync.js b/lib/copy-sync/copy-sync.js index 8168deee..113e512d 100644 --- a/lib/copy-sync/copy-sync.js +++ b/lib/copy-sync/copy-sync.js @@ -23,14 +23,16 @@ function copySync (src, dest, options) { var destFolderExists = fs.existsSync(destFolder) var performCopy = false - if (stats.isFile()) { - if (options.filter instanceof RegExp) performCopy = options.filter.test(src) - else if (typeof options.filter === 'function') performCopy = options.filter(src) + if (options.filter instanceof RegExp) performCopy = options.filter.test(src) + else if (typeof options.filter === 'function') performCopy = options.filter(src) + + if (!performCopy) { + return; + } - if (performCopy) { - if (!destFolderExists) mkdir.mkdirsSync(destFolder) - copyFileSync(src, dest, {clobber: options.clobber, preserveTimestamps: options.preserveTimestamps}) - } + if (stats.isFile()) { + if (!destFolderExists) mkdir.mkdirsSync(destFolder) + copyFileSync(src, dest, {clobber: options.clobber, preserveTimestamps: options.preserveTimestamps}) } else if (stats.isDirectory()) { if (!fs.existsSync(dest)) mkdir.mkdirsSync(dest) var contents = fs.readdirSync(src)