1.0.2 • Published 1 year ago

jsonbank-env v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

JsonBank Env

Npm | Github

What is it?

A command line tool to Get your env files from the cloud as json.

Save as a JSON file remotely and Load it to your project as ENV.

Menu

Installation

You can use this via npx or install it globally.

npm i jsonbank-env
# or
npx jsonbank-env

Json Syntax

The json file must be an object or an array of objects.

Object

The object syntax env file is generated without empty lines.

{
  "NODE_ENV": "development",
  "PORT": 3000,
  "SSL": null,
  "DB_HOST": "localhost",
  "DB_USER": "root",
  "DB_PASS": "root",
  "DB_NAME": "test"
}

Will generate the following env file:

NODE_ENV="development"
PORT=3000
SSL=
DB_HOST="localhost"
DB_USER="root"
DB_PASS="root"
DB_NAME="test"

Array of objects

The array of objects syntax env file is generated with empty lines between each object.

[
  {
    "NODE_ENV": "development",
    "PORT": 3000,
    "SSL": null
  },
  "Comment: Database Configuration",
  {
    "DB_HOST": "localhost",
    "DB_USER": "root",
    "DB_PASS": "root",
    "DB_NAME": "test"
  }
]

Will generate the following env file:

NODE_ENV="development"
PORT=3000
SSL=

# Comment: Database Configuration
DB_HOST="localhost"
DB_USER="root"
DB_PASS="root"
DB_NAME="test"

Configuration

A jsonbank.env.json Configuration file is required. This is where the public key will be defined.

Create config file.

# Create a config file
npx jsonbank-env init

# Create a config file and force overwrite
npx jsonbank-env init force

# Create a config file from custom factory file
npx jsonbank-env init "path/to/factory/file.json"

# Create a config file from custom factory file and force overwrite
npx jsonbank-env init "path/to/factory/file.json" force

The following file will be created.

{
  public_key: "",
  envs: {
    dev: "project/file.json",
  },
}

Insert your public key in the public_key field.

envs

The envs config is where you define the jsonbank remote url of your json files. Given that

  • Project Name on jsonbank is envs
  • File Path is file.json

your config will look like this:

{
  "public_key": "public_key",
  "envs": {
    "dev": "envs/file.json"
  }
}

Commands

Using the example config file below:

{
  "public_key": "public_key",
  "envs": {
    "dev": "envs/default.json",
    "prod": "envs/prod.json"
  }
}

Load env

# Load env to custom local file
npx jsonbank-env <env> <local_path>

# Load env to custom local file and force overwrite
npx jsonbank-env <env> <local_path> force


# Using the example config above
# The command below will load remote "envs/prod.json" to ".env"
npx jsonbank-env prod .env

Load Remote file

# Load remote file
npx jsonbank-env <remote_path> <local_path>

# Load remote file and force overwrite
npx jsonbank-env <remote_path> <local_path> force

# The command below will load remote "envs/prod.json" to ".env"
npx jsonbank-env envs/prod.json .env

Env to Json

How to convert a env file to a json file? We got you covered. You don't need any initialization or configuration. Just run the following command and you are good to go.

# convert json to env and log to console (.env is the default input file)
npx jsonbank-env json

# convert json to env and log to console (custom input file)
npx jsonbank-env json <env_path>

# convert json to env and save to file (custom input file)
npx jsonbank-env json <env_path> <json_path>
1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.1

2 years ago