UNPKG

actionhero

Version:

The reusable, scalable, and quick node.js API server for stateless and stateful applications

49 lines (48 loc) 1.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GenerateInitializerCLI = void 0; const fs = require("fs"); const path = require("path"); const index_1 = require("./../../../index"); class GenerateInitializerCLI extends index_1.CLI { constructor() { super(...arguments); this.name = "generate-initializer"; this.description = "Generate a new Initializer"; this.example = "actionhero generate initializer --name=<name> --loadPriority=[p] --startPriority=[p] --stopPriority=[p]"; this.inputs = { name: { required: true, description: "The name of the Initializer to generate", letter: "n", }, loadPriority: { required: true, description: "The order that this Initializer will initialize", default: "1000", }, startPriority: { required: true, description: "The order that this Initializer will start", default: "1000", }, stopPriority: { required: true, description: "The order that this Initializer will stop", default: "1000", }, }; } async run({ params }) { let templateBuffer = fs.readFileSync(path.join(__dirname, "/../../../../templates/initializer.ts.template")); let template = String(templateBuffer); for (const [k, v] of Object.entries(params)) { const regex = new RegExp("%%" + k + "%%", "g"); template = template.replace(regex, v); } const message = index_1.utils.fileUtils.createFileSafely(index_1.utils.replaceDistWithSrc(index_1.config.general.paths.initializer[0] + "/" + params.name + ".ts"), template); console.log(message); return true; } } exports.GenerateInitializerCLI = GenerateInitializerCLI;