ts-morpheus
    Preparing search index...

    ts-morpheus

    ts-morpheus

    Node.js CI

    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.

    • 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
    npm install ts-morpheus
    # or
    yarn add ts-morpheus

    Peer Dependencies:

    • ts-morph: ^27.0.0

    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

    The 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
    
    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

    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/

    • ts-morph - TypeScript Compiler API wrapper
    • Angular - The web framework this library is designed to work with