diff --git a/src/commands/command/build-command.ts b/src/commands/command/build-command.ts index df6683ac..61874fc9 100644 --- a/src/commands/command/build-command.ts +++ b/src/commands/command/build-command.ts @@ -1,10 +1,11 @@ import { exec, OutputMode } from 'https://deno.land/x/exec@0.0.5/mod.ts'; import { CommandInterface } from './command-interface.ts'; import { Options } from '../../config/options.ts'; -import { Action, Cache, CloudRunner, Docker, ImageTag, Output } from '../../model/index.ts'; +import { Action, Cache, CloudRunner, Docker, ImageTag, Input, Output } from '../../model/index.ts'; import PlatformSetup from '../../model/platform-setup.ts'; import { core, process } from '../../dependencies.ts'; import MacBuilder from '../../model/mac-builder.ts'; +import Parameters from '../../model/parameters.ts'; export class BuildCommand implements CommandInterface { public readonly name: string; @@ -13,6 +14,8 @@ export class BuildCommand implements CommandInterface { this.name = name; } + public async parseParameters(input: Input, parameters: Parameters) {} + public async execute(options: Options): Promise { try { log.info('options', options); diff --git a/src/commands/command/build-remote-command.ts b/src/commands/command/build-remote-command.ts index 4b582897..326ff5a0 100644 --- a/src/commands/command/build-remote-command.ts +++ b/src/commands/command/build-remote-command.ts @@ -1,7 +1,8 @@ import { CommandInterface } from './command-interface.ts'; import { Options } from '../../config/options.ts'; -import { CloudRunner, ImageTag, Output } from '../../model/index.ts'; +import { CloudRunner, ImageTag, Input, Output } from '../../model/index.ts'; import { core } from '../../dependencies.ts'; +import Parameters from '../../model/parameters.ts'; // Todo - Verify this entire flow export class BuildRemoteCommand implements CommandInterface { @@ -11,6 +12,8 @@ export class BuildRemoteCommand implements CommandInterface { this.name = name; } + public async parseParameters(input: Input, parameters: Parameters) {} + public async execute(options: Options): Promise { try { const { buildParameters } = options; diff --git a/src/commands/command/command-interface.ts b/src/commands/command/command-interface.ts index 667845f2..a74d16e1 100644 --- a/src/commands/command/command-interface.ts +++ b/src/commands/command/command-interface.ts @@ -1,6 +1,9 @@ import { Options } from '../../config/options.ts'; +import Parameters from '../../model/parameters.ts'; +import { Input } from '../../model/index.ts'; export interface CommandInterface { name: string; execute: (options: Options) => Promise; + parseParameters: (input: Input, parameters: Parameters) => Promise>; } diff --git a/src/commands/command/non-existent-command.ts b/src/commands/command/non-existent-command.ts index 193316ea..ea3bee45 100644 --- a/src/commands/command/non-existent-command.ts +++ b/src/commands/command/non-existent-command.ts @@ -11,4 +11,6 @@ export class NonExistentCommand implements CommandInterface { public async execute(options: Options): Promise { throw new Error(`Command ${this.name} does not exist`); } + + public async parseParameters() {} } diff --git a/src/config/options.ts b/src/config/options.ts index 9ec764f2..c2340581 100644 --- a/src/config/options.ts +++ b/src/config/options.ts @@ -1,20 +1,26 @@ import { CliArguments } from '../core/cli/cli-arguments.ts'; import { EnvVariables } from '../core/env/env-variables.ts'; import { Parameters, Input } from '../model/index.ts'; +import { CommandInterface } from '../commands/command/command-interface.ts'; export class Options { public input: Input; public parameters: Parameters; + private readonly env: EnvVariables; + private readonly command: CommandInterface; - constructor(env: EnvVariables) { + constructor(command: CommandInterface, env: EnvVariables) { + this.input = null; + this.parameters = null; this.env = env; + this.command = command; return this; } public async generateParameters(args: CliArguments) { this.input = new Input(args); - this.parameters = await new Parameters(this.input, this.env).parse(); + this.parameters = await new Parameters(this.input, this.env).registerCommand(this.command).parse(); log.debug('Parameters generated.'); diff --git a/src/model/parameters.ts b/src/model/parameters.ts index c2de8981..132debc2 100644 --- a/src/model/parameters.ts +++ b/src/model/parameters.ts @@ -10,8 +10,10 @@ import { GitRepoReader } from './input-readers/git-repo.ts'; import { GithubCliReader } from './input-readers/github-cli.ts'; import { Cli } from './cli/cli.ts'; import { EnvVariables } from '../core/env/env-variables.ts'; +import { CommandInterface } from '../commands/command/command-interface.ts'; class Parameters { + private command: CommandInterface; public editorVersion!: string; public customImage!: string; public unitySerial!: string; @@ -99,25 +101,24 @@ class Parameters { // Todo - Don't use process.env directly, that's what the input model class is for. // --- let unitySerial = ''; - if (!Deno.env.get('UNITY_SERIAL') && this.input.githubInputEnabled) { + if (!this.env.UNITY_SERIAL && this.input.githubInputEnabled) { // No serial was present, so it is a personal license that we need to convert - if (!Deno.env.get('UNITY_LICENSE')) { + if (!this.env.UNITY_LICENSE) { throw new Error(`Missing Unity License File and no Serial was found. If this is a personal license, make sure to follow the activation steps and set the UNITY_LICENSE GitHub secret or enter a Unity serial number inside the UNITY_SERIAL GitHub secret.`); } - unitySerial = this.getSerialFromLicenseFile(Deno.env.get('UNITY_LICENSE')); + unitySerial = this.getSerialFromLicenseFile(this.env.UNITY_LICENSE); } else { - unitySerial = Deno.env.get('UNITY_SERIAL')!; + unitySerial = this.env.UNITY_SERIAL!; } - return { + const parameters = { editorVersion, customImage: this.input.customImage, unitySerial, - - runnerTempPath: Deno.env.get('RUNNER_TEMP'), + runnerTempPath: this.env.RUNNER_TEMP, targetPlatform: this.input.targetPlatform, projectPath: this.input.projectPath, buildName: this.input.buildName, @@ -168,6 +169,14 @@ class Parameters { startDependenciesOverride: this.input.startDependenciesOverride, cacheKey: this.input.cacheKey, }; + + const commandParameterOverrides = this.command.parseParameters(this.input, parameters); + + // Todo - Maybe return an instance instead + return { + ...parameters, + ...commandParameterOverrides, + }; } static parseBuildFile(filename, platform, androidAppBundle) { @@ -194,6 +203,12 @@ class Parameters { // Slice off the first 4 characters as they are garbage values return Buffer.from(license.slice(startIndex, endIndex), 'base64').toString('binary').slice(4); } + + registerCommand(command: CommandInterface) { + this.command = command; + + return this; + } } export default Parameters;