#!/usr/bin/env bash

set -eu

. ./node_modules/release-util-fnd/lib.sh

root=`dirname $0`
root=`realpath "$root/.."`
branch="main"
packages=`find "$root/pkg" -type d -d 1`

report() {
	echo "$@" >&2
}

pre_release_checks "$branch"
npm test

"$root/bin/validate-versions" $packages

report "== publishing gorgeon =="
create_package > /dev/null
publish_package origin "$branch"

for dir in $packages; do
	report; report "== publishing `basename $dir` plugin =="
	(cd "$dir"; npm publish)
done
