<commit_before><?php
namespace Mouf\Html\Utils\WebLibraryManager\ComponentInstaller;

use Composer\Package\PackageInterface;
use Composer\Installer\LibraryInstaller;
use Composer\Repository\InstalledRepositoryInterface;
use Mouf\MoufManager;
use Mouf\Html\Utils\WebLibraryManager\WebLibraryInstaller;
use Composer\Config;

/**
 * This Composer installer is in charge of the installation of component files in the Mouf framework.
 * 
 * @author <NAME>
 */
class ComponentInstaller extends LibraryInstaller
{
    /**
	 * {@inheritDoc}
	 */
	public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
	{
		parent::update($repo, $initial, $target);
		$this->installUpdate($repo, $target);
	}
	
	/**
	 * {@inheritDoc}
	 */
	public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
	{
		parent::install($repo, $package);
		$this->installUpdate($repo, $package);
	}
	
	/**
	 * {@inheritDoc}
	 */
	public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
	{
		parent::uninstall($repo, $package);
		
		if (!file_exists(__DIR__.'/../../../../mouf/Mouf.php')) {
			continue;
		}
		require_once(__DIR__.'/../../../../mouf/Mouf.php');
		
		$moufManager = MoufManager::getMoufManager();
		
		echo 'CHECKING FOR '."component.".$package->getName();
		if ($moufManager->has("component.".$package->getName())) {
			echo 'WE REMOVE '."component.".$package->getName();
			$moufManager->removeComponent("component.".$package->getName());
		}
		$moufManager->rewriteMouf();
		echo 'FINISHED REWRITE '."component.".$package->getName();
	}
	
	protected function installUpdate(InstalledRepositoryInterface $repo, PackageInterface $package) {
		if (!file_exists(__DIR__.'/../../../../mouf/Mouf.php')) {
			continue;
		}
		require_once(__DIR__.'/../../../../mouf/Mouf.php');
		
		$moufManager = MoufManager::getMoufManager();
		self::installComponent($package, $this->composer->getConfig(), $moufManager);
	}

    /**
     * {@inheritDoc}
     */
    public function supports($packageType)
    {
        return 'component' === $packageType;
    }
    
    /**
     * 
     * @param PackageInterface $package
     * @param Config $config
     * @param MoufManager $moufManager
     */
    public static function installComponent(PackageInterface $package, Config $config, $moufManager) {
    	if (!$moufManager->has('defaultWebLibraryManager')) {
    		return;
    	}
    	
    	$packageName = explode('/', $package->getName())[1];
    		
    	if (!$moufManager->has("component.".$package->getName())) {
    		$extra = $package->getExtra();
    			
    		$targetDir = $config->get('component-dir');
    		$baseUrl = $config->get('component-baseurl');
    			
    		if (!$targetDir) {
    			$targetDir = 'components';
    		}
    		if (!$baseUrl) {
    			$baseUrl = $targetDir;
    		}
    			
    		$targetDir = trim($targetDir,'/\\').'/';
    		$baseUrl = trim($baseUrl,'/\\').'/';
    	
    		$scripts = [];
    		if (isset($extra['component']['scripts'])) {
    			$scripts = array_map(function($script) use ($packageName, $baseUrl) {
    				return $baseUrl.$packageName.'/'.$script;
    			}, $extra['component']['scripts']);
    		}
    	
    		$css = [];
    		if (isset($extra['component']['styles'])) {
    			$css = array_map(function($script) use ($packageName, $baseUrl) {
    				return $baseUrl.$packageName.'/'.$script;
    			}, $extra['component']['styles']);
    		}
    	
    		$deps = [];
    		/*if (isset($extra['component']['deps'])) {
    			$deps = array_map(function($script) {
    				return "component.".$script;
    			}, $extra['component']['css']);
    		}*/
    	
    		WebLibraryInstaller::installLibrary("component.".$packageName, $scripts, $css, $deps, true, $moufManager);
    	}
    	$moufManager->rewriteMouf();	 
    }
}
<commit_msg>Fix from scratch install (missing config.php)<commit_after><?php
namespace Mouf\Html\Utils\WebLibraryManager\ComponentInstaller;

use Composer\Package\PackageInterface;
use Composer\Installer\LibraryInstaller;
use Composer\Repository\InstalledRepositoryInterface;
use Mouf\MoufManager;
use Mouf\Html\Utils\WebLibraryManager\WebLibraryInstaller;
use Composer\Config;

/**
 * This Composer installer is in charge of the installation of component files in the Mouf framework.
 * 
 * @author <NAME>
 */
class ComponentInstaller extends LibraryInstaller
{
    /**
	 * {@inheritDoc}
	 */
	public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
	{
		parent::update($repo, $initial, $target);
		
		if (!file_exists(__DIR__.'/../../../../mouf/Mouf.php') || !file_exists(__DIR__.'/../../../../config.php')) {
			continue;
		}
		require_once(__DIR__.'/../../../../mouf/Mouf.php');
		
		$moufManager = MoufManager::getMoufManager();
		self::installComponent($target, $this->composer->getConfig(), $moufManager);
	}
		
	/**
	 * {@inheritDoc}
	 */
	public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
	{
		parent::uninstall($repo, $package);
		
		if (!file_exists(__DIR__.'/../../../../mouf/Mouf.php') || !file_exists(__DIR__.'/../../../../config.php')) {
			continue;
		}
		require_once(__DIR__.'/../../../../mouf/Mouf.php');
		
		$moufManager = MoufManager::getMoufManager();
		
		if ($moufManager->has("component.".$package->getName())) {
			$moufManager->removeComponent("component.".$package->getName());
		}
		$moufManager->rewriteMouf();
	}
	
    /**
     * {@inheritDoc}
     */
    public function supports($packageType)
    {
        return 'component' === $packageType;
    }
    
    /**
     * 
     * @param PackageInterface $package
     * @param Config $config
     * @param MoufManager $moufManager
     */
    public static function installComponent(PackageInterface $package, Config $config, $moufManager) {
    	if (!$moufManager->has('defaultWebLibraryManager')) {
    		return;
    	}
    	
    	$packageName = explode('/', $package->getName())[1];
    		
    	if (!$moufManager->has("component.".$package->getName())) {
    		$extra = $package->getExtra();
    			
    		$targetDir = $config->get('component-dir');
    		$baseUrl = $config->get('component-baseurl');
    			
    		if (!$targetDir) {
    			$targetDir = 'components';
    		}
    		if (!$baseUrl) {
    			$baseUrl = $targetDir;
    		}
    			
    		$targetDir = trim($targetDir,'/\\').'/';
    		$baseUrl = trim($baseUrl,'/\\').'/';
    	
    		$scripts = [];
    		if (isset($extra['component']['scripts'])) {
    			$scripts = array_map(function($script) use ($packageName, $baseUrl) {
    				return $baseUrl.$packageName.'/'.$script;
    			}, $extra['component']['scripts']);
    		}
    	
    		$css = [];
    		if (isset($extra['component']['styles'])) {
    			$css = array_map(function($script) use ($packageName, $baseUrl) {
    				return $baseUrl.$packageName.'/'.$script;
    			}, $extra['component']['styles']);
    		}
    	
    		$deps = [];
    		/*if (isset($extra['component']['deps'])) {
    			$deps = array_map(function($script) {
    				return "component.".$script;
    			}, $extra['component']['css']);
    		}*/
    	
    		WebLibraryInstaller::installLibrary("component.".$packageName, $scripts, $css, $deps, true, $moufManager);
    	}
    	$moufManager->rewriteMouf();	 
    }
}

{'fraction_non_alphanumeric': 0.1867338599836557, 'fraction_numerical': 0.00027240533914464724, 'mean_word_length': 3.1229646266142614, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 40, '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': '2103257', 'n_tokens_mistral': 2543, 'n_tokens_neox': 2405, 'n_words': 366}