ericmurphyxyz / cpa

Create (React) Parcel App / Light-weight React starter with Parcel for practice projects
7 stars 2 forks source link

sed command fails (on macOS) #1

Open storypixel opened 4 years ago

storypixel commented 4 years ago

Hi, I loved your approach for spinning up a parcel project... note that on OSX this fails sed -i "/scripts/ a\ \ \ \ \"start\": \"parcel index.html\"," package.json

complains about extra characters after the command p so it thinks package.json is an malformed argument or something. I understand what the intent of this command is i am just lost on the syntax. Maybe you are using Linux containers to run your stuff in?

storypixel commented 4 years ago
# sed -i '' "/scripts/ a\ \ \ \ \"start\": \"parcel index.html\"," package.json
jq '.scripts |= . + {"start": "parcel index.html"}' package.json|sponge package.json

this is how i ended up solving it. I just am terrible at sed and couldn't pinpoint why my sed attempts weren't working

ericmurphyxyz commented 4 years ago

Thanks for catching that! I'm on Linux, and the GNU version of sed is different from the BSD version of sed that MacOS uses, so that's why the error is there.

I think this should work cross-platform:

sed -i'' -e "/scripts/ {a\
\ \ \ \ \"start\": \"parcel index.html\",
}" package.json

Can you test it to see if it works on MacOS and I'll update the code? Thanks!

storypixel commented 4 years ago

thanks for the reply! so i ran that verbatim above and it yielded:

sed: 1: "/scripts/ {a\ \ \ \ "st ...": extra characters after \ at the end of a command

i tried a bunch of variations too to see if i could get past the error to be helpful but i couldn't solve it