<commit_before>var es = require('event-stream');
var path = require('path');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
var htmlJsStr = require('js-string-escape');

module.exports = function(filename, options) {
	if (!filename) {
		throw new PluginError('gulp-concat', 'Missing filename option for gulp-angular-templatecache');
	}
	options = options || {};
	options.root = options.root || '';

	var buffer = [];
	var firstFile;

	function bufferFiles(file) {
		if (file.isNull()) {
			return;
		}
		if (file.isStream()) {
			return this.emit('error', new PluginError('gulp-angular-templatecache', 'Streaming not supported'));
		}
		if (!firstFile) {
			firstFile = file;
		}

		buffer.push(file);
	}

	function endStream() {
		if (buffer.length === 0) {
			return this.emit('end');
		}

		var result = 'angular.module("templates", []).run(["$templateCache", function($templateCache) {';

		result += buffer.map(function(file) {
			var url = path.join(options.root, file.path.replace(file.base, ''));
			var template = '$templateCache.put("' + url + '","';
			template += htmlJsStr(file.contents);
			template += '");';
			return template;
		}).join('');

		result += '}]);';

		var resultPath = path.join(firstFile.base, filename);

		var templatesFile = new gutil.File({
			cwd: buffer[0].cwd,
			base: buffer[0].base,
			path: resultPath,
			contents: new Buffer(result)
		});

		this.emit('data', templatesFile);
		this.emit('end');
	}

	return es.through(bufferFiles, endStream);
};<commit_msg>Enable module to be specified<commit_after>var es = require('event-stream');
var path = require('path');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
var htmlJsStr = require('js-string-escape');

module.exports = function(filename, options) {
	if (!filename) {
		throw new PluginError('gulp-concat', 'Missing filename option for gulp-angular-templatecache');
	}
	options = options || {};
	options.root = options.root || '';
	options.module = options.module || 'templates';

	var buffer = [];
	var firstFile;

	function bufferFiles(file) {
		if (file.isNull()) {
			return;
		}
		if (file.isStream()) {
			return this.emit('error', new PluginError('gulp-angular-templatecache', 'Streaming not supported'));
		}
		if (!firstFile) {
			firstFile = file;
		}

		buffer.push(file);
	}

	function endStream() {
		if (buffer.length === 0) {
			return this.emit('end');
		}

		var result = 'angular.module("' + options.module + '", []).run(["$templateCache", function($templateCache) {';

		result += buffer.map(function(file) {
			var url = path.join(options.root, file.path.replace(file.base, ''));
			var template = '$templateCache.put("' + url + '","';
			template += htmlJsStr(file.contents);
			template += '");';
			return template;
		}).join('');

		result += '}]);';

		var resultPath = path.join(firstFile.base, filename);

		var templatesFile = new gutil.File({
			cwd: buffer[0].cwd,
			base: buffer[0].base,
			path: resultPath,
			contents: new Buffer(result)
		});

		this.emit('data', templatesFile);
		this.emit('end');
	}

	return es.through(bufferFiles, endStream);
};
{'fraction_non_alphanumeric': 0.18295019157088122, 'fraction_numerical': 0.0019157088122605363, 'mean_word_length': 4.16996699669967, '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': '2778807', 'n_tokens_mistral': 1132, 'n_tokens_neox': 1011, 'n_words': 222}