Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would be amazing if this could configure enviroment variables as well #12

Open
1 of 3 tasks
khrome83 opened this issue May 19, 2020 · 7 comments
Open
1 of 3 tasks

Comments

@khrome83
Copy link

Issue Type

  • Bug Report
  • Feature Request
  • Other

Possible Solutions

scripts:
  # "denox run start" will execute main.ts with example.com networking permissions
  start:
    file: main.ts
    env:
      PORT: 80
      DOMAIN: "example.net"
    deno_options:
      allow-net: example.com
  # "denox run develop" will execute main.ts with localhost networking permissions and source code cache reloaded
  develop:
    file: main.ts
    env:
      PORT: 3000
      DOMAIN: "localhost"
    deno_options:
      allow-net: localhost
      reload: true

Then it would add the variables to Deno using Deno.env.set('NAME', 'VALUE')
Then we can access it via Deno.env.get("NAME")

It would require --allow-env to be set.

@BentoumiTech
Copy link
Owner

Thank you @khrome83 for the suggestion, I will soon add support for configuring env variables as well as loading them from .env file

@khrome83
Copy link
Author

Yeah, I was thinking about this last night. Being able to specify loading from .env or better .env.dev, .env.stage, .env.prod would be ideal as well.

There are 3-4 third party mods that take care of .env files, but they either always assume .env or they require you specify the file to load in code, which defeats the purpose.

@BentoumiTech
Copy link
Owner

Agreed specifying it in code does defeat the purpose.

I'm wondering what naming would be better for loading env file and specifying env variables in deno-workspace

scripts:
  start:
    file: main.ts
    env_file: ./.env
    env:
      PORT: 80
      DOMAIN: "example.net"

OR

scripts:
  start:
    file: main.ts
    env: ./.env
    env_vars:
      PORT: 80
      DOMAIN: "example.net"

OR

I think this may be best as to clearly define what the value should be

scripts:
  start:
    file: main.ts
    env_file: ./.env
    env_vars:
      PORT: 80
      DOMAIN: "example.net"

@khrome83
Copy link
Author

I am fine with the last one.

I can also see something like this -

scripts:
  start:
    file: main.ts
    env: 
      file: ./.env
      vars:
        PORT: 80
        DOMAIN: "example.net"

I think this should also allow the global layer, like you do with permissions.

Optionally, would you use a file and the vars at the same time? In other words if the YAML parsed as a string vs a object, you could handle it different.

Parse as a object, no need for a file

scripts:
  start:
    file: main.ts
    env: 
      PORT: 80
      DOMAIN: "example.net"

Parses as a string, going to disk

scripts:
  start:
    file: main.ts
    env: ./.env

@wattry
Copy link

wattry commented Jun 15, 2020

Which module will you be using for the environment variable file read? I'm assuming dotenv?

@khrome83
Copy link
Author

khrome83 commented Jun 15, 2020 via email

@wattry
Copy link

wattry commented Jun 15, 2020

Yeah, that was my thought.

--- Zane Milakovic
On Jun 15, 2020, 10:56 AM -0500, Ryan @.***>, wrote: Which module will you be using for the environment variable file read? I'm assuming dotenv? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

It was always the defacto package I would turn to. I'd like to see support for inline scripts in denox and env variable support would be an important component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
DenoX 1.0.0
  
In progress
Development

No branches or pull requests

3 participants