|
2 | 2 | <img src=".github/assets/migrations-template.png" alt="<ECOSYSTEM_NAME> Codemods" /> |
3 | 3 | </div> |
4 | 4 |
|
5 | | -This repository serves as a template for open-source migrations, allowing contributors & framework maintainers to quickly whip up a repository for codemods that resolve breaking changes, refactors, and more. |
| 5 | +> **Remove this section once the repo is customized** |
| 6 | +> Framework/SDK maintainers: This template comes with setup guides, utilities, and a GitHub Action to help you and your community build and publish codemods with ease. Once you, the repo maintainers, approve codemod PRs, they’ll be automatically published as official codemods to the [Codemod Registry](https://app.codemod.com/registry) under your org scope. Check out the [Node.js codemods](https://codemod.link/nodejs-official) for an example. See [AUTO_PUBLISH_SETUP.md](.github/AUTO_PUBLISH_SETUP.md) for setup instructions. |
6 | 7 |
|
7 | | -This template repository comes pre-configured with a GitHub workflow that automatically publishes the latest version of your codemods, keeping them up-to-date on [Codemod Registry](https://app.codemod.com/registry). |
| 8 | +This repository contains codemods for <FRAMEWORK_OR_SDK_NAME>. These codemods facilitate adopting new features and upgrading across breaking changes. |
8 | 9 |
|
9 | | -> **Initial setup guide (remove once the repo is customized)** |
10 | | -> |
11 | | -> 1. Search and replace placeholders: |
12 | | -> - `<ECOSYSTEM_NAME>` (e.g., "React", "Node.js", "AcmeLib") |
13 | | -> - `@<NAMESPACE>` (e.g., `acme`) |
14 | | -> - `<MAJOR_VERSION>` (e.g., `v5`) |
15 | | -> 2. Scaffold new codemods under `recipes` and name them like `@<NAMESPACE>/<MAJOR_VERSION> (optional)/<codemod-name>`: |
16 | | -> |
17 | | -> ```bash |
18 | | -> npx codemod@latest init recipes/my-codemod |
19 | | -> ``` |
20 | | -> |
21 | | -> 3. Build codemod manually or with **[Codemod Studio](https://app.codemod.com/studio) (recommended)** ([Read docs →](https://go.codemod.com/studio-docs)). |
22 | | -> 4. Validate and test: |
23 | | -> |
24 | | -> ```bash |
25 | | -> npm run validate |
26 | | -> npm run test |
27 | | -> ``` |
28 | | -> |
29 | | -> 5. Commit hooks and CI run lint, validate, typecheck, and tests. |
30 | | -> |
31 | | -> 6. Set up auto-publishing to [Codemod Registry](https://app.codemod.com/registry): |
32 | | -> |
33 | | -> 1. **Get API key**: [https://app.codemod.com/api-keys](https://app.codemod.com/api-keys) |
34 | | -> 2. **Create GitHub Environment**: Repository Settings → Environments → New environment (name it `production`) |
35 | | -> 3. **Add secret**: `CODEMOD_API_KEY` with your API key |
36 | | -> 4. **Optional variables**: `CODEMOD_REGISTRY_SCOPE`, `CODEMOD_REGISTRY_URL` |
37 | | -> |
38 | | -> This automatically publishes codemods when you merge changes to `main`. See [AUTO_PUBLISH_SETUP.md](./AUTO_PUBLISH_SETUP.md) for details. |
39 | 10 |
|
| 11 | +## Running codemods |
| 12 | +> [!CAUTION] |
| 13 | +> Codemods edit your code. Run them only on files tracked by Git, and make sure to commit or stash your changes first. |
40 | 14 |
|
41 | | -## Overview |
42 | | -
|
43 | | -This repository contains codemods (automated migrations) for <ECOSYSTEM_NAME>. These codemods facilitate adopting new features and upgrading across breaking changes. |
44 | | -
|
45 | | -Codemods, public or private, are preferred to reside in repositories owned by the main organization of their respective projects. This repository serves as a template for codemod packages, allowing contributors to quickly create a repository for their published codemods. |
46 | | -
|
47 | | -This template repository comes pre-configured with a GitHub workflow that automatically publishes the latest version of your codemod, eliminating the need to manually publish codemods after making updates. |
48 | | -
|
49 | | -## Running Codemods |
50 | | -
|
51 | | -To run your codemods use the codemod command below: |
52 | | -
|
| 15 | +Run codemods from the registry by using the names defined in their codemod.yaml: |
53 | 16 | ```bash |
54 | | -npx codemod@latest @<NAMESPACE>/<codemod-name> |
| 17 | +npx codemod@latest <codemod-name> |
55 | 18 | ``` |
56 | | -
|
57 | | -- `codemod-name` - name of transform. Use the name of your codemod in Codemod Registry. |
58 | | - |
59 | | -See the [Codemod CLI documentation](https://go.codemod.com/cli-docs) for a full list of available commands and options. |
60 | | - |
61 | | -## Available Codemods |
62 | | - |
63 | | -> [!CAUTION] |
64 | | -> These scripts change source code. Commit or stash your changes before running them. |
65 | | -
|
66 | | -List your published codemods here, e.g.: |
67 | | -- `@<NAMESPACE>/<MAJOR_VERSION>/example-codemod` — short description |
68 | | - |
69 | | -## Important |
70 | | - |
71 | | -After using this template, it's recommended that you update this README with: |
72 | | - |
73 | | -1. Details about what your codemod does (e.g. before/after code snippets) |
74 | | -2. A link to the published codemod in Codemod Registry |
75 | | -3. The accurate run command |
| 19 | +For example: |
| 20 | +``` |
| 21 | +npx codemod@latest @nodejs/tmpDir-to-tmpdir |
| 22 | +``` |
| 23 | +See the [Codemod documentation](https://go.codemod.com/cli-docs) for a full list of available CLI commands and options. |
76 | 24 |
|
77 | 25 | ## Contributing |
78 | 26 |
|
|
0 commit comments