From 6def00df56aa970f72426d3cd59c5b0686e82a64 Mon Sep 17 00:00:00 2001 From: xRaz Date: Mon, 13 Nov 2017 14:19:06 +0100 Subject: [PATCH] fix existing folder bug on packaging + installing --- builder/installer.js | 19 +++++++++++++++++++ builder/packager.js | 19 ++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/builder/installer.js b/builder/installer.js index f76e892..0a6c9e4 100644 --- a/builder/installer.js +++ b/builder/installer.js @@ -1,6 +1,8 @@ const path = require('path'); const json = require(path.resolve('./package.json')); const exec = require('child_process').exec; +const execSync = require('child_process').execSync; +const fs = require('fs'); // See available platform and arch here : // https://github.com/electron-userland/electron-packager/blob/master/docs/api.md @@ -32,6 +34,11 @@ const linuxConfig = { switch (process.env.NODE_OS) { case "mac": + if (fs.existsSync('./mac_installer')) { + console.log('Removing existing ./mac_installer...'); + execSync("rm -rf mac_installer", { maxBuffer: 1024 * 2048 }); + console.log('Successfully removed ./mac_installer/'); + } console.log('Creating mac installer...'); exec("mkdir mac_installer && electron-installer-dmg ./mac_packager/" + json.name + "-" + spec['platform']['2'] + "-" + spec['arch']['2'] + "/" + json.name + ".app " + json.name + " --out=mac_installer --overwrite && rm -rf mac_packager", (error) => { if (!error) { @@ -45,6 +52,12 @@ switch (process.env.NODE_OS) { case "linux": const linuxInstaller = require('electron-installer-debian'); + if (fs.existsSync('./linux_installer')) { + console.log('Removing existing ./linux_installer...'); + execSync("rm -rf linux_installer", { maxBuffer: 1024 * 2048 }); + console.log('Successfully removed ./linux_installer/'); + } + console.log('Creating linux installer...'); linuxInstaller(linuxConfig, (error) => { @@ -68,6 +81,12 @@ switch (process.env.NODE_OS) { name: json.name.replace(/-/g, "_") }; + if (fs.existsSync('./win_installer')) { + console.log('Removing existing ./win_installer...'); + execSync("del /s /q win_installer && rmdir /s /q win_installer", { maxBuffer: 1024 * 2048 }); + console.log('Successfully removed ./win_installer/'); + } + console.log('Creating windows installer...'); resultPromise = electronInstaller.createWindowsInstaller(settings); diff --git a/builder/packager.js b/builder/packager.js index d0aacee..53b8f2f 100644 --- a/builder/packager.js +++ b/builder/packager.js @@ -1,6 +1,8 @@ const path = require('path'); const json = require(path.resolve('./package.json')); const exec = require('child_process').exec; +const execSync = require('child_process').execSync; +const fs = require('fs'); // See available platforms and archs here : // https://github.com/electron-userland/electron-packager/blob/master/docs/api.md @@ -20,7 +22,12 @@ const spec = { switch (process.env.NODE_OS) { case "mac": - console.log('Creating mac packager...'); + if (fs.existsSync('./mac_packager')) { + console.log('Removing existing ./mac_packager...'); + execSync("rm -rf mac_packager", { maxBuffer: 1024 * 2048 }); + console.log('Successfully removed ./mac_packager/'); + } + console.log('Creating mac packager...'); exec("cross-env NODE_ENV=prod webpack && electron-packager . --overwrite --platform=" + spec['platform']['2'] + " --arch=" + spec['arch']['2'] + " --prune=true --out=mac_packager --icon=builder/icons/mac/icon.icns", (error) => { if (!error) { console.log('Successfully created packager at ./mac_packager/'); @@ -30,6 +37,11 @@ switch (process.env.NODE_OS) { }); break; case "linux": + if (fs.existsSync('./linux_packager')) { + console.log('Removing existing ./linux_packager...'); + execSync("rm -rf linux_packager", { maxBuffer: 1024 * 2048 }); + console.log('Successfully removed ./linux_packager/'); + } console.log('Creating linux packager...'); exec("cross-env NODE_ENV=prod webpack && electron-packager . --overwrite --platform=" + spec['platform']['3'] + " --arch=" + spec['arch']['2'] + " --prune=true --out=linux_packager --icon=builder/icons/linux/icon.png", (error) => { if (!error) { @@ -40,6 +52,11 @@ switch (process.env.NODE_OS) { }); break; case "win": + if (fs.existsSync('./win_packager')) { + console.log('Removing existing ./win_packager...'); + execSync("del /s /q linux_packager && rmdir /s /q linux_packager", { maxBuffer: 1024 * 2048 }); + console.log('Successfully removed ./win_packager/'); + } console.log('Creating windows packager...'); exec("cross-env NODE_ENV=prod webpack && electron-packager . --overwrite --platform=" + spec['platform']['1'] + " --arch=" + spec['arch']['2'] + " --prune=true --out=win_packager --icon=builder/icons/win/icon.ico", (error) => { if (!error) {