Skip to content

Commit

Permalink
refactor(maker): use the target platform/arch API from Packager to de…
Browse files Browse the repository at this point in the history
…termine "all" archs

Adds arm64 support to `make --arch=all`
  • Loading branch information
malept committed Sep 16, 2017
1 parent 1e7c175 commit f9c4c20
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"electron-forge-template-react": "^1.0.2",
"electron-forge-template-react-typescript": "^1.0.3",
"electron-forge-template-vue": "^1.0.2",
"electron-packager": "^9.0.0",
"electron-packager": "^9.1.0",
"electron-rebuild": "^1.6.0",
"form-data": "^2.1.4",
"fs-extra": "^4.0.0",
Expand Down
21 changes: 2 additions & 19 deletions src/api/make.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import electronHostArch from '../util/electron-host-arch';
import getForgeConfig from '../util/forge-config';
import runHook from '../util/hook';
import { info, warn } from '../util/messages';
import parseArchs from '../util/parse-archs';
import readPackageJSON from '../util/read-package-json';
import { requireSearchRaw } from '../util/require-search';
import resolveDir from '../util/resolve-dir';
Expand Down Expand Up @@ -116,33 +117,15 @@ export default async (providedOptions = {}) => {
warn(interactive, 'WARNING: Skipping the packaging step, this could result in an out of date build'.red);
}

const declaredArch = arch;

info(interactive, 'Making for the following targets:', `${targets.join(', ')}`.cyan);

let targetArchs = declaredArch.split(',');
if (declaredArch === 'all') {
switch (platform) {
case 'darwin':
targetArchs = ['x64'];
break;
case 'linux':
targetArchs = ['ia32', 'x64', 'armv7l'];
break;
case 'win32':
default:
targetArchs = ['ia32', 'x64'];
break;
}
}

const packageJSON = await readPackageJSON(dir);
const appName = forgeConfig.electronPackagerConfig.name || packageJSON.productName || packageJSON.name;
let outputs = [];

await runHook(forgeConfig, 'preMake');

for (const targetArch of targetArchs) {
for (const targetArch of parseArchs(platform, arch, packageJSON.devDependencies['electron-prebuilt-compile'])) {
const packageDir = path.resolve(outDir, `${appName}-${platform}-${targetArch}`);
if (!(await fs.pathExists(packageDir))) {
throw new Error(`Couldn't find packaged app at: ${packageDir}`);
Expand Down
9 changes: 9 additions & 0 deletions src/util/parse-archs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { allOfficialArchsForPlatformAndVersion } from 'electron-packager/targets';

export default function parseArchs(platform, declaredArch, electronVersion) {
if (declaredArch === 'all') {
return allOfficialArchsForPlatformAndVersion(platform, electronVersion) || ['x64'];
}

return declaredArch.split(',');
}
21 changes: 21 additions & 0 deletions test/fast/parse-archs_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { expect } from 'chai';

import parseArchs from '../../src/util/parse-archs';

describe('parse-archs', () => {
it('should make an Array out of one arch', () => {
expect(parseArchs('linux', 'x64', '1.7.0')).to.deep.equal(['x64']);
});

it('should transform comma-separated values into an Array', () => {
expect(parseArchs('linux', 'ia32,x64', '1.7.0')).to.deep.equal(['ia32', 'x64']);
});

it('should use the official Electron arch list when arch is "all"', () => {
expect(parseArchs('win32', 'all', '1.7.0')).to.deep.equal(['ia32', 'x64']);
});

it('should default to [x64] when the platform is unknown', () => {
expect(parseArchs('nonexistent', 'all', '1.7.0')).to.deep.equal(['x64']);
});
});

0 comments on commit f9c4c20

Please sign in to comment.