1
0
mirror of https://github.com/jiahaog/Nativefier synced 2024-07-05 09:00:55 +02:00

Support --overwrite

This commit is contained in:
Yifei Teng 2015-06-17 18:31:43 -07:00
parent fc98b0c8cb
commit f39ba8c8f2
3 changed files with 48 additions and 17 deletions

2
cli.js
View File

@ -1,6 +1,6 @@
#!/usr/bin/env node #!/usr/bin/env node
var fs = require('fs') var fs = require('fs')
var args = require('minimist')(process.argv.slice(2), {boolean: ['prune', 'asar']}) var args = require('minimist')(process.argv.slice(2), {boolean: ['prune', 'asar', 'overwrite']})
var packager = require('./') var packager = require('./')
var usage = fs.readFileSync(__dirname + '/usage.txt').toString() var usage = fs.readFileSync(__dirname + '/usage.txt').toString()

View File

@ -2,6 +2,7 @@ var path = require('path')
var fs = require('fs') var fs = require('fs')
var mkdirp = require('mkdirp') var mkdirp = require('mkdirp')
var ncp = require('ncp').ncp var ncp = require('ncp').ncp
var rimraf = require('rimraf')
var common = require('./common') var common = require('./common')
module.exports = { module.exports = {
@ -12,10 +13,25 @@ module.exports = {
var finalBinary = path.join(finalDir, opts.name) var finalBinary = path.join(finalDir, opts.name)
function copyApp () { function copyApp () {
mkdirp(finalDir, function AppFolderCreated (err) { var createApp = function (err) {
if (err) return cb(err) if (err) return cb(err)
copyAppTemplate() mkdirp(finalDir, function AppFolderCreated (err) {
}) if (err) return cb(err)
copyAppTemplate()
})
}
if (opts.overwrite) {
fs.exists(finalDir, function (exists) {
if (exists) {
console.log('Overwriting existing ' + finalDir + ' ...')
rimraf(finalDir, createApp)
} else {
createApp()
}
})
} else {
createApp()
}
} }
function copyAppTemplate () { function copyAppTemplate () {

41
mac.js
View File

@ -79,24 +79,39 @@ function buildMacApp (opts, cb, newApp) {
mkdirp(outdir, function mkoutdirp () { mkdirp(outdir, function mkoutdirp () {
if (err) return cb(err) if (err) return cb(err)
fs.rename(newApp, finalPath, function moved (err) { var deploy = function (err) {
if (err) return cb(err) if (err) return cb(err)
if (opts.asar) { fs.rename(newApp, finalPath, function moved (err) {
var finalPath = path.join(opts.out || process.cwd(), opts.name + '.app', 'Contents', 'Resources') if (err) return cb(err)
common.asarApp(finalPath, function (err) { if (opts.asar) {
if (err) return cb(err) var finalPath = path.join(opts.out || process.cwd(), opts.name + '.app', 'Contents', 'Resources')
common.asarApp(finalPath, function (err) {
if (err) return cb(err)
updateMacIcon(function (err) {
if (err) return cb(err)
codesign()
})
})
} else {
updateMacIcon(function (err) { updateMacIcon(function (err) {
if (err) return cb(err) if (err) return cb(err)
codesign() codesign()
}) })
}) }
} else { })
updateMacIcon(function (err) { }
if (err) return cb(err) if (opts.overwrite) {
codesign() fs.exists(finalPath, function (exists) {
}) if (exists) {
} console.log('Overwriting existing ' + finalPath + ' ...')
}) rimraf(finalPath, deploy)
} else {
deploy()
}
})
} else {
deploy()
}
}) })
} }