Skip to content

Instantly share code, notes, and snippets.

@mmazzarolo
Created June 28, 2018 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmazzarolo/d76007035f6aa41e392d4912e91dfd19 to your computer and use it in GitHub Desktop.
Save mmazzarolo/d76007035f6aa41e392d4912e91dfd19 to your computer and use it in GitHub Desktop.
React-Native development script
#!/bin/bash
# Starts the metro bundler and runs react-native in a single terminal (à la Expo).
# CTRL + C kills the metro bundler.
# Arguments:
# -p Development platform [ios (default), android].
# -s Starts scrcpy too. Android only. (https://github.com/Genymobile/scrcpy)
COLOR_RED='\033[0;31m'
COLOR_CYAN='\033[0;36m'
COLOR_PURPLE='\033[0;35m'
COLOR_DEFAULT='\033[0m'
use_scrcpy=0
platform="ios"
while getopts ":p:" option;
do
case "${option}" in
p) platform=${OPTARG};;
esac
done
for arg in "$@"
do
if [ "$arg" == "--scrcpy" ] || [ "$arg" == "-s" ]; then
use_scrcpy=1
fi
done
if [[ "$platform" == "android" ]];
then
(sleep 4 && react-native run-android) & pid=$!
PID_LIST+=" $pid";
if [[ "$use_scrcpy" == 1 ]]; then
scrcpy & pid=$!
PID_LIST+=" $pid";
fi
elif [[ "$platform" == "ios" ]];
then
(sleep 4 && react-native run-ios) & pid=$!
PID_LIST+=" $pid";
else
echo -e "${COLOR_RED}Invalid platform. Allowed platforms: ios, android${COLOR_DEFAULT}"
exit 1
fi
npm run start & pid=$!
PID_LIST+=" $pid";
trap "kill $PID_LIST" SIGINT
echo -e "${COLOR_PURPLE}Metro bundler started and ${platform} development started ${COLOR_DEFAULT}";
wait $PID_LIST
echo
echo -e "${COLOR_PURPLE}Metro bundler started and ${platform} development completed ${COLOR_DEFAULT}";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment