#!/bin/bash set -e function help() { echo echo "task [options]" echo echo "commands:" echo # Define column widths CMD_WIDTH=10 OPT_WIDTH=6 DESC_WIDTH=40 COLUMN="| %-${CMD_WIDTH}s | %-${OPT_WIDTH}s | %-${DESC_WIDTH}s |\n" # Print table header printf "$COLUMN" "Command" "Option" "Description" echo "|$(printf '%*s' $((CMD_WIDTH + 2)) '' | tr ' ' '-')|$(printf '%*s' $((OPT_WIDTH + 2)) '' | tr ' ' '-')|$(printf '%*s' $((DESC_WIDTH + 2)) '' | tr ' ' '-')|" # Print table rows printf "$COLUMN" "all" "" "Run all tasks." printf "$COLUMN" "install" "" "Install node packages." printf "$COLUMN" "dev" "" "Run 11ty server." printf "$COLUMN" "lint" "" "Lint code with prettier." printf "$COLUMN" "run-tests" "" "Test with shellcheck." printf "$COLUMN" "build" "" "Build the 11ty website." printf "$COLUMN" "serve" "" "Serve the 11ty output folder." printf "$COLUMN" "version" "" "Show version of required tools." echo } function install() { npm install } function dev() { npx eleventy --serve } function lint() { pnpm exec prettier . --write } function run-tests() { echo "Test with shellcheck." shellcheck task } function build() { npx eleventy } function serve() { npx serve ./_site } function version() { echo "eleventy: $(npx eleventy --version)" } if declare -f "$1" > /dev/null; then "$1" "${@:2}" else case "$1" in all) install build ;; *) echo "Unknown command: $1" help exit 1 ;; esac fi