| #!/usr/bin/env node |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| import { Command } from 'commander' |
| import { runUpgrade } from './upgrade' |
| import { runTransform } from './transform' |
| import { BadInput } from './shared' |
|
|
| const packageJson = require('../package.json') |
| const program = new Command(packageJson.name) |
| .description('Codemods for updating Next.js apps.') |
| .version( |
| packageJson.version, |
| '-v, --version', |
| 'Output the current version of @next/codemod.' |
| ) |
| .argument( |
| '[codemod]', |
| 'Codemod slug to run. See "https://github.com/vercel/next.js/tree/canary/packages/next-codemod".' |
| ) |
| .argument( |
| '[source]', |
| 'Path to source files or directory to transform including glob patterns.' |
| ) |
| .usage('[codemod] [source] [options]') |
| .helpOption('-h, --help', 'Display this help message.') |
| .option('-f, --force', 'Bypass Git safety checks and forcibly run codemods') |
| .option('-d, --dry', 'Dry run (no changes are made to files)') |
| .option( |
| '-p, --print', |
| 'Print transformed files to stdout, useful for development' |
| ) |
| .option('--verbose', 'Show more information about the transform process') |
| .option( |
| '-j, --jscodeshift', |
| '(Advanced) Pass options directly to jscodeshift' |
| ) |
| .action(runTransform) |
| .allowUnknownOption() |
| |
| |
| |
| |
| |
| |
| .enablePositionalOptions() |
|
|
| program |
| .command('upgrade') |
| .description( |
| 'Upgrade Next.js apps to desired versions with a single command.' |
| ) |
| .argument( |
| '[revision]', |
| 'Specify the target Next.js version using an NPM dist tag (e.g. "latest", "canary", "rc") or an exact version number (e.g. "15.0.0").', |
| packageJson.version.includes('-canary.') |
| ? 'canary' |
| : packageJson.version.includes('-rc.') |
| ? 'rc' |
| : 'latest' |
| ) |
| .usage('[revision] [options]') |
| .option('--verbose', 'Verbose output', false) |
| .action(async (revision, options) => { |
| try { |
| await runUpgrade(revision, options) |
| } catch (error) { |
| if (!options.verbose && error instanceof BadInput) { |
| console.error(error.message) |
| } else { |
| console.error(error) |
| } |
| process.exit(1) |
| } |
| }) |
|
|
| program.parse(process.argv) |
|
|