From 9e036893fef53533b14b6a4f670f51f2d3186c88 Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Wed, 13 Nov 2019 17:11:44 +0100 Subject: [PATCH] fix(project): correctly pack app to zip on MacOS As of `electron-builder@20.38.2`, the built zip files has been incorrect. On the other hand, older versions of `electron-builder` are unable to build application on MacOS 10.15 Catalina. Due to above, this commit removes `zip` from MacOS targets and adds a script that adds the built application to a correct zip archive. Related https://github.com/electron-userland/electron-builder/issues/3534 Closes https://github.com/camunda/camunda-modeler/issues/1529 --- electron-builder.json | 6 +- tasks/after-all-artifact-build.js | 28 ++++++++ .../after-all-artifact-build/build-mac-zip.js | 71 +++++++++++++++++++ 3 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 tasks/after-all-artifact-build.js create mode 100644 tasks/after-all-artifact-build/build-mac-zip.js diff --git a/electron-builder.json b/electron-builder.json index 26a4a74daa..a34131dd56 100644 --- a/electron-builder.json +++ b/electron-builder.json @@ -12,6 +12,7 @@ } ], "afterPack": "./tasks/after-pack.js", + "afterAllArtifactBuild": "./tasks/after-all-artifact-build.js", "win": { "target": [ { @@ -30,10 +31,7 @@ ] }, "mac": { - "target": [ - "dmg", - "zip" - ] + "target": "dmg" }, "fileAssociations": [ { diff --git a/tasks/after-all-artifact-build.js b/tasks/after-all-artifact-build.js new file mode 100644 index 0000000000..724b488b79 --- /dev/null +++ b/tasks/after-all-artifact-build.js @@ -0,0 +1,28 @@ +/** + * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH + * under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright + * ownership. + * + * Camunda licenses this file to you under the MIT; you may not use this file + * except in compliance with the MIT License. + */ + +module.exports = async function(context) { + + const handlers = [ + require('./after-all-artifact-build/build-mac-zip') + ]; + + let result = []; + + for (const handler of handlers) { + const additionalArtifacts = await handler(context); + + if (additionalArtifacts) { + result = result.concat(...additionalArtifacts); + } + } + + return result; +}; diff --git a/tasks/after-all-artifact-build/build-mac-zip.js b/tasks/after-all-artifact-build/build-mac-zip.js new file mode 100644 index 0000000000..05b864e2ca --- /dev/null +++ b/tasks/after-all-artifact-build/build-mac-zip.js @@ -0,0 +1,71 @@ +/** + * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH + * under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright + * ownership. + * + * Camunda licenses this file to you under the MIT; you may not use this file + * except in compliance with the MIT License. + */ + +const exec = require('execa').sync; + +const del = require('del').sync; + +const path = require('path'); + +/** + * Build zip artifact for MacOS since electron-builder breaks zips + * + * @param {import('electron-builder').BuildResult} context + * + * @return {Promise} + */ +module.exports = async function(context) { + + if (!isBuildingMacDistro(context)) { + return; + } + + const { + artifactPaths, + configuration, + outDir + } = context; + + const { + productName + } = configuration; + + const dmgPath = artifactPaths.find(path => /\.dmg$/.test(path)); + const zipPath = dmgPath.replace(/dmg$/, 'zip'); + + const appDir = path.join(outDir, 'mac'); + + console.log(` • building target=ZIP arch=x64 file=${zipPath}`); + + del(zipPath); + + exec('zip', [ '-r', zipPath, `${productName}.app` ], { cwd: appDir }); + + // TODO: update dist/latest-mac.yml with blockmap information + // As of `electron-builder@22.1.0`, the `app-builder-bin` blockmap utility + // modifies the digested ZIP file and thus makes the central record directory broken. + + return [ zipPath ]; +}; + + +function isBuildingMacDistro(context) { + const { + platformToTargets + } = context; + + for (const platform of platformToTargets.keys()) { + if (platform.name === 'mac') { + return true; + } + } + + return false; +}