Created
August 22, 2024 23:58
-
-
Save scottschreckengaust/50e8279113c4109d704ecd7b1bde991b to your computer and use it in GitHub Desktop.
Install latest maintained node in a virtual environment using pipenv and nodeenv
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
| #!/bin/sh | |
| # Installation looks like this: | |
| # nodeenv --node=20.16.0 --python-virtual; | |
| # Install nodeenv if not present | |
| which nodeenv || pipenv install --dev nodeenv; | |
| # If asking for a specific version just try to install it... | |
| # Otherwise, get the latest and install it unless it is already installed | |
| if [ ! -z "$1" ] | |
| then | |
| nodeenv --node=${1} --python-virtual; | |
| else | |
| # Get in YYYY-MM-DD format | |
| NOW=$(date +"%Y-%m-%d") | |
| # Get latest maintained code named version | |
| LATEST=$(curl --silent https://raw.githubusercontent.com/nodejs/Release/main/schedule.json | jq --raw-output "to_entries[] | select(.value.codename) | select(.value.codename != \"\") | select(.value.end > \"$NOW\") | .key" | sort | tail -1 | sed -e "s/^v//g") | |
| NODE_VERSION=$(nodeenv --list 2>&1 > /dev/null | tr -s "[:space:]" "\n" | grep -e "^$LATEST\." | tail -1) | |
| INSTALLED_VERSION="" | |
| which node && INSTALLED_VERSION=$(node --version); | |
| if [ "$INSTALLED_VERSION" != "v${NODE_VERSION}" ] | |
| then | |
| echo "node version ${INSTALLED_VERSION} to v${NODE_VERSION}..." | |
| nodeenv --node=${NODE_VERSION} --python-virtual; | |
| else | |
| echo "node version ${NODE_VERSION} already installed"; | |
| fi | |
| fi | |
| exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment