Skip to content

Commit

Permalink
🎉 Add overwrite option
Browse files Browse the repository at this point in the history
This closes #130
  • Loading branch information
cstruct committed Oct 29, 2017
1 parent deb0ee7 commit a98ef5f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ the JSON file's path.
+ `background` (string, optional) - Path to your background
+ `background-color` (string, optional) - Background color (accepts css colors)
+ `icon-size` (number, optional) - Size of all the icons inside the DMG
+ `overwrite-target` (boolean, optional) - Overwrite target if it exists
+ `window` (object, optional) - Window options
+ `position` (object, optional) - Position when opened
+ `x` (number, required) - X position relative to left of the screen
Expand Down
40 changes: 20 additions & 20 deletions lib/appdmg.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,6 @@ module.exports = exports = function (options) {

var pipeline = new Pipeline()

/**
**
**/

pipeline.addStep('Looking for target', function (next) {
fs.writeFile(global.target, '', { flag: 'wx' }, function (err) {
if (err && err.code === 'EEXIST') return next(new Error('Target already exists'))
if (err) return next(err)

pipeline.addCleanupStep('unlink-target', 'Removing target image', function (next, hasErrored) {
if (hasErrored) {
fs.unlink(global.target, next)
} else {
next(null)
}
})
next(null)
})
})

/**
**
**/
Expand Down Expand Up @@ -148,6 +128,26 @@ module.exports = exports = function (options) {
next(new Error(message))
})

/**
**
**/

pipeline.addStep('Looking for target', function (next) {
fs.writeFile(global.target, '', { flag: global.opts['overwrite-target'] ? 'w' : 'wx' }, function (err) {
if (err && err.code === 'EEXIST') return next(new Error('Target already exists'))
if (err) return next(err)

pipeline.addCleanupStep('unlink-target', 'Removing target image', function (next, hasErrored) {
if (hasErrored) {
fs.unlink(global.target, next)
} else {
next(null)
}
})
next(null)
})
})

/**
**
**/
Expand Down
3 changes: 3 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"icon-size": {
"type": "integer"
},
"overwrite-target": {
"type": "boolean"
},
"window": {
"type": "object",
"properties": {
Expand Down

0 comments on commit a98ef5f

Please sign in to comment.