version: 2
jobs:
  build:
    docker:
      - image: circleci/node:latest

    working_directory: ~/repo

    steps:
      - checkout

      - restore_cache:
          keys:
            - dependency-cache-{{ checksum "package.json" }}
            - dependency-cache-
      - run:
          name: Install dependencies
          command: npm install

      - save_cache:
          key: dependency-cache-{{ checksum "package.json" }}
          paths:
            - node_modules

      - run:
          name: Build
          command: npm run build

      - run:
          name: Collect data
          command: cd src/scraper && npx babel-node scrape.js

      - run:
          name: Match words
          command: cd src/scraper && npx babel-node match.js

      - run:
          name: Copy data to build folder
          command: cp -R src/data/ build/data

      - run:
          name: Install now-cli
          command: sudo npm install now -g -y

      - run:
          name: Deploy on Zeit now
          command: now --prod -t ${NOW_TOKEN} --confirm --local-config ${CIRCLE_WORKING_DIRECTORY}/now.json

      - run:
          name: Save data to the Google Sheet
          command: npm run save

workflows:
  version: 2
  commit-workflow:
    jobs:
      - build
  daily-workflow:
    triggers:
      - schedule:
          cron: '0 14 * * *'
          filters:
            branches:
              only:
                - dev
    jobs:
      - build

version: 2
jobs:
  build:
    docker:
      - image: circleci/node:latest

    working_directory: ~/repo

    steps:
      - checkout

      - restore_cache:
          keys:
            - dependency-cache-{{ checksum "package.json" }}
            - dependency-cache-
      - run:
          name: Install dependencies
          command: npm install

      - save_cache:
          key: dependency-cache-{{ checksum "package.json" }}
          paths:
            - node_modules

      - run:
          name: Build
          command: npm run build

      - run:
          name: Collect data
          command: cd src/scraper && npx babel-node scrape.js

      - run:
          name: Match words
          command: cd src/scraper && npx babel-node match.js

      - run:
          name: Copy data to build folder
          command: cp -R src/data/ build/data

      - run:
          name: Deploy on Zeit now
          command: npx now --prod -t ${NOW_TOKEN} --confirm --local-config ${CIRCLE_WORKING_DIRECTORY}/now.json

      - run:
          name: Save data to the Google Sheet
          command: npm run save

workflows:
  version: 2
  commit-workflow:
    jobs:
      - build
  daily-workflow:
    triggers:
      - schedule:
          cron: '0 14 * * *'
          filters:
            branches:
              only:
                - dev
    jobs:
      - build

Remove global install of now-cli
Remove global install of now-cli
