Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 19 additions & 26 deletions scripts/check-and-run-apollo-cli.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Only major and minor version should be specified here
REQUIRED_APOLLO_CLI_VERSION=1.9
# Only major version should be specified here
REQUIRED_NODE_VERSION=8
# Specify fully qualified version here
REQUIRED_NODE_VERSION=8.0.0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think sticking with the major is probably better; especially considering that 8.0.0 is EOL and only the latest 8 (8.15.0 at this writing) is considered LTS.

Copy link
Copy Markdown
Contributor Author

@bachand bachand Jan 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good context. Thanks @ljharb. Nodenv was requiring me to specify a fully qualified version. I’ll update this to be 8.15.0 since that is LTS.


# Using npx to execute 'apollo' looks for a local install in node_modules before checking $PATH (for a global install)
APOLLO_CLI="npx --no-install apollo"
Expand All @@ -17,18 +17,33 @@ if [[ -z "$CONFIGURATION" ]]; then
exit 1
fi

# Define NVM_DIR and source the nvm.sh setup script
[[ -z "$NVM_DIR" ]] && export NVM_DIR="$HOME/.nvm"
use_correct_node_via_nvm() {
nvm version $REQUIRED_NODE_VERSION > /dev/null
if [[ $? -eq 0 ]]; then
# The version of node that we want is installed.
nvm use $REQUIRED_NODE_VERSION
else
nvm install $REQUIRED_NODE_VERSION
fi
}

use_correct_node_via_nodenv() {
nodenv install -s $REQUIRED_NODE_VERSION
nodenv shell $REQUIRED_NODE_VERSION
}

if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
. "$HOME/.nvm/nvm.sh"
use_correct_node_via_nvm
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
. "$(brew --prefix nvm)/nvm.sh"
use_correct_node_via_nvm
fi

# Set up the nodenv node version manager if present
if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full transparency: I just installed a clean version of Nodenv and this file doesn't exist, so I am wondering if this check is incorrect. That being said, I've tested the commands here for installing Node 8.15.0 via Nodenv and they work. Determining if in fact there is an issue in this check should be a separate investigation / PR.

eval "$("$HOME/.nodenv/bin/nodenv" init -)"
use_correct_node_via_nodenv
fi

parse_version() {
Expand All @@ -37,28 +52,6 @@ parse_version() {
fi
}

get_installed_node_version() {
version=$(node -v)
if [[ $? -eq 0 ]]; then
echo "$version"
fi
}

is_mimimum_major_version() {
[[ "$(parse_version $1 | cut -d. -f1)" -ge $2 ]]
}

# Check the installed version of Node, if available
INSTALLED_NODE_VERSION="$(get_installed_node_version)"
if [[ -z "$INSTALLED_NODE_VERSION" ]]; then
echo "error: Apollo CLI requires Node $REQUIRED_NODE_VERSION or higher to be installed."
exit 1
elif ! is_mimimum_major_version "$INSTALLED_NODE_VERSION" $REQUIRED_NODE_VERSION; then
echo "error: Apollo CLI requires Node $REQUIRED_NODE_VERSION or higher, \
but $INSTALLED_NODE_VERSION seems to be installed."
exit 1
fi

get_installed_cli_version() {
version=$($APOLLO_CLI -v)
if [[ $? -eq 0 ]]; then
Expand Down
⚔