version: 2.1
jobs:
  build:
    docker:
      - image: circleci/node:12.16.0
    steps:
      - checkout
      - run:
          name: Check current version of node
          command: node -v
      - restore_cache:
          keys:
            - node_modules_cache_{{ checksum "package-lock.json" }}
      - run:
          name: Install project dependencies
          command: |
            if [ ! -d "node_modules" ]; then
            npm ci -f
            fi
      - save_cache:
          key: node_modules_cache_{{ checksum "package-lock.json" }}
          paths:
            - node_modules
      - run:
          name: Publish to NPM
          command: |
            if [ -z $CIRCLE_PR_NUMBER ]; then
              npm pack
              echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
              npm publish project-sunbird-sb-styles-*  --access=public
            else
              npm pack
            fi