Last active
March 14, 2020 01:26
-
-
Save mattriley/5d963cb6735a888d9b51f3ba8c48f907 to your computer and use it in GitHub Desktop.
Writes a .nvmrc file containing the current Node LTS version. Requires nvm.
This file contains hidden or 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
# Usage: ./nvmrc-latest-lts.sh | |
# Load NVM | |
export NVM_DIR="$HOME/.nvm" | |
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | |
# Find latest Node LTS version | |
last_line=$(nvm ls-remote --lts --no-colors | tail -n 1) | |
# Match the version number | |
if [[ "$last_line" =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then | |
old=$(cat .nvmrc 2>/dev/null) | |
new=${BASH_REMATCH[0]} | |
echo "Old: \"${old}\" New: \"${new}\"" | |
echo $new > .nvmrc | |
else | |
echo "Failed to extract latest LTS version" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment