refactorwave
v1.0.0
Published
TypeScript CLI tool for automated code refactoring
Maintainers
Readme
RefactorWave
RefactorWave is a powerful TypeScript CLI tool for automating code refactoring. It allows you to create refactoring rules, preview changes, and roll back changes when needed.
Features
- Refactoring Rules: Create and manage rules to automate code changes
- Preview: Review changes before applying them
- Rollback System: Create backups and revert changes
- Flexible Configuration: Customize rules to fit your needs
- Multi-Language Support: JavaScript, TypeScript, and more
Quick Start
Installation
# Using npm
npm install refactorwave
# Using yarn
yarn add refactorwave
# Using pnpm
pnpm add refactorwave
# Using bun
bun add refactorwaveUsage
Initialize Project
npx refactorwave initView Available Rules
npx refactorwave rules --listPreview Changes
npx refactorwave apply "**/*.js" --previewApply Refactoring
# With backup creation
npx refactorwave apply "**/*.js" --backup
# Apply a specific rule
npx refactorwave apply "**/*.js" --rule var-to-let-constManage Rules
# Enable a rule
npx refactorwave rules --enable var-to-let-const
# Disable a rule
npx refactorwave rules --disable remove-console-log
# Add a new rule
npx refactorwave rules --add ./examples/my-rule.jsonRoll Back Changes
# Show available backups
npx refactorwave rollback --list
# Restore from a backup
npx refactorwave rollback --restore backup_1234567890Creating Refactoring Rules
Refactoring rules are defined in JSON format:
{
"name": "var-to-let-const",
"description": "Replace var with let/const",
"enabled": true,
"filePatterns": ["*.js", "*.ts"],
"conditions": [
{
"type": "contains",
"value": "var "
}
],
"transformations": [
{
"type": "replace",
"pattern": "\\bvar\\b",
"replacement": "let",
"flags": "g"
}
],
"priority": 1
}Rule Structure
- name: Unique rule name
- description: Rule description
- enabled: Whether the rule is active
- filePatterns: File patterns to apply the rule to
- conditions: Conditions for applying the rule
- transformations: List of transformations
- priority: Execution priority
