payload-contracts/scripts/create-work-order.sh
Martin Porwoll d4e1ef1035 feat: add work-order orchestration scripts (Phase 3)
- create-work-order.sh: auto-fills CMS commit, date, contracts version
- execute-work-order.sh: updates contracts on sv-frontend, provides
  implementation instructions for Claude Code
- Updated CLAUDE.md with complete work order lifecycle documentation
- Added pnpm shortcuts: wo:create, wo:execute

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 22:30:57 +00:00

100 lines
2.6 KiB
Bash
Executable file

#!/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