varq v11.0.0
varq
A fork of env-cmd with diffrent defaults
A simple node program for executing commands using a package.json config.
š¾ Install
npm install varq or npm install -g varq
āØļø Basic Usage
Package.json
{
"config": {
"varq": {
"dev": {
"ENV1": "THANKS",
"ENV2": "FOR ALL",
"ENV3": "THE FISH"
}
}
},
"scripts": {
"test": "varq -e dev \"mocha -R spec\""
}
}š Help
Usage: _ [options] <command> [...args]
Options:
-v, --version output the version number
-e, --environments [env1,env2,...] The rc file environment(s) to use
-f, --file [path] Custom env file path (default path: ./.env)
--fallback Fallback to default env file path, if custom env file path not found
--no-override Do not override existing environment variables
-r, --rc-file [path] Custom rc file path (default path: ./.varqrc(|.js|.json)
--silent Ignore any varq errors and only fail on executed program failure.
--use-shell Execute the command in a new shell with the given environment (true by default)
--verbose Print helpful debugging information
-x, --expand-envs Replace $var in args and command with environment variables
-h, --help output usage informationš API Usage
EnvCmd
A function that executes a given command in a new child process with the given environment and options
options{object}command{string}: The command to execute (node,mocha, ...)commandArgs{string[]}: List of arguments to pass to thecommand(['-R', 'Spec'])envFile{object}filePath{string}: Custom path to .env file to read from (defaults to:./.env)fallback{boolean}: Should fall back to default./.envfile if custom path does not exist
rc{object}environments{string[]}: List of environment to read from the.rcfilefilePath{string}: Custom path to the.rcfile (defaults to:./.varqrc(|.js|.json))
options{object}expandEnvs{boolean}: Expand$varvalues passed tocommandArgs(default:false)noOverride{boolean}: Prevent.envfile vars from overriding existingprocess.envvars (default:false)silent{boolean}: Ignore any errors thrown by varq, used to ignore missing file errors (default:false)useShell{boolean}: Runs command inside a new shell instance (default:true)verbose{boolean}: Prints extra debug logs toconsole.info(default:false)
- Returns {
Promise<object>}: key is env var name and value is the env var value
GetEnvVars
A function that parses environment variables from a .env or a .rc file
options{object}envFile{object}filePath{string}: Custom path to .env file to read from (defaults to:./.env)fallback{boolean}: Should fall back to default./.envfile if custom path does not exist
rc{object}environments{string[]}: List of environment to read from the.rcfilefilePath{string}: Custom path to the.rcfile (defaults to:./.varqrc(|.js|.json))
verbose{boolean}: Prints extra debug logs toconsole.info(default:false)
- Returns {
Promise<object>}: key is env var name and value is the env var value
š§ Why
Because sometimes it is just too cumbersome passing a lot of environment variables to scripts. It is usually just easier to have a file with all the vars in them, especially for development and testing.
šØDo not commit sensitive environment data to a public git repo! šØ
𧬠Related Projects
env-cmd - Executes a command using the environment variables in an env file
cross-env - Cross platform setting of environment scripts
š Special Thanks
Special thanks to env-cmd and cross-env for inspiration (uses the
same cross-spawn lib underneath too).
š Contributing Guide
I welcome all pull requests. Please make sure you add appropriate test cases for any features added. Before opening a PR please make sure to run the following scripts:
npm run lintchecks for code errors and format according to ts-standardnpm testmake sure all tests passnpm run test-covermake sure the coverage has not decreased from current master
4 years ago