<commit_before><?php defined('SYSPATH') or die('No direct script access.');

class Compiler_JS {

	public static function compile(array $filepaths)
	{

	}<commit_msg>implemented the main features of the JS compiler<commit_after><?php defined('SYSPATH') or die('No direct script access.');

class Compiler_JS extends Media_Compiler{

	public static function compile(array $filepaths, array $options)
	{
		$file_meta = array();

		foreach ($filepaths as $relative_path => $absolute_path)
		{
			foreach ($options['concat'] as $group => $properties)
			{
				// If the relative path matches the pattern
				if (preg_match($properties['pattern'], $relative_path))
				{
					// This file belongs to this group
					$file_meta[$properties['order']][$relative_path] = $absolute_path;
					break; // No need to check the other groups
				}
			}
		}

		if (empty($file_meta))
			return TRUE; // Nothing to compile

		// Sort the $file_meta array by order (key) before concatinating
		ksort($file_meta);

		$files = Arr::flatten($file_meta);
		$content = '';

		foreach ($files as $path)
		{
			$content .= file_get_contents($path);
		}

		$unmin_path = $options['save_paths']['unminified'];
		$min_path = $options['save_paths']['minified'];
		// Save the unminified version
		Compiler_JS::put_contents($unmin_path, $content);

		// Not mangling variable names and not removing unused code
		$uglify_cmd = 'uglifyjs '
			.'--no-mangle '
			.'--no-dead-code '
			.'--output '.escapeshellarg($min_path).' '
			.escapeshellarg($unmin_path);

		exec($uglify_cmd);
	}
{'fraction_non_alphanumeric': 0.14294913071474566, 'fraction_numerical': 0.0, 'mean_word_length': 3.9967845659163985, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2323136', 'n_tokens_mistral': 566, 'n_tokens_neox': 494, 'n_words': 130}