forked from apollographql/apollo-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check-and-run-apollo-codegen script
- Loading branch information
1 parent
b2a2a81
commit 31f3632
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
|
||
REQUIRED_APOLLO_CODEGEN_VERSION=0.6 | ||
|
||
# Part of this code has been adapted from https://github.com/facebook/react-native/blob/master/packager/react-native-xcode.sh | ||
|
||
# This script is supposed to be invoked as part of the Xcode build process | ||
# and relies on environment variables set by Xcode | ||
|
||
if [[ -z "$CONFIGURATION" ]]; then | ||
echo "$0 must be invoked as part of an Xcode script phase" | ||
exit 1 | ||
fi | ||
|
||
# Define NVM_DIR and source the nvm.sh setup script | ||
[[ -z "$NVM_DIR" ]] && export NVM_DIR="$HOME/.nvm" | ||
|
||
if [[ -s "$HOME/.nvm/nvm.sh" ]]; then | ||
. "$HOME/.nvm/nvm.sh" | ||
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then | ||
. "$(brew --prefix nvm)/nvm.sh" | ||
fi | ||
|
||
# Set up the nodenv node version manager if present | ||
if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then | ||
eval "$("$HOME/.nodenv/bin/nodenv" init -)" | ||
fi | ||
|
||
if ! type "apollo-codegen" >/dev/null 2>&1; then | ||
echo "error: Can't find apollo-codegen command; make sure to run 'npm install -g apollo-codegen' first." | ||
exit 1 | ||
fi | ||
|
||
# We consider versions to be compatible if the major and minor versions match | ||
are_versions_compatible() { | ||
[[ "$(cut -d. -f1-2 <<< $1)" == "$(cut -d. -f1-2 <<< $2)" ]] | ||
} | ||
|
||
INSTALLED_APOLLO_CODEGEN_VERSION=$(apollo-codegen --version) || "an unknown older version" | ||
|
||
if ! are_versions_compatible $INSTALLED_APOLLO_CODEGEN_VERSION $REQUIRED_APOLLO_CODEGEN_VERSION; then | ||
echo "error: The version of Apollo.framework in your project requires the use of version $REQUIRED_APOLLO_CODEGEN_VERSION of apollo-codegen, \ | ||
but $INSTALLED_APOLLO_CODEGEN_VERSION seems to be installed." | ||
exit 1 | ||
fi | ||
|
||
# Print commands before executing them (useful for troubleshooting) | ||
set -x | ||
|
||
$(apollo-codegen "$@") |