#!/bin/bash
# Script to help create a GitHub release for the helper tool

set -e

echo "🎵 Audio Espresso Helper Tool - Release Creator"
echo "================================================"
echo ""

VERSION="1.0.0"
TAG="helper-v${VERSION}"
TARBALL="audio-espresso-helper-${VERSION}.tgz"

# Check if tarball exists
if [ ! -f "$TARBALL" ]; then
    echo "❌ Tarball not found: $TARBALL"
    echo "Creating tarball..."
    npm pack
fi

echo "✅ Tarball found: $TARBALL"
echo ""

# Check if gh CLI is installed
if command -v gh &> /dev/null; then
    echo "📦 GitHub CLI found. Creating release..."
    echo ""
    
    # Create release with gh CLI
    gh release create "$TAG" \
        "$TARBALL" \
        --title "Audio Espresso Helper Tool v${VERSION}" \
        --notes "# Audio Espresso Helper Tool v${VERSION}

Download YouTube audio locally and upload to Audio Espresso.

## Installation

\`\`\`bash
npm install -g https://github.com/0c0-ol/audio-espresso/releases/download/${TAG}/${TARBALL}
\`\`\`

## Quick Start

\`\`\`bash
audio-espresso setup --url https://api.audioespresso.com
audio-espresso process \"https://www.youtube.com/watch?v=VIDEO_ID\"
\`\`\`

## Why Use This?

- ✅ Bypasses YouTube bot detection
- ✅ Downloads on your computer
- ✅ Automatically uploads to Audio Espresso
- ✅ Works with age-restricted content (using cookies)

## Documentation

Full guide: https://www.audioespresso.com/helper"
    
    echo ""
    echo "✅ Release created!"
    echo ""
    echo "📥 Users can now install with:"
    echo "npm install -g https://github.com/0c0-ol/audio-espresso/releases/download/${TAG}/${TARBALL}"
    
else
    echo "⚠️  GitHub CLI (gh) not found."
    echo ""
    echo "📝 Manual steps:"
    echo "1. Go to: https://github.com/0c0-ol/audio-espresso/releases/new"
    echo "2. Tag: $TAG"
    echo "3. Title: Audio Espresso Helper Tool v${VERSION}"
    echo "4. Attach file: $TARBALL"
    echo "5. Publish release"
    echo ""
    echo "After publishing, users can install with:"
    echo "npm install -g https://github.com/0c0-ol/audio-espresso/releases/download/${TAG}/${TARBALL}"
    echo ""
    echo "💡 Install GitHub CLI with: brew install gh"
fi

