#!/bin/bash
# This script automates the process of building and publishing a preview version of the npm package.
# When executed as ./preview.sh <tag-name>, it creates and publishes a new version of the package
# with the format @applica-software-guru/persona-chat-sdk@0.1.0-<tag-name>.
# The script updates the package version with the specified tag, builds the project,
# and publishes it to the npm registry with the given preview tag.
# Usage: ./preview.sh <tag-name>
# Example: ./preview.sh beta

if [ -z "$1" ]; then
  echo "Usage: $0 <preview-tag>"
  exit 1
fi

PREVIEW_TAG=$1

echo "Creating preview version with tag: $PREVIEW_TAG"

npm run build

npm --no-git-tag-version version "$PREVIEW_TAG" -m "$PREVIEW_TAG"

npm publish --access public