From cd4355bbc1f15903653292709273a164155c9587 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sun, 24 Sep 2023 18:10:24 +0100 Subject: [PATCH] feat: add support for Astro projects --- src/Action/CreateListOfFilesToGenerate.php | 27 +++++++++++++++++++--- src/DataTransferObject/Config.php | 2 +- src/Enum/ProjectType.php | 10 ++++++++ templates/astro/.envrc.twig | 3 +++ templates/astro/flake.nix.twig | 25 ++++++++++++++++++++ templates/astro/tsconfig.json.twig | 12 ++++++++++ 6 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 src/Enum/ProjectType.php create mode 100644 templates/astro/.envrc.twig create mode 100644 templates/astro/flake.nix.twig create mode 100644 templates/astro/tsconfig.json.twig diff --git a/src/Action/CreateListOfFilesToGenerate.php b/src/Action/CreateListOfFilesToGenerate.php index 1e65aac..fd16c20 100644 --- a/src/Action/CreateListOfFilesToGenerate.php +++ b/src/Action/CreateListOfFilesToGenerate.php @@ -7,6 +7,7 @@ namespace App\Action; use App\DataTransferObject\Config; use App\DataTransferObject\TemplateFile; use App\Enum\Language; +use App\Enum\ProjectType; use App\Enum\WebServer; use Illuminate\Support\Arr; use Illuminate\Support\Collection; @@ -21,12 +22,32 @@ final class CreateListOfFilesToGenerate */ [$configurationData, $configurationDataDto] = $configurationDataAndDto; - $isDocker = static::isDocker($configurationData); - $isFlake = static::isFlake($configurationData); - /** @var Collection */ $filesToGenerate = collect(); + switch (strtolower($configurationDataDto->type)) { + case (strtolower(ProjectType::Astro->name)): + $filesToGenerate = collect([ + ['astro/.envrc', '.envrc'], + ['astro/flake.nix', 'flake.nix'], + ['astro/tsconfig.json', 'tsconfig.json'], + ])->map(function (array $file) { + return new TemplateFile( + data: $file[0], + name: $file[1], + path: null, + ); + }); + break; + } + + if ($filesToGenerate->isNotEmpty()) { + return $next([$configurationData, $configurationDataDto, $filesToGenerate]); + } + + $isDocker = static::isDocker($configurationData); + $isFlake = static::isFlake($configurationData); + if ($isDocker) { $filesToGenerate->push(new TemplateFile(data: 'common/.dockerignore', name: '.dockerignore')); $filesToGenerate->push(new TemplateFile(data: 'common/.hadolint.yaml', name: '.hadolint.yaml')); diff --git a/src/DataTransferObject/Config.php b/src/DataTransferObject/Config.php index 0420b00..17d5b12 100644 --- a/src/DataTransferObject/Config.php +++ b/src/DataTransferObject/Config.php @@ -54,7 +54,7 @@ final class Config #[Assert\NotBlank] public string $name; - #[Assert\Choice(choices: ['drupal', 'fractal', 'laravel', 'php-library', 'vuejs'])] + #[Assert\Choice(choices: ['astro', 'drupal', 'fractal', 'laravel', 'php-library', 'vuejs'])] #[Assert\NotBlank] public string $type; diff --git a/src/Enum/ProjectType.php b/src/Enum/ProjectType.php new file mode 100644 index 0000000..45f0246 --- /dev/null +++ b/src/Enum/ProjectType.php @@ -0,0 +1,10 @@ +