From f9e48e76d92408f759c0bfc4e10c23e10ffcd214 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 1 Sep 2022 10:38:58 +0200 Subject: [PATCH 1/6] Add site prefix to path to output message to be consistent --- .../framework/src/Actions/PostBuildTasks/GenerateRssFeed.php | 2 +- .../framework/src/Actions/PostBuildTasks/GenerateSitemap.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Actions/PostBuildTasks/GenerateRssFeed.php b/packages/framework/src/Actions/PostBuildTasks/GenerateRssFeed.php index 2e901794226..b1affcdc85a 100644 --- a/packages/framework/src/Actions/PostBuildTasks/GenerateRssFeed.php +++ b/packages/framework/src/Actions/PostBuildTasks/GenerateRssFeed.php @@ -20,7 +20,7 @@ public function run(): void public function then(): void { - $this->writeln(sprintf("\n > Created %s in %s", + $this->writeln(sprintf("\n > Created _site/%s in %s", RssFeedService::getDefaultOutputFilename(), $this->getExecutionTime() )); diff --git a/packages/framework/src/Actions/PostBuildTasks/GenerateSitemap.php b/packages/framework/src/Actions/PostBuildTasks/GenerateSitemap.php index 3e8f893803a..1b8bc6d44e3 100644 --- a/packages/framework/src/Actions/PostBuildTasks/GenerateSitemap.php +++ b/packages/framework/src/Actions/PostBuildTasks/GenerateSitemap.php @@ -20,7 +20,7 @@ public function run(): void public function then(): void { - $this->writeln(sprintf("\n > Created sitemap.xml in %s", + $this->writeln(sprintf("\n > Created _site/sitemap.xml in %s", $this->getExecutionTime() )); } From 876c289171eae58ed668f81b6f3eb823f615b8aa Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 1 Sep 2022 10:42:01 +0200 Subject: [PATCH 2/6] Update BuildTaskServiceTest.php --- .../framework/tests/Feature/Services/BuildTaskServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/Services/BuildTaskServiceTest.php b/packages/framework/tests/Feature/Services/BuildTaskServiceTest.php index 72bd2aca621..27aec45eea8 100644 --- a/packages/framework/tests/Feature/Services/BuildTaskServiceTest.php +++ b/packages/framework/tests/Feature/Services/BuildTaskServiceTest.php @@ -28,7 +28,7 @@ public function test_build_command_can_run_post_build_tasks() $this->artisan('build') ->expectsOutputToContain('Generating sitemap') - ->expectsOutputToContain('Created sitemap.xml') + ->expectsOutputToContain('Created _site/sitemap.xml') ->assertExitCode(0); File::cleanDirectory(Hyde::path('_site')); From da94a764c8d9c8ab829005df597f872b1ec867f4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 1 Sep 2022 10:43:06 +0200 Subject: [PATCH 3/6] Make AbstractBuildTask::createdSiteFile method chainable --- packages/framework/src/Contracts/AbstractBuildTask.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Contracts/AbstractBuildTask.php b/packages/framework/src/Contracts/AbstractBuildTask.php index 23c8264c238..9ec6049db8d 100644 --- a/packages/framework/src/Contracts/AbstractBuildTask.php +++ b/packages/framework/src/Contracts/AbstractBuildTask.php @@ -69,10 +69,12 @@ public function writeln(string $message): void $this->output?->writeln($message); } - public function createdSiteFile(string $path): void + public function createdSiteFile(string $path): static { $this->write(sprintf("\n > Created %s", str_replace('\\', '/', Hyde::pathToRelative($path)) )); + + return $this; } } From 750d79b98b5dea7dd410adc54aea718f9c785dce Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 1 Sep 2022 10:46:06 +0200 Subject: [PATCH 4/6] Add method chainable helper to print the execution time --- packages/framework/src/Contracts/AbstractBuildTask.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/framework/src/Contracts/AbstractBuildTask.php b/packages/framework/src/Contracts/AbstractBuildTask.php index 9ec6049db8d..6ca153ad808 100644 --- a/packages/framework/src/Contracts/AbstractBuildTask.php +++ b/packages/framework/src/Contracts/AbstractBuildTask.php @@ -77,4 +77,11 @@ public function createdSiteFile(string $path): static return $this; } + + public function withExecutionTime(): static + { + $this->write(" in {$this->getExecutionTime()}"); + + return $this; + } } From 43419446fc4b64b8753209da52b9cfd764ebc5c8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 1 Sep 2022 10:49:14 +0200 Subject: [PATCH 5/6] Use the new fluent execution time helper --- .../framework/src/Actions/PostBuildTasks/GenerateRssFeed.php | 5 +---- .../framework/src/Actions/PostBuildTasks/GenerateSearch.php | 5 +---- .../framework/src/Actions/PostBuildTasks/GenerateSitemap.php | 4 +--- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/framework/src/Actions/PostBuildTasks/GenerateRssFeed.php b/packages/framework/src/Actions/PostBuildTasks/GenerateRssFeed.php index b1affcdc85a..d325326b583 100644 --- a/packages/framework/src/Actions/PostBuildTasks/GenerateRssFeed.php +++ b/packages/framework/src/Actions/PostBuildTasks/GenerateRssFeed.php @@ -20,9 +20,6 @@ public function run(): void public function then(): void { - $this->writeln(sprintf("\n > Created _site/%s in %s", - RssFeedService::getDefaultOutputFilename(), - $this->getExecutionTime() - )); + $this->createdSiteFile('_site/'.RssFeedService::getDefaultOutputFilename())->withExecutionTime(); } } diff --git a/packages/framework/src/Actions/PostBuildTasks/GenerateSearch.php b/packages/framework/src/Actions/PostBuildTasks/GenerateSearch.php index 7071a12880a..80a6d8ea3e6 100644 --- a/packages/framework/src/Actions/PostBuildTasks/GenerateSearch.php +++ b/packages/framework/src/Actions/PostBuildTasks/GenerateSearch.php @@ -31,10 +31,7 @@ public function run(): void public function then(): void { - $this->writeln(sprintf("\n > Created %s in %s", - $this->normalizePath(DocumentationSearchService::$filePath), - $this->getExecutionTime() - )); + $this->createdSiteFile(DocumentationSearchService::$filePath)->withExecutionTime(); } protected function normalizePath(string $path): string diff --git a/packages/framework/src/Actions/PostBuildTasks/GenerateSitemap.php b/packages/framework/src/Actions/PostBuildTasks/GenerateSitemap.php index 1b8bc6d44e3..d03fca7fad3 100644 --- a/packages/framework/src/Actions/PostBuildTasks/GenerateSitemap.php +++ b/packages/framework/src/Actions/PostBuildTasks/GenerateSitemap.php @@ -20,8 +20,6 @@ public function run(): void public function then(): void { - $this->writeln(sprintf("\n > Created _site/sitemap.xml in %s", - $this->getExecutionTime() - )); + $this->createdSiteFile('_site/sitemap.xml')->withExecutionTime(); } } From cb6926cc769d9d753b63614735c061e8533271b7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 1 Sep 2022 10:51:49 +0200 Subject: [PATCH 6/6] Remove unused internal method --- .../framework/src/Actions/PostBuildTasks/GenerateSearch.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/framework/src/Actions/PostBuildTasks/GenerateSearch.php b/packages/framework/src/Actions/PostBuildTasks/GenerateSearch.php index 80a6d8ea3e6..3f0547c4feb 100644 --- a/packages/framework/src/Actions/PostBuildTasks/GenerateSearch.php +++ b/packages/framework/src/Actions/PostBuildTasks/GenerateSearch.php @@ -34,11 +34,6 @@ public function then(): void $this->createdSiteFile(DocumentationSearchService::$filePath)->withExecutionTime(); } - protected function normalizePath(string $path): string - { - return str_replace('\\', '/', $path); - } - /** @internal Estimated processing time per file in ms */ public static float $guesstimationFactor = 52.5;