-
Notifications
You must be signed in to change notification settings - Fork 0
/
refresh-example.sh
executable file
·50 lines (41 loc) · 1.99 KB
/
refresh-example.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
set -e
echo "You should run this from directory where you have cloned the react-native-device-info repo"
echo "You should only do this when your git working set is completely clean (e.g., git reset --hard)"
echo "You must have already run \`npm install\` in the repository so \`npx react-native\` will work"
echo "This scaffolding refresh has been tested on macOS, if you use it on linux, it might not work"
# Copy the important files out temporarily
if [ -d TEMP ]; then
echo "TEMP directory already exists - we use that to store files while refreshing."
exit 1
else
echo "Saving files to TEMP while refreshing scaffolding..."
mkdir -p TEMP/android
mkdir -p TEMP/ios
cp example/README.md TEMP/
cp example/android/local.properties TEMP/android/
cp example/App.js TEMP/
cp example/ios/Podfile TEMP/ios/
fi
# Purge the old sample
\rm -fr example
# Make the new example
npx react-native init example
pushd example
npm install github:react-native-community/react-native-device-info
npx react-native link react-native-device-info
# Patch the build.gradle directly to slice in our android play version
sed -i -e 's/ext {$/ext { googlePlayServicesVersion = "16.1.0"/' android/build.gradle
rm -f android/build.gradle??
# Patch the AndroidManifest directly to add our permissions
sed -i -e 's/INTERNET" \/>/INTERNET" \/><uses-permission android:name="android.permission.ACCESS_WIFI_STATE" \/><uses-permission android:name="android.permission.BLUETOOTH" \/><uses-permission android:name="android.permission.READ_PHONE_STATE" \/>/' android/app/src/main/AndroidManifest.xml
rm -f android/app/src/main/AndroidManifest.xml??
# Patch the AppDelegate for iOS battery level
sed -i -e $'s/return YES;/\[UIDevice currentDevice\].batteryMonitoringEnabled = true;\\\n return YES;/' ios/example/AppDelegate.m
rm -f ios/example/AppDelegate.m??
# Copy the important files back in
popd
echo "Copying device-info example files into refreshed example..."
cp -frv TEMP/* example/
# Clean up after ourselves
\rm -fr TEMP