<commit_before>'use strict';

var _ = require('lodash');
var path = require('path');
var spawn = require('child_process').spawn;
var gutil = require('gulp-util');
var through = require('through2');

var runnerjs = path.join(__dirname, 'runner.js');
var phantomcss = path.join(__dirname, 'node_modules', 'phantomcss');

var defaults = _.partialRight(_.assign, function(a, b) {
  return typeof a == 'undefined' ? b : a;
});

function spawnPhantom(args){
  var o = {
    stdio: 'inherit',
    cwd: process.cwd()
  };
  return spawn(require('phantomjs').path, args, o);
};

module.exports = function (opts) {

  if (_.isString(opts)) {
    var screenshotDir = opts;
    opts = {};
    opts.screenshots = screenshotDir;
  }

  opts = _.extend({
    screenshots: 'screenshots',
    results: 'results',
    viewportSize: [1280, 800],
    logLevel: 'error'
  }, opts || {});

  opts.phantomCSSPath = phantomcss;
  opts.test = [];

  return through.obj(function (file, enc, cb) {
    opts.test.push(path.resolve(file.path));
    cb(null, file);
  }, function(cb){
    spawnPhantom([
      runnerjs,
      JSON.stringify(opts)
    ]);
  });

};<commit_msg>End task on phantom exit<commit_after>'use strict';

var _ = require('lodash');
var path = require('path');
var spawn = require('child_process').spawn;
var gutil = require('gulp-util');
var through = require('through2');

var runnerjs = path.join(__dirname, 'runner.js');
var phantomcss = path.join(__dirname, 'node_modules', 'phantomcss');

var defaults = _.partialRight(_.assign, function(a, b) {
  return typeof a == 'undefined' ? b : a;
});

function spawnPhantom(args){
  var o = {
    stdio: 'inherit',
    cwd: process.cwd()
  };
  return spawn(require('phantomjs').path, args, o);
};

module.exports = function (opts) {

  if (_.isString(opts)) {
    var screenshotDir = opts;
    opts = {};
    opts.screenshots = screenshotDir;
  }

  opts = _.extend({
    screenshots: 'screenshots',
    results: 'results',
    viewportSize: [1280, 800],
    logLevel: 'error'
  }, opts || {});

  opts.phantomCSSPath = phantomcss;
  opts.test = [];

  return through.obj(function (file, enc, cb) {
    opts.test.push(path.resolve(file.path));
    cb(null, file);
  }, function(cb){
    spawnPhantom([
      runnerjs,
      JSON.stringify(opts)
    ]).on('exit', function(){
      cb();
    });
  });

};
{'fraction_non_alphanumeric': 0.1761194029850746, 'fraction_numerical': 0.006823027718550106, 'mean_word_length': 3.6272189349112427, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2570662', 'n_tokens_mistral': 833, 'n_tokens_neox': 783, 'n_words': 179}