machine:
  node:
    version: 6.1
  environment:
    # Save mocha test results
    MOCHA_FILE: "$CIRCLE_TEST_REPORTS/mocha.xml"
    CODECOV_TOKEN: "41286a76-6eb6-40f5-bf7a-62dd2d55e6f9"

dependencies:
  post:
    # For some reason this plugin is not automatically installed inside the CircleCI container
    - npm install eslint-plugin-import@latest

    # Needed for proper mocha test results
    - npm install mocha-circleci-reporter
    - npm install codecov

    # Needed to upload documentation
    - npm install esdoc-uploader

    # Needed to publish to npm
    - npm install publish

test:
  override:
    # Lint files
    - node_modules/.bin/eslint -f junit src > $CIRCLE_TEST_REPORTS/eslint.xml

    # Run mocha tests
    - NODE_ENV=test node_modules/.bin/nyc npm test -- --reporter mocha-circleci-reporter
    # Check coverage
    - node_modules/.bin/nyc check-coverage --statements 90 --branches 90 --functions 90 --lines 90
    # Report coverage
    - node_modules/.bin/nyc report --reporter=lcov | node_modules/.bin/codecov

    # Create API docs and validate coverage
    - npm run docs
  post:
    # Save API docs
    - cp -R docs/api $CIRCLE_ARTIFACTS

deployment:
  staging:
    branch: master
    commands:
      - node_modules/.bin/esdoc-uploader
      - echo -e "$NPM_USERNAME\n$NPM_PASSWORD\n$NPM_EMAIL" | npm login
      - node_modules/.bin/publish
