language: node_js
services:
  - docker
node_js:
  - 8.2.1
cache:
  directories:
    - node_modules
    - server/node_modules
env:
  - NODE_ENV=production
install:
  - npm install
  - cd server && npm install && cd ..
script:
  - npm test
  - npm run build
  - cd server && npm run build && cd ..
after_success:
  - if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
      export REPO=martijnhols/wowanalyzer;
      export BRANCH=$(
        if [ "$TRAVIS_BRANCH" == "master" ]; then
          echo "latest";
        else
          echo $TRAVIS_BRANCH;
        fi | sed -r 's/\//-/g'
      );
      echo "#docker build";
      docker build --tag $REPO:$BRANCH --file Dockerfile.package .;
      echo "#docker login";
      docker login --username="$DOCKER_USERNAME" --password="$DOCKER_PASSWORD";
      echo "#docker push";
      docker push $REPO:$BRANCH;
    fi

language: node_js
services:
  - docker
node_js:
  - 8.2.1
cache:
  directories:
    - node_modules
    - server/node_modules
env:
  - NODE_ENV=production
install:
  - npm install --dev
  - cd server && npm install && cd ..
script:
  - npm test
  - npm run build
  - cd server && npm run build && cd ..
after_success:
  - if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
      cd server && npm prune --production && cd ..; # The server has already been built so we no longer need the devDependencies
      export REPO=martijnhols/wowanalyzer;
      export BRANCH=$(
        if [ "$TRAVIS_BRANCH" == "master" ]; then
          echo "latest";
        else
          echo $TRAVIS_BRANCH;
        fi | sed -r 's/\//-/g'
      );
      echo "#docker build";
      docker build --tag $REPO:$BRANCH --file Dockerfile.package .;
      echo "#docker login";
      docker login --username="$DOCKER_USERNAME" --password="$DOCKER_PASSWORD";
      echo "#docker push";
      docker push $REPO:$BRANCH;
    fi

Install server dev dependencies to build the server, then when building the Docker container remove the dev dependencies again to minimize container size
Install server dev dependencies to build the server, then when building the Docker container remove the dev dependencies again to minimize container size
