Last active
October 25, 2024 00:46
-
-
Save ankjevel/00360558b1bd92c6892444e5400309a6 to your computer and use it in GitHub Desktop.
clear npm cache (when using nvm); run with `nvm list | clear-cache`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
function clear-cache { | |
versions=() | |
while read -r line; do | |
clean="$(echo ${line} | sed "s,$(printf '\033')\\[[0-9;]*[a-zA-Z],,g")" | |
valid=$(echo "${clean}" | grep '^[^a-zA-Z]' | grep -v 'system' | sed 's/->//' | sed 's/\s.*v//') | |
if [[ ! -z $valid ]]; then | |
versions+=(${valid}) | |
fi | |
done <<< "$(cat)" | |
for version in "${versions[@]}"; do | |
nvm use ${version} | |
npm cache clear -f | |
done | |
} | |
# run with: | |
# nvm list | clear-cache |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to run: