UNPKG

actionhero

Version:

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

41 lines (35 loc) 1.04 kB
import * as fs from "fs"; import * as path from "path"; import { config, utils, CLI } from "./../../../index"; export class GenerateServer extends 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 = utils.fileUtils.createFileSafely( utils.replaceDistWithSrc( config.general.paths.server[0] + "/" + params.name + ".ts" ), template ); console.log(message); return true; } }