2.0.10 • Published 1 year ago

envtk v2.0.10

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

envtk

header

npm npm oclif GitHub Workflow Status (with event) GitHub license

Features

  • run commands with preloaded environment variables from a javascript file (supports async)
  • run commands with preloaded environment variables from an existing .env file
  • output the resulting environment variables as JSON for integration with other scripting languages

Installation

Currently there are 2 ways of installing envtk

NPM

envtk can be installed via npm:

  $ npm install -g envtk

Binaries

Binaries for each OS can be downloaded from the releases page

Refer to the installation docs for each OS on how to install envtk.

Quickstart

  1. Create a javascript file (we'll call it myScript.js) and default export a function that returns an object:
  1. (optional) Create a .env file with defaults to include, lets call it defaults.env:

  2. run the envtk run command and reference the files created above, we will execute the printenv command to see all current environment variables:

  $ npx envtk run printenv -s myScript.js -e defaults.env

will result in the following output:

MY_ENV_VAR=abc123
SECRET=SomethingFromAnApi
MY_AWS_SECRET_NAME=myAppSecret
DEFAULT_ENV_VAR=someDefaultThing

Note: we see the result printed because we ran printenv. If we had let's say a project that started with npm run dev and we passed that as command (so envtk run "npm run dev" -s myScript.js -e defaults.env, that project would now have access to the above environment variables via process.env

Table of contents

Motives

I noticed that a lot of populair frameworks, infrastructure tooling or other 3rd party services make use of environment variables or .env files but provide no way to load them from a 3rd pary secret manager (for example AWS Secrets Manager).

While tooling like dotenv-vault provides alot of functionality for safely managing secrets/environment variables, not everyone uses or can use dotenv-vault. This project aims to be a simple alternative tool for retrieving your secrets from wherever: a 3rd pary API, encrypted database, whatever and then passing those variables to the next step in your startup/deploy pipeline.

Usage

$ npm install -g envtk
$ envtk COMMAND
running command...
$ envtk (--version)
envtk/2.0.10 linux-x64 node-v18.20.1
$ envtk --help [COMMAND]
USAGE
  $ envtk COMMAND
...

Commands

envtk create OUTPUT

create a .env file using env vars loaded from a script or existing .env files

USAGE
  $ envtk create OUTPUT [--json] [-s <value>] [-e <value>]

ARGUMENTS
  OUTPUT  path for the output file

FLAGS
  -e, --envFile=<value>  path to .env file with defaults to include
  -s, --script=<value>   path to .(mjs|js) script.

GLOBAL FLAGS
  --json  Format output as json.

DESCRIPTION
  create a .env file using env vars loaded from a script or existing .env files

EXAMPLES
  Create .env file with env variables returned from script

    $ envtk create ".env" -s ./load-env.js

  Create .env file with env variables returned from script and include defaults from ".defaults.env"

    $ envtk create ".env" -s ./load-env.js -e .defaults.env

See code: src/commands/create.ts

envtk help [COMMANDS]

Display help for envtk.

USAGE
  $ envtk help [COMMANDS] [-n]

ARGUMENTS
  COMMANDS  Command to show help for.

FLAGS
  -n, --nested-commands  Include all nested commands in the output.

DESCRIPTION
  Display help for envtk.

See code: @oclif/plugin-help

envtk run COMMAND

run a given command with loaded env variables

USAGE
  $ envtk run COMMAND [--json] [-s <value>] [-e <value>]

ARGUMENTS
  COMMAND  command to run with the loaded environment variables

FLAGS
  -e, --envFile=<value>  path to .env file with defaults to include
  -s, --script=<value>   path to .(mjs|js) script.

GLOBAL FLAGS
  --json  Format output as json.

DESCRIPTION
  run a given command with loaded env variables

EXAMPLES
  Run command with env variables returned from script

    $ envtk run "npm run dev" -s ./load-env.js

  Run command with env variables returned from script and include defaults from ".env"

    $ envtk run "npm run dev" -s ./load-env.js -e .env

See code: src/commands/run.ts

2.0.10

1 year ago

2.0.9

1 year ago

2.0.8

2 years ago

2.0.7

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.6

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago