<commit_before>var outputFileSync = require("output-file-sync");
var chokidar       = require("chokidar");
var path           = require("path");
var util           = require("./util");
var fs             = require("fs");
var _              = require("lodash");

module.exports = function (commander, filenames, opts) {
  if (commander.sourceMapsInline) {
    opts.sourceMap = "inline";
  }

  var write = function (src, relative) {
    var dest = path.join(commander.outDir, relative);

    var data = util.compile(src, { sourceMapName: dest });

    if (commander.sourceMaps) {
      var mapLoc = dest + ".map";
      data.code = util.addSourceMappingUrl(data.code, mapLoc);
      outputFileSync(mapLoc, JSON.stringify(data.map));
    }

    outputFileSync(dest, data.code);

    console.log(src + " -> " + dest);
  };

  var handle = function (filename) {
    if (!fs.existsSync(filename)) return;

    var stat = fs.statSync(filename);

    if (stat.isDirectory(filename)) {
      var dirname = filename;

      _.each(util.readdirFilter(dirname), function (filename) {
        write(path.join(dirname, filename), filename);
      });
    } else {
      write(filename, filename);
    }
  };

  _.each(filenames, handle);

  if (commander.watch) {
    _.each(filenames, function (dirname) {
      var watcher = chokidar.watch(dirname, {
        persistent: true,
        ignoreInitial: true
      });

      _.each(["add", "change"], function (type) {
        watcher.on(type, function (filename) {
          // chop off the dirname plus the path separator
          var relative = filename.slice(dirname.length + 1);

          console.log(type, filename);
          write(filename, relative);
        });
      });
    });
  }
};<commit_msg>improved relative resolution handling for bin/6to5 - closes #643<commit_after>var outputFileSync = require("output-file-sync");
var chokidar       = require("chokidar");
var path           = require("path");
var util           = require("./util");
var fs             = require("fs");
var _              = require("lodash");

module.exports = function (commander, filenames, opts) {
  if (commander.sourceMapsInline) {
    opts.sourceMap = "inline";
  }

  var write = function (src, relative) {
    var dest = path.join(commander.outDir, relative);

    var data = util.compile(src, { sourceMapName: dest });

    if (commander.sourceMaps) {
      var mapLoc = dest + ".map";
      data.code = util.addSourceMappingUrl(data.code, mapLoc);
      outputFileSync(mapLoc, JSON.stringify(data.map));
    }

    outputFileSync(dest, data.code);

    console.log(src + " -> " + dest);
  };

  var handle = function (filename) {
    if (!fs.existsSync(filename)) return;

    var stat = fs.statSync(filename);

    if (stat.isDirectory(filename)) {
      var dirname = filename;

      _.each(util.readdirFilter(dirname), function (filename) {
        write(path.join(dirname, filename), filename);
      });
    } else {
      write(filename, filename);
    }
  };

  _.each(filenames, handle);

  if (commander.watch) {
    _.each(filenames, function (dirname) {
      var watcher = chokidar.watch(dirname, {
        persistent: true,
        ignoreInitial: true
      });

      _.each(["add", "change"], function (type) {
        watcher.on(type, function (filename) {
          var relative = path.relative(dirname, filename) || filename;
          write(filename, relative);
        });
      });
    });
  }
};
{'fraction_non_alphanumeric': 0.1455861070911722, 'fraction_numerical': 0.0017366136034732273, 'mean_word_length': 2.6, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6387385', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1039, 'n_words': 230}