2015-10-22 01:42:08 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This source code is licensed under the BSD-style license found in the
|
|
|
|
# LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
# of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
|
|
|
|
# Bundle React Native app's code and image assets.
|
|
|
|
# This script is supposed to be invoked as part of Xcode build process
|
2016-02-01 15:42:33 +00:00
|
|
|
# and relies on environment variables (including PWD) set by Xcode
|
2015-10-22 01:42:08 +00:00
|
|
|
|
|
|
|
case "$CONFIGURATION" in
|
2017-04-15 17:08:26 +00:00
|
|
|
*Debug*)
|
2016-02-24 11:11:08 +00:00
|
|
|
# Speed up build times by skipping the creation of the offline package for debug
|
|
|
|
# builds on the simulator since the packager is supposed to be running anyways.
|
2016-10-05 14:15:25 +00:00
|
|
|
if [[ "$PLATFORM_NAME" == *simulator ]]; then
|
2016-04-06 16:20:39 +00:00
|
|
|
echo "Skipping bundling for Simulator platform"
|
|
|
|
exit 0;
|
2016-02-24 11:11:08 +00:00
|
|
|
fi
|
2016-04-06 16:20:39 +00:00
|
|
|
|
2015-10-22 01:42:08 +00:00
|
|
|
DEV=true
|
|
|
|
;;
|
|
|
|
"")
|
|
|
|
echo "$0 must be invoked by Xcode"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
2015-12-09 12:39:36 +00:00
|
|
|
DEV=false
|
2015-10-22 01:42:08 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2016-01-25 20:35:48 +00:00
|
|
|
# Path to react-native folder inside node_modules
|
|
|
|
REACT_NATIVE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
|
|
|
2015-10-22 01:42:08 +00:00
|
|
|
# Xcode project file for React Native apps is located in ios/ subfolder
|
2016-12-16 07:32:55 +00:00
|
|
|
cd "${REACT_NATIVE_DIR}"/../..
|
2015-10-22 01:42:08 +00:00
|
|
|
|
2015-11-10 00:41:23 +00:00
|
|
|
# Define NVM_DIR and source the nvm.sh setup script
|
|
|
|
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
|
|
|
|
|
2016-07-15 17:11:07 +00:00
|
|
|
# Define entry file
|
|
|
|
ENTRY_FILE=${1:-index.ios.js}
|
|
|
|
|
2015-11-10 00:41:23 +00:00
|
|
|
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
|
|
|
|
|
2015-12-17 22:09:40 +00:00
|
|
|
# Set up the nodenv node version manager if present
|
|
|
|
if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
|
2016-07-15 17:11:07 +00:00
|
|
|
eval "$("$HOME/.nodenv/bin/nodenv" init -)"
|
2015-12-17 22:09:40 +00:00
|
|
|
fi
|
|
|
|
|
2016-01-25 20:35:48 +00:00
|
|
|
[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"
|
|
|
|
|
2017-04-03 15:33:13 +00:00
|
|
|
[ -z "$CLI_PATH" ] && export CLI_PATH="$REACT_NATIVE_DIR/local-cli/cli.js"
|
|
|
|
|
2016-01-25 20:35:48 +00:00
|
|
|
nodejs_not_found()
|
|
|
|
{
|
|
|
|
echo "error: Can't find '$NODE_BINARY' binary to build React Native bundle" >&2
|
|
|
|
echo "If you have non-standard nodejs installation, select your project in Xcode," >&2
|
|
|
|
echo "find 'Build Phases' - 'Bundle React Native code and images'" >&2
|
|
|
|
echo "and change NODE_BINARY to absolute path to your node executable" >&2
|
|
|
|
echo "(you can find it by invoking 'which node' in the terminal)" >&2
|
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
|
|
|
type $NODE_BINARY >/dev/null 2>&1 || nodejs_not_found
|
|
|
|
|
|
|
|
# Print commands before executing them (useful for troubleshooting)
|
|
|
|
set -x
|
|
|
|
DEST=$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH
|
2016-01-06 19:02:35 +00:00
|
|
|
|
2016-10-05 14:15:25 +00:00
|
|
|
if [[ "$CONFIGURATION" = "Debug" && ! "$PLATFORM_NAME" == *simulator ]]; then
|
2016-06-13 22:52:19 +00:00
|
|
|
PLISTBUDDY='/usr/libexec/PlistBuddy'
|
|
|
|
PLIST=$TARGET_BUILD_DIR/$INFOPLIST_PATH
|
|
|
|
IP=$(ipconfig getifaddr en0)
|
2016-09-26 08:21:08 +00:00
|
|
|
if [ -z "$IP" ]; then
|
Ignore all loopback addresses for ip detection
Summary:
There is a bug with IP detection on Macs that have (1) multiple ethernet interfaces, (2) are using the second or third interface as their primary connection and (3) have extra loopback IPs configured (for example when running OpenVPN, running some Docker configurations or other more exotic applications). In those cases, automatic IP detection will falsely detect the IP as something like `127.94.0.1`, which will make it impossible to run debug builds from a physical device.
The underlying network configurations looks something similar to this (irrelevant parts omitted):
```
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
inet 127.0.0.1 netmask 0xff000000
inet 127.94.0.1 netmask 0xff000000
nd6 options=201<PERFORMNUD,DAD>
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV>
ether xx:xx:xx:xx:xx:xx
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
Closes https://github.com/facebook/react-native/pull/13415
Differential Revision: D4859654
Pulled By: javache
fbshipit-source-id: 3c5d06201c48a2dfe1c274ff433423e5d7f2cded
2017-04-10 17:47:29 +00:00
|
|
|
IP=$(ifconfig | grep 'inet ' | grep -v ' 127.' | cut -d\ -f2 | awk 'NR==1{print $1}')
|
2016-09-26 08:21:08 +00:00
|
|
|
fi
|
2017-04-08 03:11:25 +00:00
|
|
|
|
|
|
|
if [ -z ${DISABLE_XIP+x} ]; then
|
|
|
|
IP="$IP.xip.io"
|
|
|
|
fi
|
|
|
|
|
2016-07-15 17:11:07 +00:00
|
|
|
$PLISTBUDDY -c "Add NSAppTransportSecurity:NSExceptionDomains:localhost:NSTemporaryExceptionAllowsInsecureHTTPLoads bool true" "$PLIST"
|
2017-04-08 03:11:25 +00:00
|
|
|
$PLISTBUDDY -c "Add NSAppTransportSecurity:NSExceptionDomains:$IP:NSTemporaryExceptionAllowsInsecureHTTPLoads bool true" "$PLIST"
|
|
|
|
echo "$IP" > "$DEST/ip.txt"
|
2016-06-13 22:52:19 +00:00
|
|
|
fi
|
|
|
|
|
2016-08-21 18:25:59 +00:00
|
|
|
BUNDLE_FILE="$DEST/main.jsbundle"
|
|
|
|
|
2017-04-03 15:33:13 +00:00
|
|
|
$NODE_BINARY $CLI_PATH bundle \
|
2016-07-15 17:11:07 +00:00
|
|
|
--entry-file "$ENTRY_FILE" \
|
2015-10-22 01:42:08 +00:00
|
|
|
--platform ios \
|
|
|
|
--dev $DEV \
|
2016-08-03 08:03:25 +00:00
|
|
|
--reset-cache \
|
2016-08-21 18:25:59 +00:00
|
|
|
--bundle-output "$BUNDLE_FILE" \
|
2015-10-22 01:42:08 +00:00
|
|
|
--assets-dest "$DEST"
|
2016-08-21 18:25:59 +00:00
|
|
|
|
|
|
|
if [[ ! $DEV && ! -f "$BUNDLE_FILE" ]]; then
|
|
|
|
echo "error: File $BUNDLE_FILE does not exist. This must be a bug with" >&2
|
|
|
|
echo "React Native, please report it here: https://github.com/facebook/react-native/issues"
|
|
|
|
exit 2
|
|
|
|
fi
|