@best-shot/env

0.2.0 • Public • Published

Env variables

The Cli will find the configuration from process.cwd() according to the following priority:

  • ./best-shot/env.toml
  • ./best-shot/env.ini
  • ./best-shot/env.yaml
  • ./best-shot/env.json

Then parse your env variable with JSON.stringify and pass it to config.define.

Installation

npm install @best-shot/cli --save-dev

Usage

// example: .best-shot/config.mjs
export const config = {
  define: {
    WHATEVER: 'abc'
  }
};
# example: .best-shot/env.ini

[production]
SERVICE_URL = "https://sample.org/"
APPID = "123456789"

[development]
SERVICE_URL = "http://sample.dev/"
APPID = "987654321"

[serve]
SERVICE_URL = "http://mock.dev/"
// output: production mode
config.define = {
  'import.meta.env.APPID': '"123456789"',
  'import.meta.env.SERVICE_URL': '"https://sample.org/"',
  WHATEVER: '"abc"'
};

// output: development mode
config.define = {
  'import.meta.env.APPID': '"987654321"',
  'import.meta.env.SERVICE_URL': '"http://sample.dev/"',
  WHATEVER: '"abc"'
};

// output: serve command
config.define = {
  'import.meta.env.APPID': '"987654321"',
  'import.meta.env.SERVICE_URL': '"http://mock.dev/"',
  WHATEVER: '"abc"'
};

Tips

Git hash inject

If a process.cwd() is a git repository, GIT_HASH will be injected to your config too.

config.define = {
  'import.meta.env.GIT_HASH': '"xxxxxxxxxxxxxxxxxxxx"'
};

Package Sidebar

Install

npm i @best-shot/env

Weekly Downloads

4

Version

0.2.0

License

MIT

Unpacked Size

6.62 kB

Total Files

5

Last publish

Collaborators

  • airkro