#!/usr/bin/env bash

set -e            # fail fast
set -o pipefail   # don't ignore exit codes when piping output
# set -x          # enable debugging

# Configure directories
build_dir=$1
cache_dir=$2
env_dir=$3

bp_dir=$(cd $(dirname $0); cd ..; pwd)

# Load some convenience functions like status() and indent()
source $bp_dir/bin/common.sh

# Expose user-installed bower
export PATH=$build_dir/node_modules/.bin:$PATH

# Get gulp version
gulp_bin=$(which gulp)
status "Using Gulp from ${gulp_bin#$build_dir/}"
gulp -v 2>&1 | indent

# Run subsequent node/gulp commands from the build path
cd $build_dir

status "Building"
gulp build 2>&1 | indent
