Skip to content

Instantly share code, notes, and snippets.

@sndrs
Last active March 13, 2020 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sndrs/c9c137430a8aa7984bed290afd549baa to your computer and use it in GitHub Desktop.
Save sndrs/c9c137430a8aa7984bed290afd549baa to your computer and use it in GitHub Desktop.
Check local environment for Yarn and NVM, and prompt to install if they're missing
#!/bin/bash
log_error () {
echo -e "\x1b[31m$1\x1b[0m"
}
log_info () {
echo -e "\x1b[2m$1\x1b[0m"
}
log_info 'Checking environment'
# make sure yarn is installed, and that it supports `policies`
# https://classic.yarnpkg.com/en/docs/cli/policies/
# https://github.com/yarnpkg/yarn/releases/tag/v1.13.0
if ! [ -x "$(command -v yarn)" ]; then
log_error "Could not find Yarn. Please install it before continuing:"
log_info "https://classic.yarnpkg.com/en/docs/install"
else
YARN_VERSION=$(yarn --version)
REQUIRED_VERSION="1.13.0"
if ! [ "$(printf '%s\n' "$REQUIRED_VERSION" "$YARN_VERSION" | sort -V | head -n1)" = "$REQUIRED_VERSION" ]; then
log_error "Your version of Yarn is too old (found $YARN_VERSION but wanted $REQUIRED_VERSION or above). Please update it before continuing:"
log_info "https://classic.yarnpkg.com/en/docs/install"
fi
fi
# Check NVM is installed and usable
NVM="$HOME/.nvm/nvm.sh"
if ! [ -f "$NVM" ] || ! source $NVM || ! [ "$(command -v nvm)" ] ; then
log_error "Could not find NVM. Please install it before continuing:"
log_info "https://github.com/creationix/nvm#installation-and-update"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment