UNPKG

actionhero

Version:

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

33 lines (32 loc) 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GenerateServer = void 0; const fs = require("fs"); const path = require("path"); const index_1 = require("./../../../index"); class GenerateServer extends index_1.CLI { constructor() { super(); this.name = "generate-server"; this.description = "Generate a new Server"; this.example = "actionhero generate server --name=<name>"; this.inputs = { name: { required: true, description: "The name of the Server to generate", }, }; } async run({ params }) { let templateBuffer = fs.readFileSync(path.join(__dirname, "/../../../../templates/server.ts.template")); let template = String(templateBuffer); ["name"].forEach((v) => { const regex = new RegExp("%%" + v + "%%", "g"); template = template.replace(regex, params[v]); }); const message = index_1.utils.fileUtils.createFileSafely(index_1.utils.replaceDistWithSrc(index_1.config.general.paths.server[0] + "/" + params.name + ".ts"), template); console.log(message); return true; } } exports.GenerateServer = GenerateServer;