Init Command
The init
command sets up Codegen in your repository, creating necessary configuration files and pulling documentation locally.
Usage
Options
--repo-name
: The name of the repository (defaults to current git repo name)--organization-name
: The name of the organization (defaults to git organization)
Directory Structure
When you run init
, Codegen creates a .codegen
directory in your repository with the following structure:
Only config.toml
and the codemods/
directory are tracked in Git. The rest
of the .codegen
directory is automatically added to your .gitignore
.
This setup allows you to:
- Track and version your codemods with your repository
- Use
codebase.reset()
without losing progress on your codemod implementation - Share codemods with your team through version control
Recommended Structure
We recommend keeping your Codegen codemods in the .codegen/codemods/
directory (this is the default when using codegen create
). This:
- Keeps transformation code separate from your application code
- Makes it easy to find and manage all your codemods
- Ensures consistent behavior with
codebase.reset()
Local Documentation
Codegen pulls documentation and examples locally to:
- Provide offline access to guides and references
- Enable AI to give contextual help about your codebase
- Allow searching through examples and tutorials
Requirements
The command must be run from within a git repository. If you’re not in one, you’ll need to:
Examples
Initialize with default settings (uses git repo info):
Initialize with custom organization and repo:
Next Steps
After initializing:
- Create your first codemod:
- Run it:
Updating
You can run init
again to update your local documentation and configuration:
This will refresh the .codegen
directory while preserving your existing configuration.