nextra-codemods
v0.0.3
Published
Codemods to help migrate from Nextra v3 to v4
Maintainers
Readme
Nextra Codemods
A collection of codemods to help migrate Nextra versions.
Currently, this repository contains codemods to help migrate from Nextra v3 to v4.
Overview
Nextra v4 introduces several breaking changes, including:
- App Router support (Pages Router discontinued)
- Discontinuing
theme.configsupport - New search engine (Pagefind)
- RSC i18n support
- And more
These codemods help automate the migration process.
Quick Start
The easiest way to migrate your Nextra v3 project to v4 is to use our interactive CLI:
# Using pnpm dlx (recommended)
pnpm dlx nextra-migrate
# Or install globally
pnpm add -g nextra-codemods
nextra-migrateThis interactive tool will:
- Analyze your project structure
- Create backups of important files
- Migrate your theme configuration
- Convert pages to the App Router format
- Set up Pagefind search
- Update your Next.js configuration
- Configure Tailwind CSS and fix styling issues
- Update dependencies to Nextra v4
- Install all required packages
Just follow the prompts and your project will be migrated automatically!
Manual Migration
If you prefer to run the individual steps manually, you can use the following commands:
# Step 1: Migrate theme config
pnpm dlx nextra-codemods migrate-theme-config ./theme.config.jsx
# Step 2: Migrate pages to app directory
pnpm dlx nextra-codemods migrate-pages-to-app ./pages
# Step 3: Set up search
pnpm dlx nextra-codemods setup-search ./package.json
# Step 4: Update Next.js config
pnpm dlx nextra-codemods update-next-config ./next.config.js
# Step 5: Fix styling issues
pnpm dlx nextra-codemods fix-all-styles
# Step 6: Update dependencies
pnpm install nextra@latest nextra-theme-docs@latest
# or
pnpm add nextra@latest nextra-theme-docs@latestUsing on Your Project
To use these codemods on your actual Nextra v3 project, follow these steps:
Method 1: Using the CLI (Recommended)
Navigate to your Nextra v3 project directory:
cd your-nextra-v3-projectRun the interactive migration CLI:
pnpm dlx nextra-migrate
3. Follow the prompts to complete the migration process.
4. After migration, start your development server to verify the changes:
```bash
pnpm devMethod 2: Manual Migration
If you prefer more control over the migration process, you can run individual codemods:
Navigate to your Nextra v3 project directory:
cd your-nextra-v3-projectCreate backups of your important files:
cp -r pages pages.bak cp theme.config.jsx theme.config.jsx.bak cp next.config.js next.config.js.bakRun the individual codemods in sequence:
# Migrate theme configuration pnpm dlx nextra-codemods migrate-theme-config ./theme.config.jsx # Migrate pages to app directory pnpm dlx nextra-codemods migrate-pages-to-app ./pages # Set up Pagefind search pnpm dlx nextra-codemods setup-search ./package.json # Update Next.js configuration pnpm dlx nextra-codemods update-next-config ./next.config.js # Set up Tailwind CSS pnpm dlx nextra-codemods fix-tailwind # Fix all styling issues pnpm dlx nextra-codemods fix-all-stylesUpdate your dependencies:
pnpm add nextra@latest nextra-theme-docs@latestStart your development server to verify the changes:
pnpm dev
Troubleshooting
If you encounter any issues during migration, you can use our fix scripts:
# Fix all common issues at once
pnpm dlx nextra-codemods fix-nextra
# Or fix specific issues
pnpm dlx nextra-codemods fix-conflicts # Fix conflicting files
pnpm dlx nextra-codemods fix-tailwind # Fix Tailwind CSS issues
pnpm dlx nextra-codemods fix-next-config # Fix Next.js config
pnpm dlx nextra-codemods fix-code-hike # Set up Code HikeProject Structure After Migration
After running the migration, your project structure should look like:
- app/
- layout.tsx # Contains theme configuration
- page.mdx # Root page
- _meta.js # Navigation and page metadata
- globals.css # Global styles with Tailwind
- docs/
- page.mdx # Doc pages
- mdx-components.tsx # Custom MDX components
- next.config.js # Updated Next.js config
- package.json # Updated with Nextra v4 and Pagefind
- tailwind.config.js # Tailwind CSS configuration
- postcss.config.js # PostCSS configurationDevelopment
To contribute to this project:
Clone the repository:
git clone https://github.com/yourusername/nextra-codemods.git cd nextra-codemodsInstall dependencies:
pnpm installRun tests:
pnpm testBuild the project:
pnpm build
Releasing
This project uses release-it to manage releases. To create a new release:
Make sure all your changes are committed and pushed to the repository.
Run the release command:
pnpm releaseFollow the interactive prompts to select the new version number.
The release process will:
- Run linting and tests
- Bump the version in package.json
- Build the project
- Generate/update the CHANGELOG.md file
- Create a Git tag and commit
- Push changes to GitHub
- Create a GitHub release
- Publish to npm
For a dry run without making any changes, use:
pnpm release --dry-runCommit Guidelines
This project follows Conventional Commits for generating changelogs. Please format your commit messages as:
feat: add new feature- for new featuresfix: resolve issue- for bug fixesdocs: update documentation- for documentation changeschore: update build scripts- for maintenance tasksrefactor: improve code structure- for code improvementstest: add tests- for test additions or modifications
License
MIT
