version: 2
jobs:
  build:
    docker: &docker
      - image: circleci/node:lts
    steps:
      - checkout
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            - v1-dependencies-
      - run:
          name: Install dependencies
          command: npm install
      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}
      - persist_to_workspace:
          root: .
          paths:
            - .
  lint:
    docker: *docker
    steps:
      - attach_workspace:
          at: .
      - run:
          name: Lint files
          command: npm run lint
  test:
    docker: *docker
    steps:
      - attach_workspace:
          at: .
      - run:
          name: Unit tests
          command: npm run test:publish
  test:mutation:
    docker: *docker
    steps:
      - attach_workspace:
          at: .
      - run:
          name: Mutation tests
          command: npm run test:mutation:publish
  audit:
    docker: *docker
    steps:
      - attach_workspace:
          at: .
      - run:
          name: Audit project
          command: npm audit --audit-level=high

workflows:
  version: 2
  build:
    jobs:
      - build
      - lint:
          requires:
            - build
      - test:
          requires:
            - build
      - test:mutation:
          requires:
            - build
      - audit:
          requires:
            - build
