UNPKG

actionhero

Version:

actionhero.js is a multi-transport API Server with integrated cluster capabilities and delayed tasks

45 lines (44 loc) 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GeneratePlugin = void 0; const fs = require("fs"); const path = require("path"); const index_1 = require("./../../../index"); const PackageJSON = require(path.join(__dirname, "..", "..", "..", "package.json")); class GeneratePlugin extends index_1.CLI { constructor() { super(); this.name = "generate plugin"; this.description = "generate the structure of a new actionhero plugin in an empty directory"; this.example = "actionhero generate plugin"; this.inputs = {}; } async run() { let templateBuffer = fs.readFileSync(path.join(__dirname, "/../../../../templates/package-plugin.json.template")); let template = String(templateBuffer); const regex = new RegExp("%%versionNumber%%", "g"); template = template.replace(regex, PackageJSON.version); [ "actions", "tasks", "initializers", "servers", "config", "bin", "public", ].forEach((type) => { try { const message = index_1.utils.fileUtils.createDirSafely(path.join(process.cwd(), type)); console.info(message); } catch (error) { console.log(error.toString()); } }); const message = index_1.utils.fileUtils.createFileSafely(path.join(process.cwd(), "package.json"), template); console.info(message); return true; } } exports.GeneratePlugin = GeneratePlugin;