@cuba-platform/front-generator
Version:
CUBA Platform front-end clients generator
60 lines • 2.63 kB
JavaScript
;
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.serviceDataParams;
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 service_form_1 = require("../service-form");
class ServiceDataGenerator 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 = answersToModel(this.answers, this.options.dirShift);
this.fs.copyTpl(this.templatePath('service-data.html'), this.destinationPath(this.model.componentName + '.html'), this.model);
}
end() {
this.log(`Service data has been successfully generated into ${this.destinationRoot()}`);
}
_getParams() {
return params_1.serviceDataParams;
}
_getAvailableOptions() {
return cli_options_1.polymerElementOptionsConfig;
}
}
exports.generator = ServiceDataGenerator;
function answersToModel(answers, dirShift) {
return {
fields: service_form_1.composeParamFields(answers.serviceMethod.method.params),
componentName: answers.componentName,
className: utils_1.elementNameToClass(answers.componentName),
relDirShift: dirShift || '',
method: answers.serviceMethod.method,
service: answers.serviceMethod.service
};
}
//# sourceMappingURL=index.js.map