Codemod
npm install -D @rep-protocol/codemod# ornpx @rep-protocol/codemod [options] [files...]rep-codemod [options] [files or directories...]Options
Section titled “Options”| Flag | Default | Description |
|---|---|---|
-f, --framework <name> | vite | Framework preset: vite, cra, next |
--dry-run | false | Preview changes without writing files |
--extensions <list> | ts,tsx,js,jsx | Comma-separated file extensions to process |
Framework presets
Section titled “Framework presets”--framework vite
Section titled “--framework vite”Transforms import.meta.env.VITE_* to rep.get('*'):
// Beforeconst apiUrl = import.meta.env.VITE_API_URL;
// Afterimport { rep } from '@rep-protocol/sdk';const apiUrl = rep.get('API_URL');Vite built-ins (MODE, DEV, PROD, SSR, BASE_URL) are left untouched.
--framework cra
Section titled “--framework cra”Transforms process.env.REACT_APP_* to rep.get('*'):
// Beforeconst apiUrl = process.env.REACT_APP_API_URL;
// Afterimport { rep } from '@rep-protocol/sdk';const apiUrl = rep.get('API_URL');--framework next
Section titled “--framework next”Transforms process.env.NEXT_PUBLIC_* to rep.get('*'):
// Beforeconst apiUrl = process.env.NEXT_PUBLIC_API_URL;
// Afterimport { rep } from '@rep-protocol/sdk';const apiUrl = rep.get('API_URL');Examples
Section titled “Examples”# Transform Vite projectrep-codemod --framework vite src/
# Dry run — preview changesrep-codemod --framework cra --dry-run src/components/
# Specific filesrep-codemod --framework next src/app/page.tsx src/lib/api.ts
# JavaScript files onlyrep-codemod --framework vite --extensions js,jsx src/Behavior
Section titled “Behavior”- Idempotent — running twice produces the same result
- Import management — adds
import { rep } from '@rep-protocol/sdk'if absent - Non-destructive — only prefixed variables are transformed
- Format-preserving — original formatting and comments are preserved (via jscodeshift/recast)
Post-migration steps
Section titled “Post-migration steps”- Remove framework-specific type augmentations (e.g.,
vite-env.d.ts) - Run
rep typegento generate typed overloads - Update container config to set
REP_PUBLIC_*environment variables