import { Component, JsonObject, IConfigReader } from "merapi"; import { IMerapiDescriptor, IHelper } from "interfaces/main"; import Merapi from "components/models/merapi"; import { Answers, prompt } from "inquirer"; export default class MerapiManager extends Component { constructor( private merapi : IMerapiDescriptor, private config : IConfigReader, private helper : IHelper, ) { super(); } public async init(options : JsonObject) : Promise { try { const answer = await this.buildSchema(this.merapi); console.log(answer); await this.generate(answer); } catch (exception) { throw exception; } } public async buildSchema(schema : IMerapiDescriptor) : Promise { const {name, author, componentsPath, httpPort, plugins, servicePort} = schema; const pluginList : Map = this.config.get("config.plugins") as Map; return await prompt([ { type: "input", name: "name", message: "Name : ", default: "Merapi Service", // when: () => !name, }, { type: "input", name: "componentPath", message: "Components Path : ", default: "components/" // when: () => !componentsPath, // tslint:disable-next-line:no-shadowed-variable // filter(componentsPath : string) { // if (!componentsPath === 0) { // return null; // } // return componentsPath; // } }, { type: "checkbox", name: "plugins", message: `Plugins : `, choices: pluginList, // when: () => !plugins, // // tslint:disable-next-line:no-shadowed-variable // filter: (plugins : string) => { // return plugins.toLowerCase(); // } }, { type: "input", name: "httpPort", message: "Http Port : ", default: 8000 }, { type: "input", name: "servicePort", message: "Service Port : ", default: 5000 }, { type: "input", name: "main", message: "Main Class Path : ", default: "main" }, ]) as IMerapiDescriptor; } private async generate(descriptor : IMerapiDescriptor) : Promise { try { const serviceYmlDescriptor = { schema: "kata.ai/schema/merapi/1.0", name: (descriptor.name) ? descriptor.name : "${package.name}", version: "${package.version}", plugins: descriptor.plugins, components : { main: "Main" } , service: { port: descriptor.servicePort }, app: { host: "0.0.0.0", port: (descriptor.httpPort) ? descriptor.httpPort : "${$APP_PORT}" }, main: descriptor.main }; const pluginYmlDescriptor = { development: { exclude: [ "loggly" ] }, infomedia: { exclude: [ "loggly", "aop", "aop-logger" ] } }; this.helper.dumpYaml("./service.yml", serviceYmlDescriptor); this.helper.dumpYaml("./plugin.yml", pluginYmlDescriptor); this.helper.dumpPackageJson(descriptor); this.helper.copyAll(); console.log(`Initialized new Merapi project: ${descriptor.name}`); } catch (exception) { throw exception; } } }