ElonVolo / evcodeshift

A JavaScript codemod toolkit.
MIT License
16 stars 1 forks source link

Add a "splice into" feature for Javascript/Typescript #9

Open ElonVolo opened 1 year ago

ElonVolo commented 1 year ago

Problem: once of the most common uses of codemods, at least for me, is to update data in configuration files that are written in Javascript/Typescript instead of in JSON. I want to have a way of updating these values in a way more reliable that regexes, but I don't want to have to crack open a text editor and write a brand new set of code just to change to settings in a file.

Solution: give evcodeshift the ability to act as a simple command line utility where you can use the shell to pass evcodeshift a property name and a string with javascript code, and evcodeshift will replace the value at that property name with the new bit of code.

Here's how I envision this feature working. Let's say we have a file named my_config_file.js with the following content

let myconfigData = 
{
    "mobileID": "23423",
    "environments": {
        "ios": {
            "provisioning_profiles": [
                "15613CEFSGA",
                "235613CEFSGA",
                "AE6116341454"
            ]
        },
        "android": "8675309D",
        "electron": "ABEEF26401"
    }
}

I'd like to run the following commands on the shell to change the values of "electron" and "provisioning_profiles"

evcodeshift --edit my_config_file.js "electron" "DECAFBAD" 
evcodeshift --edit my_config_file.js "provisioning_profiles" "[\"111111\", \"22222\", \"333333\"]"

The new content of my_config_file.js look something like

let myconfigData = 
{
    "mobileID": "23423",
    "environments": {
        "ios": {
            "provisioning_profiles": [
                "111111",
                "22222",
                "333333"]
            ]
        },
        "android": "8675309D",
        "electron": "DECAFBAD"
    }
}
ishaqibrahimbot commented 1 year ago

Tracking the implementation of the above feature in this draft PR: https://github.com/ElonVolo/evcodeshift/pull/10