actionhero
Version:
The reusable, scalable, and quick node.js API server for stateless and stateful applications
45 lines (44 loc) • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GeneratePluginCLI = void 0;
const fs = require("fs");
const path = require("path");
const index_1 = require("./../../../index");
const PackageJSON = JSON.parse(fs
.readFileSync(path.join(__dirname, "..", "..", "..", "..", "package.json"))
.toString());
class GeneratePluginCLI extends index_1.CLI {
constructor() {
super(...arguments);
this.name = "generate-plugin";
this.description = "Generate the structure of a new actionhero plugin in an empty directory";
this.example = "actionhero generate plugin";
}
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.GeneratePluginCLI = GeneratePluginCLI;