<commit_before>"use strict";

var fs = require('fs');
var path = require('path');
var WrapUp = require('wrapup/lib/wrapup');
var AMDOne = require('wrapup/lib/output/amdOneFile');
var forOwn = require('prime/object/forOwn');

function pad(n) {
  return String(n < 10 ? ('0' + n) : n);
}

module.exports = function(grunt) {

  grunt.registerMultiTask('wrapup-amd', 'Build Partition JS', function() {
    var done = this.async();
    var args = this.data;

    if (!args.output && args.watch) {
      grunt.log.error('The output option is required');
      return;
    }

    var amd = new AMDOne();
    var wrup = new WrapUp();
    if (Array.isArray(args.require)) {
      args.require.forEach(function(file) {
        file = path.resolve(process.cwd(), file);
        wrup.require(file);
      });
    } else {
      for (var name in args.require) {
        var r = args.require[name];
        var file = typeof r == 'string' ? r : name;
        file = path.resolve(process.cwd(), file);
        if (typeof r == 'string') wrup.require(name, file);
        else wrup.require(file);
      }
    }

    var _path = args.path || process.cwd();

    if (args.map) {
      var map = JSON.parse(fs.readFileSync(args.map));
      forOwn(map, function(files) {
        files.forEach(function(file) {
          wrup.require(_path + '/' + file);
        });
      });
    }

    amd.set('output', args.output);
    amd.set('compress', args.compress);
    amd.set('path', _path);
    amd.set('sourcemap', args.sourceMap);
    amd.set('sourcemapURL', args.sourceMapUrl);
    amd.set('sourcemapRoot', args.sourceMapRoot);
    wrup.scanner.set('sourcemap', args.sourceMap);
    amd.set('ast', args.ast);
    wrup.withOutput(amd);
    wrup.on('change', function(file) {
      grunt.log.writeln('=> ' + path.relative(process.cwd(), file) + " was changed");
    });
    amd.on('output', function(file) {
      var d = new Date();
      var time = d.getHours() + ":" + pad(d.getMinutes()) + ":" + pad(d.getSeconds());
      grunt.log.ok("[" + time + "] The file " + path.relative(_path, file) + " has been written");
    });
    if (args.watch) wrup.watch(function() {});
    else wrup.up(done);
  });

};<commit_msg>Add error reporting to the amd watch.<commit_after>"use strict";

var fs = require('fs');
var path = require('path');
var WrapUp = require('wrapup/lib/wrapup');
var AMDOne = require('wrapup/lib/output/amdOneFile');
var forOwn = require('prime/object/forOwn');

function pad(n) {
  return String(n < 10 ? ('0' + n) : n);
}

module.exports = function(grunt) {

  grunt.registerMultiTask('wrapup-amd', 'Build Partition JS', function() {
    var done = this.async();
    var args = this.data;

    if (!args.output && args.watch) {
      grunt.log.error('The output option is required');
      return;
    }

    var amd = new AMDOne();
    var wrup = new WrapUp();
    if (Array.isArray(args.require)) {
      args.require.forEach(function(file) {
        file = path.resolve(process.cwd(), file);
        wrup.require(file);
      });
    } else {
      for (var name in args.require) {
        var r = args.require[name];
        var file = typeof r == 'string' ? r : name;
        file = path.resolve(process.cwd(), file);
        if (typeof r == 'string') wrup.require(name, file);
        else wrup.require(file);
      }
    }

    var _path = args.path || process.cwd();

    if (args.map) {
      var map = JSON.parse(fs.readFileSync(args.map));
      forOwn(map, function(files) {
        files.forEach(function(file) {
          wrup.require(_path + '/' + file);
        });
      });
    }

    amd.set('output', args.output);
    amd.set('compress', args.compress);
    amd.set('path', _path);
    amd.set('sourcemap', args.sourceMap);
    amd.set('sourcemapURL', args.sourceMapUrl);
    amd.set('sourcemapRoot', args.sourceMapRoot);
    wrup.scanner.set('sourcemap', args.sourceMap);
    amd.set('ast', args.ast);
    wrup.withOutput(amd);
    wrup.on('change', function(file) {
      grunt.log.writeln('=> ' + path.relative(process.cwd(), file) + " was changed");
    });
    amd.on('output', function(file) {
      var d = new Date();
      var time = d.getHours() + ":" + pad(d.getMinutes()) + ":" + pad(d.getSeconds());
      grunt.log.ok("[" + time + "] The file " + path.relative(_path, file) + " has been written");
    });
    if (args.watch) wrup.watch(function(err) {
      if (err) grunt.log.error(err);
    });
    else wrup.up(done);
  });

};
{'fraction_non_alphanumeric': 0.18507730226305175, 'fraction_numerical': 0.0013443871835088505, 'mean_word_length': 2.77027027027027, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, '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': '4077702', 'n_tokens_mistral': 1539, 'n_tokens_neox': 1508, 'n_words': 313}