Parse build script args with yargs
Summary: We have some custom parsing here and there and I'm going to add some more args, so decided it's better to cleanup this a bit. Reviewed By: jknoxville Differential Revision: D25398421 fbshipit-source-id: 9d43029eef07648d0b01590e9cf7e7fe400b31d0
This commit is contained in:
committed by
Facebook GitHub Bot
parent
18127ef838
commit
bc9412426f
@@ -25,6 +25,59 @@ import {getIcons, buildLocalIconPath, getIconURL} from '../app/src/utils/icons';
|
||||
import isFB from './isFB';
|
||||
import copyPackageWithDependencies from './copy-package-with-dependencies';
|
||||
import {staticDir, distDir} from './paths';
|
||||
import yargs from 'yargs';
|
||||
|
||||
const argv = yargs
|
||||
.usage('yarn build [args]')
|
||||
.version(false)
|
||||
.options({
|
||||
mac: {
|
||||
type: 'boolean',
|
||||
group: 'targets',
|
||||
},
|
||||
'mac-dmg': {
|
||||
type: 'boolean',
|
||||
group: 'targets',
|
||||
},
|
||||
win: {
|
||||
type: 'boolean',
|
||||
group: 'targets',
|
||||
},
|
||||
linux: {
|
||||
type: 'boolean',
|
||||
group: 'targets',
|
||||
},
|
||||
'linux-deb': {
|
||||
type: 'boolean',
|
||||
group: 'targets',
|
||||
},
|
||||
'linux-snap': {
|
||||
type: 'boolean',
|
||||
group: 'targets',
|
||||
},
|
||||
version: {
|
||||
description:
|
||||
'Unique build identifier to be used as the version patch part for the build',
|
||||
type: 'number',
|
||||
default: 0,
|
||||
},
|
||||
})
|
||||
.help()
|
||||
.strict()
|
||||
.check((argv) => {
|
||||
const targetSpecified =
|
||||
argv.mac ||
|
||||
argv['mac-dmg'] ||
|
||||
argv.win ||
|
||||
argv.linux ||
|
||||
argv['linux-deb'] ||
|
||||
argv['linux-snap'];
|
||||
if (!targetSpecified) {
|
||||
throw new Error('No targets specified. eg. --mac, --win, or --linux');
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.parse(process.argv.slice(1));
|
||||
|
||||
async function generateManifest(versionNumber: string) {
|
||||
await fs.writeFile(
|
||||
@@ -65,10 +118,10 @@ async function buildDist(buildFolder: string) {
|
||||
const targetsRaw: Map<Platform, Map<Arch, string[]>>[] = [];
|
||||
const postBuildCallbacks: (() => void)[] = [];
|
||||
|
||||
if (process.argv.indexOf('--mac') > -1) {
|
||||
if (argv.mac || argv['mac-dmg']) {
|
||||
targetsRaw.push(Platform.MAC.createTarget(['dir']));
|
||||
// You can build mac apps on Linux but can't build dmgs, so we separate those.
|
||||
if (process.argv.indexOf('--mac-dmg') > -1) {
|
||||
if (argv['mac-dmg']) {
|
||||
targetsRaw.push(Platform.MAC.createTarget(['dmg']));
|
||||
}
|
||||
postBuildCallbacks.push(() =>
|
||||
@@ -78,22 +131,22 @@ async function buildDist(buildFolder: string) {
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (process.argv.indexOf('--linux') > -1) {
|
||||
if (argv.linux || argv['linux-deb'] || argv['linux-snap']) {
|
||||
targetsRaw.push(Platform.LINUX.createTarget(['zip']));
|
||||
|
||||
const argv = process.argv.slice(2);
|
||||
if (argv.indexOf('--linux-deb') > -1) {
|
||||
if (argv['linux-deb']) {
|
||||
// linux targets can be:
|
||||
// AppImage, snap, deb, rpm, freebsd, pacman, p5p, apk, 7z, zip, tar.xz, tar.lz, tar.gz, tar.bz2, dir
|
||||
targetsRaw.push(Platform.LINUX.createTarget(['deb']));
|
||||
}
|
||||
if (argv.indexOf('--linux-snap') > -1) {
|
||||
if (argv['linux-snap']) {
|
||||
targetsRaw.push(Platform.LINUX.createTarget(['snap']));
|
||||
}
|
||||
}
|
||||
if (process.argv.indexOf('--win') > -1) {
|
||||
if (argv.win) {
|
||||
targetsRaw.push(Platform.WINDOWS.createTarget(['zip']));
|
||||
}
|
||||
|
||||
if (!targetsRaw.length) {
|
||||
throw new Error('No targets specified. eg. --mac, --win, or --linux');
|
||||
}
|
||||
@@ -203,7 +256,7 @@ function downloadIcons(buildFolder: string) {
|
||||
await copyStaticFolder(dir);
|
||||
await downloadIcons(dir);
|
||||
await compileRenderer(dir);
|
||||
const versionNumber = getVersionNumber();
|
||||
const versionNumber = getVersionNumber(argv.version);
|
||||
const hgRevision = await genMercurialRevision();
|
||||
await modifyPackageManifest(dir, versionNumber, hgRevision);
|
||||
await fs.ensureDir(distDir);
|
||||
|
||||
Reference in New Issue
Block a user