<commit_before>"use strict";

var _ = require( 'underscore' ),
	applyFilter = require( './filter' ).apply,
	async = require( "async" ),
	cssConcat = require( 'css-concat' ),
	dependencies = require( "./dependencies" ),
	fs = require( "fs" ),
	logger = require( 'simple-log' ).init( 'amd-builder:css' ),
	path = require( 'path' ),
	Promise = require( "node-promise" ).Promise,
	requirejs = require( 'requirejs' ),
	redefineRequireJSLogging = require( "./requirejs-utils" ).redefineRequireJSLogging;


function buildBundles( baseName, workspaceDir, relBaseUrl, compiledDir, files, filter, optimize ) {
	// logger.log( "buildCSSBundle()" );
	var promise = new Promise(),
		baseOut = path.join( compiledDir, baseName );

	// get the dependency map for all modules
	dependencies.buildMap( workspaceDir, relBaseUrl, compiledDir, files ).then(
		function( modules ) {
			var absBaseUrl = path.normalize( path.join( workspaceDir, relBaseUrl ) );
			var cssFiles = {
					default: []
				},
				contents = {
					default: ""
				},
				outputFiles = [];

			async.waterfall([
				function( next ) {
					var name,
						processed = {},
						addCssDependencies = function( m ) {
							processed[ m ] = true;
							if ( !processed[ m ] && modules[ m ] && modules[ m ].deps ) {
								modules[ m ].deps.forEach( addCssDependencies );
							}
							if ( modules[ m ] && modules[ m ].css ) {
								if ( typeof( modules[ m ].css ) === "string" ) {
									// logger.log( "Adding: " + modules[ m ].css );
									cssFiles.default = _.union( cssFiles.default, modules[ m ].css.split( "," ) );
								} else {
									for ( name in modules[ m ].css ) {
										if ( modules[ m ].css.hasOwnProperty( name ) ) {
											cssFiles[ name ] = cssFiles[ name ] || [];
											// logger.log( "Adding css." + name + ": " + modules[ m ].css[ name ]);
											cssFiles[ name ] = _.union( cssFiles[ name ], modules[ m ].css[ name ].split( "," ) );
										}
									}
								}
							}
						};

					files.forEach( addCssDependencies );
					next();
				},
				function( next ) {
					var keys = Object.keys( cssFiles );

					keys.forEach( function( name ) {
						if ( cssFiles.hasOwnProperty( name ) ) {
							// resolve the file paths
							cssFiles[ name ] = _.uniq( cssFiles[ name ]).map( function( s ) {
								return path.resolve( absBaseUrl, s.trim() );
							});

							contents[ name ] = "";
							cssFiles[ name ].forEach( function( file ) {
								contents[ name ] += "\n";<commit_msg>Changed "files" to "amdModules"<commit_after>"use strict";

var _ = require( 'lodash' ),
	applyFilter = require( './filter' ).apply,
	async = require( "async" ),
	cssConcat = require( 'css-concat' ),
	dependencies = require( "./dependencies" ),
	fs = require( "fs" ),
	logger = require( 'simple-log' ).init( 'amd-builder:css' ),
	path = require( 'path' ),
	Promise = require( "node-promise" ).Promise,
	requirejs = require( 'requirejs' ),
	redefineRequireJSLogging = require( "./requirejs-utils" ).redefineRequireJSLogging;


function buildBundles( baseName, workspaceDir, relBaseUrl, compiledDir, amdModules, filter, optimize ) {
	// logger.log( "buildCSSBundle()" );
	var promise = new Promise(),
		baseOut = path.join( compiledDir, baseName );

	// get the dependency map for all modules
	dependencies.buildMap( workspaceDir, relBaseUrl, compiledDir, amdModules ).then(
		function( modules ) {
			var absBaseUrl = path.normalize( path.join( workspaceDir, relBaseUrl ) );
			var cssFiles = {
					default: []
				},
				contents = {
					default: ""
				},
				outputFiles = [];

			async.waterfall([
				function( next ) {
					var name,
						processed = {},
						addCssDependencies = function( m ) {
							processed[ m ] = true;
							if ( !processed[ m ] && modules[ m ] && modules[ m ].deps ) {
								modules[ m ].deps.forEach( addCssDependencies );
							}
							if ( modules[ m ] && modules[ m ].css ) {
								if ( typeof( modules[ m ].css ) === "string" ) {
									// logger.log( "Adding: " + modules[ m ].css );
									cssFiles.default = _.union( cssFiles.default, modules[ m ].css.split( "," ) );
								} else {
									for ( name in modules[ m ].css ) {
										if ( modules[ m ].css.hasOwnProperty( name ) ) {
											cssFiles[ name ] = cssFiles[ name ] || [];
											// logger.log( "Adding css." + name + ": " + modules[ m ].css[ name ]);
											cssFiles[ name ] = _.union( cssFiles[ name ], modules[ m ].css[ name ].split( "," ) );
										}
									}
								}
							}
						};

					amdModules.forEach( addCssDependencies );
					next();
				},
				function( next ) {
					var keys = Object.keys( cssFiles );

					keys.forEach( function( name ) {
						if ( cssFiles.hasOwnProperty( name ) ) {
							// resolve the file paths
							cssFiles[ name ] = _.uniq( cssFiles[ name ]).map( function( s ) {
								return path.resolve( absBaseUrl, s.trim() );
							});

							contents[ name ] = "";
							cssFiles[ name ].forEach( function( file ) {
								contents[ name ] += "\n";
{'fraction_non_alphanumeric': 0.16166832174776563, 'fraction_numerical': 0.0, 'mean_word_length': 2.4119241192411924, 'pattern_counts': {'":': 2, '<': 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': '4112998', 'n_tokens_mistral': 2104, 'n_tokens_neox': 1565, 'n_words': 418}