#!/bin/sh
# patch given spec file to have the correct version and declare bundled NPM dependencies
# Usage: fix-spec <spec-file> <version>
set -eu

spec="$1"
version="$2"

ROOT_DIR=$(realpath "$(dirname "$0")/..")

PROVIDES=$(awk '{print "Provides: bundled(npm(" $1 ")) = " $2}' "${ROOT_DIR}/runtime-npm-modules.txt")
awk -v p="$PROVIDES" '/Version/ { gsub(/0/, "'$version'") }; gsub(/#NPM_PROVIDES/, p) 1' "$spec" > "$spec".new
mv -f "$spec".new "$spec"
