<commit_before>//////////////////////////////////////////////////////////////////////////
// Spawner - spawns new projects!
//////////////////////////////////////////////////////////////////////////
//
// Spawner is a 'puppet master' controller for project generation. It
// takes a template procedure, and makes calls to Maker, Changer, and
// other modules as necessary.
/* ----------------------------------------------------------------------
													Object Structures
-------------------------------------------------------------------------
	var options = {
		dest: "...path where we'll be dumping files...",
	}
*/
//////////////////////////////////////////////////////////////////////////
// Requires
var ares = require("ares").ares,
	async = require("async"),
	maker = require("maker").createMaker(),
	mover = require("mover").createMover(),
	changer = require("changer").createChanger(),
	gitOps = require("./gitOperations"),
	ares = require("ares").ares,
	fs = require("fs-extra");


//////////////////////////////////////////////////////////////////////////
// Namespace (lol)
var SHOW_DEBUG_PRINTS = true;
var log = function( a ) { if(SHOW_DEBUG_PRINTS) console.log(a); };	// A log function we can turn off


//////////////////////////////////////////////////////////////////////////
// Constructor
function spawner() {	
	var _this = this;	

	this.tempRepoDest = "/_leto_temp/";
	
} // end spawner()


//////////////////////////////////////////////////////////////////////////
// Spawns a project
spawner.prototype.spawn = function( dest, leto_setup, options, contents, shouldCloneRepo, callback ) {
	if( contents === undefined ) {
		console.log( "!!! Spawning with undefined contents !!!" );
		contents = {};
	}

	var _this = this;

	var asyncCallQueue = [];

	// Make shouldCloneRepo optional
	if( callback === undefined ) {
		callback = shouldCloneRepo;
		shouldCloneRepo = false;
	}

	function requireFromString(src, filename) {
		try {
			var m = new module.constructor();
		    m._compile(src, filename);
		    return m.exports;
		} catch( err ) {
			console.log( "Failed to load module at: " + filename );
			console.log( err );
		}	    
	}

	function templatizeAndLoadModule( src ) {
		// Load the ruleset into a string and templatize it
		var strContents = fs.readFileSync( src, 'utf8' );
		strContents = maker.renderTemplateToString( maker.template(strContents, contents) );
		return requireFromString( strContents );
	}

	function templatizeAndLoadFile( src ) {
		// Load the ruleset into a string and templatize it
		var strContents = fs.readFileSync( src, 'utf8' );
		strContents = maker.renderTemplateToString( maker.template(strContents, contents) );
		return strContents;
	}

	leto_setup.tempRepoDest = dest + this.tempRepoDest;

	// If we have a functions file defined, try to load it 
	// and override necessary parameters
	if( leto_setup.functions != undefined ) {
		try {
			var functionContents = templatizeAndLoadModule( leto_setup.__source + "/" + leto_setup.functions );
		} catch( err ) {
			console.log( "Error, failed to load functions at location " + leto_setup.functions );
			console.log( err );
			callback();
		}
		
		// Load all exports of the functions into our contents blob so that it's loaded later
		for( var iFunction in functionContents ) {
			contents[iFunction] = functionContents[iFunction];
		}
	}

	// If we have external text files that we need to laod, read them
	// all in and templatize them
	if( leto_setup.externals != undefined ) {
		for( var iExternal in leto_setup.externals ) {
			contents[iExternal] = templatizeAndLoadFile( leto_setup.__source + "/" + leto_setup.externals[iExternal] );
		}
	}

	// If we have any defaults defined, fill in missing values in the contents
	if( leto_setup.defaults != undefined ) {
		for( var iDefault in leto_setup.defaults ) {
			if( contents[iDefault] === undefined ) {
				contents[iDefault] = leto_setup.defaults[iDefault];
			}
		}
	}

	var getBatchReplace = function( step ) {
		return function( cb ) {
			var source = step.sourcedir || options.source || leto_setup.__source || process.cwd();

			// Construct our filepath map by grabbing the end values for each 
			// template from the contents we're given
			var filePathMap = {};
			for( var iKey in step.keywords ) {
				var keyword = step.keywords[iKey];

				// If this item is a function, call it to find our string key
				var keyToFind = typeof(contents[iKey]) == "function" ? contents[iKey]() : contents[iKey];

				filePathMap[keyToFind] = keyword;
			}

			maker.makeTemplatesFromDir( source, dest + "/", step.keywords, filePathMap, step.extensions || [], contents, cb );
		}
	}

	var getTemplateFiles = function( step ) {
		return function( cb ) { 
			maker.loadTemplateDir( leto_setup.__source + "/" + step.sourcedir, function( loadedTemplates ) {
				var makeFileCallQueue = [];

				for( var iTemplate=0; iTemplate<step.templates.length; ++iTemplate ) {<commit_msg>Reverse key and value to reflect changes in Maker<commit_after>//////////////////////////////////////////////////////////////////////////
// Spawner - spawns new projects!
//////////////////////////////////////////////////////////////////////////
//
// Spawner is a 'puppet master' controller for project generation. It
// takes a template procedure, and makes calls to Maker, Changer, and
// other modules as necessary.
/* ----------------------------------------------------------------------
													Object Structures
-------------------------------------------------------------------------
	var options = {
		dest: "...path where we'll be dumping files...",
	}
*/
//////////////////////////////////////////////////////////////////////////
// Requires
var ares = require("ares").ares,
	async = require("async"),
	maker = require("maker").createMaker(),
	mover = require("mover").createMover(),
	changer = require("changer").createChanger(),
	gitOps = require("./gitOperations"),
	ares = require("ares").ares,
	fs = require("fs-extra");


//////////////////////////////////////////////////////////////////////////
// Namespace (lol)
var SHOW_DEBUG_PRINTS = true;
var log = function( a ) { if(SHOW_DEBUG_PRINTS) console.log(a); };	// A log function we can turn off


//////////////////////////////////////////////////////////////////////////
// Constructor
function spawner() {	
	var _this = this;	

	this.tempRepoDest = "/_leto_temp/";
	
} // end spawner()


//////////////////////////////////////////////////////////////////////////
// Spawns a project
spawner.prototype.spawn = function( dest, leto_setup, options, contents, shouldCloneRepo, callback ) {
	if( contents === undefined ) {
		console.log( "!!! Spawning with undefined contents !!!" );
		contents = {};
	}

	var _this = this;

	var asyncCallQueue = [];

	// Make shouldCloneRepo optional
	if( callback === undefined ) {
		callback = shouldCloneRepo;
		shouldCloneRepo = false;
	}

	function requireFromString(src, filename) {
		try {
			var m = new module.constructor();
		    m._compile(src, filename);
		    return m.exports;
		} catch( err ) {
			console.log( "Failed to load module at: " + filename );
			console.log( err );
		}	    
	}

	function templatizeAndLoadModule( src ) {
		// Load the ruleset into a string and templatize it
		var strContents = fs.readFileSync( src, 'utf8' );
		strContents = maker.renderTemplateToString( maker.template(strContents, contents) );
		return requireFromString( strContents );
	}

	function templatizeAndLoadFile( src ) {
		// Load the ruleset into a string and templatize it
		var strContents = fs.readFileSync( src, 'utf8' );
		strContents = maker.renderTemplateToString( maker.template(strContents, contents) );
		return strContents;
	}

	leto_setup.tempRepoDest = dest + this.tempRepoDest;

	// If we have a functions file defined, try to load it 
	// and override necessary parameters
	if( leto_setup.functions != undefined ) {
		try {
			var functionContents = templatizeAndLoadModule( leto_setup.__source + "/" + leto_setup.functions );
		} catch( err ) {
			console.log( "Error, failed to load functions at location " + leto_setup.functions );
			console.log( err );
			callback();
		}
		
		// Load all exports of the functions into our contents blob so that it's loaded later
		for( var iFunction in functionContents ) {
			contents[iFunction] = functionContents[iFunction];
		}
	}

	// If we have external text files that we need to laod, read them
	// all in and templatize them
	if( leto_setup.externals != undefined ) {
		for( var iExternal in leto_setup.externals ) {
			contents[iExternal] = templatizeAndLoadFile( leto_setup.__source + "/" + leto_setup.externals[iExternal] );
		}
	}

	// If we have any defaults defined, fill in missing values in the contents
	if( leto_setup.defaults != undefined ) {
		for( var iDefault in leto_setup.defaults ) {
			if( contents[iDefault] === undefined ) {
				contents[iDefault] = leto_setup.defaults[iDefault];
			}
		}
	}

	var getBatchReplace = function( step ) {
		return function( cb ) {
			var source = step.sourcedir || options.source || leto_setup.__source || process.cwd();

			// Construct our filepath map by grabbing the end values for each 
			// template from the contents we're given
			var filePathMap = {};
			for( var iKey in step.keywords ) {
				var keyword = step.keywords[iKey];

				// If this item is a function, call it to find our string key
				var keyToFind = typeof(contents[iKey]) == "function" ? contents[iKey]() : contents[iKey];

				filePathMap[keyword] = keyToFind;
			}

			maker.makeTemplatesFromDir( source, dest + "/", step.keywords, filePathMap, step.extensions || [], contents, cb );
		}
	}

	var getTemplateFiles = function( step ) {
		return function( cb ) { 
			maker.loadTemplateDir( leto_setup.__source + "/" + step.sourcedir, function( loadedTemplates ) {
				var makeFileCallQueue = [];

				for( var iTemplate=0; iTemplate<step.templates.length; ++iTemplate ) {
{'fraction_non_alphanumeric': 0.2253123740427247, 'fraction_numerical': 0.0006045949214026602, 'mean_word_length': 2.2192669477781384, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6366875', 'n_tokens_mistral': 2984, 'n_tokens_neox': 2729, 'n_words': 806}