From a1fb6f26cfeaa712f447e5d41d2a98565e9ab478 Mon Sep 17 00:00:00 2001 From: hlopko Date: Tue, 30 May 2017 16:51:44 +0200 Subject: Fix scripts/serve-docs.sh RELNOTES: None. PiperOrigin-RevId: 157463020 --- scripts/serve-docs.sh | 96 +++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) (limited to 'scripts/serve-docs.sh') diff --git a/scripts/serve-docs.sh b/scripts/serve-docs.sh index 27d157731f..edbe41384d 100755 --- a/scripts/serve-docs.sh +++ b/scripts/serve-docs.sh @@ -15,6 +15,12 @@ set -eu +readonly WORKING_DIR=$(mktemp -d) +HOST=localhost +PORT=12345 +TARGET= +SERVING_PREFIX= + usage() { cat < /dev/null || (echo "$1 not installed. Please install $1."; exit 1) -} - build_tree() { bazel build //site:jekyll-tree.tar rm -rf $WORKING_DIR/* @@ -96,6 +63,20 @@ build_and_serve() { jekyll serve --host "$HOST" --detach --quiet --port "$PORT" --source "$WORKING_DIR" } +check() { + which $1 > /dev/null || (echo "$1 not installed. Please install $1."; exit 1) +} + +kill_jekyll() { + pid="$(lsof "-tiTCP:$PORT" -sTCP:LISTEN)" || true + if [ ! -z "$pid" ]; then + kill "$pid" + fi + # I found I got bind errors sometimes if I didn't wait a second for the server to + # actually shut down. + sleep 2 +} + main() { check jekyll @@ -125,15 +106,34 @@ main() { done } -kill_jekyll() { - pid="$(lsof "-tiTCP:$PORT" -sTCP:LISTEN)" || true - if [ ! -z "$pid" ]; then - kill "$pid" - fi - # I found I got bind errors sometimes if I didn't wait a second for the server to - # actually shut down. - sleep 2 -} +while [[ $# -gt 0 ]] +do + key="$1" + case $key in + --port) + PORT="$2" + shift + ;; + --share) + HOST="$HOSTNAME" + ;; + --target) + TARGET="$2" + shift + SERVING_PREFIX="${2:-}" + build_static + exit 0 + ;; + --help|help) + usage + exit 0 + ;; + *) + usage + exit 1 + esac + shift +done cleanup() { rm -rf $WORKING_DIR -- cgit v1.2.3