#!/bin/bash

# Ensure we're in the enhanced-sdk directory
cd "$(dirname "$0")/enhanced-sdk" || exit 1

# Build the package
echo "📦 Building the package..."
bash build.js

# Update version in package.json if provided
if [ ! -z "$1" ]; then
  echo "📝 Updating version to $1..."
  npm version "$1" --no-git-tag-version
fi

# Pack the package locally first
echo "📦 Creating npm package..."
npm pack

# Publish to npm
echo "🚀 Publishing to npm..."
npm publish

echo "✅ Package published successfully!"
echo "📦 Package name: realtimecursor-enhanced"
echo "📦 Version: $(node -p "require('./package.json').version")"