diff --git a/src/cmds.ts b/src/cmds.ts index c75af90..314c99b 100644 --- a/src/cmds.ts +++ b/src/cmds.ts @@ -29,6 +29,18 @@ export const commands: Cmd[] = [ description: "Doesn't check to see if all of the patches have been applied", }, + { + arg: '-j, --jobs ', + description: + 'Number of jobs to run in parallel', + parse: (val: string) => { + const parsed = parseInt(val, 10) + if (isNaN(parsed)) { + throw new Error('Invalid number of jobs') + } + return parsed + } + } ], requestController: async () => (await import('./commands/build')).build, }, diff --git a/src/commands/build.ts b/src/commands/build.ts index 0aa4ec5..3f0000c 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -110,7 +110,7 @@ const applyConfig = async (os: string) => { writeFileSync(join(ENGINE_DIR, 'browser/config/version_display.txt'), version) } -const genericBuild = async (os: string, fast = false): Promise => { +const genericBuild = async (os: string, fast = false, jobs: number): Promise => { log.info(`Building for "${os}"...`) log.warning( @@ -123,6 +123,10 @@ const genericBuild = async (os: string, fast = false): Promise => { buildOptions.push('faster') } + if (jobs) { + buildOptions.push(`-j${jobs}`) + } + log.debug(`Running with build options ${buildOptions.join(', ')}`) log.debug(`Mach exists: ${existsSync(join(ENGINE_DIR, 'mach'))}`) log.debug( @@ -156,6 +160,7 @@ const success = (date: number) => { interface Options { ui: boolean + jobs: number skipPatchCheck: boolean } @@ -177,7 +182,7 @@ export const build = async (options: Options): Promise => { log.info('Starting build...') - let exit = await genericBuild(prettyHost, options.ui) + let exit = await genericBuild(prettyHost, options.ui, options.jobs) process.exit(exit ? 0 : 1) } } diff --git a/src/index.ts b/src/index.ts index 1b3e15b..b0176f4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -108,7 +108,10 @@ for (const command of commands) { // Register all of the required options for (const opt of command?.options || []) { - buildCommand = buildCommand.option(opt.arg, opt.description) + buildCommand = + opt.parse !== undefined + ? buildCommand.option(opt.arg, opt.description, opt.parse) + : buildCommand.option(opt.arg, opt.description) } buildCommand = buildCommand.action(async (...arguments_) => { diff --git a/src/types.d.ts b/src/types.d.ts index e90a010..edcd41e 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -25,6 +25,7 @@ export interface Cmd { export interface CmdOption { arg: string description: string + parse?: (val: string) => unknown } export type CmdFlagPlatform = NodeJS.Platform