Skip to content
Open
Changes from all commits
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
105 changes: 105 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/env bash

# Builds the React Native SDK.
#
# Usage:
# ./build.sh Build the full SDK stack: JS/web, iOS, and Android.
# ./build.sh ios Install JS dependencies and pods, then build JS and the iOS example workspace.
# ./build.sh android Install JS dependencies, then build JS and Android.
# ./build.sh web Install JS dependencies, then build the web/Expo package.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can be done in a separate PR but could be nice to add commands to actually run the sample apps as well... Though in this case, maybe it shouldn't be in build.sh but a different script 😅

#
# Valid platforms: ios, android, web

set -euo pipefail

usage() {
echo "Usage: $0 [ios|android|web]"
}

if [ "$#" -gt 1 ]; then
usage
exit 1
fi

platform="${1:-}"

build_js_sdk() {
yarn build
}

install_js_dependencies() {
yarn
}

install_ios_dependencies() {
yarn example pods
}

build_web_sdk() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess this doesn't only build the web sdk, but it does build our SDKs for all platforms (and prepares it to be used by our purchase tester expo app)... Additionally, it's quite confusing with the build_js_sdk method above as well IMO

yarn prepare-expo
}

is_xcpretty_installed() {
command -v xcpretty >/dev/null 2>&1
}

compile_ios_sdk_and_purchase_tester() {
if is_xcpretty_installed; then
xcodebuild \
-workspace examples/purchaseTesterTypescript/ios/PurchaseTester.xcworkspace \
-scheme PurchaseTester \
-configuration Debug \
-sdk iphonesimulator \
-destination "generic/platform=iOS Simulator" \
build | xcpretty
else
xcodebuild \
-workspace examples/purchaseTesterTypescript/ios/PurchaseTester.xcworkspace \
-scheme PurchaseTester \
-configuration Debug \
-sdk iphonesimulator \
-destination "generic/platform=iOS Simulator" \
build
fi
}

compile_android_sdk_and_purchase_tester() {
(
cd examples/purchaseTesterTypescript/android
./gradlew :react-native-purchases:assembleDebug
)
}

case "$platform" in
"")
echo "About to build the RevenueCat React Native SDK for all platforms."
yarn bootstrap
compile_ios_sdk_and_purchase_tester
compile_android_sdk_and_purchase_tester
;;
ios)
echo "About to build the RevenueCat React Native SDK for iOS only."
install_js_dependencies
install_ios_dependencies
build_js_sdk
compile_ios_sdk_and_purchase_tester
;;
android)
echo "About to build the RevenueCat React Native SDK for Android only."
install_js_dependencies
build_js_sdk
compile_android_sdk_and_purchase_tester
;;
web)
echo "About to build the RevenueCat React Native SDK for web only."
install_js_dependencies
build_web_sdk
;;
*)
echo "Invalid platform: $platform"
usage
exit 1
;;
esac

echo "Done building the RevenueCat React Native SDK."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a thought... But should we do all this in fastlane instead of a shell script? It might be easier to share some things if we do it there... On the other hand, it's true that it requires to setup ruby + all those dependencies, but considering this is mostly meant for developers which should already be using fastlane, I think that might be ok?

One thing that I think we would need to do for this to work though (and we probably should have setup a long time ago...). We would need to setup .ruby-gemset files in all SDKs so purr can automatically checkout the correct gemset (and install missing gems if needed).

Wdyt @RevenueCat/coresdk? I'm not too opposed to go to shell script if needed... But just feels like ruby/javascript are nicer to work with