From 16b2feb39f848667c512a2ca9cca3b283a1869e4 Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Tue, 9 Jun 2015 19:26:55 -0700 Subject: [PATCH] Move user ignore filter to common module --- common.js | 21 +++++++++++++++++++++ linux.js | 14 +------------- mac.js | 13 +------------ win32.js | 16 +--------------- 4 files changed, 24 insertions(+), 40 deletions(-) diff --git a/common.js b/common.js index 2c9d522..19172fc 100644 --- a/common.js +++ b/common.js @@ -13,5 +13,26 @@ module.exports = { cb(null, dest) }) }) + }, + + userIgnoreFilter: function userIgnoreFilter (opts, is_win32, finalDir) { + return function filter (file) { + if (is_win32) { + // convert slashes so unix-format ignores work + file = file.replace(/\\/g, '/') + } + + var ignore = opts.ignore || [] + if (!Array.isArray(ignore)) ignore = [ignore] + if (typeof finalDir !== 'undefined') { + ignore = ignore.concat([finalDir]) + } + for (var i = 0; i < ignore.length; i++) { + if (file.match(ignore[i])) { + return false + } + } + return true + } } } diff --git a/linux.js b/linux.js index a00bbeb..fa37391 100644 --- a/linux.js +++ b/linux.js @@ -27,7 +27,7 @@ module.exports = { } function copyUserApp () { - ncp(opts.dir, userAppDir, {filter: userFilter, dereference: true}, function copied (err) { + ncp(opts.dir, userAppDir, {filter: common.userIgnoreFilter(opts, false, finalDir), dereference: true}, function copied (err) { if (err) return cb(err) if (opts.prune) { prune(function pruned (err) { @@ -59,18 +59,6 @@ module.exports = { return file.match(/default_app/) === null } - function userFilter (file) { - var ignore = opts.ignore || [] - if (!Array.isArray(ignore)) ignore = [ignore] - ignore = ignore.concat([finalDir]) - for (var i = 0; i < ignore.length; i++) { - if (file.match(ignore[i])) { - return false - } - } - return true - } - copyApp() } } diff --git a/mac.js b/mac.js index 6027d11..b22b110 100644 --- a/mac.js +++ b/mac.js @@ -68,19 +68,8 @@ function buildMacApp (opts, cb, newApp) { fs.writeFileSync(paths.info1, plist.build(pl1)) fs.writeFileSync(paths.info2, plist.build(pl2)) - function filter (file) { - var ignore = opts.ignore || [] - if (!Array.isArray(ignore)) ignore = [ignore] - for (var i = 0; i < ignore.length; i++) { - if (file.match(ignore[i])) { - return false - } - } - return true - } - // copy users app into .app - ncp(opts.dir, paths.app, {filter: filter, dereference: true}, function copied (err) { + ncp(opts.dir, paths.app, {filter: common.userIgnoreFilter(opts), dereference: true}, function copied (err) { if (err) return cb(err) if (opts.prune) { diff --git a/win32.js b/win32.js index f28176d..e5d7ab7 100644 --- a/win32.js +++ b/win32.js @@ -50,22 +50,8 @@ function buildWinApp (opts, cb, newApp) { app: path.join(newApp, 'resources', 'app') } - function filter (file) { - // convert slashes so unix-format ignores work - file = file.replace(/\\/g, '/') - - var ignore = opts.ignore || [] - if (!Array.isArray(ignore)) ignore = [ignore] - for (var i = 0; i < ignore.length; i++) { - if (file.match(ignore[i])) { - return false - } - } - return true - } - // copy users app into destination path - ncp(opts.dir, paths.app, {filter: filter, dereference: true}, function copied (err) { + ncp(opts.dir, paths.app, {filter: common.userIgnoreFilter(opts, true), dereference: true}, function copied (err) { if (err) return cb(err) if (opts.prune) {