A TypeScript library that provides utilities for working with Angular code using ts-morph. This library offers a collection of helper functions to analyze, manipulate, and transform Angular TypeScript code programmatically.
npm install ts-morpheus
# or
yarn add ts-morpheus
Peer Dependencies:
ts-morph: ^27.0.0The library is organized into two main modules:
ts-morpheus/angular - Angular-specific utilities for components, directives, pipes, modules, and servicests-morpheus/common - Common utilities for import management and general TypeScript manipulationThe ts-morpheus/angular module provides utilities for working with Angular-specific constructs:
import { isAngularComponent, getAngularComponentDecorator } from 'ts-morpheus/angular';
import { Project } from 'ts-morph';
const project = new Project();
const sourceFile = project.addSourceFileAtPath('path/to/component.ts');
const classDeclaration = sourceFile.getClasses()[0];
// Check if class is an Angular component
if (isAngularComponent(classDeclaration)) {
console.log('This is an Angular component!');
}
// Get the @Component decorator
const decorator = getAngularComponentDecorator(classDeclaration);
The ts-morpheus/common module provides utilities for managing TypeScript imports:
import { addImportDeclaration, removeNamedImports } from 'ts-morpheus/common';
import { Project } from 'ts-morph';
const project = new Project();
const sourceFile = project.addSourceFileAtPath('path/to/file.ts');
// Add named imports
addImportDeclaration(sourceFile, {
namedImports: ['Component', 'OnInit'],
module: '@angular/core'
});
// Remove specific named imports
removeNamedImports(sourceFile, '@angular/core', ['OnInit']);
# Build the project
yarn build
# Run tests
yarn test
# Run linting
yarn lint
# Format code
yarn format
# Type checking
yarn check
# Generate documentation
yarn docs
# Development mode (watch)
yarn dev
The project uses rstest for testing. Run tests with:
yarn test
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
Full API documentation is available at https://evg4b.github.io/ts-morpheus/