- Added `update-template` command that extracts rows from `library.md` and updates `task.template` - Implemented logic to replace existing rows in `task.template` with current rows from `library.md` - Added `update-template` to help-table for documentation and discoverability - Updated `library.md` to use consistent terminology (dotenv instead of env) - Removed outdated prompt script that was no longer needed - Ensured all rows from `library.md` are properly synchronized with `task.template`
209 lines
5.4 KiB
Bash
Executable File
209 lines
5.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
help-table() {
|
|
local -a rows
|
|
local max_cmd=7 max_opt=6 max_desc=11
|
|
|
|
rows+=("Command|Option|Description")
|
|
rows+=("all||Run all tasks.")
|
|
rows+=("build-11ty||Build the 11ty website.")
|
|
rows+=("build-image|[output]|Build Docker image with buildx.")
|
|
rows+=("commit-with-llm||Commit with llm generated commit message.")
|
|
rows+=("dev-11ty||Run 11ty server.")
|
|
rows+=("help|[grep]|Show help for commands.")
|
|
rows+=("install||Install node packages.")
|
|
rows+=("lint||Lint code with prettier.")
|
|
rows+=("run||Run Docker image.")
|
|
rows+=("run-tests||Test with shellcheck.")
|
|
rows+=("serve-11ty||Serve the 11ty output folder.")
|
|
rows+=("update-template||Update task.template from library.md.")
|
|
rows+=("version||Show version of required tools.")
|
|
|
|
for row in "${rows[@]}"; do
|
|
IFS='|' read -r cmd opt desc <<< "$row"
|
|
(( ${#cmd} > max_cmd )) && max_cmd=${#cmd}
|
|
(( ${#opt} > max_opt )) && max_opt=${#opt}
|
|
(( ${#desc} > max_desc )) && max_desc=${#desc}
|
|
done
|
|
|
|
printf '| %-*s | %-*s | %-*s |\n' \
|
|
"$max_cmd" "Command" \
|
|
"$max_opt" "Option" \
|
|
"$max_desc" "Description"
|
|
|
|
printf '|-%*s-|-%*s-|-%*s-|\n' \
|
|
"$max_cmd" "$(printf '%*s' "$max_cmd" '' | tr ' ' '-')" \
|
|
"$max_opt" "$(printf '%*s' "$max_opt" '' | tr ' ' '-')" \
|
|
"$max_desc" "$(printf '%*s' "$max_desc" '' | tr ' ' '-')"
|
|
|
|
for row in "${rows[@]:1}"; do
|
|
IFS='|' read -r cmd opt desc <<< "$row"
|
|
printf '| %-*s | %-*s | %-*s |\n' \
|
|
"$max_cmd" "$cmd" \
|
|
"$max_opt" "$opt" \
|
|
"$max_desc" "$desc"
|
|
done
|
|
}
|
|
|
|
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)"
|
|
}
|
|
|
|
update-template() {
|
|
echo "Updating task.template from library.md"
|
|
|
|
# Extract all rows from library.md that match the pattern rows+=("...")
|
|
local -a new_rows
|
|
while IFS= read -r line; do
|
|
if [[ $line =~ rows\+=\(\"(.*)\"\) ]]; then
|
|
new_rows+=("${BASH_REMATCH[1]}")
|
|
fi
|
|
done < library.md
|
|
|
|
# Create a temporary file
|
|
local temp_file=$(mktemp)
|
|
|
|
# Read the task.template file and update the rows section
|
|
local in_rows_section=false
|
|
local found_header=false
|
|
|
|
while IFS= read -r line || [[ -n "$line" ]]; do
|
|
# Check if we're at the header row
|
|
if [[ $line == *"rows+=(\"Command|Option|Description\")"* ]]; then
|
|
echo "$line" >> "$temp_file"
|
|
found_header=true
|
|
in_rows_section=true
|
|
# Add all the new rows after the header
|
|
for row in "${new_rows[@]}"; do
|
|
echo " rows+=(\"$row\")" >> "$temp_file"
|
|
done
|
|
continue
|
|
fi
|
|
|
|
# Check if we're at the for-loop that ends the rows section
|
|
if [[ $line == *"for row in \"\${rows[@]}\""* ]]; then
|
|
in_rows_section=false
|
|
fi
|
|
|
|
# Skip existing rows between header and for-loop
|
|
if $in_rows_section && $found_header; then
|
|
if [[ $line =~ rows\+=\(\"(.*)\"\) ]]; then
|
|
continue
|
|
fi
|
|
fi
|
|
|
|
echo "$line" >> "$temp_file"
|
|
done < task.template
|
|
|
|
# Replace task.template with the updated content
|
|
mv "$temp_file" task.template
|
|
|
|
echo "task.template updated successfully"
|
|
}
|
|
|
|
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
|