#!/bin/bash

# PetCareScript NPM Publish Script

echo "🚀 Publishing PetCareScript to NPM..."

# Check if logged in to npm
if ! npm whoami &> /dev/null; then
    echo "❌ You are not logged in to NPM"
    echo "Please run: npm login"
    exit 1
fi

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

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

# Build project
echo "🔨 Building project..."
npm run build

if [ $? -ne 0 ]; then
    echo "❌ Build failed. Aborting publish."
    exit 1
fi

# Publish to NPM
echo "📦 Publishing to NPM..."
npm publish

if [ $? -eq 0 ]; then
    echo "✅ Successfully published to NPM!"
    echo "🎉 PetCareScript is now available via: npm install -g petcarescript"
else
    echo "❌ Publish failed"
    exit 1
fi
