mirror of
https://github.com/status-im/react-native.git
synced 2025-02-23 14:48:25 +00:00
Summary: Latest changes inside CLI now require that Metro configuration is provided when building RNTester app. This is to let CLI know that instead of looking for "react-native" under "node_modules" (that is obviously not present since we are running from source), it should check the paths provided. When running "npm start", it finds the configuration at the root. However, when building through Xcode (e.g. "react-native bundle" or "xcodebuild" in Release scheme), it runs "react-native-xcode.sh" that works in different folder and makes Metro not detect the configuration file. This PR explicitly sets path to the configuration via `BUNDLE_CONFIG`. It also removes `pwd` from being prepended to all `BUNDLE_CONFIG` values. In my case, `pwd` was `/Users/grabbou` and the RNTester files where inside `/Users/grabbou/Repositories/react-native`. I was unable to point the script to correct location without making it aware of the folder structure - which is not going to work on the CI. Pull Request resolved: https://github.com/facebook/react-native/pull/23191 Differential Revision: D13851741 Pulled By: hramos fbshipit-source-id: d920353fd68d39468bd33bd1ad47e03b017a7727
134 lines
3.9 KiB
Bash
Executable File
134 lines
3.9 KiB
Bash
Executable File
#!/bin/bash
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
|
#
|
|
# This source code is licensed under the MIT license found in the
|
|
# LICENSE file in the root directory of this source tree.
|
|
#
|
|
# Bundle React Native app's code and image assets.
|
|
# This script is supposed to be invoked as part of Xcode build process
|
|
# and relies on environment variables (including PWD) set by Xcode
|
|
|
|
# Print commands before executing them (useful for troubleshooting)
|
|
set -x
|
|
DEST=$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH
|
|
|
|
# Enables iOS devices to get the IP address of the machine running Metro Bundler
|
|
if [[ "$CONFIGURATION" = *Debug* && ! "$PLATFORM_NAME" == *simulator ]]; then
|
|
IP=$(ipconfig getifaddr en0)
|
|
if [ -z "$IP" ]; then
|
|
IP=$(ifconfig | grep 'inet ' | grep -v ' 127.' | cut -d\ -f2 | awk 'NR==1{print $1}')
|
|
fi
|
|
|
|
echo "$IP" > "$DEST/ip.txt"
|
|
fi
|
|
|
|
if [[ "$SKIP_BUNDLING" ]]; then
|
|
echo "SKIP_BUNDLING enabled; skipping."
|
|
exit 0;
|
|
fi
|
|
|
|
case "$CONFIGURATION" in
|
|
*Debug*)
|
|
if [[ "$PLATFORM_NAME" == *simulator ]]; then
|
|
if [[ "$FORCE_BUNDLING" ]]; then
|
|
echo "FORCE_BUNDLING enabled; continuing to bundle."
|
|
else
|
|
echo "Skipping bundling in Debug for the Simulator (since the packager bundles for you). Use the FORCE_BUNDLING flag to change this behavior."
|
|
exit 0;
|
|
fi
|
|
else
|
|
echo "Bundling for physical device. Use the SKIP_BUNDLING flag to change this behavior."
|
|
fi
|
|
|
|
DEV=true
|
|
;;
|
|
"")
|
|
echo "$0 must be invoked by Xcode"
|
|
exit 1
|
|
;;
|
|
*)
|
|
DEV=false
|
|
;;
|
|
esac
|
|
|
|
# Path to react-native folder inside node_modules
|
|
REACT_NATIVE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
|
|
# Xcode project file for React Native apps is located in ios/ subfolder
|
|
cd "${REACT_NATIVE_DIR}"/../..
|
|
|
|
# Define NVM_DIR and source the nvm.sh setup script
|
|
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
|
|
|
|
# Define entry file
|
|
if [[ -s "index.ios.js" ]]; then
|
|
ENTRY_FILE=${1:-index.ios.js}
|
|
else
|
|
ENTRY_FILE=${1:-index.js}
|
|
fi
|
|
|
|
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
|
|
|
|
# Set up the nodenv node version manager if present
|
|
if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
|
|
eval "$("$HOME/.nodenv/bin/nodenv" init -)"
|
|
elif [[ -x "$(command -v brew)" && -x "$(brew --prefix nodenv)/bin/nodenv" ]]; then
|
|
eval "$("$(brew --prefix nodenv)/bin/nodenv" init -)"
|
|
fi
|
|
|
|
# Set up the ndenv of anyenv if preset
|
|
if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then
|
|
export PATH=${HOME}/.anyenv/bin:${PATH}
|
|
if [[ "$(anyenv envs | grep -c ndenv )" -eq 1 ]]; then
|
|
eval "$(anyenv init -)"
|
|
fi
|
|
fi
|
|
|
|
[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"
|
|
|
|
[ -z "$NODE_ARGS" ] && export NODE_ARGS=""
|
|
|
|
[ -z "$CLI_PATH" ] && export CLI_PATH="$REACT_NATIVE_DIR/cli.js"
|
|
|
|
[ -z "$BUNDLE_COMMAND" ] && BUNDLE_COMMAND="bundle"
|
|
|
|
if [[ -z "$BUNDLE_CONFIG" ]]; then
|
|
CONFIG_ARG=""
|
|
else
|
|
CONFIG_ARG="--config $BUNDLE_CONFIG"
|
|
fi
|
|
|
|
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
|
|
|
|
BUNDLE_FILE="$DEST/main.jsbundle"
|
|
|
|
"$NODE_BINARY" $NODE_ARGS "$CLI_PATH" $BUNDLE_COMMAND \
|
|
$CONFIG_ARG \
|
|
--entry-file "$ENTRY_FILE" \
|
|
--platform ios \
|
|
--dev $DEV \
|
|
--reset-cache \
|
|
--bundle-output "$BUNDLE_FILE" \
|
|
--assets-dest "$DEST" \
|
|
$EXTRA_PACKAGER_ARGS
|
|
|
|
if [[ $DEV != true && ! -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
|