1.1.0 • Published 12 months ago

env-toolkit v1.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

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

OptionAliasDescriptionTypeDefault Value
directory-dThe directory to scan for .env variablesstringCurrent working directory
exclude-eFolders to exclude from the scanarray["node_modules", "dist", "build", "test", ".git", "coverage", "public", "out", "tmp"]
prefixes-pPrefixes used with env variablesarray["process.env"]
name-nName of the output .env filestring.env-timestamp
output-oDirectory to place the generated .env filestringCurrent working directory
overwrite-wFlag to overwrite the previous .env filebooleanfalse
printnonePrint all of the environment variables found in the directorybooleanfalse
compare-cChecks the current .env file and prints the new o removed variables
update-uUpdates the previous .env file
versionnoneDisplays the current version
help-hList all the commands

Example

  1. It will generate an env in the root directory with name .env-timestamp
env-toolkit
  1. Specify directory and exclude folders:
env-toolkit --directory ./src --exclude '["node_modules", "dist"]'
  1. Specify prefixes and output directory:
env-toolkit --prefixes '["MY_APP"]' --output ./config
  1. Print environment variables without creating a file:
env-toolkit --print
  1. 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.

Author

1.1.0

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago