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

Move prune to common module

This commit is contained in:
Mark Lee 2015-06-09 19:30:43 -07:00
parent 16b2feb39f
commit bdc8c46362
4 changed files with 17 additions and 40 deletions

View File

@ -1,4 +1,5 @@
var asar = require('asar') var asar = require('asar')
var child = require('child_process')
var path = require('path') var path = require('path')
var rimraf = require('rimraf') var rimraf = require('rimraf')
@ -15,6 +16,17 @@ module.exports = {
}) })
}, },
prune: function prune (opts, cwd, cb, nextStep) {
if (opts.prune) {
child.exec('npm prune --production', { cwd: cwd }, function pruned (err) {
if (err) return cb(err)
nextStep()
})
} else {
nextStep()
}
},
userIgnoreFilter: function userIgnoreFilter (opts, is_win32, finalDir) { userIgnoreFilter: function userIgnoreFilter (opts, is_win32, finalDir) {
return function filter (file) { return function filter (file) {
if (is_win32) { if (is_win32) {

View File

@ -1,6 +1,5 @@
var path = require('path') var path = require('path')
var fs = require('fs') var fs = require('fs')
var child = require('child_process')
var mkdirp = require('mkdirp') var mkdirp = require('mkdirp')
var ncp = require('ncp').ncp var ncp = require('ncp').ncp
var common = require('./common') var common = require('./common')
@ -29,14 +28,7 @@ module.exports = {
function copyUserApp () { function copyUserApp () {
ncp(opts.dir, userAppDir, {filter: common.userIgnoreFilter(opts, false, finalDir), 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) { common.prune(opts, userAppDir, cb, renameElectronBinary)
prune(function pruned (err) {
if (err) return cb(err)
renameElectronBinary()
})
} else {
renameElectronBinary()
}
}) })
} }
@ -51,10 +43,6 @@ module.exports = {
}) })
} }
function prune (cb) {
child.exec('npm prune --production', { cwd: userAppDir }, cb)
}
function appFilter (file) { function appFilter (file) {
return file.match(/default_app/) === null return file.match(/default_app/) === null
} }

15
mac.js
View File

@ -72,19 +72,6 @@ function buildMacApp (opts, cb, newApp) {
ncp(opts.dir, paths.app, {filter: common.userIgnoreFilter(opts), 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) {
prune(function pruned (err) {
if (err) return cb(err)
moveApp()
})
} else {
moveApp()
}
function prune (cb) {
child.exec('npm prune --production', { cwd: paths.app }, cb)
}
function moveApp () { function moveApp () {
// finally, move app into cwd // finally, move app into cwd
var outdir = opts.out || process.cwd() var outdir = opts.out || process.cwd()
@ -134,5 +121,7 @@ function buildMacApp (opts, cb, newApp) {
cb(err, appPath) cb(err, appPath)
}) })
} }
common.prune(opts, paths.app, cb, moveApp)
}) })
} }

View File

@ -1,6 +1,5 @@
var os = require('os') var os = require('os')
var path = require('path') var path = require('path')
var child = require('child_process')
var mkdirp = require('mkdirp') var mkdirp = require('mkdirp')
var rimraf = require('rimraf') var rimraf = require('rimraf')
@ -54,19 +53,6 @@ function buildWinApp (opts, cb, newApp) {
ncp(opts.dir, paths.app, {filter: common.userIgnoreFilter(opts, true), 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) {
prune(function pruned (err) {
if (err) return cb(err)
moveApp()
})
} else {
moveApp()
}
function prune (cb) {
child.exec('npm prune --production', { cwd: paths.app }, cb)
}
function moveApp () { function moveApp () {
// finally, move app into cwd // finally, move app into cwd
var finalPath = path.join(opts.out || process.cwd(), opts.name + '-win32') var finalPath = path.join(opts.out || process.cwd(), opts.name + '-win32')
@ -97,5 +83,7 @@ function buildWinApp (opts, cb, newApp) {
cb(err, finalPath) cb(err, finalPath)
}) })
} }
common.prune(opts, paths.app, cb, moveApp)
}) })
} }