create-env is an utility to help you create .env files based on CI/CD environmental values.
You use Gitlab-CI/CD or another CI/CD to perform a build of a software artifact and you want to use the provided CI/CD secret variables as a .env file. This is where create-env comes to the rescue.
You have defined your secret-variables inside of the CI/CD, and your variables uses a prefix like DEV_, TEST_, PROD_. create-env will take the current environment for your CI/CD pipeline, a prefix related to that environment, and the name of the file you want as output.
Then, it will generate that .env file, and remove the prefix of each secret-variable.
e.g:
Your secret-variables:
TEST_NODE_ENV=production
TEST_PORT=8080Your .env file output:
NODE_ENV=production
PORT=8080create-env needs to be installed as a global dependency:
npm i -g create-envyarn global add create-envTo create a .env file you have to run create-env with the following parameters:
# Default
create-env --env-file .env --env-prefix TEST_
# NPX
npx create-env --env-file .env --env-prefix TEST_create-env comes with a set of default prefixes (DEV_, TEST_, PROD_), if your secret-variables use those default prefixes, you can run create-env with the following parameters, the only thing your have to pass is the env which can be one of development, testing or production:
# Default
create-env --env testing --env-file .env --use-default-prefix
# NPX
npx create-env --env testing --env-file .env --use-default-prefix- Add
--from-templateoption. (In order to support .env generation based on another .env file). - Add
--no-prefixoption. (In order to support generate a .env file with all the env variables). - Add
--typeoption. (In order to support other formats like JSON envs). - Add
--helpoption.
If you raise a bug, please, open an issue.
PRs are welcome. Any kind of contribution is welcome.
create-env is licensed as MIT.