|
| 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_NAME="algolia/algoliasearch-helper-swift" |
| 10 | +BRANCH_NAME="gh-pages" |
| 11 | +DST_DIR="$PROJECT_ROOT/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 [email protected]: $GIT_REPO_NAME -b "$BRANCH_NAME" --single-branch "$DST_DIR" |
| 32 | +fi |
| 33 | + |
| 34 | +# Make the documentation |
| 35 | +# ---------------------- |
| 36 | +# Clean the destination directory. |
| 37 | +# NOTE: We don't use Jazzy's `--clean` option because it deletes the destination directory; we want to preserve the |
| 38 | +# Git checkout. |
| 39 | +echo "Cleaning destination directory" |
| 40 | +rm -rf "$DST_DIR"/* |
| 41 | + |
| 42 | +# Generate the documentations with [Jazzy](https://github.com/realm/jazzy). |
| 43 | +cd "$PROJECT_ROOT" |
| 44 | +# Online flavor -> root directory. |
| 45 | +echo "# Generating online flavor" |
| 46 | +jazzy --config .jazzy.yaml |
| 47 | +# Offline flavor -> `offline` subdirectory. |
| 48 | +echo "# Generating offline flavor" |
| 49 | +jazzy --config offline.jazzy.yaml |
| 50 | + |
| 51 | +cp "$PROJECT_ROOT/LICENSE" "$DST_DIR/LICENSE.md" |
| 52 | + |
| 53 | +echo 'Done. Git diff then add and commit.' |
0 commit comments