Last active
September 24, 2024 10:59
-
-
Save pozil/a3cd83111ae50e6e4cc50faede888f86 to your computer and use it in GitHub Desktop.
Salesforce CLI update script for NPM install
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.