version: 2

defaults: &defaults
  working_directory: ~/repo
  docker:
    - image: circleci/node:8.14.1

jobs:
  deploy:
    <<: *defaults
    steps:
      - checkout
      - attach_workspace:
          at: ~/repo
      - run:
          name: Authenticate with registry
          command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/repo/.npmrc
      - run:
          name: Publish package
          command: npm run deploy

workflows:
  version: 2
  deploy:
    jobs:
      - deploy:
          filters:
            branches:
              only: master
