reactjs / react-codemod

React codemod scripts
MIT License
4.19k stars 286 forks source link

Exposing utils / helpers in some way #298

Open cbranch101 opened 3 years ago

cbranch101 commented 3 years ago

We're considering creating our own React codemods, and it seems like a lot of the legwork you've done in this repo would be useful to build off of, would it be possible to bundle up and export the contents of the utils file and maybe a few other useful functions in an index file and add a main.js to the package.json?

cbranch101 commented 3 years ago

Of course copypasta is an option, but it seems like it might be cool if there was a core api for creating react code mods

alirezamirian commented 2 years ago

react-codemod is two things now:

The CLI has some nice features like checking git status, dry run, etc. which is relevant regardless of the transform. Letting the CLI be used with custom transforms allows others to leverage those features without redoing the same, in a custom CLI tool. This seems feasible with a minor change in react-codemod cli, to let transform be a name of a predefined transform (as is now), or path to a transform file.

npx react-codemod <transformNameOrPath> <path> [...options]

UPDATE: I see now that dry-run for example is supported by the original jscodeshift cli, so maybe one could use jscodeshift cli directly for custom transform, but still it might be relevant to have the CLI of react-codemod reusable for custom transforms.