From aed5fe466c390c1d5a0a597730fc89328526d3ce Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Apr 22 2020 17:41:10 +0000 Subject: Add ./preview.sh --refresh to automatically rebuild documentation on its source change. --- diff --git a/README.md b/README.md index 1a18986..b8d81ee 100644 --- a/README.md +++ b/README.md @@ -59,3 +59,6 @@ $ ./preview.sh ``` The result will be available at http://localhost:8080 + +When using Linux, it is also possible to pass `--refresh` argument to automatically +rebuild the documentation on source change. diff --git a/preview.sh b/preview.sh index f8c48c2..3dd200a 100755 --- a/preview.sh +++ b/preview.sh @@ -13,7 +13,27 @@ elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then echo "" echo "The preview is available at http://localhost:8080" echo "" - pushd ./public - python3 -m http.server 8080 - popd + + if [[ "$*" == *--refresh* ]]; then + if ! [ -x "$(command -v inotifywait)" ]; then + echo 'Error: inofitywait (inotify-utils) is not installed.' >&2 + exit 1 + fi + + # Setup trap to kill this process group on ctrl+c. + killgroup(){ + kill 0 + } + trap killgroup SIGINT + + # Run the Python's webserver. + python3 -m http.server 8080 --directory ./public & + + while inotifywait -r ./modules -e create -e moved_to -e modify; do + echo "Documentation source changed, rebuilding ..." + ./build.sh + done + else + python3 -m http.server 8080 --directory ./public + fi fi