-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60f69d6
commit 13a6219
Showing
2 changed files
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { TRANSFORM_OPTIONS } from '../config' | ||
import { join } from 'node:path' | ||
import { getAllFiles } from '../utils/file' | ||
import prompts from 'prompts' | ||
import execa from 'execa' | ||
|
||
const jscodeshiftExecutable = require.resolve('.bin/jscodeshift') | ||
|
||
|
||
const transformerDirectory = join(__dirname, '../', 'transforms') | ||
export function onCancel() { | ||
process.exit(1) | ||
} | ||
export async function upgrade(source: string): Promise<void> { | ||
let sourceSelected = source | ||
|
||
if (!sourceSelected) { | ||
const res = await prompts( | ||
{ | ||
type: 'text', | ||
name: 'path', | ||
message: 'Which files or directories should the codemods be applied to?', | ||
initial: '.', | ||
}, | ||
{ onCancel }, | ||
) | ||
|
||
sourceSelected = res.path | ||
} | ||
|
||
const files = await getAllFiles(sourceSelected) | ||
|
||
const args: string[] = [] | ||
|
||
args.push('--no-babel') | ||
args.push('--silent') | ||
args.push('--ignore-pattern=**/node_modules/**') | ||
args.push('--extensions=cts,mts,ts,js,mjs,cjs') | ||
args.push( ...files.map((file) => file.toString())) | ||
|
||
|
||
for (const { value } of TRANSFORM_OPTIONS) { | ||
const transformerPath = require.resolve(`${transformerDirectory}/${value}.js`) | ||
const jscodeshiftProcess = execa(jscodeshiftExecutable, [...args, '--transform', transformerPath]) | ||
|
||
jscodeshiftProcess.stderr?.pipe(process.stderr) | ||
} | ||
} |
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