Skip to content

Commit

Permalink
feat(maker): allow make to target different or multiple arches
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Dec 11, 2016
1 parent 07defb7 commit 3d4ee59
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 32 deletions.
67 changes: 46 additions & 21 deletions src/electron-forge-make.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const main = async () => {
.version(require('../package.json').version)
.arguments('[cwd]')
.option('-s, --skip-package', 'Assume the app is already packaged')
.option('-a, --arch [arch]', 'Target architecture')
.option('-p, --platform [platform]', 'Target build platform')
.action((cwd) => {
if (!cwd) return;
if (path.isAbsolute(cwd) && fs.existsSync(cwd)) {
Expand All @@ -36,6 +38,11 @@ const main = async () => {

resolveSpinner.succeed();

if (program.platform && program.platform !== process.platform) {
console.error('You can not "make" for a platform other than your systems platform'.red);
process.exit(1);
}

if (!program.skipPackage) {
console.info('We need to package your application before we can make it'.green);
await packager();
Expand All @@ -48,34 +55,52 @@ const main = async () => {

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

const declaredArch = program.arch || process.arch;
let targetArchs = [declaredArch];
if (declaredArch === 'all') {
switch (process.platform) {
case 'darwin':
targetArchs = ['x64'];
break;
case 'linux':
case 'win32':
default:
targetArchs = ['ia32', 'x64'];
break;
}
}

const packageJSON = JSON.parse(await fs.readFile(path.resolve(dir, 'package.json'), 'utf8'));
const appName = packageJSON.productName || packageJSON.name;
const packageDir = path.resolve(dir, `out/${appName}-${process.platform}-${process.arch}`);
if (!(await fs.exists(packageDir))) {
throw new Error(`Couldn't find packaged app at: ${packageDir}`);
}

for (const target of targets) {
const makeSpinner = ora.ora(`Making for target: ${target.cyan} - On platform: ${process.platform.cyan}`).start();
let maker;
try {
maker = require(`./makers/${process.platform}/${target}.js`);
} catch (err1) {
for (const targetArch of targetArchs) {
const packageDir = path.resolve(dir, `out/${appName}-${process.platform}-${targetArch}`);
if (!(await fs.exists(packageDir))) {
throw new Error(`Couldn't find packaged app at: ${packageDir}`);
}

for (const target of targets) {
const makeSpinner = ora.ora(`Making for target: ${target.cyan} - On platform: ${process.platform.cyan} - For arch: ${targetArch.cyan}`).start();
let maker;
try {
maker = require(`./makers/generic/${target}.js`);
} catch (err2) {
maker = require(`./makers/${process.platform}/${target}.js`);
} catch (err1) {
try {
maker = require(`./makers/generic/${target}.js`);
} catch (err2) {
makeSpinner.fail();
throw new Error(`Could not find a build target with the name: ${target} for the platform: ${process.platform}`);
}
}
try {
await (maker.default || maker)(packageDir, appName, targetArch, forgeConfig, packageJSON);
} catch (err) {
makeSpinner.fail();
throw new Error(`Could not find a build target with the name: ${target} for the platform: ${process.platform}`);
if (err) throw err;
throw new Error(`An error occurred while making for target: ${target}`);
}
makeSpinner.succeed();
}
try {
await (maker.default || maker)(packageDir, appName, forgeConfig, packageJSON);
} catch (err) {
makeSpinner.fail();
if (err) throw err;
throw new Error(`An error occurred while making for target: ${target}`);
}
makeSpinner.succeed();
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/makers/darwin/dmg.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import pify from 'pify';

import { ensureFile } from '../../util/ensure-output';

export default async (dir, appName, forgeConfig, packageJSON) => { // eslint-disable-line
export default async (dir, appName, targetArch, forgeConfig, packageJSON) => { // eslint-disable-line
const outPath = path.resolve(dir, '../make', `${path.basename(dir)}.dmg`);
await ensureFile(outPath);
const dmgConfig = Object.assign({
Expand Down
4 changes: 2 additions & 2 deletions src/makers/generic/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const zipPromise = (from, to) =>
});
});

export default async (dir, appName, forgeConfig, packageJSON) => { // eslint-disable-line
const zipPath = path.resolve(dir, '../make', `${path.basename(dir)}.zip`);
export default async (dir, appName, targetArch, forgeConfig, packageJSON) => { // eslint-disable-line
const zipPath = path.resolve(dir, '../make', `${path.basename(dir)}_${targetArch}.zip`);
await ensureFile(zipPath);
switch (process.platform) {
case 'win32':
Expand Down
4 changes: 2 additions & 2 deletions src/makers/linux/deb.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ function debianArch(nodeArch) {
}
}

export default async (dir, appName, forgeConfig, packageJSON) => { // eslint-disable-line
const arch = debianArch(process.arch);
export default async (dir, appName, targetArch, forgeConfig, packageJSON) => { // eslint-disable-line
const arch = debianArch(targetArch);
const outPath = path.resolve(dir, '../make', `${packageJSON.name}_${packageJSON.version}_${arch}.deb`);

await ensureFile(outPath);
Expand Down
4 changes: 2 additions & 2 deletions src/makers/linux/flatpak.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function flatpakArch(nodeArch) {
}
}

export default async (dir, appName, forgeConfig, packageJSON) => { // eslint-disable-line
const arch = flatpakArch(process.arch);
export default async (dir, appName, targetArch, forgeConfig, packageJSON) => { // eslint-disable-line
const arch = flatpakArch(targetArch);
const outPath = path.resolve(dir, '../make', `${packageJSON.name}_${packageJSON.version}_${arch}.flatpak`);

await ensureFile(outPath);
Expand Down
4 changes: 2 additions & 2 deletions src/makers/linux/rpm.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ function rpmArch(nodeArch) {
}
}

export default async (dir, appName, forgeConfig, packageJSON) => { // eslint-disable-line
const arch = rpmArch(process.arch);
export default async (dir, appName, targetArch, forgeConfig, packageJSON) => { // eslint-disable-line
const arch = rpmArch(targetArch);
const outPath = path.resolve(dir, '../make', `${packageJSON.name}_${packageJSON.version}_${arch}.rpm`);

await ensureFile(outPath);
Expand Down
4 changes: 2 additions & 2 deletions src/makers/win32/squirrel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import path from 'path';

import { ensureDirectory } from '../../util/ensure-output';

export default async (dir, appName, forgeConfig, packageJSON) => { // eslint-disable-line
const outPath = path.resolve(dir, '../make/squirrel.windows');
export default async (dir, appName, targetArch, forgeConfig, packageJSON) => { // eslint-disable-line
const outPath = path.resolve(dir, `../make/squirrel.windows/${targetArch}`);
await ensureDirectory(outPath);

const winstallerConfig = Object.assign({}, forgeConfig.electronWinstallerConfig, {
Expand Down

0 comments on commit 3d4ee59

Please sign in to comment.