#!/bin/sh

npm i # Ensure the package is installed and protobufs copied.

PACKAGE_NAME=$(awk -F'"' '/"name": ".+"/{ print $4; exit; }' package.json)
PACKAGE_VERSION=$(awk -F'"' '/"version": ".+"/{ print $4; exit; }' package.json)
PACKAGE=${PACKAGE_NAME}@${PACKAGE_VERSION}

echo "\nAttempting to publish package..."
PUBLISH_COMMAND_RESULT="$(npx publish-if-not-exists)"
if [ "$PUBLISH_COMMAND_RESULT" = "Already up-to-date." ]; then
  echo "${PACKAGE} ${PUBLISH_COMMAND_RESULT} Change package version to proceed.\n"
  exit 1
fi
echo "${PACKAGE} successfully published."
exit 0
