|
1 | 1 | # Mutates
|
2 | 2 |
|
3 |
| -Mutates is a fork of [ng-morph](https://github.com/taiga-family/ng-morph) that is focused on |
4 |
| -mutating the AST of Angular components. |
| 3 | +🚀 **Mutates** is a powerful toolset for mutating the Abstract Syntax Tree (AST) of TypeScript |
| 4 | +files. It is a fork of `ng-morph`, with a broader focus beyond Angular-specific transformations, |
| 5 | +allowing for extensive AST modifications in any TypeScript project. |
5 | 6 |
|
6 |
| -The biggest difference is that this fork is not focused on Angular specific transformations. |
7 |
| -`Mutates` is a set of tools that can be used to mutate the AST of any TypeScript file. |
| 7 | +## Features |
8 | 8 |
|
9 |
| -All framework-specific transformations have been moved to separate packages (e.g. |
10 |
| -`@mutates/angular`). |
| 9 | +✨ **AST Mutations:** Modify the AST of any TypeScript file. |
| 10 | +🌐 **Framework-Agnostic:** Not limited to Angular; can be used with any TypeScript-based project. |
| 11 | +🔧 **Extensible:** Framework-specific transformations are available through separate packages. |
11 | 12 |
|
12 |
| -The main package is `@mutates/core` which provides the core functionality for mutating the AST of |
13 |
| -TypeScript files. |
| 13 | +## Packages |
| 14 | + |
| 15 | +### Core Package |
| 16 | + |
| 17 | +#### @mutates/core |
| 18 | + |
| 19 | +The core package provides the essential functionalities needed to manipulate the AST of TypeScript |
| 20 | +files. It serves as the foundation for other specialized packages. |
| 21 | + |
| 22 | +### Framework-Specific Packages |
| 23 | + |
| 24 | +Framework-specific transformations have been decoupled from the core package and are available as |
| 25 | +separate packages. For example: |
| 26 | + |
| 27 | +#### @mutates/angular |
| 28 | + |
| 29 | +This package includes transformations specific to Angular projects, leveraging the capabilities of |
| 30 | +`@mutates/core` to provide Angular-focused AST modifications. |
| 31 | + |
| 32 | +#### @mutates/nx |
| 33 | + |
| 34 | +This package includes transformations specific to Nx workspaces, allowing for Nx-specific filesystem |
| 35 | +operations and AST modifications. |
| 36 | + |
| 37 | +## Installation |
| 38 | + |
| 39 | +To install the core package, use the following command: |
| 40 | + |
| 41 | +```sh |
| 42 | +npm install @mutates/core |
| 43 | +``` |
| 44 | + |
| 45 | +For Angular-specific transformations, install the Angular package as well: |
| 46 | + |
| 47 | +```sh |
| 48 | +npm install @mutates/angular @mutates/core |
| 49 | +``` |
| 50 | + |
| 51 | +For Nx-specific transformations, install the Nx package: |
| 52 | + |
| 53 | +```sh |
| 54 | +npm install @mutates/nx @mutates/core |
| 55 | +``` |
| 56 | + |
| 57 | +## Usage |
| 58 | + |
| 59 | +### Basic Example |
| 60 | + |
| 61 | +Here is a simple example demonstrating how to use `@mutates/core` to modify a TypeScript file: |
| 62 | + |
| 63 | +```typescript |
| 64 | +import { addFunctions, creataProject, createSourceFile, saveProject } from '@mutates/core'; |
| 65 | + |
| 66 | +// Initialize a new project |
| 67 | +createProject(); |
| 68 | + |
| 69 | +// Add a TypeScript file to the project |
| 70 | +createSourceFile( |
| 71 | + 'example.ts', |
| 72 | + ` |
| 73 | + const greet = (name: string) => { |
| 74 | + return 'Hello, ' + name; |
| 75 | + }; |
| 76 | +`, |
| 77 | +); |
| 78 | + |
| 79 | +// Perform some transformations |
| 80 | +addFunctions('example.ts', { |
| 81 | + name: 'farewell', |
| 82 | + isExported: true, |
| 83 | + statements: "return 'buy!'", |
| 84 | +}); |
| 85 | + |
| 86 | +// Save the modified file |
| 87 | +saveProject(); |
| 88 | +``` |
| 89 | + |
| 90 | +### Angular Example |
| 91 | + |
| 92 | +To perform Angular-specific transformations, use `@mutates/angular` along with `@mutates/core`: |
| 93 | + |
| 94 | +```typescript |
| 95 | +import { addProviders, getComponents } from '@mutates/angular'; |
| 96 | +import { createProject, createSourceFile, saveProject } from '@mutates/core'; |
| 97 | + |
| 98 | +// Initialize a new Angular project |
| 99 | +createProject(); |
| 100 | + |
| 101 | +// Add an Angular component file to the project |
| 102 | +createSourceFile( |
| 103 | + 'app.component.ts', |
| 104 | + ` |
| 105 | + import { Component } from '@angular/core'; |
| 106 | +
|
| 107 | + @Component({ |
| 108 | + selector: 'app-root', |
| 109 | + template: '<h1>Hello, World!</h1>' |
| 110 | + }) |
| 111 | + export class AppComponent {} |
| 112 | +`, |
| 113 | +); |
| 114 | + |
| 115 | +// Perform some Angular-specific transformations |
| 116 | +addProviders(getComponents('app.component.ts').at(0)!, ['AppService']); |
| 117 | + |
| 118 | +// Save the modified file |
| 119 | +saveProject(); |
| 120 | +``` |
| 121 | + |
| 122 | +## Contributing |
| 123 | + |
| 124 | +🤝 Contributions are welcome! If you have any improvements or suggestions, feel free to open an |
| 125 | +issue or submit a pull request. |
| 126 | + |
| 127 | +## License |
| 128 | + |
| 129 | +📄 Mutates is licensed under the Apache-2.0 License. See the [LICENSE](./LICENSE) file for more |
| 130 | +information. |
| 131 | + |
| 132 | +--- |
| 133 | + |
| 134 | +For more detailed documentation, please visit the |
| 135 | +[official documentation](https://mutates.katsuba.dev). |
| 136 | + |
| 137 | +For further assistance or to report issues, please visit |
| 138 | +[GitHub repository](https://github.com/ikatsuba/mutates). |
0 commit comments