( transform: string, path: string, options: any )
| 23 | export const transformerDirectory = join(__dirname, '../', 'transforms') |
| 24 | |
| 25 | export 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 |
no test coverage detected