Skip to content
Permalink
Browse files

feat(maker): allow make to target different or multiple arches

  • Loading branch information
MarshallOfSound committed Dec 11, 2016
1 parent 07defb7 commit 3d4ee5937678c4aebb39980c0033a8267682d0fa
@@ -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)) {
@@ -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();
@@ -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();
}
};

@@ -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({
@@ -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':
@@ -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);
@@ -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);
@@ -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);
@@ -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, {

0 comments on commit 3d4ee59

Please sign in to comment.
You can’t perform that action at this time.