74 lines
1.5 KiB
Bash
Executable File
74 lines
1.5 KiB
Bash
Executable File
#!/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=""
|
|
isBeta="false"
|
|
|
|
while [[ "${#}" -gt 0 ]]; do
|
|
case "${1}" in
|
|
--beta)
|
|
isBeta="${2}"
|
|
shift 2
|
|
;;
|
|
--version)
|
|
packageVersionToDeploy="${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"
|
|
|
|
if [ "${isBeta}" == "true" ]; then
|
|
echo "Updating package.json version to [${versionToUpdate}] (beta)"
|
|
|
|
# Use jq for cross-platform compatibility
|
|
jq ".version = \"${versionToUpdate}\"" "${packageJsonPath}" > tmp.$$.json && mv tmp.$$.json "${packageJsonPath}"
|
|
fi
|
|
}
|
|
|
|
echo "Deploying [${packageVersionToDeploy}]"
|
|
echo "isBeta [${isBeta}]"
|
|
|
|
cleanDirectory "dist"
|
|
|
|
bun run ci-build
|
|
|
|
# Update version if beta and version provided
|
|
if [ "${isBeta}" == "true" ] && [ -n "${packageVersionToDeploy}" ]; 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 |