# Based on https://github.com/CircleCI-Public/circleci-demo-workflows/blob/6b20915f578f3b1450f4eb24d3775c2fd8728bea/.circleci/config.yml
#   and JavaScript example provided by CircleCI
version: 2.0

# Define common steps for all environments
node_base: &node_base
    working_directory: ~/repo
    steps:
      # Check out our files first thing
      - checkout

      # Install our dependencies
      - run:
          name: Install Ruby Sass
          command: |-
            sudo apt-get update
            sudo apt-get install -y ruby-sass
            ruby --version
            gem --version
            sass --version

      # https://github.com/sass/sassc/blob/3.6.1/docs/building/unix-instructions.md
      - run:
          name: Install sassc
          command: |-
            git clone https://github.com/sass/sassc.git
            cd sassc
            git checkout 3.6.1
            . script/bootstrap
            make -j4
            # `make install` wasn't working so this is a workaround
            sudo ln -s $PWD/bin/sassc /usr/local/bin/sassc
            sassc --version

      # Download cached dependencies
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            # Fallback to using the latest cache if no exact match is found
            - v1-dependencies-

      # Install our dependencies and save them for future usage
      - run: npm install
      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}

      # Run our tests
      - run: npm test

# Define all our environments
jobs:
  node_8:
    <<: *node_base
    docker:
      - image: circleci/node:8
  node_10:
    <<: *node_base
    docker:
      - image: circleci/node:10
  node_12:
    <<: *node_base
    docker:
      - image: circleci/node:12
workflows:
  version: 2
  build:
    jobs:
        - node_8
        - node_10
        # Node@12 disabled for now due to `natives` issue, https://app.circleci.com/jobs/github/twolfson/spritesheet-templates/9
        # - node_12
