#!/bin/sh
cwd=`pwd`
# find where this file really is by dereferencing the symlink(s).
this=$0
cd `dirname $this`
while [ -n "`readlink $this`" ] ; do
    this=`readlink $this`
    cd `dirname $this`
done
moduleDir=`pwd`
moduleDir=${moduleDir%%/bin}
# build or display help.
for arg in $@; do
    case $arg in
        '--nobuild') nobuild=1 ;;
        '--help') help=1 ;;
    esac
done
# cd to right destination
export PATH=`dirname $0`:$PATH
cd $moduleDir
# compile coffeescript
if [ -z "$nobuild" ] && [ -z "$help" ]; then
    env ./node_modules/.bin/cake build || exit 1
fi
# go back where we came from
cd "$cwd"
# execute the real program.
exec env node "$moduleDir/lib/main.js" $@

