@igmrrf/clienv

0.1.0 • Public • Published

CLIENV

A CLI tool for managing environment variables

Installation

To install convert-json-env you can use yarn, npm, brew, wget, apt-get.

yarn global add clienv

# or

npm install --global clienv

# or

brew install clienv

# or

wget install clienv

# or

apt-get install clienv

Functionalities

  1. convert - convert environment variable file/format to another

clienv convert --file=example.json --out=.env.local

e.g json to .env yaml to json 2. log - show env values in terminal 3. validate - validate env values against a schema

defaults

NODE.js - .env.local -> .env.development -> .env -> config/local.json -> config/development.json

Convert Example

$ cat example-firebaseConfig.json
{
    "apiKey": "abcdefghijklmnopqrstuvwxyz1234567890ABC",
    "authDomain": "myapp-1234a.firebaseapp.com",
    "databaseURL": "https://myapp-1234a.firebaseio.com",
    "projectId": "myapp-1234a",
    "storageBucket": "myapp-1234a.appspot.com",
    "messagingSenderId": "123456789012",
    "appId": "1:234567890124:web:1234567890abcdef"
}

Case 1. Export environment variables

$ convert-json-env example-firebaseConfig.json --prefix="export "
✅ example-firebaseConfig.env created.

$ cat example-firebaseConfig.env
export apiKey='abcdefghijklmnopqrstuvwxyz1234567890ABC'
export authDomain='myapp-1234a.firebaseapp.com'
export databaseURL='https://myapp-1234a.firebaseio.com'
export projectId='myapp-1234a'
export storageBucket='myapp-1234a.appspot.com'
export messagingSenderId='123456789012'
export appId='1:234567890124:web:1234567890abcdef'

Case 2. Environment variables in Vue application

$ clienv convert example-firebaseConfig.json --out=.local.env --prefix=VUE_APP_
.local.env created.

$ cat .env.local
VUE_APP_apiKey='abcdefghijklmnopqrstuvwxyz1234567890ABC'
VUE_APP_authDomain='myapp-1234a.firebaseapp.com'
VUE_APP_databaseURL='https://myapp-1234a.firebaseio.com'
VUE_APP_projectId='myapp-1234a'
VUE_APP_storageBucket='myapp-1234a.appspot.com'
VUE_APP_messagingSenderId='123456789012'
VUE_APP_appId='1:234567890124:web:1234567890abcdef'

Case 3. Standard output for code embedded in javascript

In this case, no files are output.

$ clienv convert firebaseConfig.json --prefix=process.env.VUE_APP_ --embed
{
  apiKey: process.env.VUE_APP_apiKey,
  authDomain: process.env.VUE_APP_authDomain,
  databaseURL: process.env.VUE_APP_databaseURL,
  projectId: process.env.VUE_APP_projectId,
  storageBucket: process.env.VUE_APP_storageBucket,
  messagingSenderId: process.env.VUE_APP_messagingSenderId,
  appId: process.env.VUE_APP_appId
}

Checker Example

{
  "scripts": {
    "check-env": "clienv check -s .env.schema -e .env.local",
    // Execute the check-env before starting your application
    "dev": "npm run check-env && next dev"
  }
}

🛠️ CLI Options

You can customize the cli options. Here you have the possible customizations:

🟣 --schema or -s (default: ".env.schema")

Sets the custom file to be used as a schema/base file. This is the file which is used to sync the environment file

# Set a custom schema (file to be based on)
dotenv-checker --schema .env.base

🟣 --env or -e (default: ".env.local")

Sets the custom file to be synchronized with the schema file.

In case this file is out-of-sync and has some keys that the schema doesn't have, it reports the named keys to you through terminal

# File to check that needs to be in sync with schema file
dotenv-checker --env .env.local

🟣 --skip-create-question or -scq (default: "true")

By default it auto create the environment file if it doesn't exist. If you set this to "false" you can force to be asked to create it or not in case it's needed

# File to check that needs to be in sync with schema file
dotenv-checker --skip-create-question=false

🟣 --skip-update-question or -suq (default: "true")

By default it auto updates the environment file if it differs from schema file. If you set this to "false" you can force to be asked to update it or not in case it's needed

# File to check that needs to be in sync with schema file
dotenv-checker --skip-update-question=false

💻 Examples

Files are in sync and no problems were found

Schema has new keys and env file is not synchronized

Environment file has keys that are not in schema



🤓 Happy Code

Created with Typescript! ⚡ and latin music 🎺🎵

This README.md file has been written keeping in mind

All CLI Options

`
usage:
\tclienv convert <input.file> <out.file> [options]
\tclienv convert --file=config.json --prefix="export "
\tclienv convert --file=config.json --prefix="NEXT_PUBLIC_"
\tclienv convert --file=.env.local --out=config.json 
\tclienv convert --file=.env.local --out=config.json --embed=VUE_APP_

\tclienv log <env.variable> [options]
\tclienv log MONGO_URL --file=".env.local"
\tclienv log --log=MONGO_URL" --file=".env.local"
\tclienv log --log=MONGO_URL --file=".env.local" --out=echo

Options:
\t--out\t\tthe output file path.
\t--prefix\t\tthe prefix of environment variables in env file
\t--suffix\t\tthe suffix of environment variables in env file
\t--embed\t\tthe suffix of environment variables in env file

Readme

Keywords

none

Package Sidebar

Install

npm i @igmrrf/clienv

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

15.1 kB

Total Files

12

Last publish

Collaborators

  • igmrrf