#!/usr/bin/env bash

# set DOCS environment variable to build documentation and unit tests
#     eg:
#     user@host:/path/to/atomos/scripts$ DOCS=1 ./buildall

echo "Atomic OS Build Utility"
echo ""

echo "building kernel"
cd ./hx; ./build

echo ""
echo "building device files"
cd ../dev; ./build

echo ""
echo "building shell commands"
cd ../bin; ./build

cd ..

#TODO zepto.eof.txt should not be required, check minifier & zepto issues on github

echo ""
echo "building system"
cat "console.js"            \
    "vendor/zepto.min.js"   \
    "zepto.eof.txt"         \
    "vendor/ejohn-class.js" \
    "vendor/tcl.04.aos.js"  \
    "hx/atomos-hx.js"       \
    "bin/atomos-bin.js"     \
    "dev/atomos-dev.js"     \
    "system.js"             \
    "libsys.js"             \
  > "atomos.t.js"

# above: libsys should come before system

echo "- adding main"
cat "atomos.t.js" "main.js" > "atomos.js"

MINNGN=`which uglifyjs`
if [ -n "$MINNGN" ]
then
    echo "- minimizing"
    $MINNGN -o atomos.min.js atomos.js
else
    echo "- skipping minification"
fi

echo ""
