Files
crowd-funder-for-time-pwa/ios/App/scripts/bundle-firebase-config.sh
T
Jose Olarte III a271cd1434 Enable Firebase by default for Android and iOS builds so normal local, test, and production builds no longer depend on passing -PfirebaseEnabled.
Opt out with -PfirebaseEnabled=false or FIREBASE_ENABLED=false. A missing google-services.json or GoogleService-Info.plist now fails the build instead of silently skipping Firebase.
2026-10-12 10:20:39 -04:00

62 lines
2.2 KiB
Bash
Executable File

#!/bin/sh
# Bundle GoogleService-Info.plist when Firebase is enabled (the default).
# Opt out with FIREBASE_ENABLED=false. The plist does not decide the switch:
# a missing file fails an enabled build, and an opt-out build does not bundle
# the plist even when the file is on disk.
#
# Xcode run-script phases invoke this with no arguments. build-ios.sh may pass
# --check to validate before a long build without copying into a product.
set -eu
check_only=0
if [ "${1:-}" = "--check" ]; then
check_only=1
fi
if [ -z "${SRCROOT:-}" ]; then
script_dir=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
SRCROOT=$(CDPATH= cd -- "$script_dir/.." && pwd)
fi
normalized=$(printf '%s' "${FIREBASE_ENABLED:-true}" | tr '[:upper:]' '[:lower:]')
plist="${SRCROOT}/App/GoogleService-Info.plist"
firebase_off=0
case "$normalized" in
false|0|no) firebase_off=1 ;;
esac
if [ "$firebase_off" -eq 1 ]; then
if [ "$check_only" -eq 0 ]; then
dest_dir="${TARGET_BUILD_DIR:-}/${UNLOCALIZED_RESOURCES_FOLDER_PATH:-}"
if [ -n "${TARGET_BUILD_DIR:-}" ] && [ -n "${UNLOCALIZED_RESOURCES_FOLDER_PATH:-}" ]; then
rm -f "${dest_dir}/GoogleService-Info.plist"
fi
fi
echo "note: Firebase disabled (FIREBASE_ENABLED=false); GoogleService-Info.plist will not be bundled."
exit 0
fi
if [ ! -s "$plist" ] || ! grep -q "GOOGLE_APP_ID" "$plist"; then
echo "error: Firebase is enabled, but ios/App/App/GoogleService-Info.plist is missing, empty, or has no GOOGLE_APP_ID." >&2
echo "error: Download it from the Firebase console (Project settings → Your apps → Apple apps)" >&2
echo "error: and place it at ios/App/App/GoogleService-Info.plist." >&2
echo "error: To build without Firebase, set FIREBASE_ENABLED=false." >&2
exit 1
fi
if [ "$check_only" -eq 1 ]; then
echo "note: Firebase enabled; ios/App/App/GoogleService-Info.plist is present."
exit 0
fi
if [ -z "${TARGET_BUILD_DIR:-}" ] || [ -z "${UNLOCALIZED_RESOURCES_FOLDER_PATH:-}" ]; then
echo "error: Bundle Firebase Config must run as an Xcode build phase (TARGET_BUILD_DIR is unset)." >&2
exit 1
fi
dest_dir="${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
mkdir -p "$dest_dir"
cp "$plist" "${dest_dir}/GoogleService-Info.plist"
echo "note: Firebase enabled; bundled GoogleService-Info.plist."