<commit_before>'use strict';
/**
 * @fileOverview This is a grunt task to precompile JST files with the option to
 *               expose the result into module.exports rather than a namespace.
 *               This has been forked and modified from grunt-contrib-jst and
 *               differs slightly. It retains all of the options of the
 *               original, but adds a new one called <code>module</code>. This
 *               is like the amdWrapper option, except it will create
 *               exports[filename] = templateCode() instead so that if you use
 *               browserify to package your code, or if you just want to call it
 *               from the server. And this one uses lodash. So there.
 *
 * @module tasks\grunt-jst-module
 * @see http://gruntjs.com/
 * @see https://github.com/gruntjs/grunt-contrib-jst
 * @copyright Copyright &copy; 2012 <NAME>, <NAME>, grunt-contrib contributers. All rights reserved.
 * @license MIT.
 */

/**
 * Figures out what the full namespace declaration looks like when rendered.
 *
 * @param {string} ns The namespace specification
 * @return {Object} And object with two components: <code>namespace</code> - the namespace specification and
 * <code>declaration</code>: the component declarations to make sure the namespace is valid at runtime.
 */
var getNamespaceDeclaration = function ( ns ) {
	var output = [];
	var curPath = 'this';
	if ( ns !== 'this' ) {
		var nsParts = ns.split( '.' );
		nsParts.forEach( function ( curPart ) {
			if ( curPart !== 'this' ) {
				curPath += '[' + JSON.stringify( curPart ) + ']';
				output.push( curPath + ' = ' + curPath + ' || {};' );
			}
		} );
	}

	return {
		namespace   : curPath,
		declaration : output.join( '\n' )
	};
};
/**
 * The task itself
 * @param {Grunt} grunt The grunt object
 */
module.exports = function ( grunt ) {

	var path = require( "path" );

	grunt.registerMultiTask( 'template-module', 'Compile underscore templates to JST file that can be exposed as a module', function () {
		var sys = require( "lodash" );
		var beautifier = require( "node-beautify" );

		var defaultOptions = {
			namespace        : null,
			templateSettings : {
				client       : true,
				compileDebug : true
			},
			lintExpr         : {
				//				unused : false, asi : true, expr : true
			},
			module           : true,
			requireProvider  : true,
			provider         : "underscore",
			processName      : function ( name ) {
				return name;
			},
			useStrict        : false,
			single 			 : false,
			prettify         : false,
			prettifyOptions  : {
				indentSize : 2
			}
		};

		var options = sys.extend( {}, defaultOptions, this.options() );
		var templateProvider = require( options.provider );

		grunt.verbose.writeflags( options, 'Options' );

		var nsInfo;
		// we want to turn module off in the event other setting would collide with it
		if ( options.amdWrapper || !sys.isEmpty( options.namespace ) ) {
			options.module = false;
		}
		if ( options.module ) {
			options.amdWrapper = false;
			nsInfo = {
				namespace   : "exports",
				declaration : ""
			};
		} else {
			options.module = false;
			options.requireProvider = false;
			options.namespace = options.namespace || "JST";
			nsInfo = getNamespaceDeclaration( options.namespace );
		}

		var output = [];
		var compiled, templateName;
		var oneSource = (this.files.length === 1);

		this.files.forEach( function ( f ) {

			sys.each( f.src, function ( srcFile ) {
				var fpath;
				if ( f.cwd ) {
					fpath = path.resolve( f.cwd, srcFile );
				} else {
					fpath = srcFile;
				}
				var src = grunt.file.read( fpath );
				try {
					if ( options.provider === "ejs" ) {
						compiled = templateProvider.compile( src, options.templateSettings );
					} else {
						compiled = templateProvider.template( src, false, options.templateSettings ).source;
					}

					if ( options.single === true && options.module === true && oneSource )
					{<commit_msg>- added ability to compile to individual files when given a glob<commit_after>'use strict';
/**
 * @fileOverview This is a grunt task to precompile JST files with the option to
 *               expose the result into module.exports rather than a namespace.
 *               This has been forked and modified from grunt-contrib-jst and
 *               differs slightly. It retains all of the options of the
 *               original, but adds a new one called <code>module</code>. This
 *               is like the amdWrapper option, except it will create
 *               exports[filename] = templateCode() instead so that if you use
 *               browserify to package your code, or if you just want to call it
 *               from the server. And this one uses lodash. So there.
 *
 * @module tasks\grunt-jst-module
 * @see http://gruntjs.com/
 * @see https://github.com/gruntjs/grunt-contrib-jst
 * @copyright Copyright &copy; 2012 <NAME>, <NAME>, grunt-contrib contributers. All rights reserved.
 * @license MIT.
 */

/**
 * Figures out what the full namespace declaration looks like when rendered.
 *
 * @param {string} ns The namespace specification
 * @return {Object} And object with two components: <code>namespace</code> - the namespace specification and
 * <code>declaration</code>: the component declarations to make sure the namespace is valid at runtime.
 */
var getNamespaceDeclaration = function ( ns ) {
	var output = [];
	var curPath = 'this';
	if ( ns !== 'this' ) {
		var nsParts = ns.split( '.' );
		nsParts.forEach( function ( curPart ) {
			if ( curPart !== 'this' ) {
				curPath += '[' + JSON.stringify( curPart ) + ']';
				output.push( curPath + ' = ' + curPath + ' || {};' );
			}
		} );
	}

	return {
		namespace   : curPath,
		declaration : output.join( '\n' )
	};
};
/**
 * The task itself
 * @param {Grunt} grunt The grunt object
 */
module.exports = function ( grunt ) {

	var path = require( "path" );

	grunt.registerMultiTask( 'template-module', 'Compile underscore templates to JST file that can be exposed as a module', function () {
		var sys = require( "lodash" );
		var beautifier = require( "node-beautify" );

		var defaultOptions = {
			namespace        : null,
			templateSettings : {
				client       : true,
				compileDebug : true
			},
			lintExpr         : {
				//				unused : false, asi : true, expr : true
			},
			module           : true,
			requireProvider  : true,
			provider         : "underscore",
			processName      : function ( name ) {
				return name;
			},
			useStrict        : false,
			single 			 : false,
			prettify         : false,
			prettifyOptions  : {
				indentSize : 2
			}
		};

		var options = sys.extend( {}, defaultOptions, this.options() );
		var templateProvider = require( options.provider );

		grunt.verbose.writeflags( options, 'Options' );

		var nsInfo;
		// we want to turn module off in the event other setting would collide with it
		if ( options.amdWrapper || !sys.isEmpty( options.namespace ) ) {
			options.module = false;
		}
		if ( options.module ) {
			options.amdWrapper = false;
			nsInfo = {
				namespace   : "exports",
				declaration : ""
			};
		} else {
			options.module = false;
			options.requireProvider = false;
			options.namespace = options.namespace || "JST";
			nsInfo = getNamespaceDeclaration( options.namespace );
		}

		var output = [];
		var compiled, templateName;
		var oneSource = (this.files.length === 1);

		//normalize this.files
		if(typeof this.data.files == "string"){
			oneSource = true;
			this.files = grunt.file.expand(this.data.files);

			this.files.forEach( function ( f , key) {
				var src = f;
				var dest = path.dirname(src) +"/"+ path.basename(src, path.extname(src)) + ".js";
				this.files[key] = {
					src: [src],
					dest:dest
				}
			},this);
		}
			console.log(this.files);

		this.files.forEach( function ( f ) {

			sys.each( f.src, function ( srcFile ) {
				var fpath;
				if ( f.cwd ) {
					fpath = path.resolve( f.cwd, srcFile );
				} else {
					fpath = srcFile;
				}
				var src = grunt.file.read( fpath );
				try {
					if ( options.provider === "ejs" ) {
						compiled = templateProvider.compile( src, options.templateSettings );
					} else {
						compiled = templateProvider.template( src, false, options.templateSettings ).source;
					}

					if ( options.single === true && options.module === true && oneSource )
					{
{'fraction_non_alphanumeric': 0.12324829320876751, 'fraction_numerical': 0.001437297879985627, 'mean_word_length': 2.56532877882152, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 2, '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': '4406865', 'n_tokens_mistral': 2868, 'n_tokens_neox': 2454, 'n_words': 777}