From e7609801e416bd94986c382ef255b90108437210 Mon Sep 17 00:00:00 2001 From: Daniel Mason Date: Mon, 9 Oct 2023 22:23:29 +0100 Subject: [PATCH] Create missing baseline directories (#7) --- config/translation-linter.php | 2 +- src/Collections/ResultObjectCollection.php | 2 +- src/Contracts/Collections/ResultObjectCollection.php | 2 +- src/Writers/UnusedBaselineFileWriter.php | 9 +++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/config/translation-linter.php b/config/translation-linter.php index a4ab52c..e58be08 100644 --- a/config/translation-linter.php +++ b/config/translation-linter.php @@ -99,7 +99,7 @@ | option when running the command. | */ - 'baseline' => base_path('translations.unused.baseline.json'), + 'baseline' => lang_path('.lint/unused.json'), /* |-------------------------------------------------------------------------- diff --git a/src/Collections/ResultObjectCollection.php b/src/Collections/ResultObjectCollection.php index a312eb2..1f4af07 100644 --- a/src/Collections/ResultObjectCollection.php +++ b/src/Collections/ResultObjectCollection.php @@ -16,7 +16,7 @@ public function reset(): void $this->items = []; } - public function toBaseLineJson(): string + public function toBaselineJson(): string { return $this ->groupBy('locale') diff --git a/src/Contracts/Collections/ResultObjectCollection.php b/src/Contracts/Collections/ResultObjectCollection.php index f0eb07f..c72fd8c 100644 --- a/src/Contracts/Collections/ResultObjectCollection.php +++ b/src/Contracts/Collections/ResultObjectCollection.php @@ -16,7 +16,7 @@ interface ResultObjectCollection extends Arrayable, Enumerable { public function reset(): void; - public function toBaseLineJson(): string; + public function toBaselineJson(): string; public function toCommandTableOutputArray(FieldCollectionContract $fields): array; diff --git a/src/Writers/UnusedBaselineFileWriter.php b/src/Writers/UnusedBaselineFileWriter.php index a97e7a8..f7d70a5 100644 --- a/src/Writers/UnusedBaselineFileWriter.php +++ b/src/Writers/UnusedBaselineFileWriter.php @@ -15,9 +15,10 @@ public function __construct( public function execute(ResultObjectCollection $results) { - $this->filesystem->put( - $this->file, - $results->toBaseLineJson(), - ); + $path = $this->filesystem->dirname($this->file); + + $this->filesystem->ensureDirectoryExists($path); + + $this->filesystem->put($this->file, $results->toBaselineJson()); } }