<commit_before>// grunt-merge-data
// Copyright (c) 2013 - 2014 <NAME>
// Licensed under the MIT license

'use strict';

var path = require('path');

var chalk = require('chalk');
var objectAssign = require('object-assign');

module.exports = grunt => {
  function mergeFileData(sources) {
    var data = {};
    sources.filter(filePath => {
      // Warn on and remove invalid source files (if nonull was set)
      if (!grunt.file.exists(filePath)) {
        grunt.log.warn(`Source file ${filePath} not found.`);
        return false;
      } else {
        return true;
      }
    }).forEach(filePath => {
      var basename = path.basename(filePath, path.extname(filePath));
      var ext = path.extname(filePath).toLowerCase();

      if (ext === '.json') {
        data[basename] = grunt.file.readJSON(filePath);
      } else if (ext === '.yml' || ext === '.yaml') {
        data[basename] = grunt.file.readYAML(filePath);
      } else {
        try {
          data[basename] = grunt.file.readJSON(filePath);
        } catch (e) {
          data[basename] = grunt.file.readYAML(filePath);
        }
      }
    });

    return data;
  }

  grunt.registerMultiTask(
    'merge_data',
    'Merge multiple data into a file or Grunt config.',
    function mergeDataTask() {
      var options = this.options({
        data: null,
        space: null,
        asConfig: false
      });

      this.files.forEach(file => {
        var data  = mergeFileData(file.src);

        if (options.data) {
          if (typeof options.data === 'function') {
            objectAssign(data, options.data(data));
          } else {
            objectAssign(data, options.data);
          }
        }

        var targetConfig;
        if (typeof options.asConfig === 'string') {
          targetConfig = options.asConfig;

        // Accept array of property name parts
        } else if (Array.isArray(options.asConfig)) {
          targetConfig = options.asConfig.join('.');

        } else if (options.asConfig === true) {
          targetConfig = grunt.task.current.nameArgs
          .replace(':', '.') + '.context';
        }

        if (targetConfig) {
          grunt.config(targetConfig, data);
          grunt.log.writeln(`Config ${chalk.green(targetConfig)} updated.`);
        }

        // Write the destination file if 'dest' is specified
        if (file.dest) {
          grunt.file.write(
            file.dest,
            JSON.stringify(data, null, options.space)
          );
          // Print a success message
          grunt.log.writeln(`File ${chalk.cyan(file.dest)} created.`);

        } else if (!targetConfig) {
          // when the task does nothing
          grunt.log.warn('Neither destination path or config specified.');
        }
      });<commit_msg>tweak comments<commit_after>// grunt-merge-data
// Copyright (c) 2013 - 2015 <NAME>
// Licensed under the MIT license

'use strict';

var path = require('path');

var chalk = require('chalk');
var objectAssign = require('object-assign');

module.exports = grunt => {
  function mergeFileData(sources) {
    var data = {};
    sources.filter(filePath => {
      // Warn on and remove invalid source files (if nonull was set)
      if (!grunt.file.exists(filePath)) {
        grunt.log.warn(`Source file ${filePath} not found.`);
        return false;
      } else {
        return true;
      }
    }).forEach(filePath => {
      var basename = path.basename(filePath, path.extname(filePath));
      var ext = path.extname(filePath).toLowerCase();

      if (ext === '.json') {
        data[basename] = grunt.file.readJSON(filePath);
      } else if (ext === '.yml' || ext === '.yaml') {
        data[basename] = grunt.file.readYAML(filePath);
      } else {
        try {
          data[basename] = grunt.file.readJSON(filePath);
        } catch (e) {
          data[basename] = grunt.file.readYAML(filePath);
        }
      }
    });

    return data;
  }

  grunt.registerMultiTask(
    'merge_data',
    'Merge multiple data into a file or Grunt config.',
    function mergeDataTask() {
      var options = this.options({
        data: null,
        space: null,
        asConfig: false
      });

      this.files.forEach(file => {
        var data  = mergeFileData(file.src);

        if (options.data) {
          if (typeof options.data === 'function') {
            objectAssign(data, options.data(data));
          } else {
            objectAssign(data, options.data);
          }
        }

        var targetConfig;
        if (typeof options.asConfig === 'string') {
          targetConfig = options.asConfig;

        // Accept an array of property name parts
        } else if (Array.isArray(options.asConfig)) {
          targetConfig = options.asConfig.join('.');

        } else if (options.asConfig === true) {
          targetConfig = grunt.task.current.nameArgs
          .replace(':', '.') + '.context';
        }

        if (targetConfig) {
          grunt.config(targetConfig, data);
          grunt.log.writeln(`Config ${chalk.green(targetConfig)} updated.`);
        }

        // Write the destination file if 'dest' is specified
        if (file.dest) {
          grunt.file.write(
            file.dest,
            JSON.stringify(data, null, options.space)
          );
          // Print a success message
          grunt.log.writeln(`File ${chalk.cyan(file.dest)} created.`);

        } else if (!targetConfig) {
          // when the task does nothing
          grunt.log.warn('Neither destination path or config specified.');
        }
      });
{'fraction_non_alphanumeric': 0.13817920115149335, 'fraction_numerical': 0.0028787333573227778, 'mean_word_length': 2.013008130081301, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '3663133', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1613, 'n_words': 384}