dotenv-generator

0.1.8 • Public • Published

Contributors Forks Stargazers Issues MIT License

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact

About The Project

asciicast

I hate having to manually think about setting up my .env files every time I have to bring up a new project without understanding any of the keys. Installing new packages also kind of implies that you manually go through the process to make and also understand the .env file that you need to have in order for the package to run successfully.

This should make that process smoother by making it interactive leaving less room for error while making for a nicer installation experience (think of zip files vs install wizards).

(back to top)

Getting Started

The project is very simple to setup, clone and run yarn to install dependencies. To run the project execute yarn start. You should have an example env file (default env.example) that will be used to generate the setup flow. It shouldn't be anything special so if you already have it chances are you can use it with dotenv-generator. You can also use comments ("#") to provide a description for the env value. By default you can put comments above the variable to describe it, or you can use an inline comment after the variable and the default value.

Installation

Run yarn to install dependencies

Testing

Run yarn test to execute tests. To generate coverage run yarn coverage

(back to top)

Usage

Example env file

# Comment that will be applied as description to the variable after it
PUBLIC=STRINGY
# Comment that will override the inline comment
BOOLEAN=true # Inline comment that will be overriden that you can use for additional info but not for setup
NUMBEROO=2
SECRETSTUFF=bar # Inline comment that will be displayed during setup
SECRET=2
# Comment that will be ignored

With the given example file the setup flow would be as following:

  • The first value would have the description as the first line comment for the value "PUBLIC" with the default value of "STRINGY". Enter applies the default value.
  • The second value would have the description of the third line comment for the value "BOOLEAN" with the default value of "true". Only boolean values would be accepted here.
  • The third value would have the generated description and it would look like this "Enter the value, type number, for NUMBEROO: 2". Only numbers would be accepted here.
  • The fourth value would have the description of the inline comment for the value "SECRETSTUFF" with the default value of "bar".
  • The last value would have the generated description.
  • The last line comment would be ignored and wouldn't impact the setup.

The following recording demonstrates this:

asciicast

How to use dotenv-generator

The easiest way to use this package is to run it (Duh). You can add a configure script to your package.json file that runs dotenv-generator. If you want users to execute this script let them know by asking them to perform this after installation npm explore {name_of_the_package} -- npm run configure.

Postinstall

Ideally your project should use dotenv-generator --postinstall as a postinstall action. This means that after installation of your package, dotenv-generator will be run. This allows for a seamless setup of your project that will magically happen after installation. Since this is not an ideal world npm 6+ doesn't play nice with interactive postinstall hooks so I've added a check for that if you include the --postinstall flag it will check the npm version and for npm 6+ the script won't execute the interactive flow.It will instead print a message saying that the configuration could be done by executing npm explore {name_of_the_package} -- npm run postinstall. To view this output you must include --foreground-scripts as a flag for package installation ie. npm i --foreground-scripts.

Don't forget to include an .env.example file with descriptions of your fields in the root directory, or anywhere else but then specifying -f inputFilePath.

Global

You can also install this package globally by running npm i -g dotenv-generator. After this you can use dotenv-generator anywhere. This makes it really simple to setup multiple projects without having to worry about the generator being a dependency.

Parameters

Available parameters are:

  • -f, --file - The environment file name to be used as an example
  • -o, --output - The environment file name to be used as an output
  • -pi, --postinstall - If set the script will check for npm version
  • -d, --debug - A flag to enable writing debug output to stdout

After completed installation your package folder inside of node_modules will contain a .env file with the provided values that your package can then use.

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this project better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.md for more information.

(back to top)

Contact

Nenad Lukic - @lnenad

(back to top)

Package Sidebar

Install

npm i dotenv-generator

Weekly Downloads

1

Version

0.1.8

License

MIT

Unpacked Size

19.7 kB

Total Files

7

Last publish

Collaborators

  • lnesiak