https://github.com/evg4b/ts-morpheus
A TypeScript library that provides utilities for working with Angular code using ts-morph
https://github.com/evg4b/ts-morpheus
angular ast code-analysis refactoring ts-morph typescript
Last synced: 4 months ago
JSON representation
A TypeScript library that provides utilities for working with Angular code using ts-morph
- Host: GitHub
- URL: https://github.com/evg4b/ts-morpheus
- Owner: evg4b
- Created: 2025-09-17T17:27:00.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-10-26T21:52:54.000Z (7 months ago)
- Last Synced: 2025-10-26T23:30:48.369Z (7 months ago)
- Topics: angular, ast, code-analysis, refactoring, ts-morph, typescript
- Language: TypeScript
- Homepage: https://evg4b.github.io/ts-morpheus/
- Size: 76.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ts-morpheus
[](https://github.com/evg4b/ts-morpheus/actions/workflows/node.js.yml)
A TypeScript library that provides utilities for working with Angular code
using [ts-morph](https://github.com/dsherret/ts-morph). This library offers a collection of helper functions to analyze,
manipulate, and transform Angular TypeScript code programmatically.
## Features
- **Angular Component Analysis**: Detect and work with Angular components, directives, pipes, modules, and services
- **Import Management**: Add, remove, and modify TypeScript imports declaratively
- **Type-Safe**: Built with TypeScript for full type safety
- **ts-morph Integration**: Seamlessly works with ts-morph AST manipulation
## Installation
```bash
npm install ts-morpheus
# or
yarn add ts-morpheus
```
**Peer Dependencies:**
- `ts-morph`: ^27.0.0
## Modules
The library is organized into two main modules:
- **`ts-morpheus/angular`** - Angular-specific utilities for components, directives, pipes, modules, and services
- **`ts-morpheus/common`** - Common utilities for import management and general TypeScript manipulation
## Usage
### Angular Components
The `ts-morpheus/angular` module provides utilities for working with Angular-specific constructs:
```typescript
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);
```
### Import Management
The `ts-morpheus/common` module provides utilities for managing TypeScript imports:
```typescript
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']);
```
## Development
### Scripts
```bash
# 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
```
### Testing
The project uses [rstest](https://github.com/rsuite/rstest) for testing. Run tests with:
```bash
yarn test
```
## Contributing
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## API Reference
Full API documentation is available at [https://evg4b.github.io/ts-morpheus/](https://evg4b.github.io/ts-morpheus/)
## Related Projects
- [ts-morph](https://github.com/dsherret/ts-morph) - TypeScript Compiler API wrapper
- [Angular](https://angular.io/) - The web framework this library is designed to work with