[READ-ONLY] Mirror of https://github.com/probablykasper/embler. Turn binaries into applications npmjs.com/package/embler
app builder cli dmg macos node package packager
0

Configure Feed

Select the types of activity you want to include in your feed.

Added clearOutput() function to make code more DRY

Kasper (Aug 18, 2020, 2:04 AM +0200) 10800cda 62a3afea

+16 -17
+16 -17
src/build.js
··· 61 61 } 62 62 } 63 63 64 - module.exports.buildMacApp = async function(options, paths) { 64 + async function clearOutput(type, path) { 65 + try { 65 66 66 - // delete existing .app 67 - try { 68 - const appPathStat = await fs.stat(paths.app) 69 - if (appPathStat.isDirectory()) { 70 - await fs.rmdir(paths.app, { recursive: true }) 67 + const pathStat = await fs.stat(path) 68 + if (type === 'dir' && pathStat.isDirectory()) { 69 + await fs.rmdir(path, { recursive: true }) 70 + } else if (type === 'file' && pathStat.isFile()) { 71 + await fs.unlink(path) 71 72 } else { 72 - log.err(`Output path exists, but is not a folder. Delete or move it manually (${paths.app})`) 73 + log.err(`Output path exists, but is not a ${type}. Delete or move it manually (${path})`) 73 74 } 75 + 74 76 } catch(err) { 75 77 if (err.code !== 'ENOENT') log.err(err) 76 78 } 79 + } 80 + 81 + module.exports.buildMacApp = async function(options, paths) { 82 + 83 + // delete existing .app 84 + await clearOutput('dir', paths.app) 77 85 78 86 // create .app folders 79 87 await fs.mkdir(paths.ResourcesDir, { recursive: true }) ··· 121 129 module.exports.buildMacAppDmg = async function(options, paths) { 122 130 123 131 // delete existing .dmg 124 - try { 125 - const dmgPathStat = await fs.stat(paths.dmg) 126 - if (dmgPathStat.isFile()) { 127 - await fs.unlink(paths.dmg) 128 - } else { 129 - log.err(`Output path exists, but is not a file. Delete or move it manually (${paths.dmg})`) 130 - } 131 - } catch(err) { 132 - if (err.code !== 'ENOENT') log.err(err) 133 - } 132 + await clearOutput('file', paths.dmg) 134 133 135 134 const appdmg = require('appdmg') 136 135 await new Promise((resolve, reject) => {