Skip to content

Commit

Permalink
fix(project): correctly pack app to zip on MacOS
Browse files Browse the repository at this point in the history
As of `[email protected]`, 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 electron-userland/electron-builder#3534

Closes #1529
  • Loading branch information
barmac authored and nikku committed Nov 15, 2019
1 parent d55d12b commit f5af0d0
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 4 deletions.
6 changes: 2 additions & 4 deletions electron-builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
}
],
"afterPack": "./tasks/after-pack.js",
"afterAllArtifactBuild": "./tasks/after-all-artifact-build.js",
"win": {
"target": [
{
Expand All @@ -30,10 +31,7 @@
]
},
"mac": {
"target": [
"dmg",
"zip"
]
"target": "dmg"
},
"fileAssociations": [
{
Expand Down
28 changes: 28 additions & 0 deletions tasks/after-all-artifact-build.js
Original file line number Diff line number Diff line change
@@ -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;
};
71 changes: 71 additions & 0 deletions tasks/after-all-artifact-build/build-mac-zip.js
Original file line number Diff line number Diff line change
@@ -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<any>}
*/
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', [ '--symlinks', '-r', zipPath, `${productName}.app` ], { cwd: appDir });

// TODO: update dist/latest-mac.yml with blockmap information
// As of `[email protected]`, 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;
}

0 comments on commit f5af0d0

Please sign in to comment.