version: 2
executorType: docker

defaults: &defaults
  working_directory: ~/project
  docker:
    - image: 'circleci/node:10'

jobs:
  build:
    <<: *defaults
    steps:
      - checkout
      - restore_cache:
          keys:
            - 'v1-yarn-{{ .Branch }}-{{ checksum "yarn.lock" }}'
            - v1-yarn
      - run: yarn
      - save_cache:
          key: v1-yarn
          paths:
            - node_modules/
      - save_cache:
          key: 'v1-yarn-{{ .Branch }}-{{ checksum "yarn.lock" }}'
          paths:
            - node_modules/
      - persist_to_workspace:
          root: ~/project
          paths:
            - node_modules
  prettier:
    <<: *defaults
    steps:
      - checkout
      - attach_workspace:
          at: ~/project
      - run: 'yarn run prettier:check'
  lint:
    <<: *defaults
    steps:
      - checkout
      - attach_workspace:
          at: ~/project
      - run: 'yarn lint'

workflows:
  version: 2
  build-and-check-prettier:
    jobs:
      - build
      - prettier:
          requires:
            - build
      - lint:
          requires:
            - build
