#!/bin/bash

# Build standalone executables using pkg
echo "🔨 Building standalone executables..."

# Install pkg if not available
if ! command -v pkg &> /dev/null; then
    echo "📦 Installing pkg..."
    npm install -g pkg
fi

# Build the project first
npm run build

# Create standalone builds
echo "🏗️ Creating executables for multiple platforms..."

# Create pkg config
cat > pkg.config.json << EOF
{
  "name": "upm",
  "bin": "./bin/upm",
  "targets": [
    "node18-macos-x64",
    "node18-macos-arm64",
    "node18-linux-x64",
    "node18-win-x64"
  ],
  "outputPath": "releases/standalone"
}
EOF

# Build executables
pkg . --config pkg.config.json

# Clean up
rm pkg.config.json

echo "✅ Standalone executables created in releases/standalone/"
echo ""
echo "📝 Available executables:"
echo "   - upm-macos (Intel)"
echo "   - upm-macos-arm64 (Apple Silicon)"
echo "   - upm-linux"
echo "   - upm-win.exe"