varq
v11.0.0
Published
Executes a command using the environment variables in an package.json config file
Downloads
2
Maintainers
Readme
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./.env
file if custom path does not exist
rc
{object
}environments
{string[]
}: List of environment to read from the.rc
filefilePath
{string
}: Custom path to the.rc
file (defaults to:./.varqrc(|.js|.json)
)
options
{object
}expandEnvs
{boolean
}: Expand$var
values passed tocommandArgs
(default:false
)noOverride
{boolean
}: Prevent.env
file vars from overriding existingprocess.env
vars (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./.env
file if custom path does not exist
rc
{object
}environments
{string[]
}: List of environment to read from the.rc
filefilePath
{string
}: Custom path to the.rc
file (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 lint
checks for code errors and format according to ts-standardnpm test
make sure all tests passnpm run test-cover
make sure the coverage has not decreased from current master