Skip to content

Commit b8c86b8

Browse files
yungstersfacebook-github-bot
authored andcommitted
RN: Revive react-native-xcode.sh
Reviewed By: mmmulani Differential Revision: D6775989 fbshipit-source-id: da17748c373dd152a743aa1ed8a5f075074415d3
1 parent 17bd6c8 commit b8c86b8

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

scripts/react-native-xcode.sh

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/bin/bash
2+
# Copyright (c) 2015-present, Facebook, Inc.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree. An additional grant
7+
# of patent rights can be found in the PATENTS file in the same directory.
8+
9+
# Bundle React Native app's code and image assets.
10+
# This script is supposed to be invoked as part of Xcode build process
11+
# and relies on environment variables (including PWD) set by Xcode
12+
13+
if [[ "$SKIP_BUNDLING" ]]; then
14+
echo "SKIP_BUNDLING enabled; skipping."
15+
exit 0;
16+
fi
17+
18+
case "$CONFIGURATION" in
19+
*Debug*)
20+
if [[ "$PLATFORM_NAME" == *simulator ]]; then
21+
if [[ "$FORCE_BUNDLING" ]]; then
22+
echo "FORCE_BUNDLING enabled; continuing to bundle."
23+
else
24+
echo "Skipping bundling in Debug for the Simulator (since the packager bundles for you). Use the FORCE_BUNDLING flag to change this behavior."
25+
exit 0;
26+
fi
27+
else
28+
echo "Bundling for physical device. Use the SKIP_BUNDLING flag to change this behavior."
29+
fi
30+
31+
DEV=true
32+
;;
33+
"")
34+
echo "$0 must be invoked by Xcode"
35+
exit 1
36+
;;
37+
*)
38+
DEV=false
39+
;;
40+
esac
41+
42+
# Path to react-native folder inside node_modules
43+
REACT_NATIVE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
44+
45+
# Xcode project file for React Native apps is located in ios/ subfolder
46+
cd "${REACT_NATIVE_DIR}"/../..
47+
48+
# Define NVM_DIR and source the nvm.sh setup script
49+
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
50+
51+
# Define entry file
52+
if [[ -s "index.ios.js" ]]; then
53+
ENTRY_FILE=${1:-index.ios.js}
54+
else
55+
ENTRY_FILE=${1:-index.js}
56+
fi
57+
58+
if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
59+
. "$HOME/.nvm/nvm.sh"
60+
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
61+
. "$(brew --prefix nvm)/nvm.sh"
62+
fi
63+
64+
# Set up the nodenv node version manager if present
65+
if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
66+
eval "$("$HOME/.nodenv/bin/nodenv" init -)"
67+
fi
68+
69+
[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"
70+
71+
[ -z "$CLI_PATH" ] && export CLI_PATH="$REACT_NATIVE_DIR/local-cli/cli.js"
72+
73+
[ -z "$BUNDLE_COMMAND" ] && BUNDLE_COMMAND="bundle"
74+
75+
if [[ -z "$BUNDLE_CONFIG" ]]; then
76+
CONFIG_ARG=""
77+
else
78+
CONFIG_ARG="--config $(pwd)/$BUNDLE_CONFIG"
79+
fi
80+
81+
nodejs_not_found()
82+
{
83+
echo "error: Can't find '$NODE_BINARY' binary to build React Native bundle" >&2
84+
echo "If you have non-standard nodejs installation, select your project in Xcode," >&2
85+
echo "find 'Build Phases' - 'Bundle React Native code and images'" >&2
86+
echo "and change NODE_BINARY to absolute path to your node executable" >&2
87+
echo "(you can find it by invoking 'which node' in the terminal)" >&2
88+
exit 2
89+
}
90+
91+
type $NODE_BINARY >/dev/null 2>&1 || nodejs_not_found
92+
93+
# Print commands before executing them (useful for troubleshooting)
94+
set -x
95+
DEST=$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH
96+
97+
if [[ "$CONFIGURATION" = "Debug" && ! "$PLATFORM_NAME" == *simulator ]]; then
98+
PLISTBUDDY='/usr/libexec/PlistBuddy'
99+
PLIST=$TARGET_BUILD_DIR/$INFOPLIST_PATH
100+
IP=$(ipconfig getifaddr en0)
101+
if [ -z "$IP" ]; then
102+
IP=$(ifconfig | grep 'inet ' | grep -v ' 127.' | cut -d\ -f2 | awk 'NR==1{print $1}')
103+
fi
104+
105+
if [ -z ${DISABLE_XIP+x} ]; then
106+
IP="$IP.xip.io"
107+
fi
108+
109+
$PLISTBUDDY -c "Add NSAppTransportSecurity:NSExceptionDomains:localhost:NSTemporaryExceptionAllowsInsecureHTTPLoads bool true" "$PLIST"
110+
$PLISTBUDDY -c "Add NSAppTransportSecurity:NSExceptionDomains:$IP:NSTemporaryExceptionAllowsInsecureHTTPLoads bool true" "$PLIST"
111+
echo "$IP" > "$DEST/ip.txt"
112+
fi
113+
114+
BUNDLE_FILE="$DEST/main.jsbundle"
115+
116+
$NODE_BINARY $CLI_PATH $BUNDLE_COMMAND \
117+
$CONFIG_ARG \
118+
--entry-file "$ENTRY_FILE" \
119+
--platform ios \
120+
--dev $DEV \
121+
--reset-cache \
122+
--bundle-output "$BUNDLE_FILE" \
123+
--assets-dest "$DEST" \
124+
$EXTRA_PACKAGER_ARGS
125+
126+
if [[ $DEV != true && ! -f "$BUNDLE_FILE" ]]; then
127+
echo "error: File $BUNDLE_FILE does not exist. This must be a bug with" >&2
128+
echo "React Native, please report it here: https://github.com/facebook/react-native/issues"
129+
exit 2
130+
fi

0 commit comments

Comments
 (0)