Skip to content

Commit 8abdedd

Browse files
authored
refactor: adopt codemod registry naming pattern (#1)
1 parent 98c75bf commit 8abdedd

File tree

14 files changed

+332
-86
lines changed

14 files changed

+332
-86
lines changed

.github/workflows/coverage.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Test & Coverage
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
permissions:
9+
contents: read
10+
id-token: write
11+
checks: write
12+
13+
jobs:
14+
test:
15+
name: Test & Upload Coverage
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: '20.x'
28+
29+
- name: Install pnpm
30+
uses: pnpm/action-setup@v4
31+
with:
32+
version: 8.15.9
33+
34+
- name: Get pnpm store directory
35+
shell: bash
36+
run: |
37+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
38+
39+
- name: Setup pnpm cache
40+
uses: actions/cache@v4
41+
with:
42+
path: ${{ env.STORE_PATH }}
43+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
44+
restore-keys: |
45+
${{ runner.os }}-pnpm-store-
46+
47+
- name: Install dependencies
48+
run: pnpm install --frozen-lockfile
49+
50+
- name: Run tests with coverage
51+
run: pnpm test
52+
53+
- name: Upload coverage to Codecov
54+
uses: codecov/codecov-action@v4
55+
with:
56+
token: ${{ secrets.CODECOV_TOKEN }}
57+
files: ./coverage/lcov.info
58+
flags: unittests
59+
name: codecov-codemod
60+
fail_ci_if_error: true
61+
verbose: true

.github/workflows/publish.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Publish Package
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: 'Distribution tag'
8+
required: true
9+
type: choice
10+
options:
11+
- latest
12+
- next
13+
- rc
14+
- dev
15+
- alpha
16+
- beta
17+
branch:
18+
description: 'Target branch'
19+
required: true
20+
type: choice
21+
options:
22+
- master
23+
- next
24+
25+
permissions:
26+
contents: write
27+
id-token: write
28+
29+
jobs:
30+
publish:
31+
name: Publish to NPM
32+
runs-on: ubuntu-latest
33+
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v4
37+
with:
38+
ref: ${{ inputs.branch }}
39+
fetch-depth: 0
40+
41+
- name: Setup Node.js
42+
uses: actions/setup-node@v4
43+
with:
44+
node-version: '20.x'
45+
registry-url: 'https://registry.npmjs.org'
46+
47+
- name: Install pnpm
48+
uses: pnpm/action-setup@v4
49+
with:
50+
version: 8.15.9
51+
52+
- name: Get pnpm store directory
53+
shell: bash
54+
run: |
55+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
56+
57+
- name: Setup pnpm cache
58+
uses: actions/cache@v4
59+
with:
60+
path: ${{ env.STORE_PATH }}
61+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
62+
restore-keys: |
63+
${{ runner.os }}-pnpm-store-
64+
65+
- name: Install dependencies
66+
run: pnpm install --frozen-lockfile
67+
68+
- name: Build
69+
run: pnpm run build
70+
71+
- name: Run tests
72+
run: pnpm test
73+
74+
- name: Run lint
75+
run: pnpm run lint
76+
77+
- name: Publish to NPM
78+
env:
79+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
80+
NPM_CONFIG_PROVENANCE: true
81+
run: |
82+
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > .npmrc
83+
npm publish --tag ${{ inputs.tag }} --provenance --access public
84+
85+
- name: Create Summary
86+
if: success()
87+
run: |
88+
echo "## ✅ Publication Successful" >> $GITHUB_STEP_SUMMARY
89+
echo "" >> $GITHUB_STEP_SUMMARY
90+
echo "Package published to npm with tag: **${{ inputs.tag }}**" >> $GITHUB_STEP_SUMMARY
91+
echo "" >> $GITHUB_STEP_SUMMARY
92+
echo "### Installation" >> $GITHUB_STEP_SUMMARY
93+
echo '```bash' >> $GITHUB_STEP_SUMMARY
94+
if [ "${{ inputs.tag }}" = "latest" ]; then
95+
echo "npm install @suites/codemod" >> $GITHUB_STEP_SUMMARY
96+
else
97+
echo "npm install @suites/codemod@${{ inputs.tag }}" >> $GITHUB_STEP_SUMMARY
98+
fi
99+
echo '```' >> $GITHUB_STEP_SUMMARY
100+
101+
- name: Create Failure Summary
102+
if: failure()
103+
run: |
104+
echo "## ❌ Publication Failed" >> $GITHUB_STEP_SUMMARY
105+
echo "" >> $GITHUB_STEP_SUMMARY
106+
echo "The package could not be published. Check the logs above for details." >> $GITHUB_STEP_SUMMARY
107+
echo "" >> $GITHUB_STEP_SUMMARY
108+
echo "### Common Issues" >> $GITHUB_STEP_SUMMARY
109+
echo "- Ensure NPM_TOKEN secret is configured correctly" >> $GITHUB_STEP_SUMMARY
110+
echo "- Check if the version already exists on npm" >> $GITHUB_STEP_SUMMARY
111+
echo "- Verify build and tests pass successfully" >> $GITHUB_STEP_SUMMARY

.releaserc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"@semantic-release/git",
6666
{
6767
"assets": ["CHANGELOG.md", "package.json"],
68-
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
68+
"message": "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}"
6969
}
7070
],
7171
"@semantic-release/github"

README.md

Lines changed: 102 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ Automated code transformations for Suites projects. Built on [jscodeshift](https
1010
## Usage
1111

1212
```bash
13-
npx @suites/codemod <path> [options]
13+
npx @suites/codemod <transform> <path> [options]
1414
```
1515

1616
**Example:**
1717
```bash
18-
npx @suites/codemod src/**/*.spec.ts
18+
npx @suites/codemod automock/2/to-suites-v3 src/**/*.spec.ts
1919
```
2020

2121
Run with `--dry-run` to preview changes without modifying files.
2222

2323
## Available Transforms
2424

25-
- **`automock-to-suites`** (default) - Migrate test files from Automock to Suites testing framework
25+
- **`automock/2/to-suites-v3`** - Migrate test files from Automock v2 to Suites v3 testing framework
2626

2727
## Example
2828

@@ -79,20 +79,20 @@ describe('UserService', () => {
7979
**More examples:**
8080
```bash
8181
# Preview changes
82-
npx @suites/codemod src --dry-run
82+
npx @suites/codemod automock/2/to-suites-v3 src --dry-run
8383

8484
# Ignore certain files
85-
npx @suites/codemod src --ignore "**/*.integration.ts"
85+
npx @suites/codemod automock/2/to-suites-v3 src --ignore "**/*.integration.ts"
8686

8787
# List all transforms
8888
npx @suites/codemod --list-transforms
8989
```
9090

9191
## Transform Details
9292

93-
### `automock-to-suites`
93+
### `automock/2/to-suites-v3`
9494

95-
Intelligently migrates Automock test files to Suites framework.
95+
Intelligently migrates Automock v2 test files to Suites v3 framework.
9696

9797
**What it transforms:**
9898
- Import statements: `@automock/jest` -> `@suites/unit`
@@ -154,6 +154,32 @@ The codemod uses [jscodeshift](https://github.com/facebook/jscodeshift) to:
154154

155155
**TypeScript Support:** First-class support with fallback parser for complex syntax (generics, type guards, decorators, JSX/TSX).
156156

157+
## Architecture
158+
159+
This codemod follows the **Codemod Registry** pattern used by React, Next.js, and other major frameworks:
160+
161+
**Transform Naming:** `<framework>/<version>/<transform>`
162+
- `automock/2/to-suites-v3` - Current migration
163+
- `automock/3/to-suites-v4` - Future migrations
164+
- Supports multiple transforms per version
165+
- Extensible to other frameworks (e.g., `jest/28/to-v29`)
166+
167+
**Directory Structure:**
168+
```
169+
src/transforms/
170+
automock/ # Framework namespace
171+
2/ # Source version
172+
to-suites-v3.ts # Migration transform
173+
3/ # Future: next version
174+
to-suites-v4.ts
175+
```
176+
177+
**Design Benefits:**
178+
- No default transform - explicit selection prevents mistakes
179+
- Version-based organization supports migration chains
180+
- Framework namespacing allows multi-framework support
181+
- Clear source → target versioning
182+
157183
## Contributing
158184

159185
Contributions welcome! To contribute:
@@ -167,18 +193,36 @@ Contributions welcome! To contribute:
167193

168194
### Adding New Transforms
169195

170-
1. Create transform file in `src/transforms/`
171-
2. Register in `src/transforms/index.ts`
172-
3. Add test fixtures in `fixtures/`
173-
4. Add integration tests in `test/integration/`
174-
5. Update this README
196+
1. Create transform directory: `src/transforms/<framework>/<version>/<transform-name>.ts`
197+
2. Export `applyTransform` function from your transform
198+
3. Register in `src/transforms/index.ts`:
199+
```typescript
200+
{
201+
name: 'framework/version/transform-name',
202+
description: 'Description of what it does',
203+
path: './transforms/framework/version/transform-name',
204+
}
205+
```
206+
4. Add test fixtures in `fixtures/`
207+
5. Add integration tests in `test/integration/`
208+
6. Update this README
209+
210+
**Example:**
211+
```typescript
212+
// src/transforms/automock/3/to-suites-v4.ts
213+
export { applyTransform } from '../../../transform';
214+
```
175215

176216
### Project Structure
177217

178218
```
179219
src/
180220
analyzers/ # Code analysis utilities
181221
transforms/ # Transform implementations
222+
automock/ # Framework namespace
223+
2/ # Version-specific transforms
224+
to-suites-v3.ts
225+
index.ts # Transform registry
182226
validators/ # Post-transform validation
183227
utils/ # Shared utilities
184228
cli.ts # CLI interface
@@ -191,6 +235,52 @@ test/
191235
fixtures/ # Test fixtures (before/after)
192236
```
193237

238+
## Local Development
239+
240+
### Running Locally
241+
242+
From within the codemod repository:
243+
244+
```bash
245+
# Build first
246+
pnpm build
247+
248+
# Run on a target repository
249+
node dist/cli.js automock/2/to-suites-v3 /path/to/repo --dry-run
250+
251+
# Run on test fixtures
252+
node dist/cli.js automock/2/to-suites-v3 fixtures/simple-final --dry-run
253+
254+
# Verbose output for debugging
255+
node dist/cli.js automock/2/to-suites-v3 /path/to/repo --dry-run --verbose
256+
```
257+
258+
### Using npm link for Testing
259+
260+
```bash
261+
# In the codemod repo
262+
npm link
263+
264+
# Now use it anywhere like npx
265+
codemod automock/2/to-suites-v3 /path/to/repo --dry-run
266+
267+
# Unlink when done
268+
npm unlink -g @suites/codemod
269+
```
270+
271+
### Running Tests
272+
273+
```bash
274+
# All tests
275+
pnpm test
276+
277+
# Specific test file
278+
pnpm test path/to/test.spec.ts
279+
280+
# With coverage
281+
pnpm test --coverage
282+
```
283+
194284
## License
195285

196286
MIT (c) [Omer Morad](https://github.com/omermorad)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@
7777
"typescript"
7878
],
7979
"publishConfig": {
80-
"registry": "http://localhost:4873",
81-
"access": "public"
80+
"access": "public",
81+
"provenance": true
8282
},
8383
"packageManager": "pnpm@8.15.9"
8484
}

0 commit comments

Comments
 (0)