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';
|
2022-08-13 00:51:26 +00:00
|
|
|
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 {
|
2022-08-13 00:51:26 +00:00
|
|
|
private readonly env: Environment;
|
2022-08-07 23:51:36 +00:00
|
|
|
|
2022-08-13 00:51:26 +00:00
|
|
|
constructor() {
|
2022-08-20 21:10:13 +00:00
|
|
|
this.env = new Environment(Deno.env, configSync());
|
2022-08-13 00:51:26 +00:00
|
|
|
this.args = Deno.args;
|
2022-08-07 23:51:36 +00:00
|
|
|
}
|
|
|
|
|
|
2022-08-13 00:51:26 +00:00
|
|
|
public async run() {
|
2022-08-07 23:51:36 +00:00
|
|
|
try {
|
2022-08-20 21:10:13 +00:00
|
|
|
// Infallible configuration
|
2022-08-20 16:12:43 +00:00
|
|
|
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)
|
|
|
|
|
|
2022-08-21 17:21:15 +00:00
|
|
|
// Determine which command to run
|
2022-08-20 16:12:43 +00:00
|
|
|
const { engine, engineVersion } = await new EngineDetector(subCommands, args).detect();
|
2022-08-13 00:51:26 +00:00
|
|
|
const command = new CommandFactory().selectEngine(engine, engineVersion).createCommand(commandName, subCommands);
|
2022-08-21 17:21:15 +00:00
|
|
|
|
|
|
|
|
// 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
|
2022-08-20 16:12:43 +00:00
|
|
|
if (log.isVerbose) log.info('Executing', command.name);
|
2022-08-20 21:10:13 +00:00
|
|
|
const success = await command.execute();
|
2022-08-21 17:21:15 +00:00
|
|
|
if (!success) log.info(`Command ${command.name} failed.`);
|
2022-08-07 23:51:36 +00:00
|
|
|
} catch (error) {
|
|
|
|
|
log.error(error);
|
|
|
|
|
Deno.exit(1);
|
|
|
|
|
}
|
2021-03-13 23:44:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-06-07 21:59:34 +00:00
|
|
|
|
2022-08-13 00:51:26 +00:00
|
|
|
await new GameCI().run();
|