#!/bin/bash
# Script to publish the SDK to npm

# Ensure we're in the right directory
cd "$(dirname "$0")/.."

# Run tests
echo "Running tests..."
npm test

# Check if tests passed
if [ $? -ne 0 ]; then
  echo "Tests failed. Aborting publish."
  exit 1
fi

# Build the package
echo "Building package..."
npm run build

# Check if build was successful
if [ $? -ne 0 ]; then
  echo "Build failed. Aborting publish."
  exit 1
fi

# Increment version (patch by default)
VERSION_TYPE=${1:-patch}
echo "Incrementing version ($VERSION_TYPE)..."
npm version $VERSION_TYPE

# Publish to npm
echo "Publishing to npm..."
npm publish --access public

echo "Package published successfully!"