2018-07-24 20:23:47 +00:00
|
|
|
unset BASH_ENV
|
|
|
|
# we don't need to run more than once
|
|
|
|
if [[ -v embark_docker_embark_user_BASH_ENV ]]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
export embark_docker_embark_user_BASH_ENV=
|
|
|
|
|
|
|
|
export embark_docker_embark_user_npm_bak_config_prefix=${HOME}/.npm-packages
|
|
|
|
export npm_config_prefix=$embark_docker_embark_user_npm_bak_config_prefix
|
|
|
|
export NPM_CONFIG_PREFIX=$npm_config_prefix
|
|
|
|
|
|
|
|
export embark_docker_embark_user_PATH_with_LOCALBIN=${HOME}/.local/bin:$PATH
|
|
|
|
export embark_docker_embark_user_PATH_with_NPM=$NPM_CONFIG_PREFIX/bin:$embark_docker_embark_user_PATH_with_LOCALBIN
|
|
|
|
export PATH=$embark_docker_embark_user_PATH_with_NPM
|
|
|
|
|
|
|
|
nac () {
|
|
|
|
local txtbld=$(tput bold)
|
|
|
|
local txtrst=$(tput sgr0)
|
|
|
|
local bldred=${txtbld}$(tput setaf 1)
|
|
|
|
local ERROR=${bldred}ERROR${txtrst}
|
|
|
|
if [[ -z "$1" ]]; then
|
|
|
|
echo "$ERROR: missing node environment name"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
if [[ ! -d "${HOME}/.local/nodeenv/$1" ]]; then
|
|
|
|
echo "$ERROR: no \"$1\" environment found in ${HOME}/.local/nodeenv"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
____nvm_unload
|
|
|
|
____denac
|
|
|
|
export PATH=$embark_docker_embark_user_PATH_with_LOCALBIN
|
|
|
|
. ${HOME}/.local/nodeenv/$1/bin/activate
|
|
|
|
if [[ $? != 0 ]]; then
|
|
|
|
____denac
|
|
|
|
return 1
|
|
|
|
fi
|
2018-07-25 16:50:07 +00:00
|
|
|
export NODE_VERSION=$(node --version)
|
2018-07-25 15:13:46 +00:00
|
|
|
alias denac='deactivate_node'
|
2018-07-24 20:23:47 +00:00
|
|
|
alias deactivate_node='__denac'
|
|
|
|
case $- in
|
2018-07-26 00:15:53 +00:00
|
|
|
*i*) __npm_completion; echo "Now using NODEENV node $NODE_VERSION (npm v$(npm --version))" ;;
|
2018-07-24 20:23:47 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
export -f nac
|
|
|
|
|
|
|
|
__nac () {
|
|
|
|
local curr_word="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
local -a envs=( $(compgen -d -- "${HOME}/.local/nodeenv/$curr_word") )
|
|
|
|
COMPREPLY=( "${envs[@]##*/}" )
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
export -f __nac
|
|
|
|
complete -F __nac nac
|
|
|
|
|
|
|
|
__denac () {
|
|
|
|
____denac
|
|
|
|
case $- in
|
2018-07-26 00:15:53 +00:00
|
|
|
*i*) echo "Now using system node $(node --version) (npm v$(npm --version))" ;;
|
2018-07-24 20:23:47 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
export -f __denac
|
|
|
|
|
|
|
|
____denac () {
|
2018-07-25 15:13:46 +00:00
|
|
|
unalias denac &> /dev/null
|
2018-07-24 20:23:47 +00:00
|
|
|
unalias deactivate_node &> /dev/null
|
|
|
|
if type deactivate_node &> /dev/null; then
|
|
|
|
deactivate_node
|
|
|
|
fi
|
|
|
|
export PATH=$embark_docker_embark_user_PATH_with_NPM
|
2018-07-25 16:50:07 +00:00
|
|
|
export NODE_VERSION=$(node --version)
|
2018-07-24 20:23:47 +00:00
|
|
|
}
|
|
|
|
export -f ____denac
|
|
|
|
|
|
|
|
__npm_completion () {
|
|
|
|
. <(npm completion)
|
|
|
|
}
|
|
|
|
export -f __npm_completion
|
|
|
|
|
|
|
|
nvm_load () {
|
2018-07-25 20:52:06 +00:00
|
|
|
__nvm_load $1
|
2018-07-24 20:23:47 +00:00
|
|
|
alias nvm_load='nvm'
|
|
|
|
alias nvm='__nvm_mask'
|
|
|
|
__nvm_mask () {
|
2018-07-25 20:17:59 +00:00
|
|
|
case "$*" in
|
2018-07-26 00:15:53 +00:00
|
|
|
unload*) __nvm_unload ;;
|
|
|
|
*) unalias nvm; nvm "$@"; alias nvm='__nvm_mask' ;;
|
2018-07-24 20:23:47 +00:00
|
|
|
esac
|
2018-07-25 16:50:07 +00:00
|
|
|
export NODE_VERSION=$(node --version)
|
2018-07-24 20:23:47 +00:00
|
|
|
}
|
|
|
|
export -f __nvm_mask
|
|
|
|
}
|
|
|
|
export -f nvm_load
|
|
|
|
|
|
|
|
__nvm_load () {
|
|
|
|
____nvm_unload
|
|
|
|
____denac
|
|
|
|
export PATH=$embark_docker_embark_user_PATH_with_LOCALBIN
|
|
|
|
. ${HOME}/.bash_env_nvm_load
|
|
|
|
. ${HOME}/.nvm/nvm.sh &> /dev/null
|
|
|
|
if [[ (-z $(nvm alias default)) && ($1 != "no-auto-lts") ]]; then
|
|
|
|
case $- in
|
2018-07-26 00:15:53 +00:00
|
|
|
*i*) nvm install --lts ;;
|
|
|
|
*) nvm install --lts &> /dev/null ;;
|
2018-07-24 20:23:47 +00:00
|
|
|
esac
|
|
|
|
local auto_lts=
|
|
|
|
fi
|
|
|
|
case $- in
|
2018-07-26 00:15:53 +00:00
|
|
|
*i*) __npm_completion ;;
|
2018-07-24 20:23:47 +00:00
|
|
|
esac
|
2018-07-26 00:15:53 +00:00
|
|
|
if [[ (! -v auto_lts) && ($(which node) = "${HOME}/.nvm/versions/"*) ]]; then
|
2018-07-25 16:50:07 +00:00
|
|
|
export NODE_VERSION=$(node --version)
|
2018-07-24 20:23:47 +00:00
|
|
|
case $- in
|
2018-07-26 00:15:53 +00:00
|
|
|
*i*) echo "Now using NVM node $NODE_VERSION (npm v$(npm --version))" ;;
|
2018-07-24 20:23:47 +00:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
export -f __nvm_load
|
|
|
|
|
|
|
|
__nvm_unload () {
|
|
|
|
____nvm_unload
|
|
|
|
case $- in
|
2018-07-26 00:15:53 +00:00
|
|
|
*i*) echo "Now using system node $NODE_VERSION (npm v$(npm --version))" ;;
|
2018-07-24 20:23:47 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
export -f __nvm_unload
|
|
|
|
|
|
|
|
____nvm_unload () {
|
|
|
|
unalias nvm_load &> /dev/null
|
|
|
|
unalias nvm &> /dev/null
|
|
|
|
unset __nvm_mask
|
|
|
|
if type nvm &> /dev/null; then
|
|
|
|
nvm unload
|
|
|
|
fi
|
|
|
|
export PATH=$embark_docker_embark_user_PATH_with_NPM
|
|
|
|
. ${HOME}/.bash_env_nvm_unload
|
2018-07-25 16:50:07 +00:00
|
|
|
export NODE_VERSION=$(node --version)
|
2018-07-24 20:23:47 +00:00
|
|
|
}
|
|
|
|
export -f ____nvm_unload
|
|
|
|
|
|
|
|
simple_nodeenv () {
|
|
|
|
pushd $PWD &> /dev/null
|
|
|
|
cd ${HOME}/.local/nodeenv
|
2018-07-25 20:17:59 +00:00
|
|
|
nodeenv --prebuilt --node "$@"
|
|
|
|
if [[ $? != 0 ]]; then
|
|
|
|
popd &> /dev/null
|
|
|
|
return 1
|
|
|
|
fi
|
2018-07-24 20:23:47 +00:00
|
|
|
popd &> /dev/null
|
2018-07-25 20:17:59 +00:00
|
|
|
nac "$2"
|
2018-07-24 20:23:47 +00:00
|
|
|
}
|
|
|
|
export -f simple_nodeenv
|