[New] add `nvm cache` with “dir” and “clean” commands.

- cache the nvm cache on travis
Jordan Harband 2016-08-13 21:15:12 -07:00
parent 57c2004ab2
commit e546149f7b
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
3 changed files with 34 additions and 6 deletions

3
.gitignore vendored
View File

@ -1,6 +1,5 @@
HEAD HEAD
bin .cache
src
v* v*
alias alias

View File

@ -6,6 +6,7 @@ addons:
cache: cache:
directories: directories:
- $HOME/.stack - $HOME/.stack
- $TRAVIS_BUILD_DIR/.cache
before_install: before_install:
- $SHELL --version 2> /dev/null || dpkg -s $SHELL 2> /dev/null || which $SHELL - $SHELL --version 2> /dev/null || dpkg -s $SHELL 2> /dev/null || which $SHELL
- curl --version - curl --version

36
nvm.sh
View File

@ -1640,9 +1640,9 @@ nvm_download_artifact() {
local tmpdir local tmpdir
if [ "${KIND}" = 'binary' ]; then if [ "${KIND}" = 'binary' ]; then
tmpdir="${NVM_DIR}/bin/${SLUG}" tmpdir="$(nvm_cache_dir)/bin/${SLUG}"
else else
tmpdir="${NVM_DIR}/src/${SLUG}" tmpdir="$(nvm_cache_dir)/src/${SLUG}"
fi fi
command mkdir -p "${tmpdir}/files" || ( command mkdir -p "${tmpdir}/files" || (
nvm_err "creating directory ${tmpdir}/files failed" nvm_err "creating directory ${tmpdir}/files failed"
@ -1975,6 +1975,10 @@ nvm_check_file_permissions() {
return 0 return 0
} }
nvm_cache_dir() {
nvm_echo "${NVM_DIR}/.cache"
}
nvm() { nvm() {
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
nvm --help nvm --help
@ -2043,6 +2047,8 @@ nvm() {
nvm_echo ' nvm reinstall-packages <version> Reinstall global `npm` packages contained in <version> to current version' nvm_echo ' nvm reinstall-packages <version> Reinstall global `npm` packages contained in <version> to current version'
nvm_echo ' nvm unload Unload `nvm` from shell' nvm_echo ' nvm unload Unload `nvm` from shell'
nvm_echo ' nvm which [<version>] Display path to installed node version. Uses .nvmrc if available' nvm_echo ' nvm which [<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 clear Empty cache directory for nvm'
nvm_echo nvm_echo
nvm_echo 'Example:' nvm_echo 'Example:'
nvm_echo ' nvm install v0.10.32 Install a specific version number' nvm_echo ' nvm install v0.10.32 Install a specific version number'
@ -2056,6 +2062,26 @@ nvm() {
nvm_echo nvm_echo
;; ;;
"cache" )
case "${1-}" in
dir) nvm_cache_dir ;;
clear)
local DIR
DIR="$(nvm_cache_dir)"
if command rm -rf "${DIR}" && command mkdir -p "${DIR}"; then
nvm_echo 'Cache cleared.'
else
nvm_err "Unable to clear cache: ${DIR}"
return 1
fi
;;
*)
>&2 nvm --help
return 127
;;
esac
;;
"debug" ) "debug" )
local ZSH_HAS_SHWORDSPLIT_UNSET local ZSH_HAS_SHWORDSPLIT_UNSET
ZSH_HAS_SHWORDSPLIT_UNSET=1 ZSH_HAS_SHWORDSPLIT_UNSET=1
@ -2353,9 +2379,11 @@ nvm() {
fi fi
# Delete all files related to target version. # Delete all files related to target version.
local CACHE_DIR
CACHE_DIR="$(nvm_cache_dir)"
command rm -rf \ command rm -rf \
"${NVM_DIR}/bin/${SLUG_BINARY}/files" \ "${CACHE_DIR}/bin/${SLUG_BINARY}/files" \
"${NVM_DIR}/src/${SLUG_SOURCE}/files" \ "${CACHE_DIR}/src/${SLUG_SOURCE}/files" \
"${VERSION_PATH}" 2>/dev/null "${VERSION_PATH}" 2>/dev/null
nvm_echo "${NVM_SUCCESS_MSG}" nvm_echo "${NVM_SUCCESS_MSG}"