<commit_before>var Server = require('../server')
  , Compiler = require('../compiler')
  , Tumblr = require('../tumblr')

  , when = require('when')
  , request = require('request')
  , chokidar = require('chokidar')
  , minimatch = require('minimatch')
  , path = require('path');

var Watcher = function (peak, options) {
  this.peak = peak;
  this.options = options || {};
  this.emitter = peak.emitter;

  this.compiler = new Compiler(this.peak, this.options);
  this.server = new Server(this.peak, this.options);
  this.tumblr = new Tumblr(this.peak, this.options);

  this.path = path.join(this.peak.path, this.options.output_path);
  this.emitter.on('exit', this.stop.bind(this));
}

Watcher.prototype = {

  start: function () {
    return this.fetch_tumblr_demo_content()
      .with(this)
      .then(this.handle_demo_content)
      .then(this.compile)
      .then(this.watch)
      .then(this.serve);
  },

  stop: function () {
    if (this.watcher) this.watcher.close();
    this.server.stop();
  },

  fetch_tumblr_demo_content: function () {
    return this.tumblr.fetch_demo_content();
  },

  handle_demo_content: function (context) {
    return this.context = context || {};
  },

  compile: function (file) {
    return this.compiler.compile_project(this.context);
  },

  serve: function () {
    return this.server.start();
  },

  watch: function () {
    if (!this.watcher) this.watcher = chokidar.watch(this.peak.path, { ignored: this.is_ignore_path.bind(this), ignoreInitial: true });
    this.watcher.on('change', this.compile.bind(this));
  },

  is_ignore_path: function (p) {
    p = p.replace(this.peak.path, '').slice(1);
    for (var x=0; x<this.options.ignore_paths.length; x++) {
      if (minimatch(p, this.options.ignore_paths[x], { dot: true })) return true;
    }
    return false;
  }

}

module.exports = Watcher;<commit_msg>On watch, only compile files with diff.<commit_after>var Server = require('../server')
  , Compiler = require('../compiler')
  , Tumblr = require('../tumblr')

  , when = require('when')
  , request = require('request')
  , chokidar = require('chokidar')
  , minimatch = require('minimatch')
  , path = require('path');

var Watcher = function (peak, options) {
  this.peak = peak;
  this.options = options || {};
  this.emitter = peak.emitter;

  this.compiler = new Compiler(this.peak, this.options);
  this.server = new Server(this.peak, this.options);
  this.tumblr = new Tumblr(this.peak, this.options);

  this.path = path.join(this.peak.path, this.options.output_path);
  this.emitter.on('exit', this.stop.bind(this));
}

Watcher.prototype = {

  start: function () {
    return this.fetch_tumblr_demo_content()
      .with(this)
      .then(this.handle_demo_content)
      .then(this.compile)
      .then(this.watch)
      .then(this.serve);
  },

  stop: function () {
    if (this.watcher) this.watcher.close();
    this.server.stop();
  },

  fetch_tumblr_demo_content: function () {
    return this.tumblr.fetch_demo_content()
      .then(function (context) {
        this.context = context || {};
        return false;
      }.bind(this));
  },

  compile: function (file) {
    if (file) {
      return this.compiler.compile_file(file, this.context);
    }
    return this.compiler.compile_project(this.context);
  },

  serve: function () {
    return this.server.start();
  },

  watch: function () {
    if (!this.watcher) this.watcher = chokidar.watch(this.peak.path, { ignored: this.is_ignore_path.bind(this), ignoreInitial: true });
    this.watcher.on('change', this.compile.bind(this));
  },

  is_ignore_path: function (p) {
    p = p.replace(this.peak.path, '').slice(1);
    for (var x=0; x<this.options.ignore_paths.length; x++) {
      if (minimatch(p, this.options.ignore_paths[x], { dot: true })) return true;
    }
    return false;
  }

}

module.exports = Watcher;
{'fraction_non_alphanumeric': 0.16783216783216784, 'fraction_numerical': 0.001036001036001036, 'mean_word_length': 3.344206974128234, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1736884', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1302, 'n_words': 239}