#!/bin/bash

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

# Build the package
echo "📦 Building the package..."
bash manual-build.sh

# 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-sdk-fixed"
echo "📦 Version: $(node -p "require('./package.json').version")"