version: 2
jobs:
  build:
    docker:
      - image: node:10
    steps:
      - checkout
      - run:
          name: dep install
          command: npm install
      - run:
          name: install codecov
          command: npm install -g codecov
      - run:
          name: test
          command: npm test && codecov
      - run:
          name: build
          command: |
            npm run build
            [ -f ./dist/index.html ] || exit 1
            [ -f ./dist/blank.html ] || exit 1
            [ -f ./dist/widget.js ] || exit 1
            [ -f ./dist/bookmarklet.js ] || exit 1
      - run:
          name: npm start works
          command: |
            npm run start &
            pid=$!
            sleep 10s
            ps $pid
      - run:
          name: deploy
          command: |
            if [ "$CIRCLE_BRANCH" = "master" ]; then
              git config --global user.email $GH_EMAIL
              git config --global user.name $GH_NAME
              npm run deploy
            fi

workflows:
  version: 2
  build-deploy:
    jobs:
      - build:
          filters:
            branches:
              ignore: gh-pages
