version: 0.9.1-{build}

environment:
  node_pre_gyp_accessKeyId:
    secure: OO3Ze5smmicHFGoIdhjXvLuelugsVJ4g/1+9gvD7Lq4=
  node_pre_gyp_secretAccessKey:
    secure: uPSniUZp6iN9q/9hF9yCIuHQcSwd8W+38rSlAB+0AUdfQ8YYyy6p7Q12JNeAZ7oK
  matrix:
    # node.js
    - nodejs_version: 0.12
    # io.js
    - iojs_version: 2
    # Previous versions
    - nodejs_version: 0.10
    - nodejs_version: 0.8
    # Previous versions of io.js
    - iojs_version: 1

platform:
  - x64
  - x86

install:
  # Install required version of Node.js/Io.js
  - ps: Install-Product node ($env:nodejs_version + $env:iojs_version) $env:platform
  # Update npm itself
  - set PATH=%APPDATA%\npm;%APPVEYOR_BUILD_FOLDER%\node_modules\.bin;%PATH%
  - npm install -g npm
  # Make sure node-gyp version supports 'win_delay_load_hook' target flag
  - if DEFINED iojs_version ( npm install -g TooTallNate/node-gyp )

build_script:
  - if %platform% == x64 ( CALL "%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat" amd64 )
  - if %platform% == x86 ( CALL "%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat" amd64_x86 )
  # Io.js support
  - npm install node-gyp-install
  - node-gyp-install
  # Force rebuild
  - npm install --build-from-source --msvs_version=2013

# Post-install test scripts
test_script:
  # Output useful info for debugging
  - node --version
  - npm --version
  # Run tests
  - npm test

on_success:
  # Finally, publish, but only if commit message contains "[publish binary]" or "[republish binary]"
  - ps: |
     $env:needPublishing = "$env:APPVEYOR_REPO_COMMIT_MESSAGE\n\n$env:APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED" -Match "\[(?<republish>re)?publish binary\]"
     If ( "republish" -In $Matches.Keys ) { $env:needUnpublishing = "unpublish" }
  - if %needPublishing% == True ( node-pre-gyp package %needUnpublishing% publish )

# Caching npm parts
cache:
  - C:\Users\appveyor\AppData\Roaming\npm\node_modules -> package.json  # global npm modules
  - C:\Users\appveyor\AppData\Roaming\npm-cache -> package.json         # npm cache
  - node_modules -> package.json                                        # local npm modules
