Add a "splice into" feature for Javascript/Typescript
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.
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!
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.