defaults: &defaults
  working_directory: ~/project
  docker:
    - image: node:latest

version: 2
jobs:
  install:
    <<: *defaults
    steps:
      - restore_cache:
          key: stylelint-application
      - checkout
      - run:
          name: Install stylelint
          command: |
            npm install --global stylelint
            npm install stylelint-config-standard
      - save_cache:
          paths:
            - /usr/local/bin/stylelint
            - /usr/local/lib/node_modules
          key: stylelint-application-{{ checksum "/usr/local/lib/node_modules/stylelint/package.json" }}
      - persist_to_workspace:
          root: /usr/local/bin
          paths:
            - stylelint
      - persist_to_workspace:
          root: /usr/local/lib
          paths:
            - node_modules
      - persist_to_workspace:
          root: ~/
          paths:
            - project
  version:
    <<: *defaults
    steps:
      - attach_workspace:
          at: /usr/local/bin
      - attach_workspace:
          at: /usr/local/lib
      - run:
          name: System information
          command: uname -a
      - run:
          name: Node.js version
          command: node --version
      - run:
          name: stylelint version
          command: stylelint --version
  lint:
    <<: *defaults
    steps:
      - attach_workspace:
          at: /usr/local/bin
      - attach_workspace:
          at: /usr/local/lib
      - attach_workspace:
          at: ~/
      - run:
          name: Run stylelint
          command: stylelint ./*.css
workflows:
  version: 2
  stylelint:
    jobs:
      - install
      - version:
          requires:
            - install
      - lint:
          requires:
            - install


defaults: &defaults
  working_directory: ~/project
  docker:
    - image: node:latest

version: 2
jobs:
  install:
    <<: *defaults
    steps:
      - checkout
      - restore_cache:
          key: stylelint-application
      - run:
          name: Install stylelint
          command: npm install stylelint stylelint-config-standard
      - save_cache:
          paths:
            - ./node_modules
            - ./package-lock.json
          key: stylelint-application-{{ checksum "./package-lock.json" }}
      - persist_to_workspace:
          root: ~/
          paths:
            - project
  version:
    <<: *defaults
    steps:
      - attach_workspace:
          at: ~/
      - run:
          name: System information
          command: uname -a
      - run:
          name: Node.js version
          command: node --version
      - run:
          name: stylelint version
          command: ./node_modules/.bin/stylelint --version
  lint:
    <<: *defaults
    steps:
      - attach_workspace:
          at: ~/
      - run:
          name: Run stylelint
          command: ./node_modules/.bin/stylelint -- ./*.css
workflows:
  version: 2
  stylelint:
    jobs:
      - install
      - version:
          requires:
            - install
      - lint:
          requires:
            - install


Install stylelint into local directory
Install stylelint into local directory

By default, npm is installed in /usr/local/lib/node_modules.
Caching /usr/local/lib/node_modules reverts version of npm to older one.
