From cfb9148e8d5feefc97935b628e95f4cb16e3e714 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 8 Feb 2024 12:06:57 +0100 Subject: [PATCH] Move media asset transfer logic to build task --- .../PreBuildTasks/TransferMediaAssets.php | 16 ++++++++++++++++ .../src/Framework/Services/BuildService.php | 15 +-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/framework/src/Framework/Actions/PreBuildTasks/TransferMediaAssets.php b/packages/framework/src/Framework/Actions/PreBuildTasks/TransferMediaAssets.php index 657fa9ffac3..025c0ee7bcc 100644 --- a/packages/framework/src/Framework/Actions/PreBuildTasks/TransferMediaAssets.php +++ b/packages/framework/src/Framework/Actions/PreBuildTasks/TransferMediaAssets.php @@ -4,9 +4,25 @@ namespace Hyde\Framework\Actions\PreBuildTasks; +use Hyde\Hyde; +use Hyde\Support\Filesystem\MediaFile; use Hyde\Framework\Features\BuildTasks\PreBuildTask; +use Hyde\Framework\Concerns\InteractsWithDirectories; class TransferMediaAssets extends PreBuildTask { protected static string $message = 'Transferring Media Assets'; + + use InteractsWithDirectories; + + public function handle(): void + { + $this->needsDirectory(Hyde::siteMediaPath()); + + $this->withProgressBar(MediaFile::files(), function (string $identifier): void { + $sitePath = Hyde::siteMediaPath($identifier); + $this->needsParentDirectory($sitePath); + copy(Hyde::mediaPath($identifier), $sitePath); + }); + } } diff --git a/packages/framework/src/Framework/Services/BuildService.php b/packages/framework/src/Framework/Services/BuildService.php index 83c2686e011..55a59ef4937 100644 --- a/packages/framework/src/Framework/Services/BuildService.php +++ b/packages/framework/src/Framework/Services/BuildService.php @@ -8,9 +8,7 @@ use Hyde\Foundation\Facades\Routes; use Hyde\Foundation\Kernel\RouteCollection; use Hyde\Framework\Actions\StaticPageBuilder; -use Hyde\Framework\Concerns\InteractsWithDirectories; use Hyde\Pages\Concerns\HydePage; -use Hyde\Support\Filesystem\MediaFile; use Hyde\Support\Models\Route; use Illuminate\Console\Concerns\InteractsWithIO; use Illuminate\Console\OutputStyle; @@ -18,7 +16,6 @@ use function class_basename; use function preg_replace; use function collect; -use function copy; /** * Moves logic from the build command to a service. @@ -30,7 +27,6 @@ class BuildService { use InteractsWithIO; - use InteractsWithDirectories; protected RouteCollection $router; @@ -50,16 +46,7 @@ public function compileStaticPages(): void public function transferMediaAssets(): void { - $this->needsDirectory(Hyde::siteMediaPath()); - - $this->comment('Transferring Media Assets...'); - $this->withProgressBar(MediaFile::files(), function (string $identifier): void { - $sitePath = Hyde::siteMediaPath($identifier); - $this->needsParentDirectory($sitePath); - copy(Hyde::mediaPath($identifier), $sitePath); - }); - - $this->newLine(2); + // } /**