language: node_js

node_js:
  - '10'

cache:
  directories:
    - '$HOME/.sonar/cache'
    - 'node_modules'
    - 'coverage'
    - 'build'

stages:
  - setup
  - audit
  - lint
  - test
  - sonar
  - build

jobs:
  include:
    - stage: setup
      script:
        - npm i
    - stage: audit
      script:
        - npm audit
    - stage: lint
      script:
        - npm run lint
    - stage: test
      script:
        - npm run coverage
    - stage: sonar
      script:
        - sonar-scanner
      addons:
        sonarcloud:
          token:
            secure: '$SONAR_API_KEY'
    - stage: build
      script:
        - npm run build
