@vygruppen/spor-codemods
v1.1.8
Published
Code modification scripts for migrating Spor code to newer versions
Downloads
944
Readme
@vygruppen/spor-codemods
Codemods for automatically migrating Spor code to newer versions. This package uses jscodeshift to transform your codebase.
Installation
pnpm add -D @vygruppen/spor-codemodsUsage
CLI
The easiest way to use codemods is through the CLI:
npx spor-codemod <transform> <path> [options]Programmatic API
You can also use codemods programmatically in Node.js:
import { runTransform } from "@vygruppen/spor-codemods";
// Run a transform
await runTransform("color-tokens", {
paths: ["src/"],
dry: true, // Preview changes without writing
});
// Run with custom options
await runTransform("color-tokens", {
paths: ["src/components/", "src/pages/"],
verbose: true,
extensions: ["tsx", "ts"],
});Available functions:
runTransform(transform, options)- Run a codemod transformgetAvailableTransforms()- Get list of available transform namesgetTransformPath(transform)- Get the file path for a transform
TypeScript types:
import type {
TransformName,
TransformOptions,
Transform,
API,
FileInfo,
} from "@vygruppen/spor-codemods";Available Transforms
color-tokens
Migrates old color token names to the new naming convention.
Example:
# Transform a single file
npx spor-codemod color-tokens src/App.tsx
# Transform an entire directory
npx spor-codemod color-tokens src/
# Dry run to preview changes
npx spor-codemod color-tokens src/ --dry
# Print transformed output
npx spor-codemod color-tokens src/Component.tsx --printWhat it does:
Replaces old color tokens with their new equivalents:
bg.tertiary→bg.brandbg.secondary→bg.subtleaccent.icon→icon.accentalert.error-secondary.surface→surface.caution- And many more...
See the full token mapping for all transformations.
Advanced Usage
You can pass any jscodeshift options:
# Only show files that would be modified
npx spor-codemod color-tokens src/ --dry --print
# Run in silent mode
npx spor-codemod color-tokens src/ --silent
# Process files in parallel (faster for large codebases)
npx spor-codemod color-tokens src/ --run-in-bandOptions
--dry- Dry run (no files are changed)--print- Print transformed output--silent- No output--extensions=<extensions>- File extensions to transform (example: tsx,ts,jsx,js)--ignore-pattern '<pattern>'- Ignore files with pattern (example: '/node_modules/')
Tips
Always run in dry mode first to preview changes:
npx spor-codemod color-tokens src/ --dryCommit your changes before running a codemod so you can review the diff and revert if needed.
Use with Git to see what changed:
npx spor-codemod color-tokens src/ git diff
Contributing
To add a new transform:
- Create a new file in
transforms/(e.g.,transforms/<category>/my-transform.js) - Export a default function that follows the jscodeshift API
- Add it to the transform map in
bin/cli.js - Update this README with documentation
