#!/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.
args=''
skipnext=0
for arg in $@; do
    if [ "$skipnext" == "1" ]; then
      skipnext=0
      continue
    fi
    case $arg in
        '--help') help=1 ;;
        '--node-debug')
            debug=" "
            if [[ $2 =~ ^[0-9]+$ ]]; then
              debug="="$2
              skipnext=1
            fi
            continue;;
    esac
    args=$args" "$arg
done

# execute the real programk
if [ -z "$debug" ]; then
  exec env node "$moduleDir/lib/main.js" $args
else
  exec env node --debug-brk$debug "$moduleDir/lib/main.js" $args
fi