2020-02-09 23:23:23 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Make sure the current directory is the location of this script to simplify matters
|
|
|
|
cd "$(dirname "$(readlink -f "$0")")";
|
|
|
|
################
|
|
|
|
### Settings ###
|
|
|
|
################
|
|
|
|
|
|
|
|
# The name of this project
|
|
|
|
project_name="pepperminty.wiki";
|
|
|
|
|
|
|
|
# The path to the lantern build engine git submodule
|
2020-02-09 23:43:39 +00:00
|
|
|
lantern_path="./lantern-build-engine";
|
2020-02-09 23:23:23 +00:00
|
|
|
|
|
|
|
###
|
|
|
|
# Custom Settings
|
|
|
|
###
|
|
|
|
|
2020-05-08 17:09:01 +00:00
|
|
|
config="./.eleventy.js"; # relative to src/
|
|
|
|
output_dir="${PWD}/public";
|
2020-02-09 23:23:23 +00:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
# Check out the lantern git submodule if needed
|
|
|
|
if [ ! -f "${lantern_path}/lantern.sh" ]; then git submodule update --init "${lantern_path}"; fi
|
|
|
|
|
|
|
|
source "${lantern_path}/lantern.sh";
|
|
|
|
|
|
|
|
if [[ "$#" -lt 1 ]]; then
|
|
|
|
echo -e "${FBLE}${project_name}${RS} build script";
|
|
|
|
echo -e " by Starbeamrainbowlabs";
|
|
|
|
echo -e "${LC}Powered by the lantern build engine, v${version}${RS}";
|
|
|
|
echo -e "";
|
|
|
|
echo -e "${CSECTION}Usage${RS}";
|
|
|
|
echo -e " ./build ${CTOKEN}{action}${RS} ${CTOKEN}{action}${RS} ${CTOKEN}{action}${RS} ...";
|
|
|
|
echo -e "";
|
|
|
|
echo -e "${CSECTION}Available actions${RS}";
|
|
|
|
echo -e " ${CACTION}setup${RS} - Perform initial setup";
|
|
|
|
echo -e " ${CACTION}build${RS} - Build the static site";
|
2020-05-08 22:59:57 +00:00
|
|
|
echo -e " ${CACTION}watch${RS} - Watch for changes and rebuild automatically";
|
2020-02-09 23:43:39 +00:00
|
|
|
echo -e " ${CACTION}serve${RS} - Start a livereload server";
|
2020-02-09 23:23:23 +00:00
|
|
|
echo -e "";
|
|
|
|
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
task_setup() {
|
|
|
|
task_begin "Checking environment";
|
|
|
|
check_command git true;
|
2020-02-10 01:32:00 +00:00
|
|
|
check_command node true;
|
|
|
|
check_command npm true;
|
|
|
|
check_command npx true;
|
2020-02-09 23:23:23 +00:00
|
|
|
task_end 0;
|
|
|
|
|
|
|
|
task_begin "Initialising submodules";
|
|
|
|
execute git submodule update --init;
|
|
|
|
task_end $?;
|
|
|
|
|
2020-02-10 01:32:00 +00:00
|
|
|
task_begin "Installing dependencies";
|
|
|
|
npm install;
|
2020-02-09 23:23:23 +00:00
|
|
|
task_end "$?";
|
|
|
|
}
|
|
|
|
|
|
|
|
task_build() {
|
|
|
|
task_begin "Building site";
|
2020-02-09 23:43:39 +00:00
|
|
|
cd src || { echo "Failed to cd into src"; exit 1; };
|
2020-05-08 17:09:01 +00:00
|
|
|
execute npx @11ty/eleventy --config="${config}" --output="${output_dir}";
|
2020-02-09 23:23:23 +00:00
|
|
|
task_end "$?";
|
|
|
|
}
|
2020-05-08 22:59:57 +00:00
|
|
|
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
|
|
|
|
}
|
2020-02-09 23:23:23 +00:00
|
|
|
task_serve() {
|
2020-05-08 22:59:57 +00:00
|
|
|
tasks_run watch &
|
|
|
|
sleep 0.2;
|
2020-02-09 23:23:23 +00:00
|
|
|
task_begin "Building site";
|
2020-02-09 23:43:39 +00:00
|
|
|
cd src || { echo "Failed to cd into src"; exit 1; };
|
2020-05-08 17:09:01 +00:00
|
|
|
execute npx @11ty/eleventy --config="${config}" --serve --output "${output_dir}";
|
2020-02-09 23:23:23 +00:00
|
|
|
task_end "$?";
|
|
|
|
}
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
tasks_run "$@";
|