Skip to content

Commit 44132df

Browse files
author
Jasper Koers
committed
✨ feat(services): ensure directories exist for generated files
- add directory existence checks for resource, DTO, test, observer, repository, and service files - improves file generation process by preventing errors when directories are missing
1 parent 12df1b2 commit 44132df

File tree

6 files changed

+12
-0
lines changed

6 files changed

+12
-0
lines changed

src/Services/APIResourceGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public function generate(string $model): void
1212
{
1313
$resourcePath = app_path("Http/Resources/{$model}Resource.php");
1414

15+
File::ensureDirectoryExists(dirname($resourcePath));
16+
1517
if (File::exists($resourcePath)) {
1618
return;
1719
}

src/Services/DTOGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public function generate(string $model, array $attributes): void
1717
{
1818
$dtoPath = app_path("DTOs/{$model}DTO.php");
1919

20+
File::ensureDirectoryExists(dirname($dtoPath));
21+
2022
if (File::exists($dtoPath)) {
2123
return;
2224
}

src/Services/FeatureTestGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public function generate(string $model): void
1212
{
1313
$testPath = base_path("tests/Feature/{$model}Test.php");
1414

15+
File::ensureDirectoryExists(dirname($testPath));
16+
1517
if (File::exists($testPath)) {
1618
return;
1719
}

src/Services/ObserverGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public function generate(string $model): void
1212
{
1313
$observerPath = app_path("Observers/{$model}Observer.php");
1414

15+
File::ensureDirectoryExists(dirname($observerPath));
16+
1517
if (File::exists($observerPath)) {
1618
return;
1719
}

src/Services/RepositoryGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public function generate(string $model): void
1212
{
1313
$repositoryPath = app_path("Repositories/{$model}Repository.php");
1414

15+
File::ensureDirectoryExists(dirname($repositoryPath));
16+
1517
if (File::exists($repositoryPath)) {
1618
return;
1719
}

src/Services/ServiceLayerGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public function generate(string $model): void
1212
{
1313
$servicePath = app_path("Services/{$model}Service.php");
1414

15+
File::ensureDirectoryExists(dirname($servicePath));
16+
1517
if (File::exists($servicePath)) {
1618
return;
1719
}

0 commit comments

Comments
 (0)