#!/usr/bin/env bash

cd "`dirname $0`/.."

echo
echo "This script assumes the following:"
echo "1. You have run the release script"
echo "2. You have a clone of CDNJS's repo with remotes 'upstream' and 'origin'"
echo "3. You have initialized CDNJS's repo with 'npm install'"
echo

# 1. make a fork of cdnjs on github
# 2. clone the fork from github (which will be the 'origin')
# 3. `git remote add upstream git@github.com:cdnjs/cdnjs.git`

version=$(sed -n 's/^.*"version" *: *"\([^"]*\)".*$/\1/p' package.json)
cdnjs_dir="$HOME/Scratch/cdnjs"

echo "FullCalendar version: $version"
echo "Default CDNJS directory: $cdnjs_dir"
echo

echo "Enter the location of the CDNJS directory. To keep the default, press enter."
read cdnjs_dir_override

if [[ "$cdnjs_dir_override" ]]
then
	cdnjs_dir="$cdnjs_dir_override"
fi 

cp -r -f dist/cdnjs/* "$cdnjs_dir/ajax/libs/fullcalendar" && \
cd $cdnjs_dir && \
npm test && \
git add "ajax/libs/fullcalendar" && \
git commit -e -m "fullcalendar v$version" && \
echo && \
echo 'Pulling from upstream...' && \
git pull --rebase upstream master && \
echo && \
echo 'DONE. It is now up to you to run `'"cd $cdnjs_dir && git push origin master"'` and submit the PR to CDNJS.' && \
echo