@wise/wds-codemods 1.0.0-experimental-1fe0062 → 1.0.0-experimental-4bcf6a2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,17 +3,19 @@
3
3
  # WDS Codemods
4
4
 
5
5
  > WDS Codemods is a collection of codemod scripts designed to automate codebase transformations
6
- > specifically for the Wise Design System. This package leverages the power of [jscodeshift](https://github.com/facebook/jscodeshift)
7
- > to perform AST-based code modifications, enabling large-scale refactoring and updates
8
- > with minimal manual effort.
6
+ > specifically for the Wise Design System. This package provides two types of transforms:
7
+ > **[jscodeshift](https://github.com/facebook/jscodeshift)** and **[Claude AI](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk)**,
8
+ > enabling large-scale refactoring and updates with minimal manual effort.
9
9
 
10
10
  ## Table of Contents
11
11
 
12
12
  - [The Repository](#-the-repository)
13
- - [Getting started](#-getting-started)
14
- - [Commands](#commands)
15
- - [Key Features](#-key-features)
13
+ - [Getting Started](#-getting-started)
14
+ - [CLI Options](#cli-options)
16
15
  - [Available Transforms](#-available-transforms)
16
+ - [Button Transform](./button.md)
17
+ - [ListItem Transform](./list-item.md)
18
+ - [Key Features](#-key-features)
17
19
  - [Working with the Project Locally](#-working-with-the-project-locally)
18
20
  - [Writing Codemod Transforms](#-writing-codemod-transforms)
19
21
  - [Developer Documentation](#-developer-documentation)
@@ -26,12 +28,11 @@ The project provides a flexible CLI interface that allows you to run codemods ei
26
28
  via prompts or directly through command-line arguments. It includes intelligent package validation,
27
29
  monorepo support, and comprehensive reporting for manual review cases.
28
30
 
29
- ## 🚀 Getting started
31
+ ## 🚀 Getting Started
30
32
 
31
- You can run codemods against your project in two ways: using interactive prompts or via CLI
32
- arguments. Here's how to do both:
33
+ ### Installation
33
34
 
34
- ### To get started, install the package
35
+ Install globally for convenience:
35
36
 
36
37
  ```bash
37
38
  # Using npm
@@ -44,7 +45,7 @@ pnpm add -g @wise/wds-codemods
44
45
  yarn global add @wise/wds-codemods
45
46
  ```
46
47
 
47
- Or, if you prefer, you can run it directly without installing globally:
48
+ Or run directly without installing:
48
49
 
49
50
  ```bash
50
51
  # Using npx
@@ -57,53 +58,60 @@ pnpm dlx @wise/wds-codemods
57
58
  yarn dlx @wise/wds-codemods
58
59
  ```
59
60
 
60
- ### Using Interactive Prompts
61
+ ### Running Codemods
61
62
 
62
- Simply run the codemod runner without any arguments:
63
+ You can run codemods in two ways:
63
64
 
64
- ```bash
65
- wds-codemods
66
- ```
65
+ #### Interactive Mode
67
66
 
68
- Or, if you prefer, you can run it directly using `npx` without installing globally:
67
+ Run without arguments to get interactive prompts:
69
68
 
70
69
  ```bash
71
- npx wds-codemods
70
+ wds-codemods
72
71
  ```
73
72
 
74
- You will be prompted to:
73
+ You'll be prompted to:
75
74
 
76
- - Select a codemod transform from the available list.
77
- - Enter the target directory or file path to apply the codemod.
78
- - Choose whether to run in dry mode (no files are modified).
79
- - Choose whether to print the transformed source code to the console.
80
- - Configure monorepo detection (automatically detected in most cases).
75
+ 1. Select a transform (`button` or `list-item`)
76
+ 2. Enter target directory or file path
77
+ 3. Choose dry-run mode (preview without writing) (🔘 `button` only)
78
+ 4. Choose whether to print transformed output
79
+ 5. Configure monorepo detection (auto-detected in most cases)
80
+ 6. Answer transform-specific configuration questions (🔘 `button` only)
81
81
 
82
- ### Using CLI Arguments
82
+ #### Direct CLI Mode
83
83
 
84
- You can also run codemods directly by providing arguments:
84
+ Run with arguments for automation:
85
85
 
86
86
  ```bash
87
- wds-codemods <transform> <targetPath> [--dry] [--print] [--monorepo]
87
+ wds-codemods <transform> <targetPath> [options]
88
88
  ```
89
89
 
90
- Or using package runners:
90
+ Example:
91
91
 
92
92
  ```bash
93
- npx @wise/wds-codemods <transform> <targetPath> [--dry] [--print] [--monorepo]
93
+ wds-codemods button ./src --dry --print
94
94
  ```
95
95
 
96
- ## Commands
96
+ ## CLI Options
97
+
98
+ All codemods support these command-line options:
99
+
100
+ | Option | Description |
101
+ | ----------------------- | ------------------------------------------------------------------------------------------------------------------ |
102
+ | `--print` | Print transformed source to console |
103
+ | `--ignore-pattern=GLOB` | Ignore files matching [glob pattern(s)](https://code.visualstudio.com/docs/editor/glob-patterns) (comma-separated) |
104
+ | `--monorepo` | Enable monorepo package checking across workspace folders |
105
+
106
+ Only button transform supports the following options:
97
107
 
98
- - `npx wds-codemods <transform> <targetPath>`: Run a specific codemod transform on the target path.
99
- - `--dry` or `--dry-run`: Run in dry mode without writing changes to files. This is useful for previewing what changes would be made before actually applying them, allowing you to review the transformations safely.
100
- - `--print`: Print transformed source to the console.
101
- - `--ignore-pattern=GLOB`: Ignore files matching the provided [glob pattern(s)](https://code.visualstudio.com/docs/editor/glob-patterns). Multiple patterns can be comma separated.
102
- - `--gitignore`: Respect `.gitignore` files to ignore files/folders during codemod runs.
103
- - `--no-gitignore`: Do not respect `.gitignore` files.
104
- - `--monorepo`: Enable monorepo package checking across multiple workspace folders.
108
+ | Option | Description |
109
+ | --------------------- | ---------------------------------------- |
110
+ | `--dry` / `--dry-run` | Preview changes without writing to files |
111
+ | `--gitignore` | Respect `.gitignore` files |
112
+ | `--no-gitignore` | Ignore `.gitignore` files |
105
113
 
106
- Examples:
114
+ ### Common Examples
107
115
 
108
116
  ```bash
109
117
  # Basic transform with dry run
@@ -127,73 +135,83 @@ wds-codemods button ./src --print --dry
127
135
 
128
136
  ## 💻 Available Transforms
129
137
 
130
- ### Button Transform (`button`)
138
+ We currently provide two codemods for migrating Wise Design System components:
131
139
 
132
- Migrates `Button` and `ActionButton` components from `@transferwise/components` (v46.5.0+) to the new v2 API.
140
+ ### 🔘 [Button Transform (`button`)](./README-BUTTON.md)
133
141
 
134
- **Key Features:**
142
+ Migrates `Button` and `ActionButton` components from `@transferwise/components` to the new v2 API.
135
143
 
136
- - **ActionButton Migration**: Converts deprecated `ActionButton` to `Button` with `v2` prop and default size
137
- - **Legacy Prop Transformations**:
138
- - `priority`: Maps legacy values to new API (`primary`, `secondary`, `tertiary`, `secondary-neutral`)
139
- - `size`: Converts to new size tokens (`sm`, `md`, `lg`, `xl`)
140
- - `type` & `htmlType`: Handles legacy button types and HTML types appropriately
141
- - `sentiment`: Manages sentiment values with special ControlType handling
142
- - `text`: Converts ActionButton text prop to children
143
- - **Smart Enum Handling**:
144
- - **Preserves** valid `ControlType` enums (`ControlType.NEGATIVE`, `ControlType.POSITIVE`, `ControlType.ACCENT`)
145
- - Converts `Priority` and `Size` enums to string equivalents
146
- - Reports deprecated `Type` enum values for manual review
147
- - **Icon Processing**: Automatically converts icon children to `addonStart`/`addonEnd` props
148
- - **Link Button Support**: Removes `as="a"` and manages `href` attributes properly
149
- - **Configurable Mapping**: Interactive prompts for accent/positive secondary button priority mapping
144
+ - **Engine**: jscodeshift (AST-based transformations)
145
+ - **Prerequisites**: `@transferwise/components >=46.5.0`
150
146
 
151
- **Configuration Options:**
147
+ **What it does:**
152
148
 
153
- During transform execution, you'll be prompted to choose:
149
+ - Converts `ActionButton` + `Button` `Button` with v2 prop
150
+ - Migrates legacy props (`priority`, `size`, `type`, `sentiment`)
151
+ - Processes icon children into addon props
152
+ - Handles link buttons and enum conversions
154
153
 
155
- - `accentSecondaryMapping`: How accent + secondary buttons are mapped (`secondary-neutral` recommended or `secondary`)
156
- - `positiveSecondaryMapping`: How positive + secondary buttons are mapped (`secondary-neutral` recommended or `secondary`)
154
+ **[→ Full Button Transform Documentation](./README-BUTTON.md)**
157
155
 
158
- **Manual Review:**
156
+ ---
157
+
158
+ ### 📋 [ListItem Transform (`list-item`)](./README-LIST-ITEM.md)
159
+
160
+ Migrates legacy `Option` and `Summary` components to `ListItem` component and subcomponents.
161
+
162
+ - **Engine**: Claude AI (context-aware transformations)
163
+ - **Prerequisites**: `@transferwise/components >=46.104.0` + LLM Gateway access
164
+
165
+ **What it does:**
159
166
 
160
- The transform generates a `codemod-report.txt` file for cases requiring manual attention:
167
+ - Converts `ActionOption`, `NavigationOption`, `Summary`, `SwitchOption`, `CheckboxOption`, `RadioOption`, `NavigationOptionList`
168
+ - Maps to `ListItem` + subcomponents (`ListItem.Button`, `ListItem.Checkbox`, etc.)
169
+ - Handles complex state requirements (modals, popovers)
170
+ - Preserves HTML attributes and removes legacy props
161
171
 
162
- - Spread props (`{...props}`)
163
- - Dynamic expressions that cannot be statically analyzed
164
- - Unsupported prop values
165
- - Ambiguous icon children (conditional rendering, complex expressions)
172
+ **[→ Full ListItem Transform Documentation](./README-LIST-ITEM.md)**
166
173
 
167
174
  ---
168
175
 
169
176
  ## 🔧 Key Features
170
177
 
171
- ### Package Requirements Validation
178
+ ### Automatic Package Validation
172
179
 
173
- - **Automatic Dependency Checking**: Validates required packages and versions before running transforms
174
- - **Multi-Package Manager Support**: Works with npm, pnpm, and yarn
175
- - **Smart Detection**: Checks package.json, lockfiles, and node_modules directories
176
- - **Comprehensive Reporting**: Clear feedback when dependencies are missing or incompatible
180
+ Before running any transform, the codemod automatically:
181
+
182
+ - Validates required package versions (e.g., `@transferwise/components >=46.5.0`)
183
+ - Checks `package.json`, lockfiles, and `node_modules`
184
+ - Supports npm, pnpm, and yarn
185
+ - Skips packages that don't meet prerequisites with clear reporting
177
186
 
178
187
  ### Monorepo Support
179
188
 
180
- - **Auto-Detection**: Automatically identifies monorepo structures (packages/, apps/, libs/, etc.)
181
- - **Cross-Package Validation**: Checks dependencies across all workspace packages
182
- - **Summary Reports**: Provides detailed breakdown of which packages have required dependencies
183
- - **Flexible Configuration**: Manual monorepo mode for custom structures
189
+ - Auto-detects monorepo structures (`packages/`, `apps/`, `libs/`, etc.)
190
+ - Validates dependencies across all workspace packages
191
+ - Provides summary reports showing which packages are ready
192
+ - Manual monorepo mode for custom structures
193
+
194
+ ### Manual Review Reporting
195
+
196
+ **🔘 Button transform only:**
197
+
198
+ - Generates `codemod-report.txt` for cases needing manual attention
199
+ - Includes file paths, line numbers, and specific issue descriptions
200
+ - Reports spread props, dynamic expressions, and unsupported values
201
+ - Auto-removes old reports and provides fresh summaries
184
202
 
185
- ### Manual Review Reports
203
+ **📋 ListItem transform:**
186
204
 
187
- - **Automated Report Generation**: Creates `codemod-report.txt` for issues requiring manual attention
188
- - **Detailed Context**: Includes file paths, line numbers, and specific issue descriptions
189
- - **Smart Cleanup**: Automatically removes old reports and provides fresh summaries
190
- - **Issue Categories**: Organised reporting for spread props, dynamic expressions, and unsupported values
205
+ - No report file generated
206
+ - Claude handles complex cases inline
207
+ - Use `--print` to review diffs before applying
191
208
 
192
- ### Intelligent Processing
209
+ ### Smart Processing
193
210
 
194
- - **Selective Execution**: Only runs transforms on projects with compatible dependencies
195
- - **Performance Optimisation**: Caching and efficient directory traversal
196
- - **Robust Error Handling**: Graceful handling of edge cases and invalid configurations
211
+ - Only runs on projects with compatible dependencies
212
+ - Efficient directory traversal and file filtering
213
+ - Graceful error handling for edge cases
214
+ - Performance-optimized for large codebases
197
215
 
198
216
  ---
199
217