Make build helper script better

This commit is contained in:
Starbeamrainbowlabs 2020-05-08 23:59:57 +01:00
parent 2b0d258bc5
commit 27a6d043d0
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

19
build
View file

@ -36,6 +36,7 @@ if [[ "$#" -lt 1 ]]; then
echo -e "${CSECTION}Available actions${RS}";
echo -e " ${CACTION}setup${RS} - Perform initial setup";
echo -e " ${CACTION}build${RS} - Build the static site";
echo -e " ${CACTION}watch${RS} - Watch for changes and rebuild automatically";
echo -e " ${CACTION}serve${RS} - Start a livereload server";
echo -e "";
@ -67,7 +68,25 @@ task_build() {
execute npx @11ty/eleventy --config="${config}" --output="${output_dir}";
task_end "$?";
}
task_watch() {
echo -e "Watching for changes.";
while :; do # : = infinite loop
# Wait for an update
# inotifywait's non-0 exit code forces an exit for some reason :-/
inotifywait -qr --event modify --event close_write --format '%:e %f' src;
# Rebuild the client code - spawn a sub-process to avoid the hard exit
# This still doesn't work though, which is *really* annoying
stage_begin "Rebuilding";
set +e; # Allow errors
./build build;
set -e;
stage_end 0;
done
}
task_serve() {
tasks_run watch &
sleep 0.2;
task_begin "Building site";
cd src || { echo "Failed to cd into src"; exit 1; };
execute npx @11ty/eleventy --config="${config}" --serve --output "${output_dir}";