readonly currentDir=$(cd $(dirname $0); pwd)
# cd ${currentDir}
echo ${currentDir}

dev()
{
  npm run watch:cache && npm run watch:common && npm run watch:core && npm run watch:forms && npm run watch:http && npm run watch:theme && npm run watch:utils
}

stop()
{
  ps -ef | grep "ng build cache" | grep -v grep | awk '{print $2}' | xargs kill -9
  ps -ef | grep "ng build common" | grep -v grep | awk '{print $2}' | xargs kill -9
  ps -ef | grep "ng build core" | grep -v grep | awk '{print $2}' | xargs kill -9
  ps -ef | grep "ng build forms" | grep -v grep | awk '{print $2}' | xargs kill -9
  ps -ef | grep "ng build http" | grep -v grep | awk '{print $2}' | xargs kill -9
  ps -ef | grep "ng build theme" | grep -v grep | awk '{print $2}' | xargs kill -9
  ps -ef | grep "ng build utils" | grep -v grep | awk '{print $2}' | xargs kill -9
}

prod()
{
  ng build cache
  echo ">>>>>>>>>>>>>>>>>>>>>>cache build finished."

  ng build common
  echo ">>>>>>>>>>>>>>>>>>>>>>common build finished."

  ng build core
  echo ">>>>>>>>>>>>>>>>>>>>>>core build finished."

  ng build forms
  echo ">>>>>>>>>>>>>>>>>>>>>>forms build finished."

  ng build http
  echo ">>>>>>>>>>>>>>>>>>>>>>http build finished."

  ng build theme
  echo ">>>>>>>>>>>>>>>>>>>>>>theme build finished."

  ng build utils
  echo ">>>>>>>>>>>>>>>>>>>>>>utils build finished."
}

case "$1" in
  prod)
    prod
    ;;
  dev)
    dev
    ;;
  stop)
    stop
    ;;
  *)
    echo $"Usage: $0 {prod|dev}"
    RETVAL=1
esac
exit $RETVAL
