All commands
Get started with using the Codemod command-line interface.
The Codemod command-line interface (CLI) allows you to interact with Codemod platform using a terminal or through an automated system.
The Codemod CLI accepts a variety of subcommands and options to explore, publish, and run codemods.
Installation
Build
codemod learn
The learn
command uses the diff of the latest edited file to automatically build a codemod using Codemod Studio.
After running this command, if any git diff exists, the Codemod Engine will use the diff as before/after snippets in Codemod Studio.
codemod learn
Share/discover
codemod search
Can be used to list the codemods available in Codemod Registry and optionally search for a specific codemod using its name or tags.
Aliases: list
and ls
codemod search [optional-search-query]
This command has special flags available to it that can be combined together to perform more advanced searches.
codemod search [optional-search-query] --mine
codemod init
Can be used to scaffold a new codemod package.
codemod init
codemod publish
Can be used to publish a codemod to Codemod Registry.
Publishing codemods requires logging in to Codemod platform and having a codemod that is compatible with Codemod Registry.
To do so, use the publish
command inside the codemod package directory:
codemod publish
Alternatively, you can publish a codemod from :
codemod publish [path] --source
codemod unpublish
Can be used to unpublish a codemod you own from Codemod Registry.
You can publish a specific version of your codemods using:
codemod unpublish [codemod-name]@[version]
Or you can completely unpublish your codemod, including all versions, from the registry:
codemod unpublish [codemod-name] -f
Run
codemod run
You can use the codemod
command to run codemods.
Codemod CLI allows you to run codemods:
- from Codemod Registry
- from source
- using a
- using a
codemod [codemod-name]
When using the codemod
command, Codemod CLI will attempt to run a codemod as long as it is not followed by a reserved command name.
Options
The following options can be used to change the default behavior of Codemod CLI.
Can be used to specify the files to be targeted by the codemod.
codemod [codemod-name] -i "example_file"
While running a codemod, you may want to prevent changes from occurring to specific parts of your project. The --exclude
option can be used to specify a glob pattern of the files to be ignored by the codemod.
By default, Codemod CLI excludes the patterns defined in the .gitignore
found in the project’s root directory.
codemod [codemod-name] -e "example_file"
Can be used to specify the directory of your project that the CLI should target while running codemods. This option is set as the current directory by default.
codemod [codemod-name] -t [path]
Can be used to switch to dry run mode. Dry running codemods helps you see the changes the codemod will make without affecting the project files.
codemod [codemod-name] --dry
Prints the readme (description) of the codemod.
codemod [codemod-name] --readme
Prints the configuration of the codemod.
codemod [codemod-name] --config
Can be used to enable prettier formatting to the files affected by the codemod.
codemod [codemod-name] --format
If you want to use ESM-specific features like top-level await
or import.meta
in your codemods, you can use this flag.
.mjs
or .mts
extension to omit using this compatibility flag.codemod [codemod-name] --json
Can be used to disable caching downloaded codemod files.
codemod [codemod-name] --no-cache
Can be used to disable dependencies installation after codemod run.
codemod [codemod-name] --no-install
Can be used to disable CLI telemetry data collection.
codemod [codemod-name] --no-telemetry
Can be used to skip interactive prompts (run the CLI in no output mode).
codemod [codemod-name] --no-interactive
Used to specify the engine for standalone codemod runs.
codemod [codemod-name] --no-interactive
Can be used to switch the CLI responses to JSON format.
codemod [codemod-name] --json
Can be used to specify the number of worker threads the CLI uses while running codemods.
codemod [codemod-name] -n [number-of-threads]
Can be used to generate a log file when running a codemod.
codemod [codemod-name] --logs
You can then open the log file by running:
codemod --logs
Other commands
Can be used to login to Codemod platform.
codemod login
Can be used to logout from Codemod platform.
codemod logout
Can be used to visit our feedback page and share your thoughts on Codemod Platform.
codemod feedback
Can be used to show a list of all available commands and options for Codemod CLI.
codemod help
You can also use this flag in combination with a particular CLI command to display usage information relevant to that command.
codemod login --help
Can be used to show the currently active version of Codemod CLI.
codemod --version