@rxap/schematics-xml-parser
Version:
This package provides utilities for parsing XML templates within Angular Schematics. It includes functionality to locate templates in a file system, parse them using a specified DOMParser, and register custom elements for parsing. The package also offers
57 lines • 2.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MethodElement = void 0;
const tslib_1 = require("tslib");
const xml_parser_1 = require("@rxap/xml-parser");
const path_1 = require("path");
const core_1 = require("@angular-devkit/core");
const schematics_utilities_1 = require("@rxap/schematics-utilities");
const schematics_ts_morph_1 = require("@rxap/schematics-ts-morph");
const type_element_1 = require("../type.element");
const { dasherize, classify, camelize, } = core_1.strings;
let MethodElement = class MethodElement {
toValue({ sourceFile, project, }) {
if (this.from) {
(0, schematics_ts_morph_1.CoerceImports)(sourceFile, {
namedImports: [this.name],
moduleSpecifier: this.from,
});
return this.name;
}
else {
const methodName = (0, schematics_utilities_1.CoerceSuffix)(classify(this.name), 'Method');
const methodFilePath = (0, path_1.join)('/methods', `${dasherize(this.name.replace(/[-_\s]?[m|M]ethod$/, ''))}.method.ts`);
const methodSourceFile = (0, schematics_ts_morph_1.CoerceSourceFile)(project, methodFilePath);
const methodOptions = {
statements: [`console.log('${dasherize(methodName)}', parameters);`],
};
if (this.parameterType) {
methodOptions.parameterType = this.parameterType.toValue({ sourceFile: methodSourceFile });
}
(0, schematics_ts_morph_1.CoerceMethodClassLegacy)(methodSourceFile, methodName, methodOptions);
return methodName;
}
}
};
exports.MethodElement = MethodElement;
tslib_1.__decorate([
(0, xml_parser_1.ElementTextContent)(),
(0, xml_parser_1.ElementRequired)(),
tslib_1.__metadata("design:type", String)
], MethodElement.prototype, "name", void 0);
tslib_1.__decorate([
(0, xml_parser_1.ElementAttribute)(),
tslib_1.__metadata("design:type", String)
], MethodElement.prototype, "from", void 0);
tslib_1.__decorate([
(0, xml_parser_1.ElementAttribute)(),
tslib_1.__metadata("design:type", Boolean)
], MethodElement.prototype, "mock", void 0);
tslib_1.__decorate([
(0, xml_parser_1.ElementChild)(type_element_1.TypeElement),
tslib_1.__metadata("design:type", type_element_1.TypeElement)
], MethodElement.prototype, "parameterType", void 0);
exports.MethodElement = MethodElement = tslib_1.__decorate([
(0, xml_parser_1.ElementDef)('method')
], MethodElement);
//# sourceMappingURL=method.element.js.map