site/scripts/serve

60 lines
1.1 KiB
Text
Raw Normal View History

#!/usr/bin/env bash
# Required Binaries:
# | simple-http-server
# | sass
# ===== Configuration ===== #
2026-01-31 09:26:27 +10:00
ADDR="127.0.0.1" # bind address
PORT="8000" # bind port
WEBROOT="www" # root web directory
USE_INDEX=true
NO_CACHE=true
declare -a SRV_ARGS=()
SCSS_PATH="$WEBROOT/scss"
CSS_PATH="$WEBROOT/css"
# ========================= #
2025-08-06 19:01:53 +10:00
# ===== Local State ===== #
SASS_PID=
# ======================= #
2026-01-31 10:33:12 +10:00
# function cleanup {
# if [[ -n "$SASS_PID" ]]; then
# kill "$SASS_PID"
# fi
# }
2025-08-06 19:01:53 +10:00
# Watch .sass/.scss files and compile on change
2026-01-31 10:33:12 +10:00
# function watch_scss {
# # watch format "SCSS_PATH:OUT_PATH"
# sass --watch "$SCSS_PATH:$CSS_PATH"
# }
function host {
2026-01-31 09:26:27 +10:00
local args=( "$@" )
# Apply Flags
if [[ "$NO_CACHE" == true ]]; then
args+=("--nocache")
fi
if [[ "$USE_INDEX" == true ]]; then
args+=("--index")
fi
# Apply Options
args+=(--ip "$ADDR" --port "$PORT")
2026-01-31 09:26:27 +10:00
simple-http-server "${args[@]}" "$@" -- "$WEBROOT"
}
2026-01-31 10:33:12 +10:00
# trap cleanup EXIT
set -ueo pipefail
set -x
2025-08-06 19:01:53 +10:00
# auto compile scss changes
2026-01-31 10:33:12 +10:00
# watch_scss &
# SASS_PID=$!
2025-08-06 19:01:53 +10:00
# host dev server
2026-01-31 09:26:27 +10:00
host "${SRV_ARGS[@]}"