#!/bin/bash

ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"

echo "🗑 Cleaning '/build'..."
rm -rf ${ROOT_DIR}/build

# Handle build flags
analyze=false

while [ "$1" != "" ]; do
    case $1 in
        # If there is a flag to analyze, set the ENV variable
        -a | --analyze)
            analyze=true
            ;;

        # Default do nothing
        * )
            ;;
    esac
    shift
done

# Build app
echo "🏗 Building for '${NODE_ENV}'"
ANALYZE_BUILD=${analyze} ${ROOT_DIR}/node_modules/.bin/webpack --config ${ROOT_DIR}/webpack/${NODE_ENV}.config.js --display-error-details
