@@ -7,6 +7,7 @@ set -euo pipefail
77ORIGINAL_DIR=$( pwd)
88SDK_ROOT=" $( cd ../../ && pwd) "
99STAMP_FILE=" $SDK_ROOT /.rn-sdk-source.stamp"
10+ DEMO_ENV_STAMP_FILE=" $ORIGINAL_DIR /.rn-demo-env.stamp"
1011TGZ_FILE=" $SDK_ROOT /react-native-onesignal.tgz"
1112INSTALLED_DIR=" $ORIGINAL_DIR /node_modules/react-native-onesignal"
1213
@@ -24,6 +25,34 @@ src_hash=$(find "$SDK_ROOT/src" "$SDK_ROOT/ios" "$SDK_ROOT/android" \
2425 | shasum \
2526 | awk ' {print $1}' )
2627
28+ demo_env_hash=$(
29+ {
30+ for file in " $ORIGINAL_DIR /.env" " $ORIGINAL_DIR /babel.config.js" ; do
31+ if [ -f " $file " ]; then
32+ shasum " $file "
33+ else
34+ echo " missing $file "
35+ fi
36+ done
37+ } | shasum | awk ' {print $1}'
38+ )
39+
40+ if [ ! -f " $DEMO_ENV_STAMP_FILE " ] || [ " $( cat " $DEMO_ENV_STAMP_FILE " ) " != " $demo_env_hash " ]; then
41+ echo " Demo env inputs changed, clearing Metro cache..."
42+ rm -rf " ${TMPDIR:-/ tmp} " /metro-* " ${TMPDIR:-/ tmp} " /haste-map-* " $ORIGINAL_DIR /node_modules/.cache/metro" 2> /dev/null || true
43+ metro_pids=$( lsof -ti tcp:8081 2> /dev/null || true)
44+ for pid in $metro_pids ; do
45+ args=$( ps -p " $pid " -o args= 2> /dev/null || true)
46+ case " $args " in
47+ * react-native* |* metro* )
48+ echo " Stopping Metro so @env values are reloaded..."
49+ kill " $pid " 2> /dev/null || true
50+ ;;
51+ esac
52+ done
53+ echo " $demo_env_hash " > " $DEMO_ENV_STAMP_FILE "
54+ fi
55+
2756# Skip the whole rebuild when:
2857# - the demo already has the SDK installed,
2958# - the cached tarball is still on disk, and
0 commit comments