<commit_before>/*
 * grunt-hashres
 * https://github.com/luismahou/grunt-hashres
 *
 * Copyright (c) 2012 Luismahou
 * Licensed under the MIT license.
 */

module.exports = function(grunt) {

  // Please see the grunt documentation for more information regarding task and
  // helper creation: https://github.com/gruntjs/grunt/blob/master/docs/toc.md

  // ==========================================================================
  // TASKS
  // ==========================================================================

  grunt.registerTask('hashres', 'Your task description goes here.', function() {
    grunt.log.write(grunt.helper('hashres'));
  });

  // ==========================================================================
  // HELPERS
  // ==========================================================================

  grunt.registerHelper('hashres', function() {
    return 'hashres!!!';
  });

};
<commit_msg>Removing sample grunt tasks.<commit_after>/*
 * grunt-hashres
 * https://github.com/luismahou/grunt-hashres
 *
 * Copyright (c) 2012 Luismahou
 * Licensed under the MIT license.
 */

module.exports = function(grunt) {

  // Loading necessary modules
  var fs = require('fs'),
      path = require('path'),
      crypto = require('crypto');

  grunt.registerMultiTask(
      'hashres',
      'Hashes your resources and updates the files that refer to them',
      function() {
    // Required properties: 'files' and 'dest'
    this.requiresConfig(this.name + '.' + this.target + '.files');
    this.requiresConfig(this.name + '.' + this.target + '.dest');
    grunt.helper('hashAndSub', this.data.files, this.data.dest, this.data.encoding);
  });
  grunt.registerHelper('hashAndSub', function(files, dest, encoding) {
    var nameToHashedName = {};
    encoding = (encoding || 'utf8');
    grunt.log.debug('Using encoding ' + encoding);

    // Converting the file to an array if is only one
    files = Array.isArray(files) ? files : [files];
    // Renaming the files using a unique name
    grunt.file.expand(files).forEach(function(f) {
      var md5 = grunt.helper('md5', f),
          fileName = path.basename(f),
          lastIndex = fileName.lastIndexOf('.'),
          renamed = [
            md5.slice(0, 8), // Starging the file with the hash that would make it unique
            fileName.slice(0, lastIndex), // Real name of the file
            'cache', // Good to have to ease apache configuration to enable 'perfect caching'
            fileName.slice(lastIndex + 1, fileName.length) // Extension of the file
          ].join('.');

      // Mapping the original name with hashed one for later use.
      nameToHashedName[fileName] = renamed;

      // Renaming the file
      fs.renameSync(f, path.resolve(path.dirname(f), renamed));
      grunt.log.write(f + ' ').ok(renamed);
    });

    // Substituting references to the given files with the hashed ones.
    var destContents = fs.readFileSync(dest, encoding);
    for (var name in nameToHashedName) {
      grunt.log.debug('Substituting ' + name + ' by ' + nameToHashedName[name]);
      destContents = destContents.replace(name, nameToHashedName[name]);
    }
    grunt.log.debug('Saving the updated contents of the destination file');
    fs.writeFileSync(dest, destContents, encoding);
  });
  // **md5** helper is a basic wrapper around crypto.createHash, with
  // given `algorithm` and `encoding`. Both are optional and defaults to
  // `md5` and `hex` values.
  grunt.registerHelper('md5', function(filepath, algorithm, encoding) {
    algorithm = algorithm || 'md5';
    encoding = encoding || 'hex';
    var hash = crypto.createHash(algorithm);
    hash.update(grunt.file.read(filepath));
    grunt.log.verbose.write('Hashing ' + filepath + '...');
    return hash.digest(encoding);
  });

};

{'fraction_non_alphanumeric': 0.20784004209418575, 'fraction_numerical': 0.005261773217574322, 'mean_word_length': 3.345142857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, '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': '3551727', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1062, 'n_words': 279}