branches:
  only:
    - master
    - appveyor
    - /^v?[0-9]/

environment:
  GYP_MSVS_VERSION: 2013

  matrix:
    - node_version: '4'
    - node_version: '5'
    - node_version: '6'
    - node_version: '7'
      APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
      GYP_MSVS_VERSION: 2015
    - node_version: '8'
      APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
      GYP_MSVS_VERSION: 2015
    - node_version: '9'
      APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
      GYP_MSVS_VERSION: 2015
    - node_version: '10'
      APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
      GYP_MSVS_VERSION: 2017

install:
  - ps: Install-Product node $env:node_version $env:platform
  - npm install -g node-gyp node-pre-gyp-github@1.3.1
  # This fixes an issue with Node 4.x on x86. If it builds without this line
  # needing to be set, we can remove it.
  - ps: npm config -g set node-gyp "$(npm config -g get prefix)\node_modules\node-gyp\bin\node-gyp.js"

  - ps: if ($env:appveyor_repo_tag -match "true" -and $env:appveyor_repo_tag_name -match '^v?[0-9]') { $publish_binary=1; }

build_script:
  - ps: echo $publish_binary
  - git submodule update --init
  - npm install --build-from-source
  - ./node_modules/.bin/node-pre-gyp package
  - ps: |
      $ErrorActionPreference = 'Continue'
      if ($publish_binary -Eq "1") {
        node-pre-gyp-github publish 2>&1 | write-host
        if (-Not ($?)) {
          throw "Failed publishing";
        }
      }
      echo "done."

platform:
  - x86
  - x64
