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
@@ -89,7 +89,9 @@ async function createZip(buildDir: string, distDir: string, targets: string[]) {
|
|||||||
console.log('Created build directory', buildDir);
|
console.log('Created build directory', buildDir);
|
||||||
await generatePluginEntryPoints();
|
await generatePluginEntryPoints();
|
||||||
await compileHeadless(buildDir);
|
await compileHeadless(buildDir);
|
||||||
const versionNumber = getVersionNumber();
|
const buildNumber = process.argv.join(' ').match(/--version=(\d+)/);
|
||||||
|
const patch = buildNumber && buildNumber.length > 0 ? buildNumber[1] : '0';
|
||||||
|
const versionNumber = getVersionNumber(parseInt(patch, 10));
|
||||||
const buildRevision = await genMercurialRevision();
|
const buildRevision = await genMercurialRevision();
|
||||||
await preludeBundle(buildDir, versionNumber, buildRevision);
|
await preludeBundle(buildDir, versionNumber, buildRevision);
|
||||||
await createBinary([
|
await createBinary([
|
||||||
|
|||||||
@@ -25,6 +25,59 @@ import {getIcons, buildLocalIconPath, getIconURL} from '../app/src/utils/icons';
|
|||||||
import isFB from './isFB';
|
import isFB from './isFB';
|
||||||
import copyPackageWithDependencies from './copy-package-with-dependencies';
|
import copyPackageWithDependencies from './copy-package-with-dependencies';
|
||||||
import {staticDir, distDir} from './paths';
|
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) {
|
async function generateManifest(versionNumber: string) {
|
||||||
await fs.writeFile(
|
await fs.writeFile(
|
||||||
@@ -65,10 +118,10 @@ async function buildDist(buildFolder: string) {
|
|||||||
const targetsRaw: Map<Platform, Map<Arch, string[]>>[] = [];
|
const targetsRaw: Map<Platform, Map<Arch, string[]>>[] = [];
|
||||||
const postBuildCallbacks: (() => void)[] = [];
|
const postBuildCallbacks: (() => void)[] = [];
|
||||||
|
|
||||||
if (process.argv.indexOf('--mac') > -1) {
|
if (argv.mac || argv['mac-dmg']) {
|
||||||
targetsRaw.push(Platform.MAC.createTarget(['dir']));
|
targetsRaw.push(Platform.MAC.createTarget(['dir']));
|
||||||
// You can build mac apps on Linux but can't build dmgs, so we separate those.
|
// 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']));
|
targetsRaw.push(Platform.MAC.createTarget(['dmg']));
|
||||||
}
|
}
|
||||||
postBuildCallbacks.push(() =>
|
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']));
|
targetsRaw.push(Platform.LINUX.createTarget(['zip']));
|
||||||
|
|
||||||
const argv = process.argv.slice(2);
|
if (argv['linux-deb']) {
|
||||||
if (argv.indexOf('--linux-deb') > -1) {
|
|
||||||
// linux targets can be:
|
// linux targets can be:
|
||||||
// AppImage, snap, deb, rpm, freebsd, pacman, p5p, apk, 7z, zip, tar.xz, tar.lz, tar.gz, tar.bz2, dir
|
// 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']));
|
targetsRaw.push(Platform.LINUX.createTarget(['deb']));
|
||||||
}
|
}
|
||||||
if (argv.indexOf('--linux-snap') > -1) {
|
if (argv['linux-snap']) {
|
||||||
targetsRaw.push(Platform.LINUX.createTarget(['snap']));
|
targetsRaw.push(Platform.LINUX.createTarget(['snap']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (process.argv.indexOf('--win') > -1) {
|
if (argv.win) {
|
||||||
targetsRaw.push(Platform.WINDOWS.createTarget(['zip']));
|
targetsRaw.push(Platform.WINDOWS.createTarget(['zip']));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!targetsRaw.length) {
|
if (!targetsRaw.length) {
|
||||||
throw new Error('No targets specified. eg. --mac, --win, or --linux');
|
throw new Error('No targets specified. eg. --mac, --win, or --linux');
|
||||||
}
|
}
|
||||||
@@ -203,7 +256,7 @@ function downloadIcons(buildFolder: string) {
|
|||||||
await copyStaticFolder(dir);
|
await copyStaticFolder(dir);
|
||||||
await downloadIcons(dir);
|
await downloadIcons(dir);
|
||||||
await compileRenderer(dir);
|
await compileRenderer(dir);
|
||||||
const versionNumber = getVersionNumber();
|
const versionNumber = getVersionNumber(argv.version);
|
||||||
const hgRevision = await genMercurialRevision();
|
const hgRevision = await genMercurialRevision();
|
||||||
await modifyPackageManifest(dir, versionNumber, hgRevision);
|
await modifyPackageManifest(dir, versionNumber, hgRevision);
|
||||||
await fs.ensureDir(distDir);
|
await fs.ensureDir(distDir);
|
||||||
|
|||||||
@@ -205,13 +205,10 @@ export function buildFolder(): Promise<string> {
|
|||||||
return '';
|
return '';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
export function getVersionNumber() {
|
export function getVersionNumber(buildNumber: number) {
|
||||||
let {version} = require('../package.json');
|
let {version} = require('../package.json');
|
||||||
// Unique build number is passed as --version parameter from Sandcastle
|
// Unique build number is passed as --version parameter from Sandcastle
|
||||||
const buildNumber = process.argv.join(' ').match(/--version=(\d+)/);
|
version = [...version.split('.').slice(0, 2), buildNumber].join('.');
|
||||||
if (buildNumber && buildNumber.length > 0) {
|
|
||||||
version = [...version.split('.').slice(0, 2), buildNumber[1]].join('.');
|
|
||||||
}
|
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user