Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-2961: Refactored Extension to rely on Encore Configuration Dumper #471

Merged
merged 2 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"symfony/asset": "^5.0",
"symfony/yaml": "^5.0",
"jms/translation-bundle": "^1.5",
"ibexa/core": "~4.1.0@dev",
"ibexa/core": "~4.1.6@dev",
"ibexa/content-forms": "~4.1.0@dev",
"ibexa/design-engine": "~4.1.0@dev",
"ibexa/user": "~4.1.0@dev",
Expand Down
64 changes: 4 additions & 60 deletions src/bundle/DependencyInjection/IbexaAdminUiExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
*/
namespace Ibexa\Bundle\AdminUi\DependencyInjection;

use Ibexa\Contracts\Core\Container\Encore\ConfigurationDumper as IbexaEncoreConfigurationDumper;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Yaml\Yaml;

Expand Down Expand Up @@ -72,13 +71,9 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('services/test/components.yaml');
}

$bundlesMetadata = $container->getParameter('kernel.bundles_metadata');
$rootPath = $container->getParameter('kernel.project_dir') . '/';
$targetPath = 'var/encore';

foreach (self::WEBPACK_CONFIG_NAMES as $configName => $configFiles) {
$this->dumpConfigurationPathsToFile($configName, $configFiles, $rootPath, $targetPath, $bundlesMetadata);
}
(new IbexaEncoreConfigurationDumper($container))->dumpCustomConfiguration(
self::WEBPACK_CONFIG_NAMES
);
}

/**
Expand Down Expand Up @@ -161,57 +156,6 @@ private function prependJMSTranslation(ContainerBuilder $container): void
]);
}

/**
* Looks for Resources/encore/ files in every registered and enabled bundle.
* Dumps json list of paths to files it finds.
*
* @param string $targetPath Where to put Ibexa Encore paths configuration file (default: var/encore)
*/
private function dumpConfigurationPathsToFile(
string $configName,
array $configFiles,
string $rootPath,
string $targetPath,
array $bundlesMetadata
): void {
$filesystem = new Filesystem();
$paths = [];

foreach ($configFiles as $configFile => $options) {
$finder = new Finder();
$finder
->in(array_column($bundlesMetadata, 'path'))
->path('Resources/encore')
->name($configFile)
->files();

/** @var \Symfony\Component\Finder\SplFileInfo $fileInfo */
foreach ($finder as $fileInfo) {
if ($options['deprecated'] ?? false) {
trigger_deprecation(
'ibexa/admin-ui',
'4.0.0',
'Support for old configuration files is deprecated, please update name of %s file, to %s',
$fileInfo->getPathname(),
$options['alternative']
);
}

$paths[] = preg_replace(
'/^' . preg_quote($rootPath, '/') . '/',
'./',
$fileInfo->getRealPath()
);
}
}

$filesystem->mkdir($rootPath . '/' . $targetPath);
$filesystem->dumpFile(
$rootPath . $targetPath . '/' . $configName,
sprintf('module.exports = %s;', json_encode($paths))
);
}

private function shouldLoadTestServices(ContainerBuilder $container): bool
{
return $container->hasParameter('ibexa.behat.browser.enabled')
Expand Down