0.9.9 • Published 11 months ago

oneenv v0.9.9

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

oneenv

OneEnv helps keep all .env files' content in one file or one NPM (or yarn) task call in a monorepo. The content is then distributed to the specified folders (targets). This is to help the developers to easily share just one master .env file (in the root of the project), but can also be used to set up CI/CD pipelines. It uses dotenv under the hood.

REMEMBER TO GITIGNORE ALL .env FILES IN YOUR PROJECT.

Install

npm i oneenv

or

yarn add oneenv

Syntax examples

Master .env file (root of your project):

# special separator for handle and variable (default is '__')
__ENV_CONFIG_SEPARATOR=--

# handles and targets definitions
front--env_config_target=frontend
back--env_config_target=backend

# handles starting with 'sv--' can be used as variables
sv--SHARED_SECRET=mysharedsecret

# all these will be in an .env file in the '/frontend' folder (without the 'front--' handle)
front--VITE_SECRET=anothersecretforfrontend
front--VITE_SHARED_SECRET=sv--SHARED_SECRET

# all these will be in an .env file in the '/backend' folder (without the 'back--' handle)
back--SECRET=anothersecretforbackend
back--SHARED_SECRET=sv--SHARED_SECRET

# root level .env variable (without any handle and separator)
SOME_ROOT_SECRET=rootsecret

Config file, oneenv.config.json (root of your project):

{
  "targets": {
    "front": "frontend",
    "back": "backend",
    "calcService": "calcService/src"
  },
  "separator": "--"
}

You need to specify the target in the root .env file, in the config file, or in a package.json script task. The defining of the separator is optional, default is __.

Targets

Targets define the handle and the folder (as the value) where the .env file is created. Targets can be set in three different ways (one of these ways is required):

  1. In the master .env file:
front__env_config_target=frontend
back__env_config_target=backend
  1. In the oneenv.config.json file:
{
  "targets": {
    "front": "frontend",
    "back": "backend",
  },
}
  1. In a package.json script task:
"scripts": {
  "env": "front__env_config_target=frontend back__env_config_target=backend oneenv"
}

Variables

The variables are defined as [handle][separator][VARIABLEKEY]=[VALUE]. The root .env file:

front__VARIABLE_KEY=somefrontendsecret
back__VARIABLE_KEY=somebackendsecret

or in a terminal call:

front__VARIABLE_KEY=somefrontendsecret back__VARIABLE_KEY=somebackendsecret npm run env

Shared values (sv)

The variables can share a value by using sv as the handle. For example:

sv__SOME_SHARED_VALUE=somesharedvalue

front__VARIABLE_KEY=sv__SOME_SHARED_VALUE
back__VARIABLE_KEY=sv__SOME_SHARED_VALUE
0.9.9

11 months ago

0.9.8

11 months ago

0.9.7

11 months ago

0.9.6

11 months ago

0.9.5

11 months ago

0.9.4

11 months ago

0.9.3

11 months ago

0.9.2

12 months ago

0.9.0

12 months ago