Template Codemods
Learn how to create and run codemods with customizable template inputs
Template codemods allow you to create reusable code modifications that can be customized with different inputs each time they run. This is particularly useful when you want to share a codemod that others can run with their own parameters.
Creating Template Codemods
To create a template codemod, you can use the TEMPLATE_ARGS
dictionary from the context object. This allows you to define parameters that users can customize when running the codemod.
Template Parameters
Template parameters are defined using the TEMPLATE_ARGS
dictionary.
Currently the support types for parameter values are:
- String
- String List
Running Template Codemods
When running a template codemod, you’ll need to provide values for the template parameters. This can be done through the web interface:
- Select your template codemod
- Look for the “Template Arguments” section in the right panel
- Fill in the values for each parameter
- Click “Run Codemod” to execute with your custom inputs
Best Practices
When creating template codemods:
- Provide clear documentation for each template parameter
- Validate template inputs before using them
- Use descriptive parameter names that indicate their purpose
- Consider adding example values in the documentation
Template codemods make your modifications more flexible and reusable across different scenarios. By following these guidelines, you can create robust and user-friendly template codemods that others can easily customize for their needs.
Was this page helpful?