node {
	checkout scm
	def json = readFile file:'package.json'
	def data = readJSON text: json;
    echo "version: ${data.version}"

    docker.image('node:8').inside() {
        stage('Build and Publish') {
        sh '''
            git status
            git config --global user.email "colin.clark@elephant-room.info"
            git config --global user.name "Colin Clark"
            npm install
            npm run build
            npm version --no-git-tag-version patch --force
            git status
            npm publish
        '''
        }
        stage('Build Styleguide') {
            sh 'npm run build-storybook'
        }
    }
    stage('Deploy s3') {
        withAWS(region:'eu-west-1', credentials:'aws_creds') {
            s3Upload(file:'storybook-static', path: data.version, bucket:'desops')
            s3Upload(file: 'storybook-config.json', path: 'storybook-config.json', bucket: 'desops')
        }
    }
}
