@taiga-ui/cdk
Version:
Base library for creating Angular components and applications using Taiga UI principles regarding of actual visual appearance
41 lines • 2.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.replaceAttrsInHost = replaceAttrsInHost;
const core_1 = require("@angular-devkit/core");
const ng_morph_1 = require("ng-morph");
const ts_morph_1 = require("ts-morph");
const constants_1 = require("../../constants");
function replaceAttrsInHost(fileSystem, replaceable, pattern = constants_1.ALL_TS_FILES) {
const classes = (0, ng_morph_1.getClasses)(pattern);
const components = (0, ng_morph_1.getDecorators)(classes, { name: 'Component' });
components.forEach((component) => {
var _a, _b, _c, _d;
const argument = (_a = component
.getArguments()[0]) === null || _a === void 0 ? void 0 : _a.asKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
if (!argument) {
return;
}
const host = (_c = (_b = argument === null || argument === void 0 ? void 0 : argument.getProperty) === null || _b === void 0 ? void 0 : _b.call(argument, 'host')) === null || _c === void 0 ? void 0 : _c.asKind(ts_morph_1.SyntaxKind.PropertyAssignment);
if (host) {
const initializer = (_d = host
.getInitializer()) === null || _d === void 0 ? void 0 : _d.asKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
const path = (0, core_1.normalize)(component.getSourceFile().getFilePath());
const recorder = fileSystem.edit(path);
if (initializer) {
replaceable.forEach(({ from, to }) => {
const oldProperty = initializer.getProperty(`'${from}'`) ||
initializer.getProperty(`"${from}"`);
if (ts_morph_1.Node.isPropertyAssignment(oldProperty)) {
const nameNode = oldProperty.getNameNode();
const start = nameNode.getStart();
const width = nameNode.getWidth();
recorder.remove(start, width);
recorder.insertLeft(start, `'${to}'`);
}
});
}
}
});
fileSystem.commitEdits();
}
//# sourceMappingURL=replace-attrs-in-host.js.map