<commit_before>'use strict';

var isFunction   = require('es5-ext/lib/Function/is-function')
  , deferred     = require('deferred')
  , resolve      = require('path').resolve
  , stat         = deferred.promisify(require('fs').stat)
  , readFile     = require('fs2/lib/read-file')
  , writeFile    = require('fs2/lib/write-file')
  , readdir      = require('fs2/lib/readdir')
  , createParser = require('./parser')

  , stringify = JSON.stringify
  , templatePath = __dirname + '/webmake.tpl'
  , separator = (process.env.OS === 'Windows_NT') ? '/[\\\\/]/' : '\'/\''
  , filesAtPath;

filesAtPath = function (path) {
	return stat(path)(function (stats) {
		if (stats.isFile()) {
			return [path];
		} else if (stats.isDirectory()) {
			return readdir(path, { depth: Infinity, type: { file: true } })(
				function (data) {
					return data.map(function (file) {
						return resolve(path, file);
					});
				}
			);
		} else {
			return [];
		}
	});
};

module.exports = function (input, options, cb) {
	var promise;
	if (isFunction(options)) {
		cb = options;
		options = {};
	} else {
		options = Object(options);
	}
	var parser = createParser();
	promise = parser.readInput(input)(function (path) {
		return deferred.map([].concat(options.include || []), function (path) {
			path = resolve(String(path));
			return filesAtPath(path).invoke('filter', function (filename) {
				return filename.slice(-3) === '.js';
			}).map(parser.readInput, parser);
		})(function () {
			return readFile(templatePath, 'utf-8');
		}, function (err) {
			return err;
		})(function (tpl) {
			var src = tpl.replace('SEPARATOR', separator) +
				'(' + parser.toString(options) + ')' +
				'(' + stringify(path) + ');\n';
			return options.output ?
					writeFile(resolve(String(options.output)), src)(parser) : src;
		});
	}).cb(cb);
	promise.parser = parser;
	return promise;
};<commit_msg>-- lint<commit_after>'use strict';

var isFunction   = require('es5-ext/lib/Function/is-function')
  , deferred     = require('deferred')
  , resolve      = require('path').resolve
  , stat         = deferred.promisify(require('fs').stat)
  , readFile     = require('fs2/lib/read-file')
  , writeFile    = require('fs2/lib/write-file')
  , readdir      = require('fs2/lib/readdir')
  , createParser = require('./parser')

  , stringify = JSON.stringify
  , templatePath = __dirname + '/webmake.tpl'
  , separator = (process.env.OS === 'Windows_NT') ? '/[\\\\/]/' : '\'/\''
  , filesAtPath;

filesAtPath = function (path) {
	return stat(path)(function (stats) {
		if (stats.isFile()) {
			return [path];
		} else if (stats.isDirectory()) {
			return readdir(path, { depth: Infinity, type: { file: true } })(
				function (data) {
					return data.map(function (file) {
						return resolve(path, file);
					});
				}
			);
		} else {
			return [];
		}
	});
};

module.exports = function (input, options, cb) {
	var promise, parser;
	if (isFunction(options)) {
		cb = options;
		options = {};
	} else {
		options = Object(options);
	}
	parser = createParser();
	promise = parser.readInput(input)(function (path) {
		return deferred.map([].concat(options.include || []), function (path) {
			path = resolve(String(path));
			return filesAtPath(path).invoke('filter', function (filename) {
				return filename.slice(-3) === '.js';
			}).map(parser.readInput, parser);
		})(function () {
			return readFile(templatePath, 'utf-8');
		}, function (err) {
			return err;
		})(function (tpl) {
			var src = tpl.replace('SEPARATOR', separator) +
				'(' + parser.toString(options) + ')' +
				'(' + stringify(path) + ');\n';
			return options.output ?
					writeFile(resolve(String(options.output)), src)(parser) : src;
		});
	}).cb(cb);
	promise.parser = parser;
	return promise;
};
{'fraction_non_alphanumeric': 0.19226666666666667, 'fraction_numerical': 0.0032, 'mean_word_length': 3.351508120649652, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1147078', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1253, 'n_words': 243}