actionhero
Version:
The reusable, scalable, and quick node.js API server for stateless and stateful applications
46 lines (45 loc) • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GenerateCLICLI = void 0;
const fs = require("fs");
const path = require("path");
const index_1 = require("./../../../index");
class GenerateCLICLI extends index_1.CLI {
constructor() {
super(...arguments);
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",
letter: "n",
},
description: {
required: false,
description: "The name of the CLI Command",
default: "an actionhero cli command",
letter: "d",
},
example: {
required: false,
description: "An example to include for the CLI Command's help",
default: "actionhero command --option=yes",
letter: "e",
},
};
}
async run({ params }) {
let templateBuffer = fs.readFileSync(path.join(__dirname, "/../../../../templates/cli.ts.template"));
let template = templateBuffer.toString();
for (const [k, v] of Object.entries(params)) {
const regex = new RegExp("%%" + k + "%%", "g");
template = template.replace(regex, 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.GenerateCLICLI = GenerateCLICLI;