- Introduce `clone-taskfile` function to manage taskfile repository cloning and pulling - Modify `dev-11ty` command to automatically open the browser at `http://localhost:8080/` - Reorder static variable declarations for better script organization - Improve output formatting with colored Git status messages
134 lines
3.3 KiB
Bash
Executable File
134 lines
3.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
help-table() {
|
|
local cmd_width=20
|
|
local opt_width=10
|
|
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
|
|
}
|
|
|
|
clone-taskfile(){
|
|
if [[ ! -d "$HOME/taskfile.build" ]]; then
|
|
echo -e '\033[38;5;214mGit\033[0m: Clone taskfile repo'
|
|
git clone https://git.taskfile.build "$HOME/taskfile.build"
|
|
else
|
|
echo -e '\033[38;5;214mGit\033[0m: Pull taskfile repo'
|
|
git -C "$HOME/taskfile.build" pull
|
|
fi
|
|
}
|
|
|
|
if [[ -d "$HOME/taskfile.build/bin" ]]; then
|
|
for file in "$HOME/taskfile.build/bin/"*; do
|
|
if [[ -f "$file" ]]; then
|
|
source "$file"
|
|
fi
|
|
done
|
|
fi
|
|
|
|
# Static vars
|
|
|
|
BUILDX_PLATFORM="linux/amd64"
|
|
CONTAINER_REGISTRY="janikvonrotz"
|
|
CONTAINER_TAG="taskfile.build:latest"
|
|
DOCKERFILE="image/Dockerfile"
|
|
|
|
# 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() {
|
|
open-with-os 'http://localhost:8080/' & 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 [[ "$1" == *","* ]]; then
|
|
# Split comma-separated commands
|
|
IFS=',' read -ra COMMANDS <<< "$1"
|
|
for cmd in "${COMMANDS[@]}"; do
|
|
# Trim whitespace
|
|
cmd=$(echo "$cmd" | xargs)
|
|
if declare -f "$cmd" > /dev/null; then
|
|
"$cmd"
|
|
else
|
|
echo "Unknown command: $cmd"
|
|
help
|
|
exit 1
|
|
fi
|
|
done
|
|
elif 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
|