├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── bin └── nodenv-vars ├── etc └── nodenv.d │ └── exec │ └── nodenv-vars.bash └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /nodenv-nodenv-vars-*.tgz 3 | /package-lock.json 4 | /yarn.lock 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: node 3 | cache: npm 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011 Sam Stephenson 4 | Copyright (c) 2015 Will McKenzie 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nodenv-vars 2 | 3 | This is a plugin for [nodenv](https://github.com/nodenv/nodenv) 4 | that lets you set global and project-specific environment variables 5 | before spawning Node processes. 6 | 7 | 8 | 9 | - [Installation](#installation) 10 | - [Usage](#usage) 11 | - [Credits](#credits) 12 | 13 | 14 | 15 | ## Installation 16 | 17 | To install nodenv-vars, clone this repository into your 18 | `$(nodenv root)/plugins` directory. (You'll need a recent version of nodenv 19 | that supports plugin bundles.) 20 | 21 | $ mkdir -p $(nodenv root)/plugins 22 | $ cd $(nodenv root)/plugins 23 | $ git clone https://github.com/nodenv/nodenv-vars.git 24 | 25 | ## Usage 26 | 27 | Define environment variables in an `.nodenv-vars` file in your project, 28 | one variable per line, in the format `VAR=value`. For example: 29 | 30 | HUBOT_CAMPFIRE_ACCOUNT=nodenv 31 | HUBOT_CAMPFIRE_TOKEN=somerandomtoken 32 | HUBOT_CAMPFIRE_ROOMS=some,campfire,rooms 33 | 34 | You can perform variable substitution with the traditional `$` 35 | syntax. For example, to append to `HUBOT_CAMPFIRE_ROOMS`: 36 | 37 | HUBOT_CAMPFIRE_ROOMS=$HUBOT_CAMPFIRE_ROOMS:some,extra,rooms 38 | 39 | You may also have conditional variable assignments, such that a 40 | variable will **only** be set if it is not already defined or is blank: 41 | 42 | USER_ID?=OiNutter 43 | 44 | In the above case, `USER_ID` will only be set if `$USER_ID` is 45 | currently empty (i.e., if `[ -z "$USER_ID" ]` is true). 46 | 47 | Spaces are allowed in values; quoting is not necessary. Expansion and 48 | command substitution are not allowed. Lines beginning with `#` or any 49 | lines not in the format VAR=value will be ignored. 50 | 51 | Variables specified in the `$(nodenv root)/vars` file will be set 52 | first. Then variables specified in `.nodenv-vars` files in any parent 53 | directories of the current directory will be set. Variables from the 54 | `.nodenv-vars` file in the current directory are set last. 55 | 56 | Use the `nodenv vars` command to print all environment variables in the 57 | order they'll be set. 58 | 59 | ## Credits 60 | 61 | Forked from [Sam Stephenson](https://github.com/sstephenson)'s 62 | [rbenv-vars](https://github.com/rbenv/rbenv-vars) by [Will 63 | McKenzie](https://github.com/oinutter) and modified for nodenv. 64 | -------------------------------------------------------------------------------- /bin/nodenv-vars: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Usage: nodenv vars 4 | # 5 | # Prints all nodenv-vars environment variables applicable to the 6 | # current working directory in the order they will be set. The output 7 | # format is a script that may be passed to `eval` in a Bourne- 8 | # compatible shell. 9 | # 10 | # For more information on nodenv-vars, see: 11 | # https://github.com/nodenv/nodenv-vars#readme 12 | 13 | set -e 14 | [ -n "$NODENV_DEBUG" ] && set -x 15 | 16 | # Provide nodenv completions 17 | for arg; do 18 | case "$arg" in 19 | --complete ) 20 | echo --version 21 | exit ;; 22 | -v | --version ) 23 | exec echo "nodenv-vars 1.2.0" ;; 24 | * ) 25 | nodenv-help --usage vars >&2 26 | exit 1 ;; 27 | esac 28 | done 29 | 30 | traverse-nodenv-vars-files() { 31 | local root="$1" 32 | local results="" 33 | 34 | while [ -n "$root" ]; do 35 | if [ -e "${root}/.nodenv-vars" ]; then 36 | results="${root}/.nodenv-vars"$'\n'"$results" 37 | fi 38 | root="${root%/*}" 39 | done 40 | 41 | if [ -n "$results" ]; then 42 | echo -n "$results" 43 | else 44 | return 1 45 | fi 46 | } 47 | 48 | find-nodenv-vars-files() { 49 | if [ -e "${NODENV_ROOT}/vars" ]; then 50 | echo "${NODENV_ROOT}/vars" 51 | fi 52 | 53 | traverse-nodenv-vars-files "$NODENV_DIR" || 54 | [ "$NODENV_DIR" = "$PWD" ] || traverse-nodenv-vars-files "$PWD" 55 | } 56 | 57 | sanitize-vars() { 58 | sed \ 59 | -e "/^[ "$'\t'"]*[A-Za-z_][0-9A-Za-z_]*?\{0,1\}=/ !d" \ 60 | -e "s/'/'\\\\''/g" \ 61 | -e "s/\(\\\\\\\$\)/'\\1'/g" \ 62 | -e "s/\\\\\\\\/\\\\/g" \ 63 | -e "s/\(\\\$[0-9A-Za-z_][0-9A-Za-z_]*\)/'\\1'/g" \ 64 | -e "s/\(\\\${[0-9A-Za-z_][0-9A-Za-z_]*}\)/'\\1'/g" \ 65 | -e "s/^[ "$'\t'"]*\([A-Za-z_][0-9A-Za-z_]*?\{0,1\}\)=\(.*\)$/export \\1='\\2'/" \ 66 | -e "s/export \([A-Za-z_][0-9A-Za-z_]*\)?=/[ -n \"\$\\1\" ] || export \\1=/g" 67 | } 68 | 69 | while read -r file; do 70 | echo "# $file" 71 | { cat "$file"; echo; } | sanitize-vars 72 | echo 73 | done < <( find-nodenv-vars-files ) 74 | -------------------------------------------------------------------------------- /etc/nodenv.d/exec/nodenv-vars.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | eval "$(nodenv-vars)" 4 | 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@nodenv/nodenv-vars", 3 | "version": "1.2.0", 4 | "description": "A nodenv plugin that safely sets global and per-project environment variables", 5 | "homepage": "https://github.com/nodenv/nodenv-vars#readme", 6 | "license": "MIT", 7 | "contributors": [ 8 | "Jason Karns (http://jason.karns.name)", 9 | "Sam Stephenson (http://sstephenson.us)", 10 | "Will McKenzie (http://www.oinutter.co.uk)" 11 | ], 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/nodenv/nodenv-vars.git" 15 | }, 16 | "bugs": { 17 | "url": "https://github.com/nodenv/nodenv-vars/issues" 18 | }, 19 | "directories": { 20 | "bin": "bin" 21 | }, 22 | "files": [ 23 | "bin", 24 | "etc" 25 | ], 26 | "scripts": { 27 | "start": "bin/npm-vars", 28 | "posttest": "npm run lint", 29 | "lint": "git ls-files bin etc | xargs shellcheck", 30 | "postversion": "npm publish", 31 | "prepublishOnly": "npm run publish:github && npm run publish:brew", 32 | "publish:brew": "brew-publish", 33 | "publish:github": "git push --follow-tags" 34 | }, 35 | "devDependencies": { 36 | "brew-publish": "^2.3.1" 37 | } 38 | } 39 | --------------------------------------------------------------------------------