#!/bin/bash

# this setup script is used locally to create an .npmrc file and run yarn install.
# It relies on Docker secrets and Docker BuildKit.

# Error on subcommand error
set -e
# Echo commands
set +x
# Don't echo variable substitutions
set -v

if [ -f /run/secrets/tokens ]; then
	GITHUB_TOKEN=$(cat /run/secrets/tokens)
fi

# Append github configuration
sed "s/{{GITHUB_TOKEN}}/$GITHUB_TOKEN/" .npmrc.shadow > .npmrc

yarn --frozen-lockfile --production=$1

rm -f .npmrc
