/** * @author Martin Karkowski * @email m.karkowski@zema.de * @create date 2020-11-11 13:27:58 * @modify date 2021-01-18 18:46:10 * @desc [description] */ import { ArgumentParser } from "argparse"; import { writeFile } from "fs/promises"; import { getNopeLogger } from "../logger/getLogger"; // Define the Main Function. // This function is used as cli tool. export const generateDefaultConfig = async function ( additionalArguments: { help: string; type: "string" | "number"; name: string | string; defaultValue?: any; }[] = [] ) { const parser = new ArgumentParser({ version: "1.0.0", addHelp: true, description: "Command Line interface, determines the available Packages." }); for (const arg of additionalArguments) { parser.addArgument(arg.name, { help: arg.help, defaultValue: arg.defaultValue, type: arg.type }); } parser.addArgument(["-f", "--file"], { help: "File containing containing the package definitions.", defaultValue: "./nopeconfig.json", type: "string", dest: "file" }); const args = parser.parseArgs(); // Define a Logger const logger = getNopeLogger("Setup-CLI"); try { // Try to read in the default config file. await writeFile( args.file, JSON.stringify( { analyzers: { typescript: { inputDir: "./modules/**/*.ts", tsConfig: "tsconfigBackend.json" } }, parsers: { openApi: { outputDir: "./open-api/backend-api" } }, tempDir: "./temp/", configDir: "./config", modules: "./dist/modules" }, undefined, 4 ) ); // Inform the user. logger.info("Created Nope-Config at " + args.file); } catch (error) { logger.error("Failed generating the Config"); logger.error(error); } }; if (require.main === module) { generateDefaultConfig().catch((e) => console.error(e)); }