#!/usr/bin/env bash set -o errexit set -o nounset set -o pipefail # Check dependencies if ! command -v jq &> /dev/null; then echo "Error: jq is required but not installed" exit 1 fi registryUrl="https://npm.techniker.me" packageVersionToDeploy=$(jq -r '.version' package.json) isBeta="false" while [[ "${#}" -gt 0 ]]; do case "${1}" in --beta) isBeta="true" shift ;; --build) packageVersionToDeploy="${packageVersionToDeploy}-build.${2}" shift 2 ;; *) echo "Unknown option [${1}]" exit "${LINENO}" ;; esac done function cleanDirectory { local directory="${1}" if [ -d "${directory}" ]; then echo "Deleting [${directory}]..." rm -rf "${directory}" fi } function updatePackageJsonVersion { local versionToUpdate="${1}" local packageJsonPath="dist/package.json" echo "Updating package.json version to [${versionToUpdate}]" # Use jq for cross-platform compatibility jq ".version = \"${versionToUpdate}\"" "${packageJsonPath}" > tmp.$$.json && mv tmp.$$.json "${packageJsonPath}" } if [[ "${isBeta}" == "true" ]]; then echo "Deploying beta [${packageVersionToDeploy}]" else echo "Deploying GA [${packageVersionToDeploy}]" fi # Update version if it differs from package.json (beta or build release) if [ "${packageVersionToDeploy}" != "$(jq -r '.version' package.json)" ]; then updatePackageJsonVersion "${packageVersionToDeploy}" fi echo "Publishing to [${registryUrl}]" cd dist if [ "${isBeta}" == "true" ]; then bun publish --registry "${registryUrl}" --tag beta else bun publish --registry "${registryUrl}" fi