Last active
March 13, 2020 14:55
-
-
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
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
#!/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