126 lines
4 KiB
Bash
Executable file
126 lines
4 KiB
Bash
Executable file
#!/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="micro-lanterns";
|
|
|
|
# The path to the lantern build engine git submodule
|
|
lantern_path="./lantern-build-engine";
|
|
|
|
###
|
|
# Custom Settings
|
|
###
|
|
|
|
# Put any custom settings here.
|
|
build_output_folder="./dist";
|
|
|
|
###############################################################################
|
|
|
|
# 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}main${RS} - Build the slide deck";
|
|
echo -e " ${CACTION}slides${RS} - Build the slides HTML";
|
|
echo -e " ${CACTION}js-css${RS} - Build the javascript / css";
|
|
echo -e " ${CACTION}dev-server${RS} - Start a development server";
|
|
echo -e " ${CACTION}dev-server-stop${RS} - Stop the currently running development server";
|
|
echo -e "";
|
|
|
|
exit 1;
|
|
fi
|
|
|
|
###############################################################################
|
|
|
|
task_setup() {
|
|
task_begin "Setting up";
|
|
|
|
check_command git true;
|
|
check_command node true;
|
|
check_command npm true;
|
|
|
|
subtask_begin "Creating build output directory";
|
|
mkdir -p "${build_output_folder}";
|
|
subtask_end $?;
|
|
|
|
subtask_begin "Initialising submodules";
|
|
git submodule update --init;
|
|
subtask_end $?;
|
|
|
|
task_end 0;
|
|
}
|
|
|
|
|
|
# ██████ ███████ ██ ██ ███████ ███████ ██████ ██ ██ ███████ ██████
|
|
# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
|
# ██ ██ █████ ██ ██ █████ ███████ █████ ██████ ██ ██ █████ ██████
|
|
# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
|
# ██████ ███████ ████ ███████ ███████ ██ ██ ████ ███████ ██ ██
|
|
task_dev-server() {
|
|
task_begin "Starting development server";
|
|
php -S [::1]:40482 -t "${build_output_folder}" &
|
|
exit_code=$?;
|
|
echo $! >/tmp/micro-lantern-dev-server.pid;
|
|
task_end $?; # Should be 0 unless php died for some reason
|
|
sleep 1;
|
|
}
|
|
|
|
task_dev-server-stop() {
|
|
task_begin "Stopping development server";
|
|
|
|
kill "$(cat /tmp/micro-lantern-dev-server.pid)";
|
|
rm /tmp/micro-lantern-dev-server.pid;
|
|
|
|
task_end $?;
|
|
}
|
|
|
|
|
|
task_main() {
|
|
tasks_run js-css slides;
|
|
|
|
task_begin "Copying html";
|
|
cp index.html "${build_output_folder}";
|
|
task_end $?;
|
|
|
|
task_begin "Copying css";
|
|
cp theme.css "${build_output_folder}";
|
|
task_end $?;
|
|
}
|
|
|
|
task_slides() {
|
|
task_begin "Creating temporary directory";
|
|
temp_dir="$(mktemp -d --suffix "linux-101-slides")";
|
|
task_end $?;
|
|
|
|
echo "[${SECONDS}] Created temporary directory ${HC}${temp_dir}${RS}.";
|
|
|
|
task_begin "Rendering slides";
|
|
find ./Sections -print0 -type f -iname "*.md" | xargs -t -P4 -0 -n1 -I{} pandoc {} -o {}.html;
|
|
task_end $?;
|
|
}
|
|
|
|
task_js-css() {
|
|
task_begin "Packaging Javascript & CSS";
|
|
node_modules/rollup/bin/rollup --sourcemap --config rollup.config.js;
|
|
task_end $? "Error: rollup packing failed!";
|
|
}
|
|
|
|
|
|
###############################################################################
|
|
|
|
tasks_run $@;
|