#!/bin/sh
# script/add-dependency: add a frontend package, or move one to another
# version, with yarn add, which changes package.json and yarn.lock
# together; then install from yarn.lock with --frozen-lockfile, as
# script/bootstrap does, to show it installs as written. --dev because
# every frontend package is used only at build time.
set -eu

ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"

main() {
    if [ -z "${1:-}" ]; then
        echo "usage: make add-dependency PACKAGE=<name>@<version>" >&2
        exit 2
    fi
    cd "$ROOT"
    yarn add --dev "$1"
    yarn install --frozen-lockfile
}

main "$@"
