Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(next-codemod): migrate to commander and prompts #70409

Merged
merged 7 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"RUST_BACKTRACE": "0"
},
"cSpell.words": [
"codemod",
"codemods",
"Destructuring",
"Entrypoints",
"jscodeshift",
Expand Down
270 changes: 0 additions & 270 deletions packages/next-codemod/bin/cli.ts

This file was deleted.

47 changes: 43 additions & 4 deletions packages/next-codemod/bin/next-codemod.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
#!/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/react-codemod.js
// next-codemod optional-name-of-transform optional/path/to/src [...options]
// 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 { runTransform } from './transform'

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 your terminal')
.option(
'-j, --jscodeshift',
'(Advanced) Pass options directly to jscodeshift'
)
.action(runTransform)
.allowUnknownOption()

program
.command('upgrade')
.description(
'Upgrade Next.js apps to desired versions with a single command.'
)
.usage('[options]')
.action(runUpgrade)

require('./cli').run()
program.parse(process.argv)
Loading
Loading