2022-12-12 21:40:11 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Usage: build-npm-package.sh <registry-url> <publish-with-this-version>
|
2023-01-05 03:43:13 +00:00
|
|
|
# Note: supply the registry auth token in CERC_NPM_AUTH_TOKEN
|
2023-01-06 17:20:18 +00:00
|
|
|
if [[ -n "$CERC_SCRIPT_DEBUG" ]]; then
|
2022-12-12 21:40:11 +00:00
|
|
|
set -x
|
|
|
|
fi
|
2023-01-05 04:23:17 +00:00
|
|
|
if ! [[ $# -eq 1 || $# -eq 2 ]]; then
|
2022-12-12 21:40:11 +00:00
|
|
|
echo "Illegal number of parameters" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-01-05 03:43:13 +00:00
|
|
|
if [[ -z "${CERC_NPM_AUTH_TOKEN}" ]]; then
|
|
|
|
echo "CERC_NPM_AUTH_TOKEN is not set" >&2
|
2022-12-12 21:40:11 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2023-01-05 04:23:17 +00:00
|
|
|
if [[ $# -eq 2 ]]; then
|
|
|
|
package_publish_version=$2
|
|
|
|
else
|
|
|
|
package_publish_version=$( cat package.json | jq -r .version )
|
|
|
|
fi
|
2023-01-19 18:33:34 +00:00
|
|
|
# Exit on error
|
|
|
|
set -e
|
2023-01-06 17:20:18 +00:00
|
|
|
# Get the name of this package from package.json since we weren't passed that
|
|
|
|
package_name=$( cat package.json | jq -r .name )
|
2022-12-12 21:40:11 +00:00
|
|
|
local_npm_registry_url=$1
|
|
|
|
npm config set @cerc-io:registry ${local_npm_registry_url}
|
2023-03-24 08:30:04 +00:00
|
|
|
npm config set @lirewine:registry ${local_npm_registry_url}
|
2023-04-13 01:46:50 +00:00
|
|
|
npm config set @muknsys:registry ${local_npm_registry_url}
|
2023-04-14 20:19:27 +00:00
|
|
|
# Workaround bug in npm unpublish where it needs the url to be of the form //<foo> and not http://<foo>
|
|
|
|
local_npm_registry_url_fixed=$( echo ${local_npm_registry_url} | sed -e 's/^http[s]\{0,1\}://')
|
|
|
|
npm config set -- ${local_npm_registry_url_fixed}:_authToken ${CERC_NPM_AUTH_TOKEN}
|
2023-01-06 17:20:18 +00:00
|
|
|
# First check if the version of this package we're trying to build already exists in the registry
|
2023-01-19 20:00:06 +00:00
|
|
|
package_exists=$( yarn info --json ${package_name}@${package_publish_version} 2>/dev/null | jq -r .data.dist.tarball )
|
2023-01-06 22:57:14 +00:00
|
|
|
if [[ ! -z "$package_exists" && "$package_exists" != "null" ]]; then
|
2023-04-14 20:19:27 +00:00
|
|
|
echo "${package_publish_version} of ${package_name} already exists in the registry"
|
|
|
|
if [[ ${CERC_FORCE_REBUILD} == "true" ]]; then
|
|
|
|
# Attempt to unpublish the existing package
|
|
|
|
echo "NOTE: unpublishing existing package version since force rebuild is enabled"
|
|
|
|
npm unpublish --force ${package_name}@${package_publish_version}
|
|
|
|
else
|
|
|
|
echo "skipping build since target version already exists"
|
|
|
|
exit 0
|
|
|
|
fi
|
2023-01-06 17:20:18 +00:00
|
|
|
fi
|
|
|
|
echo "Build and publish ${package_name} version ${package_publish_version}"
|
2022-12-12 21:40:11 +00:00
|
|
|
yarn install
|
|
|
|
yarn build
|
|
|
|
yarn publish --non-interactive --new-version ${package_publish_version} --no-git-tag-version
|