From d6d2195052efddbda0982a20c6b5804ce1a7635b Mon Sep 17 00:00:00 2001 From: Luca Patera Date: Fri, 15 Mar 2024 00:58:05 +0100 Subject: [PATCH] Fix missing lang folder --- src/Console/LarexInitCommand.php | 2 +- src/Support/Utils.php | 9 +++++++++ tests/Pest.php | 7 ++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Console/LarexInitCommand.php b/src/Console/LarexInitCommand.php index cbaa4f9..6e45da9 100644 --- a/src/Console/LarexInitCommand.php +++ b/src/Console/LarexInitCommand.php @@ -41,7 +41,7 @@ public function handle(): int return 1; } - File::put(csv_path(), Utils::getStub($stub)); + Utils::filePut(csv_path(), Utils::getStub($stub)); $this->info(csv_path(true).' created successfully.'); diff --git a/src/Support/Utils.php b/src/Support/Utils.php index cfd8aa4..8751a3d 100644 --- a/src/Support/Utils.php +++ b/src/Support/Utils.php @@ -306,4 +306,13 @@ public static function putJson(string $path, $data): void JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); File::put($path, Str::finish($content, "\n")); } + + public static function filePut(string $path, string $content): void + { + if (!File::exists(dirname($path))) { + File::makeDirectory(dirname($path), 0755, true, true); + } + + File::put($path, $content); + } } diff --git a/tests/Pest.php b/tests/Pest.php index 3e8213d..7dcb83c 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -42,6 +42,11 @@ File::delete($item); } } + + //delete lang folder + if (file_exists(lang_path())) { + @rmdir(lang_path()); + } }) ->in(__DIR__); @@ -81,7 +86,7 @@ function getTestStub(string $name, $eol = "\n"): string function initFromStub(string $stub, string $file = null): string { $filePath = Utils::normalizeDS($file ?? csv_path()); - File::put($filePath, getTestStub($stub)); + Utils::filePut($filePath, getTestStub($stub)); return $filePath; }