#!/bin/bash

# this setup script is used locally to create an .npmrc file and run yarn install.
# It does not rely on Docker secrets, instead uses secrets being passed as build arguments 
# from the docker-compose.yaml file

set -e

unique_id=theorchard_jenkins

# generate new packagecloud token
pc_token=`curl -s -XPOST --data "name=${unique_id}" https://$PACKAGECLOUD_USER:@packagecloud.io/install/repositories/orchardit/npm/tokens.text`

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

yarn install

rm -f .npmrc
