#!/bin/bash
set -e

echo "Building ProofMode CLI package..."

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

# Check if WASM package is built
if [ ! -f "../pkg/package.json" ]; then
  echo "Error: WASM package not found. Please run 'cargo make wasm-pack' first."
  exit 1
fi

# Install dependencies
echo "Installing dependencies..."
npm install

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

# Publishing steps
echo ""
echo "Ready to publish!"
echo ""
echo "To publish to npm:"
echo "1. Ensure you're logged in: npm login"
echo "2. Publish with: npm publish --access public"
echo ""
echo "To test locally first:"
echo "1. Create a tarball: npm pack"
echo "2. Install globally: npm install -g guardianproject-proofmode-cli-*.tgz"
echo "3. Test the CLI: proofmode --help"