Giter Club home page Giter Club logo

oneenv's Introduction

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

oneenv's People

Contributors

jarseal avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.