UNPKG

@cuba-platform/front-generator

Version:
86 lines 4.03 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const generation_1 = require("../../../common/generation"); const params_1 = require("./params"); exports.params = params_1.entityManagementGeneratorParams; const cli_options_1 = require("../../../common/cli-options"); exports.options = cli_options_1.polymerElementOptionsConfig; const path = require("path"); const utils_1 = require("../../../common/utils"); const entity_edit_1 = require("../entity-edit"); class Polymer2EntityManagementGenerator extends generation_1.BaseGenerator { constructor(args, options) { super(args, options); this.sourceRoot(path.join(__dirname, 'template')); } // noinspection JSUnusedGlobalSymbols prompting() { return __awaiter(this, void 0, void 0, function* () { yield this._promptOrParse(); }); } // noinspection JSUnusedGlobalSymbols writing() { this.log(`Generating to ${this.destinationPath()}`); if (!this.answers) { throw new Error('Answers not provided'); } this.model = answersToManagementModel(this.answers, this.options.dirShift); this.fs.copyTpl(this.templatePath('entity-management.html'), this.destinationPath(this.model.componentName + '.html'), this.model); this.fs.copyTpl(this.templatePath(`../../entity-${this.model.listType}/template/entity-${this.model.listType}.html`), this.destinationPath(this.model.listComponentName + '.html'), answersToListModel(this.answers, this.options.dirShift)); this.fs.copyTpl(this.templatePath(`../../entity-edit/template/entity-edit.html`), this.destinationPath(this.model.editComponentName + '.html'), answersToEditModel(this.answers, this.options.dirShift)); } end() { this.log(`Entity list have been successfully generated into ${this.destinationRoot()}`); } _getParams() { return params_1.entityManagementGeneratorParams; } _getAvailableOptions() { return cli_options_1.polymerElementOptionsConfig; } } exports.generator = Polymer2EntityManagementGenerator; function answersToManagementModel(answers, dirShift) { return { componentName: answers.managementComponentName, className: utils_1.elementNameToClass(answers.managementComponentName), relDirShift: dirShift || '', listComponentName: answers.listComponentName, editComponentName: answers.editComponentName, listType: answers.listType }; } exports.answersToManagementModel = answersToManagementModel; function answersToListModel(answers, dirShift) { return { componentName: answers.listComponentName, className: utils_1.elementNameToClass(answers.listComponentName), relDirShift: dirShift || '', entity: answers.entity, view: answers.listView }; } exports.answersToListModel = answersToListModel; function answersToEditModel(answers, dirShift) { const { fields, imports } = entity_edit_1.composeEditFields(answers.entity, answers.editView); return { fields, imports, componentName: answers.editComponentName, className: utils_1.elementNameToClass(answers.editComponentName), relDirShift: dirShift || '', view: answers.editView, entity: answers.entity, }; } exports.answersToEditModel = answersToEditModel; //# sourceMappingURL=index.js.map