evcodeshift icon indicating copy to clipboard operation
evcodeshift copied to clipboard

Add a "splice into" feature for Javascript/Typescript

Open ishaqibrahimbot opened this issue 2 years ago • 2 comments

Played around with the evcodeshift api and succeeded in creating a very minimal transformer. Next steps include making this more robust and complete, figuring out the proper file structure, adding the edit option to the cli, and writing tests.

ishaqibrahimbot avatar May 23 '23 19:05 ishaqibrahimbot

Hey @ElonVolo! I've made some good progress. There is now an --edit option for the cli runner that can directly edit properties inside objects.

To see it in action, follow these steps:

  • checkout the code in this PR
  • install the package globally by running npm install -g . in the root
  • Run the following command to do the edit:
evcodeshift --edit path-to-config.js-file --propertyName="propertyValue"

Note that propertyValue above expects a JSON-stringified value at the moment. That means you can pass literals such as strings/numbers/booleans as well as arrays and objects.

Next up, I'll be adding some test cases to cover this functionality before wrapping up the PR.

Let me know your thoughts and feedback!

ishaqibrahimbot avatar May 27 '23 18:05 ishaqibrahimbot

Update: Have added 3 test cases under an 'edit' describe block in the cli tests file. Covered these scenarios:

  • replacing string
  • replacing array
  • replacing object

This PR is now ready to be reviewed.

ishaqibrahimbot avatar May 28 '23 18:05 ishaqibrahimbot