From fc713c85dbfa8c83b458e523aca79861ef0854db Mon Sep 17 00:00:00 2001 From: Slowlife01 Date: Thu, 27 Mar 2025 10:50:31 +0700 Subject: [PATCH 1/4] add option to specify number of jobs for build command --- src/cmds.ts | 12 ++++++++++++ src/commands/build.ts | 9 +++++++-- src/index.ts | 4 +++- src/types.d.ts | 1 + 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/cmds.ts b/src/cmds.ts index c75af90..95c1130 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. Defaults to the number of cores on your machine.', + 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..9fa6675 100644 --- a/src/index.ts +++ b/src/index.ts @@ -108,7 +108,9 @@ 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 From 297568f36541d4fa0a1a68d9c2f3b5f9a7adbd11 Mon Sep 17 00:00:00 2001 From: Slowlife01 Date: Thu, 27 Mar 2025 10:53:35 +0700 Subject: [PATCH 2/4] style: format --- src/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 9fa6675..b0176f4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -108,9 +108,10 @@ for (const command of commands) { // Register all of the required options for (const opt of command?.options || []) { - buildCommand = opt.parse !== undefined ? - buildCommand.option(opt.arg, opt.description, opt.parse) : - 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_) => { From d08babdb873f238b720b2cef7d3601cbe207ded4 Mon Sep 17 00:00:00 2001 From: Slowlife01 Date: Thu, 27 Mar 2025 11:02:41 +0700 Subject: [PATCH 3/4] chore: update description for jobs option in commands --- src/cmds.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmds.ts b/src/cmds.ts index 95c1130..e51d8e1 100644 --- a/src/cmds.ts +++ b/src/cmds.ts @@ -32,7 +32,7 @@ export const commands: Cmd[] = [ { arg: "-j, --jobs ", description: - 'Number of jobs to run in parallel. Defaults to the number of cores on your machine.', + 'Number of jobs to run in parallel', parse: (val: string) => { const parsed = parseInt(val, 10) if (isNaN(parsed)) { From e4a0198e2b4e18af2255203576cd5515b3ca4eb5 Mon Sep 17 00:00:00 2001 From: Slowlife Date: Sun, 30 Mar 2025 10:00:42 +0700 Subject: [PATCH 4/4] style: change to single qoute --- src/cmds.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmds.ts b/src/cmds.ts index e51d8e1..314c99b 100644 --- a/src/cmds.ts +++ b/src/cmds.ts @@ -30,7 +30,7 @@ export const commands: Cmd[] = [ "Doesn't check to see if all of the patches have been applied", }, { - arg: "-j, --jobs ", + arg: '-j, --jobs ', description: 'Number of jobs to run in parallel', parse: (val: string) => {