mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-11 06:41:50 +00:00
[New] Add nvm self-upgrade
to upgrade nvm itself
This commit is contained in:
parent
e7b42198b4
commit
3452d73a61
@ -28,7 +28,7 @@ __nvm_commands ()
|
|||||||
current list ls list-remote ls-remote
|
current list ls list-remote ls-remote
|
||||||
install-latest-npm
|
install-latest-npm
|
||||||
cache deactivate unload
|
cache deactivate unload
|
||||||
version version-remote which'
|
version version-remote which self-upgrade'
|
||||||
|
|
||||||
if [ ${#COMP_WORDS[@]} == 4 ]; then
|
if [ ${#COMP_WORDS[@]} == 4 ]; then
|
||||||
|
|
||||||
|
47
nvm.sh
47
nvm.sh
@ -2347,6 +2347,7 @@ nvm() {
|
|||||||
nvm_echo ' nvm which [current | <version>] Display path to installed node version. Uses .nvmrc if available'
|
nvm_echo ' nvm which [current | <version>] Display path to installed node version. Uses .nvmrc if available'
|
||||||
nvm_echo ' nvm cache dir Display path to the cache directory for nvm'
|
nvm_echo ' nvm cache dir Display path to the cache directory for nvm'
|
||||||
nvm_echo ' nvm cache clear Empty cache directory for nvm'
|
nvm_echo ' nvm cache clear Empty cache directory for nvm'
|
||||||
|
nvm_echo ' nvm self-upgrade Upgrade nvm to the latest stable release version'
|
||||||
nvm_echo
|
nvm_echo
|
||||||
nvm_echo 'Example:'
|
nvm_echo 'Example:'
|
||||||
nvm_echo ' nvm install 8.0.0 Install a specific version number'
|
nvm_echo ' nvm install 8.0.0 Install a specific version number'
|
||||||
@ -2448,6 +2449,52 @@ nvm() {
|
|||||||
return 42
|
return 42
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
"self-upgrade")
|
||||||
|
local current_nvm_version
|
||||||
|
local latest_nvm_version
|
||||||
|
local origin_nvm_version
|
||||||
|
|
||||||
|
current_nvm_version="$(nvm --version)"
|
||||||
|
|
||||||
|
if nvm_has "git" && [ -d "$NVM_DIR/.git" ]; then
|
||||||
|
command cd "$NVM_DIR"
|
||||||
|
command git fetch --tags
|
||||||
|
latest_nvm_version="$(command git describe --abbrev=0 --tags --match 'v[0-9]*' origin)"
|
||||||
|
if [ "v$current_nvm_version" = "$latest_nvm_version" ]; then
|
||||||
|
nvm_echo "You already have the latest nvm ($latest_nvm_version) "
|
||||||
|
else
|
||||||
|
command git reset --hard
|
||||||
|
command git checkout "$latest_nvm_version"
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
|
||||||
|
origin_nvm_version="$current_nvm_version"
|
||||||
|
current_nvm_version="$(nvm --version)"
|
||||||
|
if [ "v$current_nvm_version" = "$latest_nvm_version" ]; then
|
||||||
|
nvm_echo "nvm successfully upgrade from v$origin_nvm_version to v$current_nvm_version!"
|
||||||
|
else
|
||||||
|
nvm_err "nvm upgrade failed!!!"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
elif nvm_has "nvm_download" && nvm_has "nvm_get_latest"; then
|
||||||
|
latest_nvm_version="$(nvm_get_latest)"
|
||||||
|
if [ "v$current_nvm_version" = "$latest_nvm_version" ]; then
|
||||||
|
nvm_echo "You already have the latest nvm ($latest_nvm_version) "
|
||||||
|
else
|
||||||
|
nvm_download "https://raw.githubusercontent.com/creationix/nvm/$latest_nvm_version/install.sh" | command bash
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
|
||||||
|
origin_nvm_version="$current_nvm_version"
|
||||||
|
current_nvm_version="$(nvm --version)"
|
||||||
|
if [ "v$current_nvm_version" = "$latest_nvm_version" ]; then
|
||||||
|
nvm_echo "nvm successfully upgrade from v$origin_nvm_version to v$current_nvm_version!"
|
||||||
|
else
|
||||||
|
nvm_err "nvm upgrade failed!!!"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
nvm_err "You need git, curl, or wget to upgrade nvm"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
"install" | "i" )
|
"install" | "i" )
|
||||||
local version_not_provided
|
local version_not_provided
|
||||||
version_not_provided=0
|
version_not_provided=0
|
||||||
|
Loading…
Reference in New Issue
Block a user