#!/bin/bash

# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"

# Source .env from project root
if [ -f "$PROJECT_ROOT/.env" ]; then
  source "$PROJECT_ROOT/.env"
else
  echo "Error: .env file not found at $PROJECT_ROOT/.env"
  exit 1
fi

# Check if OPEN_VSX_TOKEN is set
if [ -z "$OPEN_VSX_TOKEN" ]; then
  echo "Error: OPEN_VSX_TOKEN is not set in .env file"
  exit 1
fi

echo "Publishing to Open VSX..."
bunx ovsx publish --pat $OPEN_VSX_TOKEN

echo "Publishing to VS Code Marketplace..."
vsce publish