<commit_before>var fs = require('fs');
var path = require('path');
var crypto = require('crypto');
var Buffer = require('buffer').Buffer;
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
var map = require('event-stream').map;

//var FILE_DECL = /(?:href=|src=|url\()['|"]([^\s>"']+?)\?rev=([^\s>"']+?)['|"]/gi;
var FILE_DECL = /(?:templateUrl\: {0,}|href=|src=|url\()['|"]([^\s>"']+?)['|"]/gi;

var revPlugin = function revPlugin() {

  return map(function(file, cb) {

    var contents;
    var lines;
    var i, length;
    var line;
    var groups;
    var dependencyPath;
    var data, hash;
    var isNgRoute; // true if the file is contain angular-js's route

    if(!file) {
      throw new PluginError('gulp-rev-append', 'Missing file option for gulp-rev-append.');
    }

    if(!file.contents) {
      throw new PluginError('gulp-rev-append', 'Missing file.contents required for modifying files using gulp-rev-append.');
    }

    isNgRoute = file.path.indexOf('/app.js')

    contents = file.contents.toString();
    lines = contents.split('\n');
    length = lines.length;


    if (isNgRoute) {
      line = lines[0];
      result = line.match(FILE_DECL);

      for(i = 0; i < result.length; i++) {
        groups = FILE_DECL.exec(result[i]);

        console.log(groups);

        if(groups && groups.length > 1) {
          // are we an "absoulte path"? (e.g. /js/app.js)
          var normPath = path.normalize(groups[1]);
          if (normPath.indexOf(path.sep) === 0) {
            dependencyPath = path.join(file.base, normPath);
          }
          else {
            normPath = '../' + normPath;
            dependencyPath = path.resolve(path.dirname(file.path), normPath);
          }

          try {
            data = fs.readFileSync(dependencyPath);
            hash = crypto.createHash('md5');
            hash.update(data.toString(), 'utf8');
            //line = line.replace(groups[2], hash.digest('hex'));
            line = line.replace(groups[1], groups[1] + '?v=' + hash.digest('hex'));
          }
          catch(e) {
            // fail silently.
          }
        }
        FILE_DECL.lastIndex = 0;
      }
      lines[0] = line;

    } else {

      for(i = 0; i < length; i++) {
        line = lines[i];
        groups = FILE_DECL.exec(line);

        console.log(groups.length);

        if(groups && groups.length > 1) {
          // are we an "absoulte path"? (e.g. /js/app.js)<commit_msg>null异常;去掉调试日志.<commit_after>var fs = require('fs');
var path = require('path');
var crypto = require('crypto');
var Buffer = require('buffer').Buffer;
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
var map = require('event-stream').map;

//var FILE_DECL = /(?:href=|src=|url\()['|"]([^\s>"']+?)\?rev=([^\s>"']+?)['|"]/gi;
var FILE_DECL = /(?:templateUrl\: {0,}|href=|src=|url\()['|"]([^\s>"']+?)['|"]/gi;

var revPlugin = function revPlugin() {

  return map(function(file, cb) {

    var contents;
    var lines;
    var i, length;
    var line;
    var groups;
    var dependencyPath;
    var data, hash;
    var isNgRoute; // true if the file is contain angular-js's route

    if(!file) {
      throw new PluginError('gulp-rev-append', 'Missing file option for gulp-rev-append.');
    }

    if(!file.contents) {
      throw new PluginError('gulp-rev-append', 'Missing file.contents required for modifying files using gulp-rev-append.');
    }

    isNgRoute = file.path.indexOf('/app.js') > -1;

    contents = file.contents.toString();
    lines = contents.split('\n');
    length = lines.length;


    if (isNgRoute) {
      line = lines[0];
      result = line.match(FILE_DECL);

      for(i = 0; i < result.length; i++) {
        groups = FILE_DECL.exec(result[i]);

        if(groups && groups.length > 1) {
          // are we an "absoulte path"? (e.g. /js/app.js)
          var normPath = path.normalize(groups[1]);
          if (normPath.indexOf(path.sep) === 0) {
            dependencyPath = path.join(file.base, normPath);
          }
          else {
            normPath = '../' + normPath;
            dependencyPath = path.resolve(path.dirname(file.path), normPath);
          }

          try {
            data = fs.readFileSync(dependencyPath);
            hash = crypto.createHash('md5');
            hash.update(data.toString(), 'utf8');
            //line = line.replace(groups[2], hash.digest('hex'));
            line = line.replace(groups[1], groups[1] + '?v=' + hash.digest('hex'));
          }
          catch(e) {
            // fail silently.
          }
        }
        FILE_DECL.lastIndex = 0;
      }
      lines[0] = line;

    } else {

      for(i = 0; i < length; i++) {
        line = lines[i];
        groups = FILE_DECL.exec(line);

        if(groups && groups.length > 1) {
          // are we an "absoulte path"? (e.g. /js/app.js)
{'fraction_non_alphanumeric': 0.18099547511312217, 'fraction_numerical': 0.006375976964212258, 'mean_word_length': 2.237683089214381, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, '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': '6040713', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1583, 'n_words': 342}