@cuba-platform/front-generator
Version:
CUBA Platform front-end clients generator
71 lines • 3.19 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.params = exports.options = exports.generator = void 0;
const base_generator_1 = require("../../../common/base-generator");
const params_1 = require("./params");
Object.defineProperty(exports, "params", { enumerable: true, get: function () { return params_1.queryResultParams; } });
const cli_options_1 = require("../../../common/cli-options");
Object.defineProperty(exports, "options", { enumerable: true, get: function () { return cli_options_1.polymerElementOptionsConfig; } });
const path = require("path");
const utils_1 = require("../../../common/utils");
const rest_params_1 = require("../common/fields/rest-params");
const fields_1 = require("../common/fields");
class QueryResultsGenerator extends base_generator_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('query-result-list.html'), this.destinationPath(this.model.componentName + '.html'), this.model);
}
end() {
this.log(`Query results has been successfully generated into ${this.destinationRoot()}`);
}
_getParams() {
return params_1.queryResultParams;
}
_getAvailableOptions() {
return cli_options_1.polymerElementOptionsConfig;
}
}
exports.generator = QueryResultsGenerator;
function composeParamFields(params) {
if (!params) {
return [];
}
return params
.map(p => (0, rest_params_1.getRestParamFieldModel)(p, "serviceParams."))
.map(m => (0, fields_1.getFieldHtml)(m));
}
function answersToModel(answers, dirShift) {
const fields = composeParamFields(answers.query.params);
return {
fields,
componentName: answers.componentName,
className: (0, utils_1.elementNameToClass)(answers.componentName),
relDirShift: (0, utils_1.normalizeRelativePath)(dirShift),
query: answers.query
};
}
//# sourceMappingURL=index.js.map