2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-12-23 02:28:55 +00:00

Move user ignore filter to common module

This commit is contained in:
Mark Lee 2015-06-09 19:26:55 -07:00
parent f3d17bceb2
commit 16b2feb39f
4 changed files with 24 additions and 40 deletions

View File

@ -13,5 +13,26 @@ module.exports = {
cb(null, dest) 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
}
} }
} }

View File

@ -27,7 +27,7 @@ module.exports = {
} }
function copyUserApp () { 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 (err) return cb(err)
if (opts.prune) { if (opts.prune) {
prune(function pruned (err) { prune(function pruned (err) {
@ -59,18 +59,6 @@ module.exports = {
return file.match(/default_app/) === null 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() copyApp()
} }
} }

13
mac.js
View File

@ -68,19 +68,8 @@ function buildMacApp (opts, cb, newApp) {
fs.writeFileSync(paths.info1, plist.build(pl1)) fs.writeFileSync(paths.info1, plist.build(pl1))
fs.writeFileSync(paths.info2, plist.build(pl2)) 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 // 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 (err) return cb(err)
if (opts.prune) { if (opts.prune) {

View File

@ -50,22 +50,8 @@ function buildWinApp (opts, cb, newApp) {
app: path.join(newApp, 'resources', 'app') 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 // 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 (err) return cb(err)
if (opts.prune) { if (opts.prune) {