mirror of
https://github.com/opdavies/build-configs.git
synced 2025-01-22 18:27:31 +00:00
refactor: add isDocker
and isFlake
to the
...Configuration DTO
This commit is contained in:
parent
ebc4d899b2
commit
baaf3bf16b
|
@ -14,6 +14,7 @@
|
|||
### Changed
|
||||
|
||||
* Replace `set -ueo` in Git hook templates to use the long names and be consistent with `run` scripts.
|
||||
* Add `isDocker` and `isFlake` to the Configuration DTO and remove duplicate variables within templates.
|
||||
|
||||
## 2023-11-22
|
||||
|
||||
|
|
|
@ -10,6 +10,11 @@ use Symfony\Component\Yaml\Yaml;
|
|||
final class CreateFinalConfigurationData
|
||||
{
|
||||
public function handle(string $configFile, \Closure $next) {
|
||||
// Perform some initial checks before the defaults are merged.
|
||||
$configurationData = Yaml::parseFile(filename: $configFile);
|
||||
$configurationData['isDocker'] = isset($configurationData['dockerfile']);
|
||||
$configurationData['isFlake'] = isset($configurationData['flake']);
|
||||
|
||||
$configurationData = array_replace_recursive(
|
||||
Yaml::parseFile(filename: __DIR__ . '/../../resources/build.defaults.yaml'),
|
||||
Yaml::parseFile(filename: $configFile),
|
||||
|
|
|
@ -19,15 +19,12 @@ final class CreateListOfFilesToGenerate
|
|||
* @var Config $configurationDataDto,
|
||||
* @var array<string,mixed> $configurationData
|
||||
*/
|
||||
[$configurationData, $configurationDataDto] = $configurationDataAndDto;
|
||||
|
||||
$isDocker = static::isDocker($configurationData);
|
||||
$isFlake = static::isFlake($configurationData);
|
||||
[$configurationData, $configurationDataDTO] = $configurationDataAndDto;
|
||||
|
||||
/** @var Collection<int, TemplateFile> */
|
||||
$filesToGenerate = collect();
|
||||
|
||||
switch (strtolower($configurationDataDto->type)) {
|
||||
switch (strtolower($configurationDataDTO->type)) {
|
||||
case (strtolower(ProjectType::Astro->name)):
|
||||
$filesToGenerate = collect([
|
||||
new TemplateFile(data: 'astro/.envrc', name: '.envrc'),
|
||||
|
@ -44,14 +41,14 @@ final class CreateListOfFilesToGenerate
|
|||
new TemplateFile(data: 'fractal/run', name: 'run'),
|
||||
]);
|
||||
|
||||
if ($isDocker) {
|
||||
if ($configurationDataDTO->isDocker) {
|
||||
$filesToGenerate->push(new TemplateFile(data: 'fractal/.env.example', name: '.env.example'));
|
||||
$filesToGenerate->push(new TemplateFile(data: 'fractal/.dockerignore', name: '.dockerignore'));
|
||||
$filesToGenerate->push(new TemplateFile(data: 'fractal/.hadolint.yaml', name: '.hadolint.yaml'));
|
||||
$filesToGenerate->push(new TemplateFile(data: 'fractal/.yarnrc', name: '.yarnrc'));
|
||||
$filesToGenerate->push(new TemplateFile(data: 'fractal/Dockerfile', name: 'Dockerfile'));
|
||||
$filesToGenerate->push(new TemplateFile(data: 'fractal/docker-compose.yaml', name: 'docker-compose.yaml'));
|
||||
} elseif ($isFlake) {
|
||||
} elseif ($configurationDataDTO->isFlake) {
|
||||
$filesToGenerate->push(new TemplateFile(data: 'fractal/.envrc', name: '.envrc'));
|
||||
$filesToGenerate->push(new TemplateFile(data: 'fractal/flake.nix', name: 'flake.nix'));
|
||||
}
|
||||
|
@ -85,15 +82,15 @@ final class CreateListOfFilesToGenerate
|
|||
));
|
||||
}
|
||||
|
||||
if ($configurationDataDto->php['phpcs'] !== false) {
|
||||
if ($configurationDataDTO->php['phpcs'] !== false) {
|
||||
$filesToGenerate->push(new TemplateFile(data: 'drupal/phpcs.xml.dist', name: 'phpcs.xml.dist'));
|
||||
}
|
||||
|
||||
if ($configurationDataDto->php['phpstan'] !== false) {
|
||||
if ($configurationDataDTO->php['phpstan'] !== false) {
|
||||
$filesToGenerate->push(new TemplateFile(data: 'drupal/phpstan.neon.dist', name: 'phpstan.neon.dist'));
|
||||
}
|
||||
|
||||
if ($configurationDataDto->php['phpunit'] !== false) {
|
||||
if ($configurationDataDTO->php['phpunit'] !== false) {
|
||||
$filesToGenerate->push(new TemplateFile(data: 'drupal/phpunit.xml.dist', name: 'phpunit.xml.dist'));
|
||||
}
|
||||
|
||||
|
@ -156,7 +153,7 @@ final class CreateListOfFilesToGenerate
|
|||
);
|
||||
}
|
||||
|
||||
return $next([$configurationData, $configurationDataDto, $filesToGenerate]);
|
||||
return $next([$configurationData, $configurationDataDTO, $filesToGenerate]);
|
||||
}
|
||||
|
||||
private static function isCaddy(?string $webServer): bool
|
||||
|
@ -168,20 +165,6 @@ final class CreateListOfFilesToGenerate
|
|||
return strtoupper($webServer) === WebServer::Caddy->value;
|
||||
}
|
||||
|
||||
private static function isDocker(array $configurationData): bool
|
||||
{
|
||||
// This should return `false` if there is no explicit `dockerfile` key
|
||||
// in the build.yaml file. This is currently not the case, I assume
|
||||
// because of default values being added.
|
||||
// For now, if it's not a Flake, it's Docker.
|
||||
return !static::isFlake($configurationData);
|
||||
}
|
||||
|
||||
private static function isFlake(array $configurationData): bool
|
||||
{
|
||||
return Arr::get($configurationData, 'flake') !== null;
|
||||
}
|
||||
|
||||
private static function isNginx(?string $webServer): bool
|
||||
{
|
||||
if (is_null($webServer)) {
|
||||
|
|
|
@ -273,4 +273,8 @@ final class Config
|
|||
]),
|
||||
])]
|
||||
public array $web;
|
||||
|
||||
public bool $isDocker;
|
||||
|
||||
public bool $isFlake;
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
set -o errexit
|
||||
set -o pipefail
|
||||
|
||||
{% set isFlake = flake is defined %}
|
||||
|
||||
PATH="$PATH:./node_modules/.bin"
|
||||
|
||||
{% if not isFlake %}
|
||||
|
|
|
@ -5,9 +5,6 @@
|
|||
set -o errexit
|
||||
set -o pipefail
|
||||
|
||||
{% set isDocker = flake is not defined %}
|
||||
{% set isFlake = flake is defined %}
|
||||
|
||||
PATH="$PATH:./node_modules/.bin"
|
||||
|
||||
{% if isDocker %}
|
||||
|
|
Loading…
Reference in a new issue