mirror of
https://github.com/opdavies/build-configs.git
synced 2025-01-23 02:27:33 +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
|
### Changed
|
||||||
|
|
||||||
* Replace `set -ueo` in Git hook templates to use the long names and be consistent with `run` scripts.
|
* 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
|
## 2023-11-22
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,11 @@ use Symfony\Component\Yaml\Yaml;
|
||||||
final class CreateFinalConfigurationData
|
final class CreateFinalConfigurationData
|
||||||
{
|
{
|
||||||
public function handle(string $configFile, \Closure $next) {
|
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(
|
$configurationData = array_replace_recursive(
|
||||||
Yaml::parseFile(filename: __DIR__ . '/../../resources/build.defaults.yaml'),
|
Yaml::parseFile(filename: __DIR__ . '/../../resources/build.defaults.yaml'),
|
||||||
Yaml::parseFile(filename: $configFile),
|
Yaml::parseFile(filename: $configFile),
|
||||||
|
|
|
@ -19,15 +19,12 @@ final class CreateListOfFilesToGenerate
|
||||||
* @var Config $configurationDataDto,
|
* @var Config $configurationDataDto,
|
||||||
* @var array<string,mixed> $configurationData
|
* @var array<string,mixed> $configurationData
|
||||||
*/
|
*/
|
||||||
[$configurationData, $configurationDataDto] = $configurationDataAndDto;
|
[$configurationData, $configurationDataDTO] = $configurationDataAndDto;
|
||||||
|
|
||||||
$isDocker = static::isDocker($configurationData);
|
|
||||||
$isFlake = static::isFlake($configurationData);
|
|
||||||
|
|
||||||
/** @var Collection<int, TemplateFile> */
|
/** @var Collection<int, TemplateFile> */
|
||||||
$filesToGenerate = collect();
|
$filesToGenerate = collect();
|
||||||
|
|
||||||
switch (strtolower($configurationDataDto->type)) {
|
switch (strtolower($configurationDataDTO->type)) {
|
||||||
case (strtolower(ProjectType::Astro->name)):
|
case (strtolower(ProjectType::Astro->name)):
|
||||||
$filesToGenerate = collect([
|
$filesToGenerate = collect([
|
||||||
new TemplateFile(data: 'astro/.envrc', name: '.envrc'),
|
new TemplateFile(data: 'astro/.envrc', name: '.envrc'),
|
||||||
|
@ -44,14 +41,14 @@ final class CreateListOfFilesToGenerate
|
||||||
new TemplateFile(data: 'fractal/run', name: 'run'),
|
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/.env.example', name: '.env.example'));
|
||||||
$filesToGenerate->push(new TemplateFile(data: 'fractal/.dockerignore', name: '.dockerignore'));
|
$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/.hadolint.yaml', name: '.hadolint.yaml'));
|
||||||
$filesToGenerate->push(new TemplateFile(data: 'fractal/.yarnrc', name: '.yarnrc'));
|
$filesToGenerate->push(new TemplateFile(data: 'fractal/.yarnrc', name: '.yarnrc'));
|
||||||
$filesToGenerate->push(new TemplateFile(data: 'fractal/Dockerfile', name: 'Dockerfile'));
|
$filesToGenerate->push(new TemplateFile(data: 'fractal/Dockerfile', name: 'Dockerfile'));
|
||||||
$filesToGenerate->push(new TemplateFile(data: 'fractal/docker-compose.yaml', name: 'docker-compose.yaml'));
|
$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/.envrc', name: '.envrc'));
|
||||||
$filesToGenerate->push(new TemplateFile(data: 'fractal/flake.nix', name: 'flake.nix'));
|
$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'));
|
$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'));
|
$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'));
|
$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
|
private static function isCaddy(?string $webServer): bool
|
||||||
|
@ -168,20 +165,6 @@ final class CreateListOfFilesToGenerate
|
||||||
return strtoupper($webServer) === WebServer::Caddy->value;
|
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
|
private static function isNginx(?string $webServer): bool
|
||||||
{
|
{
|
||||||
if (is_null($webServer)) {
|
if (is_null($webServer)) {
|
||||||
|
|
|
@ -273,4 +273,8 @@ final class Config
|
||||||
]),
|
]),
|
||||||
])]
|
])]
|
||||||
public array $web;
|
public array $web;
|
||||||
|
|
||||||
|
public bool $isDocker;
|
||||||
|
|
||||||
|
public bool $isFlake;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,6 @@
|
||||||
set -o errexit
|
set -o errexit
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
{% set isFlake = flake is defined %}
|
|
||||||
|
|
||||||
PATH="$PATH:./node_modules/.bin"
|
PATH="$PATH:./node_modules/.bin"
|
||||||
|
|
||||||
{% if not isFlake %}
|
{% if not isFlake %}
|
||||||
|
|
|
@ -5,9 +5,6 @@
|
||||||
set -o errexit
|
set -o errexit
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
{% set isDocker = flake is not defined %}
|
|
||||||
{% set isFlake = flake is defined %}
|
|
||||||
|
|
||||||
PATH="$PATH:./node_modules/.bin"
|
PATH="$PATH:./node_modules/.bin"
|
||||||
|
|
||||||
{% if isDocker %}
|
{% if isDocker %}
|
||||||
|
|
Loading…
Reference in a new issue