npm package: @igmrrf/clienv
Description: A CLI tool for managing environment variables
Latest version: 0.1.0

# CLIENV

A CLI tool for managing environment variables

## Installation

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

```sh
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

```sh
$ 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

```sh
$ 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

```sh
$ 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.

```sh
$ 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

```sh
{
  "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

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

<br>

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

Sets the custom file to be synchronized with the schema file. <br><br>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

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

<br>

#### 🟣 `--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

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

<br>

#### 🟣 `--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

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

<br>

## 💻 Examples

#### Files are in sync and no problems were found

<img src="https://github.com/chempogonzalez/dotenv-checker/blob/master/assets/all_ok.png">

#### Schema has new keys and env file is not synchronized

<img src="https://github.com/chempogonzalez/dotenv-checker/blob/master/assets/schema_has_new_keys.png">

#### Environment file has keys that are not in schema

<img src="https://github.com/chempogonzalez/dotenv-checker/blob/master/assets/env_has_keys_are_not_in_schema.png">

------
<br>

## 🤓 Happy Code

> Created with Typescript! ⚡ and latin music 🎺🎵

### This README.md file has been written keeping in mind

- [GitHub Markdown](https://guides.github.com/features/mastering-markdown/)
- [Emoji Cheat Sheet](https://www.webfx.com/tools/emoji-cheat-sheet/)

## 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

```