From c5b4aff3b78f8d96fa0a885cb7ddf8f55fcdc6ff Mon Sep 17 00:00:00 2001 From: staszekscp Date: Wed, 2 Oct 2024 08:39:47 +0200 Subject: [PATCH] Add helper scripts to improve DevX on HybridApp --- package.json | 10 ++-- scripts/check-for-old-dot-changes.sh | 32 ++++++++++++ scripts/clean.sh | 17 +++++++ scripts/is-hybrid-app-repo.sh | 33 ++++++++++++ scripts/pod-install.sh | 15 +++++- scripts/postInstall.sh | 13 ++++- scripts/preinstall.sh | 19 +++++++ scripts/pull-old-dot.sh | 22 ++++++++ scripts/run-build.sh | 76 ++++++++++++++++++++++++++++ 9 files changed, 231 insertions(+), 6 deletions(-) create mode 100755 scripts/check-for-old-dot-changes.sh create mode 100755 scripts/clean.sh create mode 100755 scripts/is-hybrid-app-repo.sh create mode 100755 scripts/preinstall.sh create mode 100755 scripts/pull-old-dot.sh create mode 100755 scripts/run-build.sh diff --git a/package.json b/package.json index f4ac5dbe8c3b..7051fb2f083f 100644 --- a/package.json +++ b/package.json @@ -10,13 +10,14 @@ "configure-mapbox": "./scripts/setup-mapbox-sdk-walkthrough.sh", "setupNewDotWebForEmulators": "./scripts/setup-newdot-web-emulators.sh", "startAndroidEmulator": "./scripts/start-android.sh", + "preinstall": "./scripts/preinstall.sh", "postinstall": "./scripts/postInstall.sh", "clean": "npx react-native clean-project-auto", - "android": "./scripts/set-pusher-suffix.sh && npx react-native run-android --mode=developmentDebug --appId=com.expensify.chat.dev --active-arch-only", - "ios": "./scripts/set-pusher-suffix.sh && npx react-native run-ios --list-devices --mode=\"DebugDevelopment\" --scheme=\"New Expensify Dev\"", + "android": "./scripts/set-pusher-suffix.sh && scripts/run-build.sh --android", + "ios": "./scripts/set-pusher-suffix.sh && scripts/run-build.sh --ios", "pod-install": "./scripts/pod-install.sh", - "ipad": "concurrently \"npx react-native run-ios --simulator=\\\"iPad Pro (12.9-inch) (6th generation)\\\" --mode=\\\"DebugDevelopment\\\" --scheme=\\\"New Expensify Dev\\\"\"", - "ipad-sm": "concurrently \"npx react-native run-ios --simulator=\\\"iPad Pro (11-inch) (4th generation)\\\" --mode=\\\"DebugDevelopment\\\" --scheme=\\\"New Expensify Dev\\\"\"", + "ipad": "concurrently \"scripts/run-build.sh --ipad\"", + "ipad-sm": "concurrently \"scripts/run-build.sh --ios\"", "start": "npx react-native start", "web": "./scripts/set-pusher-suffix.sh && concurrently npm:web-proxy npm:web-server", "web-proxy": "ts-node web/proxy.ts", @@ -43,6 +44,7 @@ "prettier": "prettier --write .", "prettier-watch": "onchange \"**/*.{js,ts,tsx}\" -- prettier --write --ignore-unknown {{changed}}", "print-version": "echo $npm_package_version", + "pull-old-dot": "./scripts/pull-old-dot.sh", "storybook": "storybook dev -p 6006", "storybook-build": "ENV=production storybook build -o dist/docs", "storybook-build-staging": "ENV=staging storybook build -o dist/docs", diff --git a/scripts/check-for-old-dot-changes.sh b/scripts/check-for-old-dot-changes.sh new file mode 100755 index 000000000000..626c5c43e32d --- /dev/null +++ b/scripts/check-for-old-dot-changes.sh @@ -0,0 +1,32 @@ +#!/bin/bash +set -e + +# Go to NewDot project root +ROOT_DIR=$(dirname "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)") +cd "$ROOT_DIR" || exit 1 + +# See if we're in the HybridApp repo +IS_HYBRID_APP_REPO=$(scripts/is-hybrid-app-repo.sh) + +GREEN='\033[1;32m' +YELLOW='\033[1;33m' +RED='\033[1;31m' +NC='\033[0m' + +if [[ "$IS_HYBRID_APP_REPO" == "true" ]]; then + # Navigate to the OldDot repository + cd .. + + # Fetch the latest changes from the OldDot repository + git fetch + + # Count the number of commits behind + UPSTREAM=${1:-'@{u}'} + COMMITS_BEHIND=$(git rev-list --count HEAD..$UPSTREAM) + + if [[ $COMMITS_BEHIND -eq 0 ]]; then + echo -e "\n${GREEN}OldDot repository is up to date!${NC}" + else + echo -e "\n${YELLOW}[WARNING] You are ${RED}$COMMITS_BEHIND commit(s)${YELLOW} behind on the OldDot repo. Consider executing ${RED}npm run pull-old-dot${NC}" + fi +fi diff --git a/scripts/clean.sh b/scripts/clean.sh new file mode 100755 index 000000000000..f6ee24989fc6 --- /dev/null +++ b/scripts/clean.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e + +ROOT_DIR=$(dirname "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)") +cd "$ROOT_DIR" || exit 1 + +# See if we're in the HybridApp repo +IS_HYBRID_APP_REPO=$(scripts/is-hybrid-app-repo.sh) + +if [[ "$IS_HYBRID_APP_REPO" == "true" && "$1" != "--new-dot" ]]; then + # Navigate to the OldDot repository, and clean + cd .. + npm run clean +else + # Clean NewDot + npx react-native clean-project-auto +fi \ No newline at end of file diff --git a/scripts/is-hybrid-app-repo.sh b/scripts/is-hybrid-app-repo.sh new file mode 100755 index 000000000000..e683dae176c9 --- /dev/null +++ b/scripts/is-hybrid-app-repo.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -e + +# Get the current working directory +current_pwd=$(pwd) + +# Check if the current working directory ends with 'Mobile-Expensify/react-native' +if [[ "$current_pwd" == *Mobile-Expensify/react-native ]]; then + + # Go up one level to 'Mobile-Expensify' + cd .. + + # Check if 'package.json' exists + if [[ -f package.json ]]; then + # Read the 'name' field from 'package.json' + package_name=$(jq -r '.name' package.json 2>/dev/null) + + # Check if the 'name' field is 'mobile-expensify' + if [[ "$package_name" == "mobile-expensify" ]]; then + echo true + exit 0 + else + echo "Wrong package name in Mobile-Expensify" + exit 1 + fi + else + echo "package.json not found in Mobile-Expensify" + exit 1 + fi +else + echo "PWD output matches standalone NewDot repo structure" + echo false +fi \ No newline at end of file diff --git a/scripts/pod-install.sh b/scripts/pod-install.sh index cb2976d64587..506f36426f74 100755 --- a/scripts/pod-install.sh +++ b/scripts/pod-install.sh @@ -8,11 +8,24 @@ # Exit immediately if any command exits with a non-zero status set -e -# Go to project root +# Go to NewDot project root START_DIR="$(pwd)" ROOT_DIR="$(dirname "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)")" cd "$ROOT_DIR" || exit 1 +# See if we're in the HybridApp repo +IS_HYBRID_APP_REPO=$(scripts/is-hybrid-app-repo.sh) + +if [[ "$IS_HYBRID_APP_REPO" == "true" && "$1" != "--new-dot" ]]; then + cd ../ios + if [ "$1" == "--clean" ]; then + bundle exec pod deintegrate + fi + # Navigate to the OldDot repository, and run pod install + bundle exec pod install + exit 0 +fi + # Cleanup and exit # param - status code function cleanupAndExit { diff --git a/scripts/postInstall.sh b/scripts/postInstall.sh index 782c8ef5822c..818143199a12 100755 --- a/scripts/postInstall.sh +++ b/scripts/postInstall.sh @@ -3,17 +3,28 @@ # Exit immediately if any command exits with a non-zero status set -e -# Go to project root +# Go to NewDot project root ROOT_DIR=$(dirname "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)") cd "$ROOT_DIR" || exit 1 # Apply packages using patch-package scripts/applyPatches.sh +IS_HYBRID_APP_REPO=$(scripts/is-hybrid-app-repo.sh) + +if [[ "$IS_HYBRID_APP_REPO" == "true" ]]; then + echo "Applying patches to OldDot..." + + # Apply HybridApp-specific patches to NewDot + npx patch-package --patch-dir '../patches/new-dot' +fi + # Install node_modules in subpackages, unless we're in a CI/CD environment, # where the node_modules for subpackages are cached separately. # See `.github/actions/composite/setupNode/action.yml` for more context. if [[ -z ${CI+x} ]]; then + scripts/check-for-old-dot-changes.sh + cd desktop || exit 1 npm install fi diff --git a/scripts/preinstall.sh b/scripts/preinstall.sh new file mode 100755 index 000000000000..f484f9b2faa3 --- /dev/null +++ b/scripts/preinstall.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e + +# Go to NewDot project root +ROOT_DIR=$(dirname "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)") +cd "$ROOT_DIR" || exit 1 + +# See if we're in the HybridApp repo +IS_HYBRID_APP_REPO=$(scripts/is-hybrid-app-repo.sh) + +if [[ "$IS_HYBRID_APP_REPO" == "true" ]]; then + echo "We're in HybridApp. Executing npm install." + + # Navigate to the OldDot repository + cd .. + + # Perform npm install in OldDot + npm i +fi \ No newline at end of file diff --git a/scripts/pull-old-dot.sh b/scripts/pull-old-dot.sh new file mode 100755 index 000000000000..b2abd5c3b8a4 --- /dev/null +++ b/scripts/pull-old-dot.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +# Go to NewDot project root +ROOT_DIR=$(dirname "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)") +cd "$ROOT_DIR" || exit 1 + +# See if we're in the HybridApp repo +IS_HYBRID_APP_REPO=$(scripts/is-hybrid-app-repo.sh) + +if [[ "$IS_HYBRID_APP_REPO" == "true" ]]; then + echo "We're in HybridApp. Performing git pull." + + # Navigate to the OldDot repository + cd .. + + # Perform git pull, and run npm install + git pull + npm i +else + echo "We're in standalone NewDot. Nothing to pull" +fi \ No newline at end of file diff --git a/scripts/run-build.sh b/scripts/run-build.sh new file mode 100755 index 000000000000..a925b57633d6 --- /dev/null +++ b/scripts/run-build.sh @@ -0,0 +1,76 @@ +#!/bin/bash +set -e + +BUILD="$1" +NEW_DOT_FLAG="false" +MODE="DebugDevelopment" +SCHEME="New Expensify Dev" +APP_ID="com.expensify.chat.dev" + +GREEN='\033[1;32m' +YELLOW='\033[1;33m' +RED='\033[1;31m' +NC='\033[0m' + +# Function to print error message and exit +function print_error_and_exit { + echo -e "${RED}Error: Invalid invocation. Please use one of: [ios, ipad, ipad-sm, android].${NC}" + exit 1 +} + +# Assign the arguments to variables +if [ "$#" -eq 1 ]; then + BUILD="$1" +elif [ "$#" -eq 2 ]; then + if [ "$1" == "--new-dot" ]; then + BUILD="$2" + NEW_DOT_FLAG="true" + elif [ "$2" == "--new-dot" ]; then + BUILD="$1" + NEW_DOT_FLAG="true" + else + print_error_and_exit + fi +else + print_error_and_exit +fi + +# Go to NewDot project root +ROOT_DIR=$(dirname "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)") +cd "$ROOT_DIR" || exit 1 + +# See if we're in the HybridApp repo +IS_HYBRID_APP_REPO=$(scripts/is-hybrid-app-repo.sh) + + if [[ "$IS_HYBRID_APP_REPO" == "true" && "$NEW_DOT_FLAG" == "false" ]]; then + # Navigate to the OldDot repository + cd .. + # Set HybridApp-specific arguments + MODE="Debug" + SCHEME="Expensify" + APP_ID="org.me.mobiexpensifyg" + + echo -e "\n${GREEN}Starting a HybridApp build!${NC}" +else + echo -e "\n${GREEN}Starting a standalone NewDot build!${NC}" +fi + +# Check if the argument is one of the desired values +case "$BUILD" in + --ios) + npx react-native run-ios --list-devices --mode $MODE --scheme $SCHEME + ;; + --ipad) + npx react-native run-ios --simulator "iPad Pro (12.9-inch) (6th generation)" --mode $MODE --scheme $SCHEME + ;; + --ipad-sm) + npx react-native run-ios --simulator "iPad Pro (11-inch) (4th generation)" --mode $MODE --scheme $SCHEME + ;; + --android) + npx react-native run-android --list-devices --mode $MODE --appId $APP_ID --active-arch-only + ;; + *) + print_error_and_exit + exit 1 + ;; +esac \ No newline at end of file