|
| 1 | +#!/usr/bin/env ksh |
| 2 | + |
| 3 | +set -e # fail on first error |
| 4 | + |
| 5 | +# Reflection. |
| 6 | +SELF_ROOT=$(cd $(dirname "$0") && pwd) |
| 7 | +PROJECT_ROOT=$(cd "$SELF_ROOT"/.. && pwd) |
| 8 | + |
| 9 | +GIT_REPO_URL=$(cd "$PROJECT_ROOT" && git remote get-url origin) |
| 10 | +BRANCH_NAME="gh-pages" |
| 11 | +DST_DIR="$PROJECT_ROOT/algoliasearch/build/doc" |
| 12 | + |
| 13 | +# Prepare the destination directory |
| 14 | +# --------------------------------- |
| 15 | +# If the destination directory exists, make sure that it's a Git checkout of the `gh-pages` branch. |
| 16 | +if [[ -d "$DST_DIR" ]]; then |
| 17 | + branch_name=$(cd "$DST_DIR" && git rev-parse --abbrev-ref HEAD) |
| 18 | + if [[ "$branch_name" != "$BRANCH_NAME" ]]; then |
| 19 | + echo "ERROR: Directory '$DST_DIR' is not a checkout of the '$BRANCH_NAME' branch!" 1>&2 |
| 20 | + exit 1 |
| 21 | + fi |
| 22 | + pwd=$(pwd) |
| 23 | + # Clean the Git checkout. |
| 24 | + echo "Git checkout found; cleaning" |
| 25 | + cd "$DST_DIR" && git clean -f |
| 26 | + cd "$pwd" |
| 27 | +# Otherwise, create it. |
| 28 | +else |
| 29 | + echo "No Git checkout found; cloning" |
| 30 | + mkdir -p $(dirname "$DST_DIR") |
| 31 | + git clone "$GIT_REPO_URL" -b "$BRANCH_NAME" --single-branch "$DST_DIR" |
| 32 | +fi |
| 33 | + |
| 34 | +# Make the documentation |
| 35 | +# ---------------------- |
| 36 | +# Clean the destination directory. |
| 37 | +echo "Cleaning destination directory" |
| 38 | +rm -rf "$DST_DIR"/* |
| 39 | + |
| 40 | +# Online flavor -> root directory. |
| 41 | +echo "# Generating online flavor" |
| 42 | +"$PROJECT_ROOT/select-flavor.sh" online |
| 43 | +gradle javadoc |
| 44 | +# Offline flavor -> `offline` subdirectory. |
| 45 | +echo "# Generating offline flavor" |
| 46 | +"$PROJECT_ROOT/select-flavor.sh" offline |
| 47 | +gradle javadoc |
| 48 | + |
| 49 | +# Copy license. |
| 50 | +LICENSE_FILE_NAME="LICENSE.txt" |
| 51 | +cp "$PROJECT_ROOT/LICENSE" "$DST_DIR/$LICENSE_FILE_NAME" |
| 52 | +cp "$PROJECT_ROOT/LICENSE" "$DST_DIR/offline/$LICENSE_FILE_NAME" |
| 53 | + |
| 54 | +echo 'Done. Git diff then add and commit.' |
0 commit comments