-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Wallet] Create run_app.sh script to facilitate app development #2186
Changes from 2 commits
344f67a
59db38d
56e650a
8d57d73
d4aa8f3
e4150a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
# ==================================== | ||
# Configure and run the mobile app | ||
# ==================================== | ||
|
||
# Flags: | ||
# -n: Name of the network to run on | ||
# -p: Platform (android or ios) | ||
# -f: Fast (skip steps not required unless network or depedencies changes) | ||
# -h: Hot Reload (Restore nav state on reload) | ||
jmrossy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
NETWORK="" | ||
PLATFORM="" | ||
FAST=false | ||
HOT_RELOAD=false | ||
while getopts 'n:p:fh' flag; do | ||
case "${flag}" in | ||
n) NETWORK="$OPTARG" ;; | ||
p) PLATFORM="$OPTARG" ;; | ||
f) FAST=true ;; | ||
h) HOT_RELOAD=true ;; | ||
*) error "Unexpected option ${flag}" ;; | ||
esac | ||
done | ||
|
||
[ -z "$PLATFORM" ] && echo "Need to set the PLATFORM via the -p flag" && exit 1; | ||
|
||
# Get machine type (needed later) | ||
unameOut="$(uname -s)" | ||
case "${unameOut}" in | ||
Linux*) MACHINE=Linux;; | ||
Darwin*) MACHINE=Mac;; | ||
CYGWIN*) MACHINE=Cygwin;; | ||
MINGW*) MACHINE=MinGw;; | ||
*) MACHINE="UNKNOWN:${unameOut}" | ||
esac | ||
echo "Machine type: $MACHINE" | ||
echo "Current directory: `pwd`" | ||
|
||
# Read values from the .env file and put them in env vars | ||
ENV_FILENAME="${ENVFILE:-.env}" | ||
export $(grep -v '^#' $ENV_FILENAME | xargs) | ||
|
||
if [ -z "$NETWORK" ]; then | ||
echo "No network set." | ||
read -p "Use $DEFAULT_TESTNET network set in .env file (y/n)? " | ||
if [[ $REPLY =~ ^[Yy]$ ]]; then | ||
NETWORK=$DEFAULT_TESTNET | ||
else | ||
echo "No network chosen. Exiting." | ||
exit 1 | ||
fi | ||
fi | ||
|
||
# Set DEFAULT_TESTNET in .env file | ||
sed -i.bak "s/DEFAULT_TESTNET=.*/DEFAULT_TESTNET=$NETWORK/g" $ENV_FILENAME | ||
|
||
# Set Hot Reload (saved nav state) in .env file | ||
sed -i.bak "s/DEV_RESTORE_NAV_STATE_ON_RELOAD=.*/DEV_RESTORE_NAV_STATE_ON_RELOAD=$HOT_RELOAD/g" $ENV_FILENAME | ||
|
||
# Set Firebase settings in google service config files | ||
ANDROID_GSERVICES_PATH="./android/app/src/debug/google-services.json" | ||
IOS_GSERVICES_PATH="./ios/GoogleService-Info.plist" | ||
sed -i.bak "s/celo-org-mobile-.*firebaseio.com/celo-org-mobile-$NETWORK.firebaseio.com/g" $ANDROID_GSERVICES_PATH | ||
sed -i.bak "s/celo-org-mobile-.*firebaseio.com/celo-org-mobile-$NETWORK.firebaseio.com/g" $IOS_GSERVICES_PATH | ||
|
||
# Cleanup artifacts from in-place sed replacement on BSD based systems (macOS) | ||
rm -f $ENV_FILENAME.bak | ||
rm -f $ANDROID_GSERVICES_PATH.bak | ||
rm -f $IOS_GSERVICES_PATH.bak | ||
|
||
|
||
# Build Wallet Kit for env | ||
if [ "$FAST" = false ]; then | ||
echo "Building sdk for testnet $NETWORK" | ||
yarn build:sdk $NETWORK | ||
echo "Done building sdk" | ||
fi | ||
|
||
# Build the app and run it | ||
if [ $PLATFORM = "android" ]; then | ||
echo "Using platform android" | ||
|
||
NUM_DEVICES=`adb devices -l | wc -l` | ||
if [ $NUM_DEVICES -lt 3 ]; then | ||
echo "No android devices found" | ||
exit 1 | ||
fi | ||
|
||
# Run jettify to fix non-android-x compatible libs | ||
if [ "$FAST" = false ]; then | ||
echo "Jetifying react native libraries" | ||
cd ../../ && yarn run jetify && cd packages/mobile | ||
echo "Jetified" | ||
fi | ||
|
||
if [ $MACHINE = "Mac" ]; then | ||
echo "Starting packager in new terminal" | ||
RN_START_CMD="cd `pwd`;yarn react-native start" | ||
OSASCRIPT_CMD="tell application \"Terminal\" to do script \"$RN_START_CMD\"" | ||
echo "FULLCMD: $OSASCRIPT_CMD" | ||
osascript -e "$OSASCRIPT_CMD" | ||
Comment on lines
+100
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be cool to do that only if the packager is not already running. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does reset cache do? Would you like a flag for the script that sets it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It removes cached files, makes sure all files are transformed again. Fixes edge cases when changing babel config or transformer config. |
||
# Run android without packager because RN cli doesn't work with yarn workspaces | ||
yarn react-native run-android --appIdSuffix \"debug\" --no-packager | ||
jmrossy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else | ||
# Run android without packager because RN cli doesn't work with yarn workspaces | ||
yarn react-native run-android --appIdSuffix \"debug\" --no-packager | ||
yarn react-native start | ||
fi | ||
|
||
elif [ $PLATFORM = "ios" ]; then | ||
echo "Using platform ios" | ||
# TODO have iOS build and start from command line | ||
echo -e "\nFor now ios must be build and run from xcode\nStarting RN bundler\n" | ||
Comment on lines
+115
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For me it didn't work but I'll try again :) Do you want it to start it though? I thought you preferred Xcode? Maybe there's a way to trigger Xcode actions from command line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh yeah, iPhone 11 only works from Xcode 11, I think it makes sense to build it from the command line by default and have another switch to open Xcode too. What do you think? |
||
yarn react-native start | ||
|
||
else | ||
echo "Invalid value for platform, must be 'android' or 'ios'" | ||
exit 1 | ||
fi | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify:
yarn start
now would fail with a proposal to specify a platform, correct?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. Maybe it's not worth it to have this still here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine. I would assume, this is the first candidate to run when somebody has no experience with the codebase.