Files
react-native/scripts/launchPackager.command
T
Moti Zilberman 6df04ae666 Optionally capture packager logs during RNTester Xcode build
Summary:
Changelog: [Internal]

* Sets a default custom reporter in `scripts/packager.sh` that redirects Metro's logs to a JSON file when the `RCT_PACKAGER_LOG_PATH` environment variable is set. Otherwise we use Metro's `TerminalReporter`, [like the CLI does by default](https://github.com/react-native-community/cli/blob/0993f627869f4de0e5a8a9a950d38a9f15e18fb2/packages/cli-plugin-metro/src/commands/start/runServer.ts#L124).
* Modifies `scripts/launchPackager.command` to write logs to `$RCT_PACKAGER_LOGS_DIR` (and in particular use the JSON reporter) if this environment var is set.
* Uses [`open -n`](https://ss64.com/osx/open.html#:~:text=Open%20a%20new%20instance%20of%20the%20application) to execute `launchPackager.command` from Xcode, so that environment variables are reliably passed to the script even if a Terminal process is already running.

Reviewed By: yungsters

Differential Revision: D32295290

fbshipit-source-id: 4d783e1f94d122d3a35c104b2b02dbfaf8e1a1a3
2021-11-11 00:01:40 -08:00

28 lines
835 B
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.
# Set terminal title
echo -en "\\033]0;Metro\\a"
clear
THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
if [ -n "${RCT_PACKAGER_LOGS_DIR}" ] ; then
echo "Writing logs to $RCT_PACKAGER_LOGS_DIR"
# shellcheck source=/dev/null
RCT_PACKAGER_LOG_PATH="$RCT_PACKAGER_LOGS_DIR/metro.log" \
. "$THIS_DIR/packager.sh" \
> "$RCT_PACKAGER_LOGS_DIR/packager.stdout.log" \
2> "$RCT_PACKAGER_LOGS_DIR/packager.stderr.log"
else
# shellcheck source=/dev/null
. "$THIS_DIR/packager.sh"
fi
if [[ -z "$CI" ]]; then
echo "Process terminated. Press <enter> to close the window"
read -r
fi