Merge branch 'master' of github.com:creationix/nvm

This commit is contained in:
Daniel Bretoi 2014-07-05 16:08:34 -07:00
commit cbfddf432e
5 changed files with 44 additions and 34 deletions

View File

@ -8,17 +8,17 @@ First you'll need to make sure your system has a c++ compiler. For OSX, XCode w
To install you could use the [install script][2] using cURL:
curl https://raw.githubusercontent.com/creationix/nvm/v0.8.0/install.sh | sh
curl https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | bash
or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.8.0/install.sh | sh
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | bash
<sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`).</sub>
You can customize the install source, directory and profile using the `NVM_SOURCE`, `NVM_DIR` and `PROFILE` variables. Eg: `curl ... | NVM_DIR=/usr/local/nvm sh` for a global install.
<sub>*NB. The installer can use Git, cURL or Wget to download NVM, whatever is available.*</sub>
<sub>*NB. The installer can use Git, curl, or wget to download NVM, whatever is available.*</sub>
### Manual install
@ -163,7 +163,7 @@ After the v0.8.6 release of node, nvm tries to install from binary packages. But
nvm install -s 0.8.6
[1]: https://github.com/creationix/nvm.git
[2]: https://github.com/creationix/nvm/blob/v0.8.0/install.sh
[2]: https://github.com/creationix/nvm/blob/v0.10.0/install.sh
[3]: https://travis-ci.org/creationix/nvm
[Urchin]: https://github.com/scraperwiki/urchin

View File

@ -2,7 +2,7 @@
set -e
has() {
nvm_has() {
type "$1" > /dev/null 2>&1
return $?
}
@ -11,39 +11,39 @@ if [ -z "$NVM_DIR" ]; then
NVM_DIR="$HOME/.nvm"
fi
if ! has "curl"; then
if has "wget"; then
if ! nvm_has "curl"; then
if nvm_has "wget"; then
# Emulate curl with wget
curl() {
ARGS="$* "
ARGS=${ARGS/-s /-q }
ARGS=${ARGS/-o /-O }
wget $ARGS
wget "$ARGS"
}
fi
fi
install_from_git() {
install_nvm_from_git() {
if [ -z "$NVM_SOURCE" ]; then
NVM_SOURCE="https://github.com/creationix/nvm.git"
fi
if [ -d "$NVM_DIR/.git" ]; then
echo "=> nvm is already installed in $NVM_DIR, trying to update"
echo -e "\r=> \c"
cd "$NVM_DIR" && git pull 2> /dev/null || {
printf "\r=> "
cd "$NVM_DIR" && (git pull 2> /dev/null || {
echo >&2 "Failed to update nvm, run 'git pull' in $NVM_DIR yourself.."
}
})
else
# Cloning to $NVM_DIR
echo "=> Downloading nvm from git to '$NVM_DIR'"
echo -e "\r=> \c"
printf "\r=> "
mkdir -p "$NVM_DIR"
git clone "$NVM_SOURCE" "$NVM_DIR"
fi
}
install_as_script() {
install_nvm_as_script() {
if [ -z "$NVM_SOURCE" ]; then
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/master/nvm.sh"
fi
@ -63,28 +63,28 @@ install_as_script() {
if [ -z "$METHOD" ]; then
# Autodetect install method
if has "git"; then
install_from_git
elif has "curl"; then
install_as_script
if nvm_has "git"; then
install_nvm_from_git
elif nvm_has "curl"; then
install_nvm_as_script
else
echo >&2 "You need git, curl or wget to install nvm"
echo >&2 "You need git, curl, or wget to install nvm"
exit 1
fi
else
if [ "$METHOD" = "git" ]; then
if ! has "git"; then
if ! nvm_has "git"; then
echo >&2 "You need git to install nvm"
exit 1
fi
install_from_git
install_nvm_from_git
fi
if [ "$METHOD" = "script" ]; then
if ! has "curl"; then
if ! nvm_has "curl"; then
echo >&2 "You need curl or wget to install nvm"
exit 1
fi
install_as_script
install_nvm_as_script
fi
fi
@ -104,8 +104,8 @@ fi
SOURCE_STR="\nexport NVM_DIR=\"$NVM_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm"
if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
if [ -z $PROFILE ]; then
echo "=> Profile not found. Tried ~/.bash_profile ~/.zshrc and ~/.profile."
if [ -z "$PROFILE" ]; then
echo "=> Profile not found. Tried ~/.bash_profile, ~/.zshrc, and ~/.profile."
echo "=> Create one of them and run this script again"
else
echo "=> Profile $PROFILE not found"
@ -113,16 +113,15 @@ if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
fi
echo " OR"
echo "=> Append the following lines to the correct file yourself:"
echo -e "$SOURCE_STR"
printf "%s" "$SOURCE_STR"
echo
else
if ! grep -qc 'nvm.sh' $PROFILE; then
if ! grep -qc 'nvm.sh' "$PROFILE"; then
echo "=> Appending source string to $PROFILE"
echo -e "$SOURCE_STR" >> "$PROFILE"
printf "%s" "$SOURCE_STR" >> "$PROFILE"
else
echo "=> Source string already in $PROFILE"
fi
fi
echo "=> Close and reopen your terminal to start using nvm"

12
nvm.sh
View File

@ -274,7 +274,7 @@ nvm() {
echo " nvm alias default 0.10.24 Set default node version on a shell"
echo
echo "Note:"
echo " to remove, delete or uninstall nvm - just remove ~/.nvm, ~/.npm and ~/.bower folders"
echo " to remove, delete, or uninstall nvm - just remove ~/.nvm, ~/.npm, and ~/.bower folders"
echo
;;
@ -572,11 +572,15 @@ nvm() {
NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@"
;;
"ls" | "list" )
nvm_print_versions "`nvm_ls $2`"
local NVM_LS_OUTPUT
local NVM_LS_EXIT_CODE
NVM_LS_OUTPUT=$(nvm_ls "$2")
NVM_LS_EXIT_CODE=$?
nvm_print_versions "$NVM_LS_OUTPUT"
if [ $# -eq 1 ]; then
nvm alias
fi
return
return $NVM_LS_EXIT_CODE
;;
"ls-remote" | "list-remote" )
nvm_print_versions "`nvm_ls_remote $2`"
@ -651,7 +655,7 @@ nvm() {
nvm_version $2
;;
"--version" )
echo "0.8.0"
echo "0.10.0"
;;
"unload" )
unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version > /dev/null 2>&1

View File

@ -1,6 +1,6 @@
{
"name": "nvm",
"version": "0.8.0",
"version": "0.10.0",
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
"directories": {
"test": "test"

View File

@ -0,0 +1,7 @@
#!/bin/sh
. ../../nvm.sh
nvm ls nonexistent_version
[ "$?" = "3" ]