GithubHelp home page GithubHelp logo

ikatsuba / mutates Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 0.0 2.06 MB

Still afraid to do something with AST? Mutates the AST, not your brain.

Home Page: https://mutates.katsuba.dev/

License: Apache License 2.0

Shell 0.13% JavaScript 2.62% TypeScript 97.26%
angular ast code-migration generators nx schematics ts-morph typescript

mutates's Introduction

Mutates

๐Ÿš€ Mutates is a powerful toolset for mutating the Abstract Syntax Tree (AST) of TypeScript files. It is a fork of ng-morph, with a broader focus beyond Angular-specific transformations, allowing for extensive AST modifications in any TypeScript project.

Features

โœจ AST Mutations: Modify the AST of any TypeScript file.
๐ŸŒ Framework-Agnostic: Not limited to Angular; can be used with any TypeScript-based project.
๐Ÿ”ง Extensible: Framework-specific transformations are available through separate packages.

Packages

Core Package

@mutates/core

The core package provides the essential functionalities needed to manipulate the AST of TypeScript files. It serves as the foundation for other specialized packages.

Framework-Specific Packages

Framework-specific transformations have been decoupled from the core package and are available as separate packages. For example:

@mutates/angular

This package includes transformations specific to Angular projects, leveraging the capabilities of @mutates/core to provide Angular-focused AST modifications.

@mutates/nx

This package includes transformations specific to Nx workspaces, allowing for Nx-specific filesystem operations and AST modifications.

Installation

To install the core package, use the following command:

npm install @mutates/core

For Angular-specific transformations, install the Angular package as well:

npm install @mutates/angular @mutates/core

For Nx-specific transformations, install the Nx package:

npm install @mutates/nx @mutates/core

Usage

Basic Example

Here is a simple example demonstrating how to use @mutates/core to modify a TypeScript file:

import { addFunctions, creataProject, createSourceFile, saveProject } from '@mutates/core';

// Initialize a new project
createProject();

// Add a TypeScript file to the project
createSourceFile(
  'example.ts',
  `
  const greet = (name: string) => {
    return 'Hello, ' + name;
  };
`,
);

// Perform some transformations
addFunctions('example.ts', {
  name: 'farewell',
  isExported: true,
  statements: "return 'buy!'",
});

// Save the modified file
saveProject();

Angular Example

To perform Angular-specific transformations, use @mutates/angular along with @mutates/core:

import { addProviders, getComponents } from '@mutates/angular';
import { createProject, createSourceFile, saveProject } from '@mutates/core';

// Initialize a new Angular project
createProject();

// Add an Angular component file to the project
createSourceFile(
  'app.component.ts',
  `
  import { Component } from '@angular/core';

  @Component({
    selector: 'app-root',
    template: '<h1>Hello, World!</h1>'
  })
  export class AppComponent {}
`,
);

// Perform some Angular-specific transformations
addProviders(getComponents('app.component.ts').at(0)!, ['AppService']);

// Save the modified file
saveProject();

Contributing

๐Ÿค Contributions are welcome! If you have any improvements or suggestions, feel free to open an issue or submit a pull request.

License

๐Ÿ“„ Mutates is licensed under the Apache-2.0 License. See the LICENSE file for more information.


For more detailed documentation, please visit the official documentation.

For further assistance or to report issues, please visit GitHub repository.

mutates's People

Contributors

ikatsuba avatar

Stargazers

Azhar avatar Jakub Jatczak avatar Alex Skoropad avatar Ildar Asanov avatar  avatar Tim avatar Airat Khairullin avatar SuperOleg39 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.