Skip to content

Commit

Permalink
WIP: Encore Configuration Files
Browse files Browse the repository at this point in the history
  • Loading branch information
Nattfarinn committed May 30, 2022
1 parent 769fa2a commit fb9c26f
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/lib/Base/Container/Encore/ConfigurationPathLocatorTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Core\Base\Container\Encore;

use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;

trait ConfigurationPathLocatorTrait
{
public function locateConfigurationFiles(
array $bundlesMetadata,
array $configFiles,
string $rootPath
): array {
$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/core',
'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()
);
}
}

return $paths;
}

public function dumpConfigurationPaths(
string $configName,
string $targetPath,
array $paths
): void {
$filesystem = new Filesystem();
$filesystem->mkdir($targetPath);
$filesystem->dumpFile(
$targetPath . '/' . $configName,
sprintf('module.exports = %s;', json_encode($paths))
);
}
}

0 comments on commit fb9c26f

Please sign in to comment.