<commit_before>var semver = require('semver');
var webpack = require('webpack');
var webpackConfig = require('./webpack.config.js');

module.exports = function(grunt) {
  var pkg = grunt.file.readJSON('package.json');
  var semVer = semver.parse(pkg.version);

  require('time-grunt')(grunt);

  // Get the minimum minor version to put into the CDN URL
  semVer.patch = 0;
  semVer.prerelease = [];
  pkg.pinnedVersion = semVer.major + '.' + semVer.minor;

  grunt.initConfig({
    pkg: pkg,
    webpack: {
      options: webpackConfig,
      "build-dev": {
        devtool: "sourcemap",
        debug: true
      }
    },
    jshint: {
      options: {
        globals: {
          console: true,
          window: true
        }
      },
      files: ['Gruntfile.js', 'src/notifier.js', 'src/util.js', 'src/xhr.js', 'src/init.js', 'src/shim.js', 'src/shimload.js']
    },
    uglify: {
      dist: {
        files: {
          'dist/<%= pkg.name %>.min.js': 'dist/<%= pkg.name %>.js',
          'dist/<%= pkg.name %>.nojson.min.js': 'dist/<%= pkg.name %>.nojson.js',
          'dist/<%= pkg.name %>.umd.min.js': 'dist/<%= pkg.name %>.umd.js',
          'dist/<%= pkg.name %>.umd.nojson.min.js': 'dist/<%= pkg.name %>.umd.nojson.js',
          'dist/<%= pkg.name %>.snippet.min.js': 'dist/<%= pkg.name %>.snippet.js',
          'dist/plugins/jquery.min.js': 'src/plugins/jquery.js'
        }
      },
      prewebpack: {
        files: {
          'vendor/json2.min.js': 'vendor/JSON-js/json2.js',
          'vendor/trace.min.js': 'vendor/TraceKit/src/trace.js'
        }
      }
    },
    replace: {
      js: {
        src: ['src/**/*.js'],
        overwrite: true,
        replacements: [
          {
            // package version
            from: /(NOTIFIER_VERSION|notifierVersion) = (["'])[0-9_\.a-zA-Z-]+(["'])/g,
            to: '$1 = $2<%= pkg.version %>$3'
          },
          {
            // jquery plugin version
            from: /(JQUERY_PLUGIN_VERSION|jqueryPluginVersion) = (["'])[0-9_\.a-zA-Z-]+(["'])/g,
            to: '$1 = $2<%= pkg.plugins.jquery.version %>$3'
          },
          {
            // default scrub fields
            from: /(DEFAULT_SCRUB_FIELDS|defaultScrubFields) = \[.+\]/g,
            to: '$1 = <%= JSON.stringify(pkg.defaults.scrubFields) %>'
          },
          {
            // default endpoint
            from: /(DEFAULT_ENDPOINT|defaultEndpoint) = (["'])[0-9_\.a-zA-Z:\/]+(["'])/g,
            to: '$1 = $2<%= pkg.defaults.endpoint %>$3'
          },
          {
            // default log level
            from: /(DEFAULT_LOG_LEVEL|defaultLogLevel) = (["'])(debug|info|warning|error|critical)(["'])/g,
            to: '$1 = $2<%= pkg.defaults.logLevel %>$4'
          },
          {
            // default min report level
            from: /(DEFAULT_REPORT_LEVEL|defaultReportLevel) = (["'])(debug|info|warning|error|critical)(["'])/g,
            to: '$1 = $2<%= pkg.defaults.reportLevel %>$4'
          },
          {
            // default min uncaught error level
            from: /(DEFAULT_UNCAUGHT_ERROR_LEVEL|defaultUncaughtErrorLevel) = (["'])(debug|info|warning|error|critical)(["'])/g,
            to: '$1 = $2<%= pkg.defaults.uncaughtErrorLevel %>$4'
          },
          {
            // default rollbar.js CDN URL
            from: /(DEFAULT_ROLLBARJS_URL|defaultRollbarJsUrl) = (["']).*(["'])/g,
            to: '$1 = $2//<%= pkg.cdn.host %>/js/v<%= pkg.pinnedVersion %>/rollbar.min.js$3'
          },
          {
            // default max items
            from: /(DEFAULT_MAX_ITEMS) = ([0-9]+)/g,
            to: '$1 = <%= pkg.defaults.maxItems %>'
          },
          {
            // default items per min
            from: /(DEFAULT_ITEMS_PER_MIN) = ([0-9]+)/g,
            to: '$1 = <%= pkg.defaults.itemsPerMin %>'
          }
        ]
      }
    },
    mocha_phantomjs: {
      test: {
        options: {
          '--web-security' : false,
          '--local-to-remote-url-access' : true,
          run: true,
          log: true,
          urls: ['http://localhost:3000/test/util.html',
                 'http://localhost:3000/test/json.html',
                 'http://localhost:3000/test/xhr.html',
                 'http://localhost:3000/test/notifier.html',
                 'http://localhost:3000/test/notifier.ratelimit.html',
                 'http://localhost:3000/test/rollbar.html',
                 'http://localhost:3000/test/shim.html',
                 'http://localhost:3000/test/shimalias.html',
                 'http://localhost:3000/test/integrations/mootools.html',
                 'http://localhost:3000/test/plugins/jquery.html'
                ]
        }
      }
    },
    /* Serves up responses to requests from the notifier */
    express: {
      test: {
        options: {
          server: './test/express',
          port: 3000
        }
      }
    },
    /* Serves up the static test .html files */
    connect: {
      test: {
        options: {
          base: '.',
          port: 3000
        }
      }
    },
    bumpup: ['package.json', 'bower.json'],
    tagrelease: {
      file: 'package.json',
      prefix: 'v',
      commit: false
    },
    'saucelabs-mocha': {
      all: {
        options: {
          urls: ['http://localhost:3000/test/rollbar.html'],
                 //'http://localhost:3000/test/shim.html',
                 //'http://localhost:3000/test/notifier.html',
                 //'http://localhost:3000/test/components.html'],
          tunnelTimeout: 5,
          build: process.env.TRAVIS_JOB_ID,
          concurrency: 3,
          browsers: browsers,
          testname: "mocha tests",
          username: process.env.SAUCE_USERNAME,
          key: process.env.SAUCE_ACCESS_KEY
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-mocha-phantomjs');
  grunt.loadNpmTasks('grunt-express');
  grunt.loadNpmTasks('grunt-contrib-connect');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-text-replace');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-bumpup');
  grunt.loadNpmTasks('grunt-tagrelease');
  grunt.loadNpmTasks('grunt-saucelabs');
  grunt.loadNpmTasks('grunt-webpack');

  grunt.registerTask('build', ['replace', 'jshint', 'uglify:prewebpack', 'webpack', 'uglify:dist']);
  grunt.registerTask('release', ['build', 'copyrelease']);

  var testjobs = ['express'];
  if (typeof process.env.SAUCE_ACCESS_KEY !== 'undefined'){
    testjobs.push('saucelabs-mocha');
  } else {
    testjobs.push('mocha_phantomjs');
  }
  grunt.registerTask('test', testjobs);

  // This will allow you to run "grunt test-debug" and then open your
  // browser to http://localhost:3000/test/XXX.html to run tests.
  grunt.registerTask('test-browser', function() {
    console.log('Open your browser to http://localhost:3000/test/rollbar.html');
    grunt.task.run('express');
    grunt.task.run('express-keepalive');
  });

  grunt.registerTask('default', ['build']);

  grunt.registerTask('bumpversion', function(type) {
    type = type ? type : 'patch';
    grunt.task.run('bumpup:' + type);
  });

  grunt.registerTask('copyrelease', function() {
    var version = pkg.version;

    var rollbarJs = 'dist/rollbar.js';
    var releaseRollbarJs = 'release/rollbar-' + version + '.js';

    var rollbarMinJs = 'dist/rollbar.min.js';
    var releaseRollbarMinJs = 'release/rollbar-' + version + '.min.js';
    
    var rollbarNojsonJs = 'dist/rollbar.nojson.js';
    var releaseRollbarNojsonJs = 'release/rollbar-' + version + '.nojson.js';

    var rollbarNojsonMinJs = 'dist/rollbar.nojson.min.js';
    var releaseRollbarNojsonMinJs = 'release/rollbar-' + version + '.nojson.min.js';

    var rollbarAmdJs = 'dist/rollbar.amd.js';
    var releaseRollbarAmdJs = 'release/rollbar-' + version + '.amd.js';

    var rollbarAmdMinJs = 'dist/rollbar.amd.min.js';
    var releaseRollbarAmdMinJs = 'release/rollbar-' + version + '.amd.min.js';

    var rollbarCommonJs = 'dist/rollbar.commonjs.js';
    var releaseRollbarCommonJs = 'release/rollbar-' + version + '.commonjs.js';

    var rollbarCommonMinJs = 'dist/rollbar.commonjs.min.js';
    var releaseRollbarCommonMinJs = 'release/rollbar-' + version + '.commonjs.min.js';

    grunt.file.copy(rollbarJs, releaseRollbarJs);
    grunt.file.copy(rollbarMinJs, releaseRollbarMinJs);
    grunt.file.copy(rollbarNojsonJs, releaseRollbarNojsonJs);
    grunt.file.copy(rollbarNojsonMinJs, releaseRollbarNojsonMinJs);
    grunt.file.copy(rollbarAmdJs, releaseRollbarAmdJs);
    grunt.file.copy(rollbarAmdMinJs, releaseRollbarAmdMinJs);
    grunt.file.copy(rollbarCommonJs, releaseRollbarCommonJs);
    grunt.file.copy(rollbarCommonMinJs, releaseRollbarCommonMinJs);

    //grunt.task.run('tagrelease');
  });
};


var browsers = [
  {
    browserName: 'firefox',
    version: '19',
    platform: 'XP'
  },
  {
    browserName: 'chrome',
    platform: 'XP'
  },
  {
    browserName: 'chrome',
    platform: 'linux'
  },
  {
    browserName: 'internet explorer',
    platform: 'WIN8',
    version: '10'
  },
  {
    browserName: 'internet explorer',
    platform: 'VISTA',
    version: '9'
  },
  {
    browserName: 'internet explorer',
    platform: 'XP',
    version: '8'
  },
  {
    browserName: 'opera',
    platform: 'Windows 2008',
    version: '12'
  }
];

<commit_msg>Execute webpack task before tests.<commit_after>var semver = require('semver');
var webpack = require('webpack');
var webpackConfig = require('./webpack.config.js');

module.exports = function(grunt) {
  var pkg = grunt.file.readJSON('package.json');
  var semVer = semver.parse(pkg.version);

  require('time-grunt')(grunt);

  // Get the minimum minor version to put into the CDN URL
  semVer.patch = 0;
  semVer.prerelease = [];
  pkg.pinnedVersion = semVer.major + '.' + semVer.minor;

  grunt.initConfig({
    pkg: pkg,
    webpack: {
      options: webpackConfig,
      "build-dev": {
        devtool: "sourcemap",
        debug: true
      }
    },
    jshint: {
      options: {
        globals: {
          console: true,
          window: true
        }
      },
      files: ['Gruntfile.js', 'src/notifier.js', 'src/util.js', 'src/xhr.js', 'src/init.js', 'src/shim.js', 'src/shimload.js']
    },
    uglify: {
      dist: {
        files: {
          'dist/<%= pkg.name %>.min.js': 'dist/<%= pkg.name %>.js',
          'dist/<%= pkg.name %>.nojson.min.js': 'dist/<%= pkg.name %>.nojson.js',
          'dist/<%= pkg.name %>.umd.min.js': 'dist/<%= pkg.name %>.umd.js',
          'dist/<%= pkg.name %>.umd.nojson.min.js': 'dist/<%= pkg.name %>.umd.nojson.js',
          'dist/<%= pkg.name %>.snippet.min.js': 'dist/<%= pkg.name %>.snippet.js',
          'dist/plugins/jquery.min.js': 'src/plugins/jquery.js'
        }
      },
      prewebpack: {
        files: {
          'vendor/json2.min.js': 'vendor/JSON-js/json2.js',
          'vendor/trace.min.js': 'vendor/TraceKit/src/trace.js'
        }
      }
    },
    replace: {
      js: {
        src: ['src/**/*.js'],
        overwrite: true,
        replacements: [
          {
            // package version
            from: /(NOTIFIER_VERSION|notifierVersion) = (["'])[0-9_\.a-zA-Z-]+(["'])/g,
            to: '$1 = $2<%= pkg.version %>$3'
          },
          {
            // jquery plugin version
            from: /(JQUERY_PLUGIN_VERSION|jqueryPluginVersion) = (["'])[0-9_\.a-zA-Z-]+(["'])/g,
            to: '$1 = $2<%= pkg.plugins.jquery.version %>$3'
          },
          {
            // default scrub fields
            from: /(DEFAULT_SCRUB_FIELDS|defaultScrubFields) = \[.+\]/g,
            to: '$1 = <%= JSON.stringify(pkg.defaults.scrubFields) %>'
          },
          {
            // default endpoint
            from: /(DEFAULT_ENDPOINT|defaultEndpoint) = (["'])[0-9_\.a-zA-Z:\/]+(["'])/g,
            to: '$1 = $2<%= pkg.defaults.endpoint %>$3'
          },
          {
            // default log level
            from: /(DEFAULT_LOG_LEVEL|defaultLogLevel) = (["'])(debug|info|warning|error|critical)(["'])/g,
            to: '$1 = $2<%= pkg.defaults.logLevel %>$4'
          },
          {
            // default min report level
            from: /(DEFAULT_REPORT_LEVEL|defaultReportLevel) = (["'])(debug|info|warning|error|critical)(["'])/g,
            to: '$1 = $2<%= pkg.defaults.reportLevel %>$4'
          },
          {
            // default min uncaught error level
            from: /(DEFAULT_UNCAUGHT_ERROR_LEVEL|defaultUncaughtErrorLevel) = (["'])(debug|info|warning|error|critical)(["'])/g,
            to: '$1 = $2<%= pkg.defaults.uncaughtErrorLevel %>$4'
          },
          {
            // default rollbar.js CDN URL
            from: /(DEFAULT_ROLLBARJS_URL|defaultRollbarJsUrl) = (["']).*(["'])/g,
            to: '$1 = $2//<%= pkg.cdn.host %>/js/v<%= pkg.pinnedVersion %>/rollbar.min.js$3'
          },
          {
            // default max items
            from: /(DEFAULT_MAX_ITEMS) = ([0-9]+)/g,
            to: '$1 = <%= pkg.defaults.maxItems %>'
          },
          {
            // default items per min
            from: /(DEFAULT_ITEMS_PER_MIN) = ([0-9]+)/g,
            to: '$1 = <%= pkg.defaults.itemsPerMin %>'
          }
        ]
      }
    },
    mocha_phantomjs: {
      test: {
        options: {
          '--web-security' : false,
          '--local-to-remote-url-access' : true,
          run: true,
          log: true,
          urls: ['http://localhost:3000/test/util.html',
                 'http://localhost:3000/test/json.html',
                 'http://localhost:3000/test/xhr.html',
                 'http://localhost:3000/test/notifier.html',
                 'http://localhost:3000/test/notifier.ratelimit.html',
                 'http://localhost:3000/test/rollbar.html',
                 'http://localhost:3000/test/shim.html',
                 'http://localhost:3000/test/shimalias.html',
                 'http://localhost:3000/test/integrations/mootools.html',
                 'http://localhost:3000/test/plugins/jquery.html'
                ]
        }
      }
    },
    /* Serves up responses to requests from the notifier */
    express: {
      test: {
        options: {
          server: './test/express',
          port: 3000
        }
      }
    },
    /* Serves up the static test .html files */
    connect: {
      test: {
        options: {
          base: '.',
          port: 3000
        }
      }
    },
    bumpup: ['package.json', 'bower.json'],
    tagrelease: {
      file: 'package.json',
      prefix: 'v',
      commit: false
    },
    'saucelabs-mocha': {
      all: {
        options: {
          urls: ['http://localhost:3000/test/rollbar.html'],
                 //'http://localhost:3000/test/shim.html',
                 //'http://localhost:3000/test/notifier.html',
                 //'http://localhost:3000/test/components.html'],
          tunnelTimeout: 5,
          build: process.env.TRAVIS_JOB_ID,
          concurrency: 3,
          browsers: browsers,
          testname: "mocha tests",
          username: process.env.SAUCE_USERNAME,
          key: process.env.SAUCE_ACCESS_KEY
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-mocha-phantomjs');
  grunt.loadNpmTasks('grunt-express');
  grunt.loadNpmTasks('grunt-contrib-connect');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-text-replace');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-bumpup');
  grunt.loadNpmTasks('grunt-tagrelease');
  grunt.loadNpmTasks('grunt-saucelabs');
  grunt.loadNpmTasks('grunt-webpack');

  grunt.registerTask('build', ['replace', 'jshint', 'uglify:prewebpack', 'webpack', 'uglify:dist']);
  grunt.registerTask('release', ['build', 'copyrelease']);

  var testjobs = ['webpack', 'express'];
  if (typeof process.env.SAUCE_ACCESS_KEY !== 'undefined'){
    testjobs.push('saucelabs-mocha');
  } else {
    testjobs.push('mocha_phantomjs');
  }
  grunt.registerTask('test', testjobs);

  // This will allow you to run "grunt test-debug" and then open your
  // browser to http://localhost:3000/test/XXX.html to run tests.
  grunt.registerTask('test-browser', function() {
    console.log('Open your browser to http://localhost:3000/test/rollbar.html');
    grunt.task.run('express');
    grunt.task.run('express-keepalive');
  });

  grunt.registerTask('default', ['build']);

  grunt.registerTask('bumpversion', function(type) {
    type = type ? type : 'patch';
    grunt.task.run('bumpup:' + type);
  });

  grunt.registerTask('copyrelease', function() {
    var version = pkg.version;

    var rollbarJs = 'dist/rollbar.js';
    var releaseRollbarJs = 'release/rollbar-' + version + '.js';

    var rollbarMinJs = 'dist/rollbar.min.js';
    var releaseRollbarMinJs = 'release/rollbar-' + version + '.min.js';
    
    var rollbarNojsonJs = 'dist/rollbar.nojson.js';
    var releaseRollbarNojsonJs = 'release/rollbar-' + version + '.nojson.js';

    var rollbarNojsonMinJs = 'dist/rollbar.nojson.min.js';
    var releaseRollbarNojsonMinJs = 'release/rollbar-' + version + '.nojson.min.js';

    var rollbarAmdJs = 'dist/rollbar.amd.js';
    var releaseRollbarAmdJs = 'release/rollbar-' + version + '.amd.js';

    var rollbarAmdMinJs = 'dist/rollbar.amd.min.js';
    var releaseRollbarAmdMinJs = 'release/rollbar-' + version + '.amd.min.js';

    var rollbarCommonJs = 'dist/rollbar.commonjs.js';
    var releaseRollbarCommonJs = 'release/rollbar-' + version + '.commonjs.js';

    var rollbarCommonMinJs = 'dist/rollbar.commonjs.min.js';
    var releaseRollbarCommonMinJs = 'release/rollbar-' + version + '.commonjs.min.js';

    grunt.file.copy(rollbarJs, releaseRollbarJs);
    grunt.file.copy(rollbarMinJs, releaseRollbarMinJs);
    grunt.file.copy(rollbarNojsonJs, releaseRollbarNojsonJs);
    grunt.file.copy(rollbarNojsonMinJs, releaseRollbarNojsonMinJs);
    grunt.file.copy(rollbarAmdJs, releaseRollbarAmdJs);
    grunt.file.copy(rollbarAmdMinJs, releaseRollbarAmdMinJs);
    grunt.file.copy(rollbarCommonJs, releaseRollbarCommonJs);
    grunt.file.copy(rollbarCommonMinJs, releaseRollbarCommonMinJs);

    //grunt.task.run('tagrelease');
  });
};


var browsers = [
  {
    browserName: 'firefox',
    version: '19',
    platform: 'XP'
  },
  {
    browserName: 'chrome',
    platform: 'XP'
  },
  {
    browserName: 'chrome',
    platform: 'linux'
  },
  {
    browserName: 'internet explorer',
    platform: 'WIN8',
    version: '10'
  },
  {
    browserName: 'internet explorer',
    platform: 'VISTA',
    version: '9'
  },
  {
    browserName: 'internet explorer',
    platform: 'XP',
    version: '8'
  },
  {
    browserName: 'opera',
    platform: 'Windows 2008',
    version: '12'
  }
];


{'fraction_non_alphanumeric': 0.17520415738678544, 'fraction_numerical': 0.013150917382543217, 'mean_word_length': 2.2155157715260017, 'pattern_counts': {'":': 2, '<': 45, '<?xml version=': 0, '>': 45, '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': '1113860', 'n_tokens_mistral': 6715, 'n_tokens_neox': 6349, 'n_words': 1007}