Files
git.taskfile.build/task
T

112 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
help-table() {
local cmd_width=20
local opt_width=6
local desc_width=42
local column="| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n"
printf "$column" "Command" "Option" "Description"
echo "|$(printf '%*s' $((cmd_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((opt_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((desc_width + 2)) '' | tr ' ' '-')|"
printf "$column" "all" "" "Run all tasks."
printf "$column" "build-11ty" "" "Build the 11ty website."
printf "$column" "build-image" "[output]" "Build Docker image with buildx."
printf "$column" "commit-with-llm" "" "Commit with llm generated commit message."
printf "$column" "dev-11ty" "" "Run 11ty server."
printf "$column" "help" "[grep]" "Show help for commands."
printf "$column" "install" "" "Install node packages."
printf "$column" "lint" "" "Lint code with prettier."
printf "$column" "run" "" "Run Docker image."
printf "$column" "run-tests" "" "Test with shellcheck."
printf "$column" "serve-11ty" "" "Serve the 11ty output folder."
printf "$column" "version" "" "Show version of required tools."
}
help() {
echo
if [[ -n "$1" ]]; then
help-table | grep -i "$1" | column -t -s'|'
else
echo "task <command> [options]"
echo
echo "commands:"
echo
help-table
fi
echo
}
# Static vars
BUILDX_PLATFORM="linux/amd64"
CONTAINER_REGISTRY="janikvonrotz"
CONTAINER_TAG="taskfile.build:latest"
DOCKERFILE="image/Dockerfile"
# Import commands
if [[ -d "$HOME/taskfile.build/bin" ]]; then
for file in "$HOME/taskfile.build/bin/"*; do
if [[ -f "$file" ]]; then
source "$file"
fi
done
fi
# Project commands
run() {
echo "Open http://localhost:8080 in your browser"
docker run -p 8080:80 \
-e GIT_URL="https://git.taskfile.build" \
-e TASK_COMMANDS="install,build-11ty" \
-e CADDY_ROOT="_site" \
janikvonrotz/taskfile.build:latest
}
install() {
pnpm install
}
dev-11ty() {
pnpm dlx @11ty/eleventy --serve
}
lint() {
pnpm exec prettier . --write
}
run-tests() {
echo "Test with shellcheck."
shellcheck task
}
build-11ty() {
pnpm dlx @11ty/eleventy
}
serve-11ty() {
pnpx serve ./_site
}
version() {
echo "eleventy: $(pnpm dlx @11ty/eleventy --version)"
}
if declare -f "$1" > /dev/null; then
"$1" "${@:2}"
else
case "$1" in
all)
install
build-11ty
;;
*)
echo "Unknown command: $1"
help
exit 1
;;
esac
fi