-
Notifications
You must be signed in to change notification settings - Fork 8
/
insert-bundle.sh
executable file
·50 lines (43 loc) · 1.21 KB
/
insert-bundle.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/sh
INNER_BINS="$(pwd)/node_modules/.bin"
OUTER_BINS="$(pwd)/../.bin"
NODERIFY="$INNER_BINS/noderify"
if [ ! -e "$NODERIFY" ]; then
NODERIFY="$OUTER_BINS/noderify"
fi
RNNODE="$INNER_BINS/react-native-node"
if [ ! -e "$RNNODE" ]; then
RNNODE="$OUTER_BINS/react-native-node"
fi
PATCH_SCUTTLEBOT_BIN="$(pwd)/patch-scuttlebot.js"
PROJECT="$(pwd)/../.."
ORIG="$(pwd)/rnnodeapp"
DEST="$PROJECT/rnnodeapp"
# Set up destination
rm -rf "$DEST";
mkdir -p "$DEST";
cp -r "$ORIG" "$DEST/../";
# Install dependencies there
cd "$DEST";
npm i;
# Setup native libraries and fix other libraries
PREBUILT_PATH_1="$DEST/node_modules/leveldown-android-prebuilt/compiled"
cp -R "$PREBUILT_PATH_1" "$DEST/";
node "$PATCH_SCUTTLEBOT_BIN" "$DEST";
# Minify the bundle
cd "$DEST";
$NODERIFY \
--replace.chloride=sodium-browserify-tweetnacl \
--replace.sodium-chloride=sodium-browserify-tweetnacl \
--replace.node-extend=xtend \
--replace.leveldown=leveldown-android-prebuilt \
"$DEST/index.js" > "$DEST/_index.js";
rm "$DEST/index.js";
mv "$DEST/_index.js" "$DEST/index.js";
# Pre-insert clean up
rm -rf "$DEST/node_modules";
# Insert bundle into the project
cd $PROJECT;
$RNNODE insert "$DEST";
# Post-insert clean up
#`rm -rf ${dest}`