env-toolkit
v1.1.0
Published
This is a package that can generate or compare env files for your project.
Downloads
9
Maintainers
Readme
env-toolkit
env-toolkit
is a command-line tool for generating and managing environment variables. It scans a directory for environment variables and creates a .env
file based on the results. You can configure it to exclude certain folders, specify prefixes for environment variables, and control whether to overwrite existing .env
files.
Generating Files
By default, env-toolkit scans the current working directory for environment variables and generates a .env file with the format env-timestamp. You can pass a name for the output file or choose to overwrite the existing .env file.
Scanned directory: my-fancy-project
Excluded folders: node_modules,dist,build,test,.git,build,coverage,public,out,tmp
Total environment variables found: 72
Output file: /my-fancy-project/.env-1722716928992
Printing Variables
Use the --print
option to print a table of all the variables found in the current directory, ordered alphabetically.
Scanned directory: my-fancy-project
Excluded folders: node_modules,dist,build,test,.git,build,coverage,public,out,tmp
Total environment variables found: 3
╔════╤════════════════════════════════════════╗
║ # │ Environment Variables ║
╟────┼────────────────────────────────────────╢
║ 1 │ VARIABLE_1 ║
╟────┼────────────────────────────────────────╢
║ 2 │ VARIABLE_2 ║
╟────┼────────────────────────────────────────╢
║ 3 │ VARIABLE_3 ║
╚════╧════════════════════════════════════════╝
Comparing Variables
Use the --compare
or -c
option to compare your current .env file (default: .env) and see which variables have been added or removed. This helps identify changes rather than simply printing all variables.
The current .env file is out of date!
New variables: 3
Removed variables: 1
┌─────────────────┬──────────────────┐
│ Added Variables │ Removed Variable │
├─────────────────┼──────────────────┤
│ VARIABLE_1 │ VARIABLE_4 │
├─────────────────┼──────────────────┤
│ VARIABLE_2 │ │
├─────────────────┼──────────────────┤
│ VARIABLE_3 │ │
└─────────────────┴──────────────────┘
Updating Variables
If you only want to add newly added variables to your existing .env file, use the --update
or -u
option. This will append the new variables at the end of your .env file with the current time.
# Newly added env variables (time)
VAR1 =
VAR2 =
Installation
To use env-toolkit
, you need to have Node.js and npm installed. You can install the package globally using npm:
npm install -g env-toolkit
Usage
You can run env-toolkit
using the command line. Below are the available options:
Command Line Options
| Option | Alias | Description | Type | Default Value |
| ----------- | ----- | --------------------------------------------------------------------- | --------- | --------------------------------------------------------------------------------------- |
| directory
| -d
| The directory to scan for .env
variables | string
| Current working directory |
| exclude
| -e
| Folders to exclude from the scan | array
| ["node_modules", "dist", "build", "test", ".git", "coverage", "public", "out", "tmp"]
|
| prefixes
| -p
| Prefixes used with env variables | array
| ["process.env"]
|
| name
| -n
| Name of the output .env
file | string
| .env
-timestamp
|
| output
| -o
| Directory to place the generated .env
file | string
| Current working directory |
| overwrite
| -w
| Flag to overwrite the previous .env
file | boolean
| false
|
| print
| none | Print all of the environment variables found in the directory | boolean
| false
|
| compare
| -c
| Checks the current .env
file and prints the new o removed variables | | |
| update
| -u
| Updates the previous .env
file | | |
| version
| none | Displays the current version | | |
| help
| -h
| List all the commands | | |
Example
- It will generate an env in the root directory with name .env-timestamp
env-toolkit
- Specify directory and exclude folders:
env-toolkit --directory ./src --exclude '["node_modules", "dist"]'
- Specify prefixes and output directory:
env-toolkit --prefixes '["MY_APP"]' --output ./config
- Print environment variables without creating a file:
env-toolkit --print
- Overwrite existing .env file:
env-toolkit --overwrite
Contributing
Contributions are welcome! Please open an issue or a pull request if you have any improvements or bug fixes.
License
This project is licensed under the ISC License. See the LICENSE file for details.