#!/bin/sh

# readonly thisDir=$(cd $(dirname $0); pwd)
cd $(dirname $0)/../..
readonly BASE_HOME="`pwd`"
readonly DIST="$BASE_HOME/dist"

if  [ $# -le 0 ]; then
  echo "Usage: sh $0 <module name> ..."
  exit 1;
fi

for ARG in "$@"; do
  if [ ! -d "$DIST/$ARG" ]; then
    echo "publish dir not found."
    exit 1;
  fi
done

publish() {
  cd ${DIST};
  # for p in `ls .`;
  #   do npm publish --access public $p;
  # done
  # 所有参数：模块名
  for ARG in "$@"; do
    VERSION=$(node -p "require('./$ARG/package.json').version")
    npm publish --access public $ARG;
    echo "Version ${VERSION}"
  done
}

publish $@
