add option to specify number of jobs for build command

This commit is contained in:
Slowlife01 2025-03-27 10:50:31 +07:00
parent fd234005ec
commit fc713c85db
4 changed files with 23 additions and 3 deletions

View file

@ -29,6 +29,18 @@ export const commands: Cmd[] = [
description: description:
"Doesn't check to see if all of the patches have been applied", "Doesn't check to see if all of the patches have been applied",
}, },
{
arg: "-j, --jobs <number>",
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, requestController: async () => (await import('./commands/build')).build,
}, },

View file

@ -110,7 +110,7 @@ const applyConfig = async (os: string) => {
writeFileSync(join(ENGINE_DIR, 'browser/config/version_display.txt'), version) writeFileSync(join(ENGINE_DIR, 'browser/config/version_display.txt'), version)
} }
const genericBuild = async (os: string, fast = false): Promise<boolean> => { const genericBuild = async (os: string, fast = false, jobs: number): Promise<boolean> => {
log.info(`Building for "${os}"...`) log.info(`Building for "${os}"...`)
log.warning( log.warning(
@ -123,6 +123,10 @@ const genericBuild = async (os: string, fast = false): Promise<boolean> => {
buildOptions.push('faster') buildOptions.push('faster')
} }
if (jobs) {
buildOptions.push(`-j${jobs}`)
}
log.debug(`Running with build options ${buildOptions.join(', ')}`) log.debug(`Running with build options ${buildOptions.join(', ')}`)
log.debug(`Mach exists: ${existsSync(join(ENGINE_DIR, 'mach'))}`) log.debug(`Mach exists: ${existsSync(join(ENGINE_DIR, 'mach'))}`)
log.debug( log.debug(
@ -156,6 +160,7 @@ const success = (date: number) => {
interface Options { interface Options {
ui: boolean ui: boolean
jobs: number
skipPatchCheck: boolean skipPatchCheck: boolean
} }
@ -177,7 +182,7 @@ export const build = async (options: Options): Promise<void> => {
log.info('Starting build...') 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) process.exit(exit ? 0 : 1)
} }
} }

View file

@ -108,7 +108,9 @@ for (const command of commands) {
// Register all of the required options // Register all of the required options
for (const opt of command?.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_) => { buildCommand = buildCommand.action(async (...arguments_) => {

1
src/types.d.ts vendored
View file

@ -25,6 +25,7 @@ export interface Cmd {
export interface CmdOption { export interface CmdOption {
arg: string arg: string
description: string description: string
parse?: (val: string) => unknown
} }
export type CmdFlagPlatform = NodeJS.Platform export type CmdFlagPlatform = NodeJS.Platform