#!/usr/bin/env bash # # create-work-order.sh — Create a work order after CMS changes # # Usage: # ./scripts/create-work-order.sh "Add stats-block" [--extract] # # This script: # 1. Optionally re-extracts types from CMS (--extract flag) # 2. Creates a work order from template with pre-filled metadata # 3. Opens it for editing (or prints path if no $EDITOR) # # Run from the payload-contracts repo root on sv-payload. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" ROOT="$(dirname "$SCRIPT_DIR")" WO_DIR="${ROOT}/work-orders" TEMPLATE="${WO_DIR}/_template.md" CMS_DIR="${ROOT}/../payload-cms" # --- Args --- TITLE="${1:-}" DO_EXTRACT=false for arg in "$@"; do case "$arg" in --extract) DO_EXTRACT=true ;; esac done if [ -z "$TITLE" ] || [ "$TITLE" = "--extract" ]; then echo "Usage: $0 \"Work Order Title\" [--extract]" echo "" echo "Options:" echo " --extract Re-extract types from CMS before creating work order" echo "" echo "Example:" echo " $0 \"Add stats-block to page layout\" --extract" exit 1 fi # --- Optional: Re-extract types --- if [ "$DO_EXTRACT" = true ]; then echo "=== Extracting types from CMS ===" cd "$ROOT" pnpm extract echo "" fi # --- Get CMS commit info --- CMS_COMMIT="unknown" CMS_MSG="unknown" if [ -d "$CMS_DIR/.git" ]; then CMS_COMMIT=$(git -C "$CMS_DIR" rev-parse --short HEAD 2>/dev/null || echo "unknown") CMS_MSG=$(git -C "$CMS_DIR" log -1 --format="%s" 2>/dev/null || echo "unknown") fi # --- Get contracts commit --- CONTRACTS_COMMIT=$(git -C "$ROOT" rev-parse --short HEAD 2>/dev/null || echo "unknown") # --- Generate filename --- DATE=$(date +%Y-%m-%d) SLUG=$(echo "$TITLE" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//') FILENAME="${DATE}-${SLUG}.md" FILEPATH="${WO_DIR}/${FILENAME}" if [ -f "$FILEPATH" ]; then echo "Error: Work order already exists: ${FILEPATH}" exit 1 fi # --- Create work order from template --- sed \ -e "s/\[Titel\]/${TITLE}/" \ -e "s/\[hash\] (\[Beschreibung\])/${CMS_COMMIT} (${CMS_MSG})/" \ -e "s/\[version \/ commit hash\]/${CONTRACTS_COMMIT}/" \ -e "s/YYYY-MM-DD/${DATE}/" \ "$TEMPLATE" > "$FILEPATH" echo "=== Work order created ===" echo "File: ${FILEPATH}" echo "CMS commit: ${CMS_COMMIT} (${CMS_MSG})" echo "Contracts: ${CONTRACTS_COMMIT}" echo "" # --- Open in editor if available --- if [ -n "${EDITOR:-}" ]; then "$EDITOR" "$FILEPATH" else echo "Edit the work order:" echo " nano ${FILEPATH}" echo "" echo "Then commit and push:" echo " cd ${ROOT}" echo " git add work-orders/${FILENAME}" echo " git commit -m \"wo: ${TITLE}\"" echo " git push origin main" fi