MCPcopy
hub / github.com/vercel/next.js / runTransform

Function runTransform

packages/next-codemod/bin/transform.ts:25–239  ·  view source on GitHub ↗
(
  transform: string,
  path: string,
  options: any
)

Source from the content-addressed store, hash-verified

23export const transformerDirectory = join(__dirname, '../', 'transforms')
24
25export async function runTransform(
26 transform: string,
27 path: string,
28 options: any
29) {
30 let transformer = transform
31 let directory = path
32
33 if (!options.dry) {
34 checkGitStatus(options.force)
35 }
36
37 if (
38 transform &&
39 !TRANSFORMER_INQUIRER_CHOICES.find((x) => x.value === transform)
40 ) {
41 console.error('Invalid transform choice, pick one of:')
42 console.error(
43 TRANSFORMER_INQUIRER_CHOICES.map((x) => '- ' + x.value).join('\n')
44 )
45 process.exit(1)
46 }
47
48 if (!path) {
49 const res = await prompts(
50 {
51 type: 'text',
52 name: 'path',
53 message: 'On which files or directory should the codemods be applied?',
54 initial: '.',
55 },
56 { onCancel }
57 )
58
59 directory = res.path
60 }
61 if (!transform) {
62 const res = await prompts(
63 {
64 type: 'select',
65 name: 'transformer',
66 message: 'Which transform would you like to apply?',
67 choices: TRANSFORMER_INQUIRER_CHOICES.reverse().map(
68 ({ title, value, version }) => {
69 return {
70 title: `(v${version}) ${value}`,
71 description: title,
72 value,
73 }
74 }
75 ),
76 },
77 { onCancel }
78 )
79
80 transformer = res.transformer
81 }
82

Callers 1

runUpgradeFunction · 0.90

Calls 15

checkGitStatusFunction · 0.90
uninstallPackageFunction · 0.90
installPackagesFunction · 0.90
expandFilePathsIfNeededFunction · 0.85
atMethod · 0.80
splitMethod · 0.80
errorMethod · 0.65
pushMethod · 0.65
joinFunction · 0.50
requireFunction · 0.50
parseIntFunction · 0.50
findMethod · 0.45

Tested by

no test coverage detected