#!/usr/bin/env bash

if [ -z "${NPM_TOKEN}" ]; then
    echo "Need to set NPM_TOKEN env variable to release node modules"
    exit 1
fi

if [ $# -eq 0 ]; then
    echo "No arguments provided"
    exit 1
fi

touch ~/.npmrc
grep --fixed-strings --line-regexp --silent "//registry.npmjs.org/:_authToken=$NPM_TOKEN"  ~/.npmrc || echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc
for project in $@
do
    pushd ${project}
    yarn publish --non-interactive
    pwd
    popd
done
