Skip to content
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

Merged
merged 6 commits into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/mobile/.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ SHOW_TESTNET_BANNER=true
SHOW_GET_INVITE_LINK=false
DEV_SETTINGS_ACTIVE_INITIALLY=true
# Enable for true hot reloading while dev-ing UI
DEV_RESTORE_NAV_STATE_ON_RELOAD=false
DEV_RESTORE_NAV_STATE_ON_RELOAD=false
8 changes: 3 additions & 5 deletions packages/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
"license": "Apache-2.0",
"private": true,
"scripts": {
"start": "react-native start",
"start:bg": "react-native start &",
"start": "./scripts/run_app.sh",
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

"start:android": "./scripts/run_app.sh -p android",
"start:ios": "./scripts/run_app.sh -p ios",
"lint": "tslint -c tslint.json --project tsconfig.json",
"build": "yarn run build:ts && yarn run build:metro",
"build:sdk": "yarn --cwd ../walletkit build:for-env",
"build:ts": "tsc --noEmit",
"build:metro": "echo 'NOT WORKING RIGHT NOW'",
"build:gen-graphql-types": "gql-gen --schema http://localhost:8080/graphql --template graphql-codegen-typescript-template --out ./typings/ 'src/**/*.tsx'",
"predev": "./scripts/pre-dev.sh",
"dev": "react-native run-android --appIdSuffix \"debug\" --no-packager && yarn start || echo 'Could not start metro server'",
"dev:ios": "react-native run-ios --simulator \"iPhone 11\"",
jmrossy marked this conversation as resolved.
Show resolved Hide resolved
"dev:show-menu": "adb devices | grep '\t' | awk '{print $1}' | sed 's/\\s//g' | xargs -I {} adb -s {} shell input keyevent 82",
"dev:clear-data": "adb shell pm clear org.celo.mobile.debug",
"dev:clean-android": "cd android && ./gradlew clean",
Expand Down
16 changes: 0 additions & 16 deletions packages/mobile/scripts/pre-dev.sh

This file was deleted.

123 changes: 123 additions & 0 deletions packages/mobile/scripts/run_app.sh
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
I usually start the packager separately so I can launch it with custom options like --reset-cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.
Not sure it's worth having a flag for now here.

# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do yarn react-native run-ios --simulator "iPhone 11". Last time I checked it worked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, iPhone 11 only works from Xcode 11,
I just checked, and yarn react-native run-ios --simulator "iPhone Xʀ" works.

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

2 changes: 1 addition & 1 deletion packages/mobile/scripts/run_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bash ./scripts/unlock.sh
echo "Killing previous metro server (if any)"
react-native-kill-packager || echo 'Failed to kill for some reason'
echo "Start metro server"
yarn start:bg
yarn react-native start &


echo "Waiting for device to connect to Wifi, this is a good proxy the device is ready"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ENVIRONMENT=integration
PORT=80
FIREBASE_DB=https://celo-org-mobile-int.firebaseio.com
FIREBASE_DB=https://celo-org-mobile-integration.firebaseio.com
BLOCKSCOUT_API=https://integration-blockscout.celo-testnet.org/api?
NODE_TLS_REJECT_UNAUTHORIZED=0
DEFAULT_LOCALE=en
Expand Down