reactjs / react-codemod

React codemod scripts
MIT License
4.2k stars 288 forks source link

feat(cli): Support passing class flags on CLI #317

Open tbranyen opened 8 months ago

tbranyen commented 8 months ago

While working on transforming our legacy codebase I'm finding that we have hundreds of files that are not completely converted and need additional processing. I added react-codemod as a starting point to go from createReactClass -> React.createClass -> class extends React.Component, which is in the middle of our codemod stack. I was able to use the class transform in isolation running directly from in node and filling in the options/jscodeshiftapi/etc. Unfortunately this doesn't work for all files. I found many issues with jscodeshift getting into infinite loops that did not appear when invoking react-codemod from the terminal.

The problem with invoking from the terminal in node via something like execSync is that it uses inquirer to be interactive. This PR makes it so that all class options can be specified on the terminal.

Here is an example of what the command I'm running looks like now:

npx react-codemod class /home/tim/netflix/tmp.jsx --force --parser=babel --classFlow=false --classRemoveRuntimePropTypes=false --classPureComponent=false

 OKK /home/tim/netflix/tmp.jsx
All done. 
Results: 
0 errors
0 unmodified
0 skipped
1 ok