generate_doc.sh 1.24 KB
Newer Older
Aravind Bk's avatar
Aravind Bk committed
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
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# assuming sphinx is installed
function build_doc() {
  curr_dir=$(pwd)
  cd "$SCRIPT_DIR"/../documentation/sphinx
  rm -rf .build
  mkdir .build
  sphinx-apidoc -o ./.doc ../../.
  sphinx-build -b html . ./.build
  rm -rf .doc
  ln -s sphinx/.build/index.html ../index.html
  cd "$curr_dir"  
  echo "Documentation files placed in the .build directory in sphinx folder."

}

function clean_doc() {
  curr_dir=$(pwd)
  cd "$SCRIPT_DIR"/../documentation/sphinx
  rm -rf .build
  rm ../index.html
  cd "$curr_dir"
  echo "Cleaned .build folder."
}

# if arg0 is clean then kill session
if [[ "$#" -eq 1 ]]; then
  if [[ "$1" == "clean" ]]; then
    clean_doc
    exit 0
  elif [[ "$1" == "build" ]]; then
    build_doc
  elif [[ "$1" == "launch" ]]; then
    case "$(uname -s)" in
     Darwin)
       open "$SCRIPT_DIR/../documentation/index.html"
       ;;
     Linux)
       xdg-open "$SCRIPT_DIR/../documentation/index.html"
       ;;
     *)
       echo 'Cannot determine your OS. Open the .build/index.html file in the root folder.' 
       ;;
    esac
  else
    echo "Usage: generate_doc.sh {build|clean|launch}" 
  fi
else
  echo "Usage: generate_doc.sh {build|clean|launch}" 
fi