<commit_before>#!/usr/bin/env box
<cftry>
<cfscript>
	YAMLParser = new vagrant.cfml.lib.YAMLParser()
	
	_echo( '' )
	_echo( "================= START CONFIGURE-SITES.SH #now()# =================" )
	_echo( '' )
	
	// Clean up old Nginx site configs
	directoryDelete( '/etc/nginx/sites/', true )
	directoryCreate( '/etc/nginx/sites/' )
	
	siteConfigPaths = getSiteConfigs()
	siteConfigs = {}
	for( siteConfigPath in siteConfigPaths ) {
		siteName = siteConfigPath
		
		try {
			config = YAMLParser.yamlToCfml( fileRead( siteConfigPath ) )
			siteName = config['name']
			
			configureNginx( config, siteConfigPath )
			configureMappings( config, siteConfigPath )
		
			siteConfigs[ siteConfigPath ] = { 'error' : false }.append( config )
			
			_echo( "" )	
		} catch( Any e ) {
			_echo( "================= Error configuring site '#siteName#'.  Error to follow. =================" )
			writeDump( var=e, format="text" )
			_echo( "================= end '#siteName#' error =================" )
			
			siteConfigs[ siteConfigPath ] = { 'error' : true, 'errorStruct' : e }
		}
	}
	
	writeDefaultIndex( siteConfigs )
		
	_echo( '' )
	_echo( "================= FINISH CONFIGURE-SITES.SH #now()# =================" )
	_echo( '' )


	//////////////////////////////////////////////////////
	//  Get site configs by convention
	//
	//  Look for "VagrantConfig.yaml" files in
	//  the root of other repos cloned in the same dir 
	/////////////////////////////////////////////////////
	function getSiteConfigs() {
		var configs = []
		var dirs = directoryList( '/vagrant-parent' )
		for( var dir in dirs ) {
			configFile = dir & '/VagrantConfig.yaml'
			if( fileExists( configFile ) ) {
				configs.append( configFile )
			}
		}
		return configs
	}


	/////////////////////////////////////
	//  Setup Nginx server
	/////////////////////////////////////
	function configureNginx( config, siteConfigPath ) {
		var webRoot = convertPath( config['webroot'], siteConfigPath )
		
		// Read in our Nginx template file<commit_msg>Echo error to log<commit_after>#!/usr/bin/env box
<cftry>
<cfscript>
	YAMLParser = new vagrant.cfml.lib.YAMLParser()
	
	_echo( '' )
	_echo( "================= START CONFIGURE-SITES.SH #now()# =================" )
	_echo( '' )
	
	removePreviousConfig()
	
	siteConfigPaths = getSiteConfigs()
	siteConfigs = {}
	for( siteConfigPath in siteConfigPaths ) {
		siteName = siteConfigPath
		
		try {
			config = YAMLParser.yamlToCfml( fileRead( siteConfigPath ) )
			siteName = config['name']
			
			configureNginx( config, siteConfigPath )
			configureMappings( config, siteConfigPath )
		
			siteConfigs[ siteConfigPath ] = { 'error' : false }.append( config )
			
			_echo( "" )	
		} catch( Any e ) { 
			_echo( "================= Error configuring site '#siteName#'.  Error to follow. =================" )
			_echo( e.message )
			_echo( e.detail )
			_echo( e.stackTrace )
			_echo( "================= end '#siteName#' error =================" )
			
			siteConfigs[ siteConfigPath ] = { 'error' : true, 'errorStruct' : e }
		}
	}
	
	writeDefaultIndex( siteConfigs )
		
	_echo( '' )
	_echo( "================= FINISH CONFIGURE-SITES.SH #now()# =================" )
	_echo( '' )


	//////////////////////////////////////////////////////
	//  Remove previous config 
	/////////////////////////////////////////////////////
	function removePreviousConfig() {
		// Clean up old Nginx site configs
		directoryDelete( '/etc/nginx/sites/', true )
		directoryCreate( '/etc/nginx/sites/' )
		
		// Mappings? Datasources? Bueller? BUELLER?
	}



	//////////////////////////////////////////////////////
	//  Get site configs by convention
	//
	//  Look for "VagrantConfig.yaml" files in
	//  the root of other repos cloned in the same dir 
	/////////////////////////////////////////////////////
	function getSiteConfigs() {
		var configs = []
		var dirs = directoryList( '/vagrant-parent' )
		for( var dir in dirs ) {
			configFile = dir & '/VagrantConfig.yaml'
			if( fileExists( configFile ) ) {
				configs.append( configFile )
			}
		}
		return configs
	}


	/////////////////////////////////////
	//  Setup Nginx server
	/////////////////////////////////////
	function configureNginx( config, siteConfigPath ) {
		var webRoot = convertPath( config['webroot'], siteConfigPath )
		
		// Read in our Nginx template file
{'fraction_non_alphanumeric': 0.2778679026651217, 'fraction_numerical': 0.0, 'mean_word_length': 2.208921933085502, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6946636', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1282, 'n_words': 307}