You can build a codemod package using three different ways:

  • Build with Codemod Studio
  • Build with codemod learn
  • Scaffold a codemod package

By building a codemod with Codemod Studio or with codemod learn, your codemod package will automatically have the recommended package structure.

If you build a codemod from scratch or a previously built codemod, you will have to scaffold a valid codemod package using Codemod CLI.

Building with Codemod Studio

To learn how to build codemods with Codemod Studio, please refer to the detailed Codemod Studio usage guide.

Building with codemod learn

You can use codemod learn to build a codemod from the latest diff made in your current project. This allows you to seamlessly build codemods right from your IDE.

1

Make a change

Start by manually making change in a file that you would like to see repeated over many files in your project.

2

Run `codemod learn`

Open a terminal in your current project and run codemod learn. Codemod AI will use the diff of the latest edited file to automatically generate a codemod.

3

Building the codemod

Codemod Studio will automatically open, with pre-populated data, and begin building your codemod. Allow Codemod Studio to finish generating your codemod.

4

Export/publish the generated codemod

After Codemod Studio builds your codemod, you can easily export and run your codemod over your local project.

Scaffolding a codemod package

Scaffolding a codemod package allows you to either:

  1. manually write your own codemod
  2. turn an existing codemod into a Codemod-compatible package.

To scaffold a new codemod package, you should:

1

Verify codemod engine compatibility

Verify that the existing codemod is built by one of the supported codemod engines.

2

Initialize codemod package

Initialize a Codemod-compatible package by running:

codemod init
3

Update transform file content

For jscodeshift/ts-morph/workflow codemods:

Update the content inside the src/index.ts file with the content of your codemod’s transform file.

For ast-grep codemods:

Update the content inside the src/rule.yaml file with the content of your ast-grep rule.

4

Update package configuration file

Add information about your codemod to the .codemodrc.json configuration file. Refer to .codemodrc.json reference here.

Next steps

Publishing your codemod ->

Get started with publishing your codemod to Codemod Registry.