import {ConfigFileCommandTemplateLoader} from '../loader/impl/configFileCommandTemplateLoader' import {Command} from '../models/command'; const configuration = require('../../../configs/command-config.json'); const commandsDefault = require('../../../configs/commands.json'); export class CommandController{ private _loader: ConfigFileCommandTemplateLoader; private _configuration: any; constructor(commandConfiguration?: any, commands?: any){ this._loader = (commands !== undefined)? new ConfigFileCommandTemplateLoader(JSON.parse(commands)) : new ConfigFileCommandTemplateLoader(commandsDefault); this._configuration = (commandConfiguration !== undefined)? JSON.parse(commandConfiguration) : configuration; if(this._loader == undefined) throw new Error("loader cannot be undefined"); if(this._configuration == undefined) throw new Error("configuration cannot be undefined"); } printAllCommandsOf(project: string){ const commands = this._configuration.commands[project]; commands.forEach(command => { (async function () { const foundCommandTemplate = await this._loader.loadCommandTemplateBy(command.file); const commandRender = new Command(foundCommandTemplate.template); const finalCommand = commandRender.render(command); console.log("------------------------\n"); console.log("Name: ", command.name); console.log("Command: ", finalCommand); console.log("\n------------------------"); }); }); } }