env-cmd icon indicating copy to clipboard operation
env-cmd copied to clipboard

YAML Support 🙌

Open Pytal opened this issue 4 years ago • 4 comments

It would be great if YAML support could be added for .env.yaml and .env-cmdrc.yaml, would this be possible?

Pytal avatar May 01 '20 20:05 Pytal

This is a cool idea. Interested in opening a PR?

toddbluhm avatar May 02 '20 06:05 toddbluhm

I just took a look at the loader and it would be very easy to implement. i'd also suggest you don't use require to get the file, but use a native dynamic import to load .js/.cjs and use a parser wrapped inside a helper-function otherwhise.

This would have a couple of benefits:

  • the loader itself would be vanilla JS/ES
  • the code would be more straigth-forward
  • any kind of object-notation can be supported by simply adding a case for it's extension that points to its parser

the change should not amount to more than 30 lines and performance and stability can only increase

i'll have a look at it

btw i love that you include esm-loading, and what are your thoughts on JSON5 support?

KilianKilmister avatar Jul 12 '20 19:07 KilianKilmister

This would be great, especially when working with other libraries that force use of yaml (e.g. gcloud functions). I used this ugly sed-workaround to operate both:

  "scripts": {
    "generate-env": "cat .env.yaml | sed \"s#: #=#g\" > build/.env",
    "start": "yarn generate-env && env-cmd -f build/.env YOUR_CODE_HERE",
    "deploy": "gcloud functions deploy --env-vars-file .env.yaml ..."
  }

johantiden avatar Apr 07 '22 14:04 johantiden

our workaround.

yq -o=json eval .env.yaml > .env.json https://github.com/mikefarah/yq

aliwatters avatar Jun 30 '22 19:06 aliwatters