actionhero
Version:
actionhero.js is a multi-transport API Server with integrated cluster capabilities and delayed tasks
32 lines (31 loc) • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GenerateCLI = void 0;
const fs = require("fs");
const path = require("path");
const index_1 = require("./../../../index");
class GenerateCLI extends index_1.CLI {
constructor() {
super();
this.name = "generate cli";
this.description = "generate a new cli command";
this.example = "actionhero generate cli --name=[name]";
this.inputs = {
name: { required: true },
description: { required: false, default: "an actionhero cli command" },
example: { required: false, default: "actionhero command --option=yes" },
};
}
async run({ params }) {
let templateBuffer = fs.readFileSync(path.join(__dirname, "/../../../../templates/cli.ts.template"));
let template = templateBuffer.toString();
["name", "description", "example"].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.cli[0] + "/" + params.name + ".ts"), template);
console.log(message);
return true;
}
}
exports.GenerateCLI = GenerateCLI;