#!/usr/bin/env bash
# One-line installer for release-notes-writer. Author: Auto Joe (Godmode custom builds).
# Local:  bash examples/custom-build-demo/install.sh
# Remote: curl -fsSL https://getgodmode.dev/assets/examples/release-notes-writer/install.sh | bash
set -euo pipefail

SKILLS_DIR="${CLAUDE_SKILLS_DIR:-$HOME/.claude/skills}"
DEST="$SKILLS_DIR/release-notes-writer"
BASE_URL="${RNW_BASE_URL:-https://getgodmode.dev/assets/examples/release-notes-writer}"

mkdir -p "$DEST/scripts"
HERE="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd || true)"
SRC="$HERE/skill/release-notes-writer"

if [ -n "$HERE" ] && [ -f "$SRC/SKILL.md" ]; then
  cp "$SRC/SKILL.md" "$DEST/SKILL.md"
  cp "$SRC/scripts/release-notes.mjs" "$DEST/scripts/release-notes.mjs"
else
  curl -fsSL "$BASE_URL/skill/release-notes-writer/SKILL.md" > "$DEST/SKILL.md"
  curl -fsSL "$BASE_URL/skill/release-notes-writer/scripts/release-notes.mjs" > "$DEST/scripts/release-notes.mjs"
fi

command -v node >/dev/null || { echo "installed, but Node 18+ is needed to run it"; exit 0; }
echo "installed release-notes-writer to $DEST"
echo "try: say 'write the release notes' in Claude Code"
