UNPKG

@shagital/adonisjs-crud-generator

Version:

Adonisjs Admin Panel Generator is a package that helps you quickly scaffold your typical CRUD admin interfaces. It generates the admin panel code based on the existing (migrated) table in the database

70 lines (69 loc) 3.62 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const standalone_1 = require("@adonisjs/core/build/standalone"); const helpers_1 = require("../common/helpers"); const util_1 = __importDefault(require("util")); const execSync = util_1.default.promisify(require('child_process').execSync); class CrudGenerator extends standalone_1.BaseCommand { async run() { const dbInstance = this.application.container.use('Adonis/Lucid/Database'); if (this.connection) { (0, helpers_1.validateConnection)(dbInstance, this.application.config, this.connection); } const tableColumns = (0, helpers_1.getTableColumnsAndTypes)(dbInstance, this.application.config); let tableName = this.table; // this is just to check if the table exists and fail at this point await tableColumns(tableName, this.connection); execSync(`node ace crud:model ${tableName} ${this.connection ? `--connection=${this.connection}` : ``}`, (_e, _stdout, _stderr) => { }); execSync(`node ace crud:controller ${tableName} ${this.connection ? `--connection=${this.connection}` : ``}`, (_e, _stdout, _stderr) => { }); execSync(`node ace crud:permission ${tableName} ${this.migrate ? '--migrate' : ''} ${this.connection ? `--connection=${this.connection}` : ``}`, (_e, _stdout, _stderr) => { }); execSync(`node ace crud:view ${tableName} ${this.connection ? `--connection=${this.connection}` : ``}`, (_e, _stdout, _stderr) => { }); this.logger.info('Done'); process.exit(); } } /** * Command name is used to run the command */ CrudGenerator.commandName = 'crud:generate'; /** * Command description is displayed in the "help" output */ CrudGenerator.description = 'Generate CRUD for a table'; CrudGenerator.settings = { /** * Set the following value to true, if you want to load the application * before running the command */ loadApp: true, /** * Set the following value to true, if you want this command to keep running until * you manually decide to exit the process */ stayAlive: false, }; __decorate([ standalone_1.args.string({ description: 'Table to generate CRUD for' }), __metadata("design:type", String) ], CrudGenerator.prototype, "table", void 0); __decorate([ standalone_1.flags.boolean({ description: 'Automatically run newly created migration' }), __metadata("design:type", Boolean) ], CrudGenerator.prototype, "migrate", void 0); __decorate([ standalone_1.flags.string({ description: 'Specify custom DB connection to use' }), __metadata("design:type", String) ], CrudGenerator.prototype, "connection", void 0); exports.default = CrudGenerator;