mirror of
https://github.com/opdavies/build-configs.git
synced 2025-01-22 18:27:31 +00:00
Automatically find the build configuration file
Automatically find and use a `build-configs.yaml` or `build.yaml` if it exists. The `--config-file` option is still available if a custom filename needs to be used, and it's currently used when running snapshot tests.
This commit is contained in:
parent
2ca755ee28
commit
af3c1fb840
43
src/Command/FindBuildConfigurationFileCommand.php
Normal file
43
src/Command/FindBuildConfigurationFileCommand.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
final class FindBuildConfigurationFileCommand
|
||||
{
|
||||
/**
|
||||
* Supported build configuration file names.
|
||||
*/
|
||||
private static $configFiles = [
|
||||
'build-configs.yaml',
|
||||
'build.yaml',
|
||||
];
|
||||
|
||||
public function __construct(private Filesystem $filesystem)
|
||||
{
|
||||
}
|
||||
|
||||
public function execute(string|null $configFile = null, \Closure $next)
|
||||
{
|
||||
if ($configFile !== null) {
|
||||
if (!$this->filesystem->exists($configFile)) {
|
||||
throw new \RuntimeException(sprintf('%s not found', $configFile));
|
||||
}
|
||||
|
||||
return $next($configFile);
|
||||
}
|
||||
|
||||
// Search for a configuration file in the order of the filenames within
|
||||
// the array and continue if one exists.
|
||||
foreach (self::$configFiles as $i) {
|
||||
if ($this->filesystem->exists($i)) {
|
||||
return $next($i);
|
||||
}
|
||||
}
|
||||
|
||||
throw new \RuntimeException("No configuration file found");
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ namespace App\Console\Command;
|
|||
|
||||
use App\Command\CreateFinalConfigurationDataCommand;
|
||||
use App\Command\CreateListOfFilesToGenerateCommand;
|
||||
use App\Command\FindBuildConfigurationFileCommand;
|
||||
use App\Command\GenerateConfigurationFilesCommand;
|
||||
use App\Command\ValidateConfigurationDataCommand;
|
||||
use App\DataTransferObject\ConfigDto;
|
||||
|
@ -67,6 +68,7 @@ class GenerateCommand extends Command
|
|||
$isDryRun = $input->getOption(name: 'dry-run');
|
||||
|
||||
$pipelines = [
|
||||
new FindBuildConfigurationFileCommand($this->filesystem),
|
||||
new CreateFinalConfigurationDataCommand(),
|
||||
new ValidateConfigurationDataCommand(),
|
||||
new CreateListOfFilesToGenerateCommand(),
|
||||
|
|
Loading…
Reference in a new issue