Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
105 lines
3.4 KiB
JavaScript
105 lines
3.4 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Copyright 2015-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
*/
|
|
// Based on https://github.com/reactjs/react-codemod/blob/dd8671c9a470a2c342b221ec903c574cf31e9f57/bin/cli.js
|
|
// @next/codemod optional-name-of-transform optional/path/to/src [...options]
|
|
|
|
import { Command } from 'commander'
|
|
import { runUpgrade } from './upgrade'
|
|
import { runAgentsMd } from './agents-md'
|
|
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()
|
|
// This is needed for options for subcommands to be passed correctly.
|
|
// Because by default the options are not positional, which will pass options
|
|
// to the main command "@next/codemod" even if it was passed after subcommands,
|
|
// e.g. "@next/codemod upgrade --verbose" will be treated as "next-codemod --verbose upgrade"
|
|
// By enabling this, it will respect the position of the options and pass it to subcommands.
|
|
// x-ref: https://github.com/tj/commander.js/pull/1427
|
|
.enablePositionalOptions()
|
|
|
|
program
|
|
.command('upgrade')
|
|
.description(
|
|
'Upgrade Next.js apps to desired versions with a single command.'
|
|
)
|
|
.argument(
|
|
'[revision]',
|
|
'Specify the upgrade type ("patch", "minor", "major"), an NPM dist tag (e.g. "latest", "canary", "rc"), or an exact version (e.g. "15.0.0"). Defaults to "minor".'
|
|
)
|
|
.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
|
|
.command('agents-md')
|
|
.description(
|
|
'Generate Next.js documentation index for AI coding agents (Claude, Cursor, etc.).'
|
|
)
|
|
.option(
|
|
'--version <version>',
|
|
'Next.js version (auto-detected if not provided)'
|
|
)
|
|
.option('--output <file>', 'Target file path (e.g., CLAUDE.md, AGENTS.md)')
|
|
.action(async (options) => {
|
|
try {
|
|
await runAgentsMd(options)
|
|
} catch (error) {
|
|
if (error instanceof BadInput) {
|
|
console.error(error.message)
|
|
} else {
|
|
console.error(error)
|
|
}
|
|
process.exit(1)
|
|
}
|
|
})
|
|
|
|
program.parse(process.argv)
|