#!/bin/bash
set -e

if [ -z "$1" ]; then
    echo "Error: Token required"
    echo "Usage: $0 <token> [--pypi]"
    exit 1
fi

TOKEN="$1"

rm -rf dist/
poetry lock
poetry install
poetry build

if [ "$2" == "--pypi" ]; then
    echo "Publishing to PyPI..."
    poetry config --local pypi-token.pypi "$TOKEN"
    poetry publish
else
    echo "Publishing to Test-PyPI..."
    poetry config --local pypi-token.test-pypi "$TOKEN"
    poetry publish -r test-pypi
fi