2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-06-20 12:22:21 +00: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
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 usage = fs.readFileSync(__dirname + '/usage.txt').toString()

View File

@ -2,6 +2,7 @@ var path = require('path')
var fs = require('fs')
var mkdirp = require('mkdirp')
var ncp = require('ncp').ncp
var rimraf = require('rimraf')
var common = require('./common')
module.exports = {
@ -12,11 +13,26 @@ module.exports = {
var finalBinary = path.join(finalDir, opts.name)
function copyApp () {
var createApp = function (err) {
if (err) return cb(err)
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 () {
ncp(templateApp, finalDir, {filter: appFilter}, function AppCreated (err) {

15
mac.js
View File

@ -78,6 +78,8 @@ function buildMacApp (opts, cb, newApp) {
var finalPath = path.join(outdir, opts.name + '.app')
mkdirp(outdir, function mkoutdirp () {
if (err) return cb(err)
var deploy = function (err) {
if (err) return cb(err)
fs.rename(newApp, finalPath, function moved (err) {
if (err) return cb(err)
@ -97,6 +99,19 @@ function buildMacApp (opts, cb, newApp) {
})
}
})
}
if (opts.overwrite) {
fs.exists(finalPath, function (exists) {
if (exists) {
console.log('Overwriting existing ' + finalPath + ' ...')
rimraf(finalPath, deploy)
} else {
deploy()
}
})
} else {
deploy()
}
})
}