#!/usr/bin/env bash

$(npm bin)/eslint --fix .eslintrc.json **/src/**.js

if [ $? -ne 0 ]; then
    echo "ESLint Failed"
    exit 1
fi

NODE_PATH="${NODE_PATH}:$(pwd)"

#Set the log level to 1 if it isn't already set
if [ -z ${EXPOSE_LOG_LEVEL+x} ]; then
	EXPOSE_LOG_LEVEL="1"
fi

. ./scripts/build/build_babelconfig > babel.config.js

echo "Building Libs"
. ./scripts/build/build_libs

if [ $? -ne 0 ]; then
	exit 1
fi

echo "Building Distributor"
#Build the thread distributor
. ./scripts/build/build Distributor src bin

echo "Building Analyser"
#Build the actual analyser
. ./scripts/build/build Analyser src bin
./scripts/build/bundle Analyser "bin/Analyser.js" "bin/bundle.js"

if [ $? -ne "0" ]; then
	echo "Analyser failed to build"
	exit 1
fi

rm babel.config.js
