Skip to content

Commit

Permalink
refactor(next-codemod): migrate to commander and prompts (vercel#70409)
Browse files Browse the repository at this point in the history
### 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
devjiwonchoi committed Sep 24, 2024
1 parent 6f64af6 commit 4ceb050
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 308 deletions.
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

0 comments on commit 4ceb050

Please sign in to comment.