MCPcopy Index your code
hub / github.com/reactjs/react-codemod / runTransform

Function runTransform

bin/cli.js:44–111  ·  view source on GitHub ↗
({ files, flags, parser, transformer, answers })

Source from the content-addressed store, hash-verified

42}
43
44function runTransform({ files, flags, parser, transformer, answers }) {
45 const transformerPath = path.join(transformerDirectory, `${transformer}.js`);
46
47 let args = [];
48
49 const { dry, print, explicitRequire } = flags;
50
51 if (dry) {
52 args.push('--dry');
53 }
54 if (print) {
55 args.push('--print');
56 }
57
58 if (explicitRequire === 'false') {
59 args.push('--explicit-require=false');
60 }
61
62 args.push('--verbose=2');
63
64 args.push('--ignore-pattern=**/node_modules/**');
65
66 args.push('--parser', parser);
67
68 if (parser === 'tsx') {
69 args.push('--extensions=tsx,ts,jsx,js');
70 }
71 else {
72 args.push('--extensions=jsx,js');
73 }
74
75 args = args.concat(['--transform', transformerPath]);
76
77 if (transformer === 'class') {
78 args.push('--flow=' + answers.classFlow);
79 args.push('--remove-runtime-props=' + answers.classRemoveRuntimePropTypes);
80 args.push('--pure-component=' + answers.classPureComponent);
81 args.push('--mixin-module-name=' + answers.classMixinModuleName);
82 }
83 if (transformer === 'pure-render-mixin') {
84 args.push('--mixin-name=' + answers.pureRenderMixinMixinName);
85 }
86 if (transformer === 'pure-component') {
87 if (answers.pureComponentUseArrows) {
88 args.push('--useArrows=true');
89 }
90 if (answers.pureComponentDestructuring) {
91 args.push('--destructuring=true');
92 }
93 }
94
95 if (flags.jscodeshift) {
96 args = args.concat(flags.jscodeshift);
97 }
98
99 args = args.concat(files);
100
101 console.log(`Executing command: jscodeshift ${args.join(' ')}`);

Callers 2

runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected