Skip to content

Commit

Permalink
Add check-and-run-apollo-codegen script
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnwalraven committed Oct 12, 2016
1 parent b2a2a81 commit 31f3632
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions Apollo.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '8.0'

s.source_files = 'Apollo/**/*.swift'
s.resource = 'scripts/*'
end
12 changes: 12 additions & 0 deletions Apollo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
9FC750541D2A532D00458D91 /* ParseQueryResultDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FC750531D2A532D00458D91 /* ParseQueryResultDataTests.swift */; };
9FC750611D2A59C300458D91 /* GraphQL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FC750601D2A59C300458D91 /* GraphQL.swift */; };
9FC750631D2A59F600458D91 /* ApolloClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FC750621D2A59F600458D91 /* ApolloClient.swift */; };
9FE3F3981DADBD870072078F /* check-and-run-apollo-codegen.sh in Resources */ = {isa = PBXBuildFile; fileRef = 9FE3F3971DADBD870072078F /* check-and-run-apollo-codegen.sh */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -59,6 +60,7 @@
9FC750551D2A532D00458D91 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9FC750601D2A59C300458D91 /* GraphQL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphQL.swift; sourceTree = "<group>"; };
9FC750621D2A59F600458D91 /* ApolloClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApolloClient.swift; sourceTree = "<group>"; };
9FE3F3971DADBD870072078F /* check-and-run-apollo-codegen.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = "check-and-run-apollo-codegen.sh"; path = "scripts/check-and-run-apollo-codegen.sh"; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -132,6 +134,7 @@
9FC750461D2A532C00458D91 /* Apollo */ = {
isa = PBXGroup;
children = (
9FE3F3961DADBD0D0072078F /* Supporting Files */,
9FC750621D2A59F600458D91 /* ApolloClient.swift */,
9F69FFA81D42855900E000B1 /* NetworkTransport.swift */,
9F578D8F1D8D2CB300C0EA36 /* Utilities.swift */,
Expand All @@ -155,6 +158,14 @@
path = ApolloTests;
sourceTree = "<group>";
};
9FE3F3961DADBD0D0072078F /* Supporting Files */ = {
isa = PBXGroup;
children = (
9FE3F3971DADBD870072078F /* check-and-run-apollo-codegen.sh */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -254,6 +265,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9FE3F3981DADBD870072078F /* check-and-run-apollo-codegen.sh in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
50 changes: 50 additions & 0 deletions scripts/check-and-run-apollo-codegen.sh
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 "$@")

0 comments on commit 31f3632

Please sign in to comment.