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

feat: add env:add command #4533

Merged
merged 4 commits into from
Apr 30, 2024
Merged

feat: add env:add command #4533

merged 4 commits into from
Apr 30, 2024

Conversation

Julien-R44
Copy link
Member

@Julien-R44 Julien-R44 commented Apr 20, 2024

Okay, so this is something that's been bugging me for a long time. I'm often in the middle of development, and I realize that I need to add an environment variable. And then I have to open 3 different files in my editor: env.example, the .env, and the start/env.ts to add my new variable.

Then I find myself with lots of new tabs open in my IDE, which is a mess. And even without that, it's boring to do manually.

That's why I suggest the env:add command, which works like this:

node ace env:add MY_VARIABLE value --type=string

executing this command will add the variable to the .env.example, .env and start/env.ts files. The variable name will be converted to SCREAMING_SNAKE_CASE.

node ace env:add

executing the command without any arguments/flags will display prompts for each of the required values.


Small doubt about the env.example: the current implementation adds the value of the variable in the .env.example which can be problematic if people aren't careful before committing: they'll push the values to the repo.

So, if we want to change this, we'd have to add the possibility of having a specific value for the .env.example when using the add method of @adonisjs/env EnvEditor: https://github.com/adonisjs/env/blob/develop/src/editor.ts#L61

I think it makes sense. I'll do a PR if you guys confirm this

@afgallo
Copy link

afgallo commented Apr 22, 2024

This is great to see! On a related note, I've noticed when I generate a new value for APP_KEY, adonis also adds it to the .env.example file which in my view is problematic. You certainly don't want to accidentally commit this value to a repo. So I think your suggestion is valuable and it makes a lot of sense.

@thetutlage
Copy link
Member

Small doubt about the env.example: the current implementation adds the value of the variable in the .env.example which can be problematic if people aren't careful before committing: they'll push the values to the repo.

Yeah, I think we should accept a flag in the EnvEditor that will set an empty value for the key within the .env.example file.

@Julien-R44
Copy link
Member Author

Ready to merge. Documentation updated adonisjs/v6-docs#84

@Julien-R44 Julien-R44 marked this pull request as ready for review April 29, 2024 10:56
@thetutlage thetutlage merged commit c8251b5 into develop Apr 30, 2024
12 checks passed
@thetutlage thetutlage deleted the feat/set-env branch April 30, 2024 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants