branch="$(git rev-parse --abbrev-ref HEAD)"

if [ "$branch" = "main" ]; then
  echo "You can't push directly to main - please check out a branch."
  exit 1
fi

# Detect if running on Windows and use npm.cmd, otherwise use npm
if [ "$OS" = "Windows_NT" ]; then
  npm_cmd="npm.cmd"
else
  npm_cmd="npm"
fi

"$npm_cmd" run compile

# Check for new changesets.
NEW_CHANGESETS=$(find .changeset -name "*.md" ! -name "README.md" | wc -l | tr -d ' ')
echo "Changeset files: $NEW_CHANGESETS"

if [ "$NEW_CHANGESETS" == "0" ]; then
  echo "-------------------------------------------------------------------------------------"
  echo "Changes detected. Please run 'npm run changeset' to create a changeset if applicable."
  echo "-------------------------------------------------------------------------------------"
fi
