-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nx): inroduce the
@mutates/nx
package
- Loading branch information
Showing
27 changed files
with
769 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,138 @@ | ||
# Mutates | ||
|
||
Mutates is a fork of [ng-morph](https://github.com/taiga-family/ng-morph) that is focused on | ||
mutating the AST of Angular components. | ||
🚀 **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. | ||
|
||
The biggest difference is that this fork is not focused on Angular specific transformations. | ||
`Mutates` is a set of tools that can be used to mutate the AST of any TypeScript file. | ||
## Features | ||
|
||
All framework-specific transformations have been moved to separate packages (e.g. | ||
`@mutates/angular`). | ||
✨ **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. | ||
|
||
The main package is `@mutates/core` which provides the core functionality for mutating the AST of | ||
TypeScript files. | ||
## 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: | ||
|
||
```sh | ||
npm install @mutates/core | ||
``` | ||
|
||
For Angular-specific transformations, install the Angular package as well: | ||
|
||
```sh | ||
npm install @mutates/angular @mutates/core | ||
``` | ||
|
||
For Nx-specific transformations, install the Nx package: | ||
|
||
```sh | ||
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: | ||
|
||
```typescript | ||
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`: | ||
|
||
```typescript | ||
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](./LICENSE) file for more | ||
information. | ||
|
||
--- | ||
|
||
For more detailed documentation, please visit the | ||
[official documentation](https://mutates.katsuba.dev). | ||
|
||
For further assistance or to report issues, please visit | ||
[GitHub repository](https://github.com/ikatsuba/mutates). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: '@mutates/angular' | ||
nextjs: | ||
metadata: | ||
title: '@mutates/angular' | ||
description: How to install `@mutates/angular` and get started. | ||
--- | ||
|
||
WIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: '@mutates/core' | ||
nextjs: | ||
metadata: | ||
title: '@mutates/core' | ||
description: How to install `@mutates/core` and get started. | ||
--- | ||
|
||
WIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: '@mutates/nx' | ||
nextjs: | ||
metadata: | ||
title: '@mutates/nx' | ||
description: How to install `@mutates/nx` and get started. | ||
--- | ||
|
||
WIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.