2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-12-22 18:18:55 +00:00

hoist + reorganize code from #7, and use fs.rename instead of spawn mv

This commit is contained in:
Max Ogden 2015-03-23 16:59:46 -07:00
parent 24f0476eeb
commit cbc585393b

View File

@ -89,23 +89,27 @@ module.exports = function packager (opts, cb) {
ncp(opts.dir, paths.app, {filter: filter}, function copied (err) {
if (err) return cb(err)
function moveApp (err) {
if (err) return cb(err)
// finally, move app into cwd
var finalPath = opts.out || process.cwd()
// TODO dont spawn, but I couldn't find a good module
child.exec('mv "' + newApp + '" "' + finalPath + '"', function moved (err) {
cb(err, path.join(finalPath, opts.name + '.app'))
})
}
// run npm prune
if (opts.prune) {
child.exec('npm prune --production', { cwd: paths.app }, moveApp)
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 () {
// finally, move app into cwd
var finalPath = path.join(opts.out || process.cwd(), opts.name + '.app')
fs.rename(newApp, finalPath, function moved (err) {
cb(err, finalPath)
})
}
})
}
}