pipeline {
  agent {
    docker {
      image 'docker.pkgs.xarth.tv/devtools/bionic/node12.10.0:latest'
      args '-u root'
    }
  }
  environment {
    NPM_REPO="https://npm.pkgs.xarth.tv"
  }
  stages {
    stage('build') {
      steps {
        sh 'npm ci'
        sh 'npm run build'
      }
    }
    stage('deploy') {
      when { branch 'master' }
      steps {
        withCredentials([[$class: 'StringBinding', credentialsId: 'dta_tools_deploy', variable: 'DTA_TOOLS_DEPLOY_PASS']]) {
          sh 'curl -udta_tools:$DTA_TOOLS_DEPLOY_PASS $NPM_REPO/auth > ~/.npmrc'
          sh 'echo "email = dta@justin.tv" >> ~/.npmrc'
          sh 'npm publish --registry "$NPM_REPO"'
        }
      }
    }
  }
}
