#!/bin/bash # Generate dacli/docs/anti-patterns.md from _anti_patterns.ts (single source of truth). # Usage: bash scripts/gen-anti-patterns-md.sh [--check] # --check: diff against dacli/docs/anti-patterns.md, exit non-zero if stale set -euo pipefail DACLI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" OUT="$DACLI_DIR/docs/anti-patterns.md" # Extract ANTI_PATTERNS entries via npx tsx TMP=$(mktemp) npx tsx "$DACLI_DIR/scripts/extract_anti_patterns.ts" > "$TMP" 2>/dev/null # Wrap with markdown header { echo "# dacli Anti-Patterns (Auto-Generated)" echo "" echo "> **Source**: \`dacli/src/commands/_anti_patterns.ts\` (single source of truth)" echo "> **Generator**: \`scripts/gen-anti-patterns-md.sh\`" echo "> **DO NOT EDIT MANUALLY.** Run \`bash scripts/gen-anti-patterns-md.sh\` to regenerate." echo "" cat "$TMP" } > "$OUT" rm -f "$TMP" if [ "${1:-}" = "--check" ]; then REGEN=$(mktemp) npx tsx "$DACLI_DIR/scripts/extract_anti_patterns.ts" > "$REGEN" 2>/dev/null { echo "# dacli Anti-Patterns (Auto-Generated)" echo "" echo "> **Source**: \`dacli/src/commands/_anti_patterns.ts\` (single source of truth)" echo "> **Generator**: \`scripts/gen-anti-patterns-md.sh\`" echo "> **DO NOT EDIT MANUALLY.** Run \`bash scripts/gen-anti-patterns-md.sh\` to regenerate." echo "" cat "$REGEN" } > "$REGEN.md" if ! diff -q "$OUT" "$REGEN.md" > /dev/null; then echo "ERROR: $OUT is stale. Run: bash scripts/gen-anti-patterns-md.sh" >&2 rm -f "$REGEN" "$REGEN.md" exit 1 fi rm -f "$REGEN" "$REGEN.md" echo "OK: $OUT is up to date" else echo "Generated: $OUT" fi