-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(next-codemod): migrate to commander and prompts (#70409)
### Why? Prerequisite of `@next/codemod upgrade`. Current status of next-codemod is difficult to extend another commands as it relies on [meow](https://www.npmjs.com/package/meow) which requires to handle args and flags manually. For consistency with `next` and `create-next-app`, migrated to `commander` and `prompts`. https://github.com/user-attachments/assets/8d2e53be-4b7d-4755-9a3f-c73df1f9ef7e No behavioral changes **except the help message**.
- Loading branch information
1 parent
6f64af6
commit 4ceb050
Showing
8 changed files
with
287 additions
and
308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.