|
| 1 | +import { Command, EnumType, ValidationError } from '/deps.ts' |
| 2 | + |
| 3 | +import { createEngine, Engine, EngineConfiguration, EnginePlatform, EngineTarget } from '/lib/engine.ts' |
| 4 | +import { findProjectFile, getProjectName } from '/lib/utils.ts' |
| 5 | +import { GlobalOptions } from '/index.ts' |
| 6 | +import { config } from '/lib/config.ts' |
| 7 | +import { CliOptions } from '/lib/types.ts' |
| 8 | + |
| 9 | +const TargetError = (target: string, targets: string[]) => { |
| 10 | + return new ValidationError(`Invalid Target: ${target} |
| 11 | +Valid Targets: ${targets.join(', ')} |
| 12 | + `) |
| 13 | +} |
| 14 | +export type BuildOptions = typeof build extends Command<any, any, infer Options, any, any> ? Options |
| 15 | + : never |
| 16 | + |
| 17 | +export const build = new Command<GlobalOptions>() |
| 18 | + .description('build') |
| 19 | + .type('Configuration', new EnumType(EngineConfiguration)) |
| 20 | + .type('Platform', new EnumType(EnginePlatform)) |
| 21 | + .option('-p, --platform <platform:Platform>', 'Platform', { default: Engine.getCurrentPlatform() }) |
| 22 | + .option('-c, --configuration <configuration:Configuration>', 'Configuration', { |
| 23 | + default: EngineConfiguration.Development, |
| 24 | + }) |
| 25 | + .option('-d, --dry-run', 'Dry run') |
| 26 | + .arguments('<target:string>') |
| 27 | + .action(async (options, target = EngineTarget.Editor) => { |
| 28 | + const { platform, configuration, dryRun } = options as BuildOptions |
| 29 | + const { engine: { path: enginePath }, project: { path: projectPath } } = config.get(options as CliOptions) |
| 30 | + |
| 31 | + const engine = await createEngine(enginePath) |
| 32 | + const validTargets = await engine.parseEngineTargets() |
| 33 | + const extraArgs = [] |
| 34 | + |
| 35 | + const projectFile = await findProjectFile(projectPath).catch(() => null) |
| 36 | + if (projectFile) { |
| 37 | + extraArgs.push(`-project=${projectFile}`) |
| 38 | + validTargets.push(...(await engine.parseProjectTargets(projectPath))) |
| 39 | + } |
| 40 | + |
| 41 | + // Shorthand target specifier: Editor, Game, Client, Server |
| 42 | + if (Object.values(EngineTarget).includes(target as EngineTarget)) { |
| 43 | + if (projectFile) { |
| 44 | + const projectName = await getProjectName(projectPath) |
| 45 | + target = `${projectName}${target}` |
| 46 | + } else { |
| 47 | + target = `Unreal${target}` |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + if (!validTargets.includes(target)) { |
| 52 | + throw TargetError(target, validTargets) |
| 53 | + } |
| 54 | + |
| 55 | + if (dryRun) { |
| 56 | + console.log(`[build] enginePath: ${enginePath}`) |
| 57 | + console.log(`[build] projectPath: ${projectPath}`) |
| 58 | + console.log(`[build] projectFile: ${projectFile}`) |
| 59 | + console.log(`[build] command: ${configuration} ${target} ${platform}`) |
| 60 | + } |
| 61 | + |
| 62 | + // const manifest = `${enginePath}/Manifests/${target}-${configuration}-${platform}-Manifest.xml` |
| 63 | + // extraArgs.push(`-Manifest=${manifest}`) |
| 64 | + extraArgs.push('-NoUBTMakefiles') |
| 65 | + extraArgs.push('-NoHotReload') |
| 66 | + extraArgs.push('-TraceWrites') |
| 67 | + extraArgs.push('-NoXGE') |
| 68 | + // extraArgs.push('-UsePrecompiled') |
| 69 | + |
| 70 | + // Build Target |
| 71 | + // Build.bat TestProjectEditor Win64 Development -project=E:\Project\TestProject.uproject |
| 72 | + await engine.runUBT({ |
| 73 | + target, |
| 74 | + configuration: configuration as EngineConfiguration, |
| 75 | + platform: platform as EnginePlatform, |
| 76 | + extraArgs, |
| 77 | + dryRun, |
| 78 | + }) |
| 79 | + }) |
0 commit comments