-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle-jss.sh
More file actions
executable file
·99 lines (86 loc) · 2.8 KB
/
bundle-jss.sh
File metadata and controls
executable file
·99 lines (86 loc) · 2.8 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
#
# bundle-jss.sh — populate app/src/main/assets/jss/ with a JSS bundle
#
# Pulls the published `javascript-solid-server` tarball from npm, installs
# its production dependencies, and copies the result to
# app/src/main/assets/jss/. That directory is then bundled into the APK
# as the Node.js project root; on first launch MainActivity / JssService
# copy it out to <filesDir>/jss/ so Node can write to it.
#
# Usage:
# ./scripts/bundle-jss.sh # latest published version
# ./scripts/bundle-jss.sh 0.0.169 # a specific version
# ./scripts/bundle-jss.sh --source ../JavaScriptSolidServer
# # bundle from a local checkout (dev)
#
# Aborts if any *.node binaries or binding.gyp files turn up in the tree —
# nodejs-mobile can't load native addons unless they're cross-compiled for
# Android, and we explicitly want to keep the bundle pure-JS.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
DEST="$REPO_ROOT/app/src/main/assets/jss"
SOURCE_DIR=""
VERSION="latest"
while [[ $# -gt 0 ]]; do
case "$1" in
--source)
SOURCE_DIR="$2"
shift 2
;;
-h|--help)
sed -n '2,15p' "$0"
exit 0
;;
*)
VERSION="$1"
shift
;;
esac
done
TMPDIR="$(mktemp -d)"
trap 'rm -rf "$TMPDIR"' EXIT
if [[ -n "$SOURCE_DIR" ]]; then
if [[ ! -f "$SOURCE_DIR/package.json" ]]; then
echo "ERROR: --source path '$SOURCE_DIR' has no package.json" >&2
exit 1
fi
echo "==> Packing local source: $SOURCE_DIR"
( cd "$SOURCE_DIR" && npm pack --pack-destination "$TMPDIR" >/dev/null )
else
echo "==> Pulling javascript-solid-server@$VERSION from npm"
( cd "$TMPDIR" && npm pack "javascript-solid-server@$VERSION" >/dev/null )
fi
cd "$TMPDIR"
TARBALL="$(ls javascript-solid-server-*.tgz | head -1)"
tar -xzf "$TARBALL"
cd package
echo "==> Installing production dependencies"
npm install --omit=dev --no-package-lock --no-audit --no-fund >/dev/null
echo "==> Sanity check: no native modules"
NATIVE_HITS="$(find . \( -name "*.node" -o -name "binding.gyp" \) 2>/dev/null || true)"
if [[ -n "$NATIVE_HITS" ]]; then
echo "ERROR: native modules detected — nodejs-mobile won't load these" >&2
echo "$NATIVE_HITS" >&2
exit 1
fi
PKG_VERSION="$(node -p "require('./package.json').version")"
FILE_COUNT="$(find . -type f | wc -l | tr -d ' ')"
SIZE="$(du -sh . | cut -f1)"
echo "==> Copying to $DEST"
mkdir -p "$DEST"
rm -rf "${DEST:?}"/*
cp -r bin src package.json node_modules "$DEST/"
cat > "$DEST/.bundle-info" <<EOF
javascript-solid-server@$PKG_VERSION
bundled at $(date -u +%Y-%m-%dT%H:%M:%SZ)
files: $FILE_COUNT
size: $SIZE
source: ${SOURCE_DIR:-npm:$VERSION}
EOF
echo
echo "Done."
echo " Version: $PKG_VERSION"
echo " Files: $FILE_COUNT"
echo " Size: $SIZE"
echo " Path: $DEST"