zents-cli
Version:
ZenTS is a Node.js & TypeScript MVC-Framework for building rich web applications, released as free and open-source software under the MIT License. It is designed for building web applications with modern tools and design patterns.
52 lines (51 loc) • 2.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const log_1 = require("../../helper/log");
const AbstractCommand_1 = require("../../classes/AbstractCommand");
const doesDirOrFileExists_1 = require("../../helper/doesDirOrFileExists");
const command_1 = require("@oclif/command");
const path_1 = require("path");
class Controller extends AbstractCommand_1.AbstractCommand {
async run() {
var _a, _b, _c, _d, _e;
const { args, flags } = this.parse(Controller);
this.welcome('Create a ZenTS controller!');
const filename = `${args.name}Controller.ts`;
const config = await this.getZenConfig();
const controllerPath = typeof ((_c = (_b = (_a = config.config) === null || _a === void 0 ? void 0 : _a.paths) === null || _b === void 0 ? void 0 : _b.base) === null || _c === void 0 ? void 0 : _c.src) === 'string' &&
typeof ((_e = (_d = config.config) === null || _d === void 0 ? void 0 : _d.paths) === null || _e === void 0 ? void 0 : _e.controller) === 'string'
? path_1.join(config.config.paths.base.src, config.config.paths.controller)
: path_1.join(process.cwd(), 'src', 'controller');
if (!(await doesDirOrFileExists_1.doesDirOrFileExists(controllerPath))) {
this.log(log_1.error(`Controller directory "${controllerPath}" doesn't exist!`));
process.exit(42);
}
else if (!flags.force && (await doesDirOrFileExists_1.doesDirOrFileExists(path_1.join(controllerPath, filename)))) {
this.log(log_1.error(`Controller file "${path_1.join(controllerPath, filename)}" already exists. Use --force flag to overwrite this file.`));
process.exit(42);
}
await this.generate('Controller', {
cwd: process.cwd(),
filename,
controllerPath,
});
this.log(log_1.success(`New ZenTS controller created successfully (${path_1.join(controllerPath, filename)})`));
}
}
exports.default = Controller;
Controller.description = 'create a new ZenTS controller class.';
Controller.examples = ['$ zen add:controller Product', '$ zen add:controller User'];
Controller.args = [
{
name: 'name',
description: 'name of the controller, e.g. "Product". The "Controller" appendix should be omitted.',
required: true,
},
];
Controller.flags = {
force: command_1.flags.boolean({
char: 'f',
description: 'force creation, eventually overwriting existing file',
default: false,
}),
};