actionhero
Version:
The reusable, scalable, and quick node.js API server for stateless and stateful applications
43 lines (42 loc) • 1.67 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: "The name of the CLI Command to generate",
},
description: {
required: false,
description: "The name of the CLI Command",
default: "an actionhero cli command",
},
example: {
required: false,
description: "An example to include for the CLI Command's help",
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;