# Node.js with webpack
# Build a Node.js project using the webpack CLI.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

# specific branch build
trigger:
    branches:
        include:
            - refs/tags/v*

pool:
    vmImage: 'ubuntu-latest'

steps:
    -   task: NodeTool@0
        inputs:
            versionSpec: '10.x'
        displayName: 'Install Node.js'
    -   task: Npm@1
        displayName: npm
        inputs:
            command: custom
            verbose: false
            customCommand: 'install -g npm@latest'

    -   task: Npm@1
        displayName: 'npm install'
        inputs:
            verbose: false

    -   task: Npm@1
        displayName: 'npm install dev'
        inputs:
            command: custom
            verbose: false
            customCommand: 'install --only=dev'

    -   task: Npm@1
        displayName: 'npm test'
        inputs:
            command: custom
            verbose: false
            customCommand: test

    -   task: PublishTestResults@2
        displayName: 'Publish Test Results $(System.DefaultWorkingDirectory)/**/test-results.xml'
        inputs:
            testResultsFiles: '$(System.DefaultWorkingDirectory)/**/test-results.xml'
        condition: succeededOrFailed()

    -   task: PublishCodeCoverageResults@1
        displayName: 'Publish code coverage from $(System.DefaultWorkingDirectory)/**/*coverage.xml'
        inputs:
            codeCoverageTool: Cobertura
            summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/*coverage.xml'
            reportDirectory: '$(System.DefaultWorkingDirectory)/**/coverage'

    -   task: npmAuthenticate@0
        inputs:
            workingFile: .npmrc
            customEndpoint: NPMJS.Simbachain

    -   script: npm run publish-npmjs
