Skip to content

Instantly share code, notes, and snippets.

@ippa
Created May 21, 2016 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ippa/ea3693dd1f530021bca764dbe2b227b2 to your computer and use it in GitHub Desktop.
Save ippa/ea3693dd1f530021bca764dbe2b227b2 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Bash-script for easy switching between dev and prod settings in your xcode project
# Run in root of your project. Details: https://facebook.github.io/react-native/docs/running-on-device-ios.html
#
# ./xcode dev
# - Detects local IP and tells xcode to access packager live-bundling through that
# - Sets xcode build configuration to Debug
#
# ./xcode prod
# - Bundles JS and tells xcode to use that bundle
# - Sets xcode build configuration to Release
#
IP=`ipconfig getifaddr en0`
START_OF_PROD_STRING='jsCodeLocation = \[\[NSBundle'
START_OF_DEV_STRING='jsCodeLocation = \[NSURL'
APPDELEGATE=`find ios -name AppDelegate.m`
SCHEME=`find ios -name "*.xcscheme"`
PROD_BUILD='buildConfiguration = "Release"'
DEV_BUILD='buildConfiguration = "Debug"'
echo "* Modifies" $APPDELEGATE "&" $SCHEME
case $1 in
dev)
echo "=> DEV-mode"
sed -i .bak "s/localhost/$IP/g" $APPDELEGATE
sed -i .bak "s/^[ /]*\($START_OF_DEV_STRING\)/ \1/g" $APPDELEGATE
sed -i .bak "s/^[^/]*\(.$START_OF_PROD_STRING\)/\/\/ \1/g" $APPDELEGATE
sed -i .bak "s/$PROD_BUILD/$DEV_BUILD/g" $SCHEME
;;
prod)
echo "=> PROD-mode"
sed -i .bak "s/^[ /]*\($START_OF_PROD_STRING\)/ \1/g" $APPDELEGATE
sed -i .bak "s/^[^/]*\(.$START_OF_DEV_STRING\)/\/\/ \1/g" $APPDELEGATE
sed -i .bak "s/$DEV_BUILD/$PROD_BUILD/g" $SCHEME
react-native bundle --platform ios --dev false --entry-file index.ios.js --bundle-output ios/main.jsbundle
;;
*) echo "./xcode.sh [dev|prod] - switch settings in xcodeproject between development and production settings";
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment