#!/bin/bash

set -e

echo "OpenCrates Simple Publishing Script v3.0.0"
echo "==========================================="

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

echo "Checking library compilation..."
cargo check --lib

echo "Checking code formatting..."
cargo fmt --check

echo "Running linters on library..."
cargo clippy --lib -- -D warnings

echo "Building documentation..."
cargo doc --lib --no-deps

echo "Verifying package contents..."
cargo package --dry-run

echo "Running dry-run publish..."
cargo publish --dry-run

echo "Library package verification passed!"

read -p "Ready to publish to crates.io? (y/N): " -n 1 -r
echo ""

if [[ $REPLY =~ ^[Yy]$ ]]; then
    echo "Publishing to crates.io..."
    cargo publish
    echo "Successfully published OpenCrates v3.0.0!"
    echo "View at: https://crates.io/crates/opencrates"
else
    echo "Publishing cancelled."
fi 