2018-10-31 11:35:03 +03:00
#!/bin/bash
2021-12-31 02:08:43 +03:00
# Copyright (c) Meta Platforms, Inc. and affiliates.
2018-10-31 11:35:03 +03:00
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
2016-01-05 19:59:43 +03:00
RED = "\033[0;31m"
GREEN = "\033[0;32m"
BLUE = "\033[0;35m"
ENDCOLOR = "\033[0m"
error( ) {
2018-09-29 03:00:18 +03:00
echo -e " $RED " " $* " " $ENDCOLOR "
2022-02-03 20:08:43 +03:00
popd >/dev/null || exit
2016-01-05 19:59:43 +03:00
exit 1
}
success( ) {
2018-09-29 03:00:18 +03:00
echo -e " $GREEN " " $* " " $ENDCOLOR "
2016-01-05 19:59:43 +03:00
}
info( ) {
2018-09-29 03:00:18 +03:00
echo -e " $BLUE " " $* " " $ENDCOLOR "
2016-01-05 19:59:43 +03:00
}
2022-02-03 20:08:43 +03:00
# Ensures commands are executed from the repo root folder
dir_absolute_path = $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " || exit ; pwd -P )
pushd " $dir_absolute_path /../ " >/dev/null || exit
2016-03-24 15:30:49 +03:00
repo_root = $( pwd )
2022-01-20 23:02:05 +03:00
selected_platform = ""
selected_vm = ""
PACKAGE_VERSION = ""
test_android( ) {
generate_maven_artifacts
if [ " $1 " = = "1" ] ; then
test_android_hermes
elif [ " $1 " = = "2" ] ; then
test_android_jsc
fi
}
2016-01-05 19:59:43 +03:00
2022-01-20 23:02:05 +03:00
generate_maven_artifacts( ) {
rm -rf android
./gradlew :ReactAndroid:installArchives || error "Couldn't generate artifacts"
2016-01-05 19:59:43 +03:00
2022-01-20 23:02:05 +03:00
success "Generated artifacts for Maven"
}
2016-01-05 19:59:43 +03:00
2022-01-20 23:02:05 +03:00
test_android_hermes( ) {
./gradlew :packages:rn-tester:android:app:installHermesDebug || error "Couldn't build RNTester Android"
2017-03-30 02:12:39 +03:00
2022-01-20 23:02:05 +03:00
info "Press any key to run RNTester on Android with Hermes enabled"
info ""
read -r -n 1
adb shell am start -n com.facebook.react.uiapp/.RNTesterActivity
}
2017-03-30 02:12:39 +03:00
2022-01-20 23:02:05 +03:00
test_android_jsc( ) {
./gradlew :packages:rn-tester:android:app:installJscDebug || error "Couldn't build RNTester Android"
2017-03-30 02:12:39 +03:00
2022-01-20 23:02:05 +03:00
info "Press any key to run RNTester in an already running Android emulator/device"
info ""
read -r -n 1
adb shell am start -n com.facebook.react.uiapp/.RNTesterActivity
}
2017-03-30 02:12:39 +03:00
2022-01-20 23:02:05 +03:00
test_ios( ) {
if [ " $1 " = = "1" ] ; then
test_ios_hermes
elif [ " $1 " = = "2" ] ; then
test_ios_jsc
fi
}
2017-03-30 02:12:39 +03:00
2022-01-20 23:02:05 +03:00
test_ios_hermes( ) {
success "About to test iOS Hermes... "
success "Installing CocoaPods dependencies..."
rm -rf packages/rn-tester/Pods
( cd packages/rn-tester && USE_HERMES = 1 bundle exec pod install)
2021-08-27 00:58:39 +03:00
2022-01-20 23:02:05 +03:00
info "Press any key to open the workspace in Xcode, then build and test manually."
info ""
read -r -n 1
2021-08-27 00:58:39 +03:00
2022-01-20 23:02:05 +03:00
open "packages/rn-tester/RNTesterPods.xcworkspace"
}
2021-08-27 00:58:39 +03:00
2022-01-20 23:02:05 +03:00
test_ios_jsc( ) {
success "About to test iOS JSC... "
success "Installing CocoaPods dependencies..."
rm -rf packages/rn-tester/Pods
( cd packages/rn-tester && bundle exec pod install)
2021-08-27 00:58:39 +03:00
2022-01-20 23:02:05 +03:00
info "Press any key to open the workspace in Xcode, then build and test manually."
info ""
read -r -n 1
2020-04-17 03:44:49 +03:00
2022-01-20 23:02:05 +03:00
open "packages/rn-tester/RNTesterPods.xcworkspace"
}
2021-08-27 00:58:39 +03:00
2022-01-20 23:02:05 +03:00
kill_packagers( ) {
success "Killing any running packagers"
lsof -i :8081 | grep LISTEN
lsof -i :8081 | grep LISTEN | /usr/bin/awk '{print $2}' | xargs kill
}
2021-08-27 00:58:39 +03:00
2022-01-20 23:02:05 +03:00
init_template_app( ) {
kill_packagers
2021-08-27 00:58:39 +03:00
2022-01-20 23:02:05 +03:00
PACKAGE_VERSION = $( cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]' )
2021-08-27 00:58:39 +03:00
2022-01-20 23:02:05 +03:00
success " Preparing version $PACKAGE_VERSION "
2020-04-17 03:44:49 +03:00
2022-01-20 23:02:05 +03:00
npm pack
2017-03-30 02:12:39 +03:00
2022-01-20 23:02:05 +03:00
TIMESTAMP = $( date +%s)
PACKAGE = $( pwd ) /react-native-$PACKAGE_VERSION -$TIMESTAMP .tgz
success " Package bundled ( $PACKAGE ) "
2017-03-30 02:12:39 +03:00
2022-01-20 23:02:05 +03:00
mv " $( pwd ) /react-native- $PACKAGE_VERSION .tgz " " $PACKAGE "
2017-03-30 02:12:39 +03:00
2022-01-20 23:02:05 +03:00
node scripts/set-rn-template-version.js " file: $PACKAGE "
success "React Native version changed in the template"
2021-10-29 01:46:53 +03:00
2022-01-20 23:02:05 +03:00
project_name = "RNTestProject"
2021-10-29 01:46:53 +03:00
2022-02-03 20:08:43 +03:00
pushd /tmp/ >/dev/null || exit
2022-01-20 23:02:05 +03:00
rm -rf " $project_name "
node " $repo_root /cli.js " init " $project_name " --template " $repo_root "
2021-10-29 01:46:53 +03:00
2022-01-20 23:02:05 +03:00
info "Double checking the versions in package.json are correct:"
grep " \"react-native\": \".*react-native- $PACKAGE_VERSION - $TIMESTAMP .tgz\" " " /tmp/ ${ project_name } /package.json " || error " Incorrect version number in /tmp/ ${ project_name } /package.json "
grep -E "com.facebook.react:react-native:\\+" " ${ project_name } /android/app/build.gradle " || error " Dependency in /tmp/ ${ project_name } /android/app/build.gradle must be com.facebook.react:react-native:+ "
2016-01-05 19:59:43 +03:00
2022-01-20 23:02:05 +03:00
success " New sample project generated at /tmp/ ${ project_name } "
2022-02-03 20:08:43 +03:00
popd >/dev/null || exit
2022-01-20 23:02:05 +03:00
}
2016-01-05 19:59:43 +03:00
2022-01-20 23:02:05 +03:00
test_template_app( ) {
if [ " $PACKAGE_VERSION " = = "" ] ; then
init_template_app
fi
2022-02-03 20:08:43 +03:00
pushd " /tmp/ ${ project_name } " >/dev/null || exit
2022-01-20 23:02:05 +03:00
if [ " $selected_platform " = = "1" ] ; then
info "Test the following on Android:"
info " - Disable Fast Refresh. It might be enabled from last time (the setting is stored on the device)"
info " - Verify 'Reload JS' works"
info ""
info "Press any key to run the sample in Android emulator/device"
info ""
read -r -n 1
2022-02-03 20:08:43 +03:00
npx react-native run-android
2022-01-20 23:02:05 +03:00
elif [ " $selected_platform " = = "2" ] ; then
info "Test the following on iOS:"
info " - Disable Fast Refresh. It might be enabled from last time (the setting is stored on the device)"
info " - Verify 'Reload JS' works"
info " - Test Chrome debugger by adding breakpoints and reloading JS. We don't have tests for Chrome debugging."
info " - Disable Chrome debugging."
info " - Enable Fast Refresh, change a file (index.js) and save. The UI should refresh."
info " - Disable Fast Refresh."
info ""
info "Press any key to open the project in Xcode"
info ""
read -r -n 1
2022-02-03 20:08:43 +03:00
open " ios/ ${ project_name } .xcworkspace "
2022-01-20 23:02:05 +03:00
fi
2022-02-03 20:08:43 +03:00
popd >/dev/null || exit
2022-01-20 23:02:05 +03:00
}
2021-09-15 20:55:47 +03:00
2019-04-25 11:58:43 +03:00
2022-01-20 23:02:05 +03:00
show_menu( ) {
echo " Which app do you want to test?
1 - RNTester
2 - A new RN app using the template"
read -p "> " selected_app
2016-01-05 19:59:43 +03:00
2022-01-20 23:02:05 +03:00
echo " What platform do you want to test?
1 - Android
2 - iOS"
read -p "> " selected_platform
2016-01-05 21:51:50 +03:00
2022-01-20 23:02:05 +03:00
if [ " $selected_app " = = "1" ] ; then
echo " What VM are you testing?
1 - Hermes
2 - JSC"
read -p "> " selected_vm
fi
2016-01-05 19:59:43 +03:00
2022-01-20 23:02:05 +03:00
}
2016-01-05 19:59:43 +03:00
2022-01-20 23:02:05 +03:00
handle_menu_input( ) {
if [ " $selected_app " = = "1" ] ; then
info "Start the packager in another terminal by running 'npm start' from the root"
info "and then press any key."
info ""
read -r -n 1
if [ " $selected_platform " = = "1" ] ; then
test_android " $selected_vm "
elif [ " $selected_platform " = = "2" ] ; then
test_ios " $selected_vm "
fi
elif [ " $selected_app " = = "2" ] ; then
test_template_app
fi
read -p "Would you like to test something else? (Y/N)" confirm
if [ " $confirm " = = " ${ confirm #[Yy] } " ] ; then
info "Next steps:"
info "https://github.com/facebook/react-native/wiki/Release-Process"
2022-02-03 20:08:43 +03:00
popd >/dev/null || exit
2022-01-20 23:02:05 +03:00
exit 1
else
show_menu
handle_menu_input
fi
}
2016-01-05 19:59:43 +03:00
2022-01-20 23:02:05 +03:00
init( ) {
show_menu
yarn
kill_packagers
handle_menu_input
}
2016-01-05 19:59:43 +03:00
2022-01-20 23:02:05 +03:00
init
2016-01-05 19:59:43 +03:00