#!/usr/bin/env bash

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/"
PROJECT_ROOT="$(realpath $SCRIPT_DIR'../../')/"
APPLICATION_PATH="${PROJECT_ROOT}application/"
TEST_PATH="$(realpath $SCRIPT_DIR'../test/')/"
BUILD_PATH="${PROJECT_ROOT}deployment/build/npm/"
DEVELOPMENT_PATH="${PROJECT_ROOT}development/"

if [ -d $BUILD_PATH ]; then
  rm -rf $BUILD_PATH}
fi
 
mkdir -p ${BUILD_PATH}

cp -r ${APPLICATION_PATH}* ${BUILD_PATH}
cp -r ${TEST_PATH} ${BUILD_PATH}
cp -r ${PROJECT_ROOT}README.md ${BUILD_PATH}

git add ${APPLICATION_PATH}package.json
git add ${DEVELOPMENT_PATH}package.json
git add ${PROJECT_ROOT}release.json
git commit -m "release and publish to npm"

cd ${BUILD_PATH}
pnpm publish --dry-run --access public
cd -

