UNPKG

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.

53 lines (52 loc) 2.44 kB
"use strict"; 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 Entity extends AbstractCommand_1.AbstractCommand { async run() { var _a, _b, _c, _d, _e; const { args, flags } = this.parse(Entity); this.welcome('Create a ZenTS entity!'); const filename = `${args.name}.ts`; const config = await this.getZenConfig(); const entityPath = 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.entity) === 'string' ? path_1.join(config.config.paths.base.src, config.config.paths.entity) : path_1.join(process.cwd(), 'src', 'entity'); if (!(await doesDirOrFileExists_1.doesDirOrFileExists(entityPath))) { this.log(log_1.error(`Entity directory "${entityPath}" doesn't exist!`)); process.exit(42); } else if (!flags.force && (await doesDirOrFileExists_1.doesDirOrFileExists(path_1.join(entityPath, filename)))) { this.log(log_1.error(`Entity file "${path_1.join(entityPath, filename)}" already exists. Use --force flag to overwrite this file.`)); process.exit(42); } await this.generate('Entity', { cwd: process.cwd(), filename, name: args.name, entityPath, }); this.log(log_1.success(`New ZenTS service created successfully (${path_1.join(entityPath, filename)})`)); } } exports.default = Entity; Entity.description = 'create a new ZenTS/TypeORM entity class.'; Entity.examples = ['$ zen add:entity Product', '$ zen add:entity User']; Entity.args = [ { name: 'name', description: 'name of the entity, e.g. "Product"', required: true, }, ]; Entity.flags = { force: command_1.flags.boolean({ char: 'f', description: 'force creation, eventually overwriting existing file', default: false, }), };