diff --git a/src/webview/static/README.md b/src/webview/static/README.md new file mode 100644 index 00000000000..0d6b490c084 --- /dev/null +++ b/src/webview/static/README.md @@ -0,0 +1,16 @@ +# Webview static files + +This directory holds static files to be packaged for use by the embedded +WebView. Files herein (other than those named `README.md`) will be copied out to +the packaged application at build time. + +Although the files in this directory are static at _runtime_, some of them may +still be generated dynamically at _build time_. Such files should not be tracked +in the Git repository, but instead rebuilt as needed; see [the build-webview +script][build-webview] for an appropriate hook. + +[build-webview]: ../../../tools/build-webview + +_N.B._: When editing and testing, changes made to this directory will **not** be +uploaded to an emulator after a mere reload! You must perform a rebuild +(`react-native run-${TARGET}`) to repackage any new or altered assets. \ No newline at end of file diff --git a/tools/build-webview b/tools/build-webview new file mode 100755 index 00000000000..91f0198865c --- /dev/null +++ b/tools/build-webview @@ -0,0 +1,135 @@ +#!/bin/bash +set -eu +unset CDPATH + +# CAVEAT EMENDATOR: Neither of the build systems have any visibility into this +# script's dependencies -- it is run unconditionally, and must ensure on its own +# that it performs as few actions as possible when nothing has changed. + +################################################################################ +# Common functions +################################################################################ + +# print usage message; do not die +usage() { + cat >&2 <&2 + exit 1; +} + + + +################################################################################ +# Parameters and environment +################################################################################ + +# chdir to the current git repo's root +ROOT="$(git rev-parse --show-toplevel)" +cd "$ROOT" + +# Parse arguments. Sloppy, but sufficient for now. +unset TARGET +unset DEST +while (( $# )); do + case "$1" in + --help|-h|help) + usage; exit 0;; + android|ios) + # no check for multiple nouns; oh well + TARGET="$1"; shift;; + --destination) + # note: this doesn't permit an equals sign after `--destination` + shift; DEST="$1"; shift;; + *) usage; exit 2;; + esac +done + +if [ -z "${TARGET-}" ]; then + usage; exit 2 +elif [ -z "${DEST-}" ]; then + usage; exit 2 +fi + +# Sanity-check DEST and TARGET. +case "$TARGET" in + ios) + if [ "$(uname)" != "Darwin" ]; then + err "iOS builds only supported on macOS"; + fi + + # $DEST should be copied to `${bundle_root}/webview`. + # + # It must be specified twice in Xcode: once in the invocation of this + # script, and once in the "Copy Bundle Resources" step. If you change + # it, you'll need to change it in both places. (And here, of course.) + if [[ "$DEST" != "$ROOT/ios/"* ]]; then + err "unexpected destination directory '$DEST' (expected target in iOS build dir)" + fi + ;; + android) + # $DEST should be copied to `file:///android_asset/webview`. + # + # Gradle -- more precisely, the Android Gradle plugin -- is already + # configured to copy some directory from build/ into the bundle. We + # determine which directory that is in Gradle, and pass it here. + if [[ "$DEST" != "$ROOT/android/app/build/"* ]]; then + err "unexpected destination directory '$DEST' (expected target in Android build dir)" + fi + ;; + *) err "impossible target $TARGET";; +esac + +# The target directory basename should be 'webview' -- both build systems will +# preserve the name they're given here. +if [[ "$DEST" != *"/webview" ]]; then + err "unexpected destination directory '$DEST'" +fi + +# Set SRC. +SRC=src/webview/static +if [ ! -d "$SRC" ]; then + err "cannot find asset source directory '$SRC'"; +fi + + +################################################################################ +# Pre-sync: platform-agnostic build steps +################################################################################ + +# Currently none, but this is where they'll go. +# +# TODO: Use something like `make -f src/webview/static.Makefile`, to ensure that +# complicated build steps are not run unconditionally. + + + +################################################################################ +# Sync +################################################################################ + +# Sync the directory structure, preserving metadata. (We ignore any files named +# 'README.md'; these should be strictly informative.) +# +# We use `rsync` here, as it will skip unchanged files. +mkdir -p "$DEST" +rsync -a --no-D --delete --delete-excluded --exclude=README.md "$SRC/." "$DEST" + + + +################################################################################ +# Post-sync: platform-specific build steps +################################################################################ + +# None yet.