stack-orchestrator/app/data/container-build/cerc-builder-js/build-npm-package-local-dependencies.sh

38 lines
1.6 KiB
Bash
Raw Normal View History

#!/bin/bash
# Usage: build-npm-package-local-dependencies.sh <registry-url> <publish-with-this-version>
2023-01-04 04:17:30 +00:00
# Runs build-npm-package.sh after first fixing up yarn.lock to use a local
2023-04-13 01:46:50 +00:00
# npm registry for all packages in a spcific scope (currently @cerc-io, @lirewine and @muknsys)
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
2023-01-05 04:23:17 +00:00
if ! [[ $# -eq 1 || $# -eq 2 ]]; then
echo "Illegal number of parameters" >&2
exit 1
fi
2023-01-05 03:50:23 +00:00
if [[ -z "${CERC_NPM_AUTH_TOKEN}" ]]; then
echo "CERC_NPM_AUTH_TOKEN is not set" >&2
exit 1
fi
2023-01-19 18:33:34 +00:00
# Exit on error
set -e
local_npm_registry_url=$1
package_publish_version=$2
2023-03-24 08:30:04 +00:00
# If we need to handle an additional scope, add it to the list below:
2023-04-13 01:46:50 +00:00
npm_scopes_to_handle=("@cerc-io" "@lirewine" "@muknsys")
2023-03-24 08:52:37 +00:00
for npm_scope_for_local in ${npm_scopes_to_handle[@]}
do
2023-03-24 08:31:19 +00:00
# We need to configure the local registry
2023-03-24 08:30:04 +00:00
npm config set ${npm_scope_for_local}:registry ${local_npm_registry_url}
npm config set -- ${local_npm_registry_url}:_authToken ${CERC_NPM_AUTH_TOKEN}
# Find the set of dependencies from the specified scope
mapfile -t dependencies_from_scope < <(cat package.json | jq -r '.dependencies | with_entries(if (.key|test("^'${npm_scope_for_local}'/.*$")) then ( {key: .key, value: .value } ) else empty end ) | keys[]')
2023-03-24 08:52:37 +00:00
echo "Fixing up dependencies in scope ${npm_scope_for_local}"
2023-03-24 08:30:04 +00:00
for package in "${dependencies_from_scope[@]}"
do
echo "Fixing up package ${package}"
yarn-local-registry-fixup.sh $package ${local_npm_registry_url}
done
done
echo "Running build"
build-npm-package.sh ${local_npm_registry_url} ${package_publish_version}