|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | +# |
| 4 | +# This source code is licensed under the MIT license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | + |
| 7 | +# This script is used to source in Xcode the environment settings required to run properly. |
| 8 | +# The script first sources the base `.xcode.env` file. |
| 9 | +# Then it sources the `.xcode.env.local` file if present, to override some local config |
| 10 | +# Finally, it will execute the command passed i input if any. |
| 11 | +# |
| 12 | +# USAGE: |
| 13 | +# ./with-environment.sh command |
| 14 | + |
| 15 | +# Start with a default |
| 16 | +NODE_BINARY=$(command -v node) |
| 17 | +export NODE_BINARY |
| 18 | + |
| 19 | +# Override the default with the global environment |
| 20 | +ENV_PATH="$PODS_ROOT/../.xcode.env" |
| 21 | +if [ -f "$ENV_PATH" ]; then |
| 22 | + source "$ENV_PATH" |
| 23 | +fi |
| 24 | + |
| 25 | +# Override the global with the local environment |
| 26 | +LOCAL_ENV_PATH="${ENV_PATH}.local" |
| 27 | +if [ -f "$LOCAL_ENV_PATH" ]; then |
| 28 | + source "$LOCAL_ENV_PATH" |
| 29 | +fi |
| 30 | + |
| 31 | +# Check whether NODE_BINARY has been properly set, otherwise help the users with a meaningful error. |
| 32 | +if [ -n "$NODE_BINARY" ]; then |
| 33 | + echo "Node found at: ${NODE_BINARY}" |
| 34 | +else |
| 35 | + echo "[Warning] You need to configure your node path in the `'.xcode.env' file` environment. " \ |
| 36 | + "You can set it up quickly by running: " \ |
| 37 | + "echo 'export NODE_BINARY=$(command -v node)' > .xcode.env " \ |
| 38 | + "in the ios folder. This is needed by React Native to work correctly. " \ |
| 39 | + "We fallback to the DEPRECATED behavior of finding `node`. This will be REMOVED in a future version. " \ |
| 40 | + "You can read more about this here: <TODO-ADD LINK HERE>" >&2 |
| 41 | + source "../find-node-for-xcode.sh" |
| 42 | +fi |
| 43 | + |
| 44 | +# Execute argument, if present |
| 45 | +if [ -n "$1" ]; then |
| 46 | + $1 |
| 47 | +fi |
0 commit comments