UNPKG

@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

32 lines 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EnforceUseFormControlOrderRule = EnforceUseFormControlOrderRule; const schematics_utilities_1 = require("@rxap/schematics-utilities"); const ts_morph_transform_1 = require("../ts-morph-transform"); function EnforceUseFormControlOrderRule(options) { const { formName } = options; const className = (0, schematics_utilities_1.CoerceSuffix)((0, schematics_utilities_1.classify)(formName), 'Form'); return (0, ts_morph_transform_1.TsMorphAngularProjectTransformRule)(options, (project) => { const sourceFile = project.getSourceFileOrThrow('/' + (0, schematics_utilities_1.CoerceSuffix)(formName, '.form.ts')); const classDeclaration = sourceFile.getClassOrThrow(className); for (const propertyDeclaration of classDeclaration.getProperties()) { const decoratorCount = propertyDeclaration.getDecorators().length; if (decoratorCount === 1) { continue; } const useFormControlDecorator = propertyDeclaration.getDecorator('UseFormControl'); if (useFormControlDecorator) { const useFormControlIndex = useFormControlDecorator.getChildIndex(); if (useFormControlIndex !== decoratorCount - 1) { const args = useFormControlDecorator.getArguments().map((a) => a.getText()); useFormControlDecorator.remove(); propertyDeclaration.addDecorator({ name: 'UseFormControl', arguments: args, }); } } } }); } //# sourceMappingURL=enforce-use-form-control-order.js.map