<commit_before>/* eslint-env node */

'use strict';

var _ = require('lodash');
var gulp = require('gulp');
var gutil = require('gulp-util');
var runSequence = require('run-sequence');


// Task sequences
//------------------------------------------------------------------------------

gulp.task('dev', function(done) {
  runSequence('webpack:dev', 'lint', 'test', done);
});

gulp.task('dist', function(done) {
  runSequence('webpack:dist', 'uglify', 'headers', done);
});

gulp.task('default', function(done) {
  runSequence('dev', 'dist', done);
});


// Config
//------------------------------------------------------------------------------

var config = {};

// Paths
config.path = {};
config.path.root = require('path').resolve(__dirname) + '/';
config.path.dist = config.path.root + 'dist/';
config.path.test = config.path.root + 'test/';
config.path.lib = config.path.root + 'lib/';

// Package
config.pkg = require(config.path.root + 'package.json');
config.lib = {
  'entry': config.path.root + config.pkg.main,
  'exports': 'Viewport',
  'file': 'viewport.js', // Output file name
  'sources': [
    config.path.lib,
    config.path.root + 'node_modules/'
  ]
};

// Test
config.karma = {
  'configFile': config.path.root + 'karma.conf.js',
  'files': [
    {'pattern': config.path.test + 'vendor/**/*.js', 'watched': false},
    config.path.test + 'lib.js',
    config.path.test + 'lib/**/*.js'
  ],
  'preprocessors': {}
};
config.karma.preprocessors[config.path.test + 'lib.js'] = ['coverage'];


// Logging
//------------------------------------------------------------------------------

var notify = require('gulp-notify');

var logger = {
  'error': function(error) {
    notify.onError({
      'title': 'Error (' + error.plugin + ')',
      'message': logger.format(error.message)
    }).apply(this, arguments);

    this.emit('end'); // Prevent gulp hanging on task
  },
  'format': function() {
    return [].slice.call(arguments).join(' ').replace(config.path.root, '', 'g');
  },
  'log': function() {
    gutil.log.call(null, logger.format.apply(null, arguments));
  }
};


// Test
//------------------------------------------------------------------------------

var spawn = require('child_process').spawn;

var startKarma = function(done, options) {
  if (global.isKarmaRunning) {
    return;
  }
  global.isKarmaRunning = true;

  var child = spawn('node', [
    config.path.test + 'karma.js',
    JSON.stringify(_.assign({}, config.karma, options))
  ], {'stdio': 'inherit'});

  child.on('exit', done);
};

gulp.task('test', function(done) {
  startKarma(done, {'singleRun': true, 'autoWatch': false});
});

gulp.task('test:sauce', function(done) {
  // Sauce Labs is disabled by default (unless running on Travis)
  // `test:sauce` can be used to test locally with Sauce Labs (requires SAUCE_USERNAME and SAUCE_ACCESS_KEY to be exported in shell)
  process.env.FORCE_SAUCE = true;
  startKarma(done, {'singleRun': true, 'autoWatch': false});
});


// Webpack
//------------------------------------------------------------------------------

var webpack = require('webpack');

var runWebpack = function(done, options) {
  var webpackConfig = {
    'entry': [config.lib.entry],
    'output': {
      'library': config.lib.exports
    },
    'resolve': {'root': config.lib.sources}
  };

  webpack(_.merge({}, webpackConfig, options), function(error, stats) {
    var end = function() {
      done(+!!error);
    };

    if (stats.compilation.errors.length > 0) {
      error = true;
      logger.error.call(this, new gutil.PluginError('webpack', {
        'message': stats.compilation.errors[0].message
      }));
    }

    if (global.isWatching) {
      if (!error) {
        runSequence('lint', function() {
          startKarma(function(exitCode) {
            end();
            global.watchDone(exitCode);
          });
        });
      }
    } else {
      end();
    }
  }.bind(this));<commit_msg>Fail on webpack compilation error/warning<commit_after>/* eslint-env node */

'use strict';

var _ = require('lodash');
var gulp = require('gulp');
var gutil = require('gulp-util');
var runSequence = require('run-sequence');


// Task sequences
//------------------------------------------------------------------------------

gulp.task('dev', function(done) {
  runSequence('webpack:dev', 'lint', 'test', done);
});

gulp.task('dist', function(done) {
  runSequence('webpack:dist', 'uglify', 'headers', done);
});

gulp.task('default', function(done) {
  runSequence('dev', 'dist', done);
});


// Config
//------------------------------------------------------------------------------

var config = {};

// Paths
config.path = {};
config.path.root = require('path').resolve(__dirname) + '/';
config.path.dist = config.path.root + 'dist/';
config.path.test = config.path.root + 'test/';
config.path.lib = config.path.root + 'lib/';

// Package
config.pkg = require(config.path.root + 'package.json');
config.lib = {
  'entry': config.path.root + config.pkg.main,
  'exports': 'Viewport',
  'file': 'viewport.js', // Output file name
  'sources': [
    config.path.lib,
    config.path.root + 'node_modules/'
  ]
};

// Test
config.karma = {
  'configFile': config.path.root + 'karma.conf.js',
  'files': [
    {'pattern': config.path.test + 'vendor/**/*.js', 'watched': false},
    config.path.test + 'lib.js',
    config.path.test + 'lib/**/*.js'
  ],
  'preprocessors': {}
};
config.karma.preprocessors[config.path.test + 'lib.js'] = ['coverage'];


// Logging
//------------------------------------------------------------------------------

var notify = require('gulp-notify');

var logger = {
  'error': function(error) {
    notify.onError({
      'title': 'Error (' + error.plugin + ')',
      'message': logger.format(error.message)
    }).apply(this, arguments);

    this.emit('end'); // Prevent gulp hanging on task
  },
  'format': function() {
    return [].slice.call(arguments).join(' ').replace(config.path.root, '', 'g');
  },
  'log': function() {
    gutil.log.call(null, logger.format.apply(null, arguments));
  },
  'success': function(plugin, message) {
    gulp.src('').pipe(notify({ // gulp.src is a hack to get pipes working w/out a real stream
      'title': '✅  ' + plugin,
      'message': 'OK: ' + logger.format(message)
    }));
  }
};


// Test
//------------------------------------------------------------------------------

var spawn = require('child_process').spawn;

var startKarma = function(done, options) {
  if (global.isKarmaRunning) {
    return;
  }
  global.isKarmaRunning = true;

  var child = spawn('node', [
    config.path.test + 'karma.js',
    JSON.stringify(_.assign({}, config.karma, options))
  ], {'stdio': 'inherit'});

  child.on('exit', done);
};

gulp.task('test', function(done) {
  startKarma(done, {'singleRun': true, 'autoWatch': false});
});

gulp.task('test:sauce', function(done) {
  // Sauce Labs is disabled by default (unless running on Travis)
  // `test:sauce` can be used to test locally with Sauce Labs (requires SAUCE_USERNAME and SAUCE_ACCESS_KEY to be exported in shell)
  process.env.FORCE_SAUCE = true;
  startKarma(done, {'singleRun': true, 'autoWatch': false});
});


// Webpack
//------------------------------------------------------------------------------

var webpack = require('webpack');

var runWebpack = function(done, options) {
  var webpackConfig = {
    'entry': [config.lib.entry],
    'output': {
      'library': config.lib.exports
    },
    'resolve': {'root': config.lib.sources}
  };

  webpack(_.merge({}, webpackConfig, options), function(error, stats) {
    var end;

    if (stats.hasErrors) {
      error = stats.compilation.errors[0];
    } else if (stats.hasWarnings) {
      error = stats.compilation.warnings[0];
    }

    if (error) {
      logger.error.call(this, new gutil.PluginError('webpack', error.error));
    } else {
      logger.success('webpack', stats.compilation.outputOptions.path + stats.compilation.outputOptions.filename);
    }

    end = function() {
      done(+!!error);
    };

    if (global.isWatching) {
      if (!error) {
        runSequence('lint', function() {
          startKarma(function(exitCode) {
            end();
            global.watchDone(exitCode);
          });
        });
      }
    } else {
      end();
    }
  }.bind(this));
{'fraction_non_alphanumeric': 0.27076072587429395, 'fraction_numerical': 0.00048071145295036654, 'mean_word_length': 2.2495119094103866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '45099', 'n_tokens_mistral': 2623, 'n_tokens_neox': 2564, 'n_words': 517}