unity-builder/src/index.ts

48 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-08-20 21:10:13 +00:00
import { configSync } from './dependencies.ts';
2022-08-20 19:34:41 +00:00
import { configureLogger } from './core/logger/index.ts';
2022-08-07 23:51:36 +00:00
import { Options } from './config/options.ts';
import { CommandFactory } from './commands/command-factory.ts';
import { ArgumentsParser } from './core/cli/arguments-parser.ts';
import { Environment } from './core/env/environment.ts';
import { EngineDetector } from './core/engine/engine-detector.ts';
2022-08-23 23:21:00 +00:00
import { ParameterOptions } from './model/parameter-options.ts';
2022-08-07 23:51:36 +00:00
export class GameCI {
private readonly env: Environment;
2022-08-07 23:51:36 +00:00
constructor() {
2022-08-20 21:10:13 +00:00
this.env = new Environment(Deno.env, configSync());
this.args = Deno.args;
2022-08-07 23:51:36 +00:00
}
public async run() {
2022-08-07 23:51:36 +00:00
try {
2022-08-20 21:10:13 +00:00
// Infallible configuration
const { commandName, subCommands, args, verbosity } = new ArgumentsParser().parse(this.args);
await configureLogger(verbosity);
2022-08-07 23:51:36 +00:00
2022-08-23 23:21:00 +00:00
// Todo - set default values for parameters to restore functionality.
// Todo - investigate how fitting a CLI lib will be for us
// (now that things are starting to be more separated)
// Determine which command to run
const { engine, engineVersion } = await new EngineDetector(subCommands, args).detect();
const command = new CommandFactory().selectEngine(engine, engineVersion).createCommand(commandName, subCommands);
// Provide the command with options
const options = await new Options(command, this.env).generateParameters(args);
2022-08-20 21:10:13 +00:00
await command.configure(options).validate();
2022-08-07 23:51:36 +00:00
2022-08-20 21:10:13 +00:00
// Execute
if (log.isVerbose) log.info('Executing', command.name);
2022-08-20 21:10:13 +00:00
const success = await command.execute();
if (!success) log.info(`Command ${command.name} failed.`);
2022-08-07 23:51:36 +00:00
} catch (error) {
log.error(error);
Deno.exit(1);
}
}
}
2022-06-07 21:59:34 +00:00
await new GameCI().run();