Skip to content

Instantly share code, notes, and snippets.

@pozil
Last active September 24, 2024 10:59
Show Gist options
  • Save pozil/a3cd83111ae50e6e4cc50faede888f86 to your computer and use it in GitHub Desktop.
Save pozil/a3cd83111ae50e6e4cc50faede888f86 to your computer and use it in GitHub Desktop.
Salesforce CLI update script for NPM install
VERSION_REGEX="([0-9]+\.[0-9]+\.[0-9]+)"
# Get local version
LOCAL_VERSION=$(sf -v)
if [[ $LOCAL_VERSION =~ $VERSION_REGEX ]]
then
LOCAL_VERSION="${BASH_REMATCH[1]}"
echo Local CLI version: $LOCAL_VERSION
else
echo Could not retrieve local CLI version.
exit 1
fi
# Get NPM version
REMOTE_VERSION=$(npm view @salesforce/cli@latest version)
echo Remote CLI version: $REMOTE_VERSION
# Check if update is needed
if [[ $LOCAL_VERSION == $REMOTE_VERSION ]]
then
echo You have the latest CLI version.
else
echo Installing latest CLI version...
npm install -g @salesforce/cli@latest
fi
@fracarma
Copy link

Amazing! However, what's the reason to use volta? Can't you use npm?

npm install -g @salesforce/cli@latest

@pozil
Copy link
Author

pozil commented Sep 24, 2024

Good catch, let me fix it. I'm using volta because I have a number of node install in my projects and this can mess up with the CLI global install.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment