From a98ef5f5770d2f1d88284b798796e31cc876467c Mon Sep 17 00:00:00 2001 From: Albin Mattsson Date: Sun, 29 Oct 2017 13:57:09 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=89=20Add=20overwrite=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This closes #130 --- README.md | 1 + lib/appdmg.js | 40 ++++++++++++++++++++-------------------- schema.json | 3 +++ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 069ca0a..51e138e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/appdmg.js b/lib/appdmg.js index e689436..da45630 100644 --- a/lib/appdmg.js +++ b/lib/appdmg.js @@ -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) - }) - }) - /** ** **/ @@ -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) + }) + }) + /** ** **/ diff --git a/schema.json b/schema.json index a7d5dce..39ab774 100644 --- a/schema.json +++ b/schema.json @@ -19,6 +19,9 @@ "icon-size": { "type": "integer" }, + "overwrite-target": { + "type": "boolean" + }, "window": { "type": "object", "properties": {