0.2.2 • Published 11 months ago

@best-shot/env v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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"'
};
0.2.1

11 months ago

0.2.2

11 months ago

0.2.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago