Skip to content

Commit

Permalink
Move media asset transfer logic to build task
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Feb 8, 2024
1 parent 2259a40 commit cfb9148
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
}
15 changes: 1 addition & 14 deletions packages/framework/src/Framework/Services/BuildService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@
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;

use function class_basename;
use function preg_replace;
use function collect;
use function copy;

/**
* Moves logic from the build command to a service.
Expand All @@ -30,7 +27,6 @@
class BuildService
{
use InteractsWithIO;
use InteractsWithDirectories;

protected RouteCollection $router;

Expand All @@ -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);
//
}

/**
Expand Down

0 comments on commit cfb9148

Please sign in to comment.