 #!/bin/bash

publish(){
    npm cache clean --force
    CURRENT_STAGING_VERSION=$(npm view $1@staging version)
    echo "current staging version is => $CURRENT_STAGING_VERSION"

    # set current version
    npm --no-git-tag-version version $CURRENT_STAGING_VERSION --allow-same-version

    # update current version
    NEXT_STAGING_VERSION=$(npm --no-git-tag-version version prerelease --preid=staging)
    echo "next staging version is ==> $NEXT_STAGING_VERSION"

    # build new version
    npm i
    npm run build
    npm publish --no-git-tag-version --tag staging

    # Configure 'origin' for ssh.
    git remote set-url origin ${BITBUCKET_GIT_SSH_ORIGIN}
    git config --add user.email "bitbucket-bot@aui.io"
    git config --add user.name "bitbucket bot"

    git add -A
    git commit -m "[skip ci] pub new staging version for $1"
    git push
}


publish stuff-ui
