steps:
  - checkout
  - run:
      command: |
        # sync submodules as checkout doesn't do this automatically
        if [[ $(git config --file .gitmodules --get-regexp path) ]]; then
          git submodule sync && git submodule update --init
        fi
  - run:
      command: |
        if [[ -n "$\{NPM_TOKEN}" ]]; then
          echo "//registry.npmjs.org/:_authToken=$\{NPM_TOKEN}" > ~/.npmrc
        fi
  - restore_cache:
      name: Restore Yarn Package Cache
      keys:
        - yarn-packages-{{ checksum "yarn.lock" }}
  - run:
      name: Install Dependencies
      command: yarn install --frozen-lockfile
  - save_cache:
      name: Save Yarn Package Cache
      key: yarn-packages-{{ checksum "yarn.lock" }}
      paths:
        - ~/.cache/yarn
