@rxap/schematics-ts-morph
Version:
This package provides utilities for manipulating TypeScript code using ts-morph, particularly for Angular and NestJS projects. It offers functions to add, coerce, and modify code elements like classes, methods, decorators, and imports. The package also in
20 lines • 971 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetComponentOptionsObject = GetComponentOptionsObject;
const ts_morph_1 = require("ts-morph");
function GetComponentOptionsObject(sourceFile) {
const classWithComponent = sourceFile.getClasses().find(cls => cls.getDecorator('Component'));
if (!classWithComponent) {
throw new Error('Could not find class with Component decorator!');
}
const componentDecorator = classWithComponent.getDecorator('Component');
let componentOptions = componentDecorator.getArguments()[0];
if (!componentOptions) {
componentOptions = componentDecorator.addArgument(ts_morph_1.Writers.object({}));
}
if (!(componentOptions.isKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression))) {
throw new Error('The Component options is not an object literal expression');
}
return componentOptions;
}
//# sourceMappingURL=get-component-options-object.js.map