Skip to content

Commit f363981

Browse files
committed
feat: introduce file syncing so that debugging is easy
1 parent a616611 commit f363981

File tree

11 files changed

+146
-20
lines changed

11 files changed

+146
-20
lines changed

examples/ExpoMessaging/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"version": "1.0.0",
44
"main": "expo-router/entry",
55
"scripts": {
6+
"sync-native": "bash ../../package/scripts/sync-shimmer-from-package.sh expo-package && bash ../../package/scripts/sync-shimmer-native.sh expo-package",
7+
"prestart": "yarn sync-native",
8+
"preandroid": "yarn sync-native",
9+
"preios": "yarn sync-native",
610
"start": "expo start --dev-client",
711
"android": "expo run:android",
812
"ios": "expo run:ios",

examples/SampleApp/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3735,7 +3735,7 @@ SPEC CHECKSUMS:
37353735
SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d
37363736
SDWebImageWebPCoder: 908b83b6adda48effe7667cd2b7f78c897e5111d
37373737
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
3738-
stream-chat-react-native: 4c7b4132ab6b45c016273a35e465583c3cd8b151
3738+
stream-chat-react-native: 7849b617fe4d5f0c5eec30dc69a4f8e4a049d1a3
37393739
Teleport: 9ae328b3384204b23236e47bd0d8e994ce6bdb48
37403740
Yoga: ce248fb32065c9b00451491b06607f1c25b2f1ed
37413741

examples/SampleApp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/GetStream/stream-chat-react-native.git"
88
},
99
"scripts": {
10-
"sync-native": "bash ../../package/scripts/sync-shimmer-native.sh native-package",
10+
"sync-native": "bash ../../package/scripts/sync-shimmer-from-package.sh native-package && bash ../../package/scripts/sync-shimmer-native.sh native-package",
1111
"preandroid": "yarn sync-native",
1212
"android": "react-native run-android",
1313
"preios": "yarn sync-native",

package/expo-package/android/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ if (isNewArchitectureEnabled()) {
2929
def getExtOrIntegerDefault(name) {
3030
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["StreamChatExpo_" + name]).toInteger()
3131
}
32-
3332
def localShimmerSourceDir = new File(projectDir, "src/main/java/com/streamchatreactnative")
3433
def sharedShimmerSourceDir = new File(projectDir, "../../shared-native/android/src/main/java/com/streamchatreactnative")
3534
def generatedShimmerSourceDir = new File(project.buildDir, "generated/stream-shimmer/src/main/java/com/streamchatreactnative")

package/expo-package/stream-chat-expo.podspec

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ Pod::Spec.new do |s|
1414
s.source = { :git => "./ios", :tag => "#{s.version}" }
1515
s.prepare_command = <<-CMD
1616
if [ -d ../shared-native/ios ]; then
17-
cp -f ../shared-native/ios/* ios/
17+
mkdir -p ios
18+
for file in ../shared-native/ios/*; do
19+
dest="ios/$(basename "$file")"
20+
rm -f "$dest"
21+
cp "$file" "$dest"
22+
done
1823
fi
1924
CMD
2025
s.source_files = "ios/**/*.{h,m,mm,swift}"

package/native-package/android/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def getExtOrDefault(name) {
3636
def getExtOrIntegerDefault(name) {
3737
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ImageResizer_" + name]).toInteger()
3838
}
39-
4039
def localShimmerSourceDir = new File(projectDir, "src/main/java/com/streamchatreactnative")
4140
def sharedShimmerSourceDir = new File(projectDir, "../../shared-native/android/src/main/java/com/streamchatreactnative")
4241
def generatedShimmerSourceDir = new File(project.buildDir, "generated/stream-shimmer/src/main/java/com/streamchatreactnative")

package/native-package/stream-chat-react-native.podspec

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ Pod::Spec.new do |s|
1414
s.source = { :git => "./ios", :tag => "#{s.version}" }
1515
s.prepare_command = <<-CMD
1616
if [ -d ../shared-native/ios ]; then
17-
cp -f ../shared-native/ios/* ios/
17+
mkdir -p ios
18+
for file in ../shared-native/ios/*; do
19+
dest="ios/$(basename "$file")"
20+
rm -f "$dest"
21+
cp "$file" "$dest"
22+
done
1823
fi
1924
CMD
2025
s.source_files = "ios/**/*.{h,m,mm,swift}"

package/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
],
2525
"scripts": {
2626
"install-all": "(yarn install --force && (cd native-package && yarn install --force) && (cd expo-package && yarn install --force))",
27+
"shimmer:sync": "bash ./scripts/sync-shimmer-native.sh all",
28+
"shimmer:clean-copies": "bash ./scripts/clean-shimmer-native-copies.sh all",
2729
"build": "rimraf lib && yarn run --silent build-translations && bob build && yarn run --silent copy-translations",
2830
"build-translations": "i18next-cli sync",
2931
"copy-translations": "echo '\u001b[34mℹ\u001b[0m Copying translation files to \u001b[34mlib/typescript/i18n\u001b[0m' && cp -R -f ./src/i18n ./lib/typescript/i18n && echo '\u001b[32m✓\u001b[0m Done Copying Translations'",
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
TARGET="${1:-all}"
6+
7+
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
8+
SHARED_ANDROID_DIR="$ROOT_DIR/shared-native/android/src/main/java/com/streamchatreactnative"
9+
SHARED_IOS_DIR="$ROOT_DIR/shared-native/ios"
10+
11+
ANDROID_FILES=(
12+
"StreamShimmerFrameLayout.kt"
13+
"StreamShimmerViewManager.kt"
14+
)
15+
IOS_FILES=(
16+
"StreamShimmerViewComponentView.h"
17+
"StreamShimmerViewComponentView.mm"
18+
"StreamShimmerView.swift"
19+
)
20+
21+
copy_file() {
22+
local src_file="$1"
23+
local dst_file="$2"
24+
if [ -e "$dst_file" ]; then
25+
local src_inode
26+
local dst_inode
27+
src_inode=$(stat -f %i "$src_file" 2>/dev/null || echo "")
28+
dst_inode=$(stat -f %i "$dst_file" 2>/dev/null || echo "")
29+
if [ -n "$src_inode" ] && [ "$src_inode" = "$dst_inode" ]; then
30+
return
31+
fi
32+
fi
33+
cp "$src_file" "$dst_file"
34+
}
35+
36+
sync_from_package() {
37+
local package_name="$1"
38+
local android_src_dir="$ROOT_DIR/$package_name/android/src/main/java/com/streamchatreactnative"
39+
local ios_src_dir="$ROOT_DIR/$package_name/ios"
40+
local missing=0
41+
42+
mkdir -p "$SHARED_ANDROID_DIR" "$SHARED_IOS_DIR"
43+
44+
for filename in "${ANDROID_FILES[@]}"; do
45+
local src_file="$android_src_dir/$filename"
46+
local dst_file="$SHARED_ANDROID_DIR/$filename"
47+
if [ ! -f "$src_file" ]; then
48+
echo "Missing Android shimmer source in $package_name (skipping reverse sync): $src_file"
49+
missing=1
50+
continue
51+
fi
52+
copy_file "$src_file" "$dst_file"
53+
done
54+
55+
for filename in "${IOS_FILES[@]}"; do
56+
local src_file="$ios_src_dir/$filename"
57+
local dst_file="$SHARED_IOS_DIR/$filename"
58+
if [ ! -f "$src_file" ]; then
59+
echo "Missing iOS shimmer source in $package_name (skipping reverse sync): $src_file"
60+
missing=1
61+
continue
62+
fi
63+
copy_file "$src_file" "$dst_file"
64+
done
65+
66+
if [ "$missing" -eq 1 ]; then
67+
return 0
68+
fi
69+
}
70+
71+
case "$TARGET" in
72+
native-package)
73+
sync_from_package "native-package"
74+
;;
75+
expo-package)
76+
sync_from_package "expo-package"
77+
;;
78+
all)
79+
# Prefer native-package as source if both are present.
80+
if [ -f "$ROOT_DIR/native-package/ios/StreamShimmerView.swift" ]; then
81+
sync_from_package "native-package"
82+
elif [ -f "$ROOT_DIR/expo-package/ios/StreamShimmerView.swift" ]; then
83+
sync_from_package "expo-package"
84+
else
85+
echo "No package shimmer sources found to sync from"
86+
exit 1
87+
fi
88+
;;
89+
*)
90+
echo "Unknown target: $TARGET"
91+
echo "Expected one of: native-package, expo-package, all"
92+
exit 1
93+
;;
94+
esac
95+
96+
echo "Synchronized shimmer native files from package mirror to shared-native for target: $TARGET"

package/scripts/sync-shimmer-native.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,35 @@ ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
88
ANDROID_SRC_DIR="$ROOT_DIR/shared-native/android/src/main/java/com/streamchatreactnative"
99
IOS_SRC_DIR="$ROOT_DIR/shared-native/ios"
1010

11+
copy_file() {
12+
local src_file="$1"
13+
local dst_file="$2"
14+
if [ -e "$dst_file" ]; then
15+
local src_inode
16+
local dst_inode
17+
src_inode=$(stat -f %i "$src_file" 2>/dev/null || echo "")
18+
dst_inode=$(stat -f %i "$dst_file" 2>/dev/null || echo "")
19+
if [ -n "$src_inode" ] && [ "$src_inode" = "$dst_inode" ]; then
20+
return
21+
fi
22+
fi
23+
rm -f "$dst_file"
24+
cp "$src_file" "$dst_file"
25+
}
26+
1127
copy_to_package() {
1228
local package_name="$1"
1329
local android_dst_dir="$ROOT_DIR/$package_name/android/src/main/java/com/streamchatreactnative"
1430
local ios_dst_dir="$ROOT_DIR/$package_name/ios"
1531

1632
mkdir -p "$android_dst_dir"
17-
cp "$ANDROID_SRC_DIR/StreamShimmerFrameLayout.kt" "$android_dst_dir/StreamShimmerFrameLayout.kt"
18-
cp "$ANDROID_SRC_DIR/StreamShimmerViewManager.kt" "$android_dst_dir/StreamShimmerViewManager.kt"
33+
copy_file "$ANDROID_SRC_DIR/StreamShimmerFrameLayout.kt" "$android_dst_dir/StreamShimmerFrameLayout.kt"
34+
copy_file "$ANDROID_SRC_DIR/StreamShimmerViewManager.kt" "$android_dst_dir/StreamShimmerViewManager.kt"
1935

2036
mkdir -p "$ios_dst_dir"
21-
cp "$IOS_SRC_DIR/StreamShimmerViewComponentView.h" "$ios_dst_dir/StreamShimmerViewComponentView.h"
22-
cp "$IOS_SRC_DIR/StreamShimmerViewComponentView.mm" "$ios_dst_dir/StreamShimmerViewComponentView.mm"
23-
cp "$IOS_SRC_DIR/StreamShimmerView.swift" "$ios_dst_dir/StreamShimmerView.swift"
37+
copy_file "$IOS_SRC_DIR/StreamShimmerViewComponentView.h" "$ios_dst_dir/StreamShimmerViewComponentView.h"
38+
copy_file "$IOS_SRC_DIR/StreamShimmerViewComponentView.mm" "$ios_dst_dir/StreamShimmerViewComponentView.mm"
39+
copy_file "$IOS_SRC_DIR/StreamShimmerView.swift" "$ios_dst_dir/StreamShimmerView.swift"
2440
}
2541

2642
case "$TARGET" in

0 commit comments

Comments
 (0)