-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathtransform.ts
More file actions
43 lines (36 loc) · 1.12 KB
/
transform.ts
File metadata and controls
43 lines (36 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { execSync } from 'child_process';
import path from 'path';
import yargs from 'yargs';
const transformerDirectory = path.join(__dirname, 'transforms');
const jscodeshiftExecutable = require.resolve('.bin/jscodeshift');
interface argsType {
path: string;
transform: string;
}
export const yargsParse = (args: string[]): argsType => {
return yargs([])
.help()
.exitProcess(false)
.option('path', {
alias: 'p',
type: 'string',
description: 'Path that transform should be run over',
normalize: true,
})
.option('transform', {
alias: 't',
type: 'string',
description: 'Name of transform to run',
choices: ['button-v0-to-v1', 'deprecate-exports'],
})
.demandOption(['path', 'transform'])
.parse(args);
};
export const transform = (args: argsType) => {
const codeshiftArgs = [];
codeshiftArgs.push('-t', path.join(transformerDirectory, args.transform + '.js'));
codeshiftArgs.push('--parser=tsx');
codeshiftArgs.push('--extensions=tsx');
codeshiftArgs.push(args.path);
execSync(jscodeshiftExecutable + ' ' + codeshiftArgs.join(' '));
};