Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ This serves two purposes:

- Added missing collection key types in Hyde facade method annotations in https://github.com/hydephp/develop/pull/1784
- The `app.js` file will now only be compiled if it has scripts in https://github.com/hydephp/develop/pull/2028
- The `app.css` file will no longer be copied to the media output directory when app styles are configured to be loaded from a CDN in https://github.com/hydephp/develop/pull/2180

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Hyde\Framework\Actions\PreBuildTasks;

use Hyde\Facades\Config;
use Hyde\Facades\Filesystem;
use Hyde\Support\Filesystem\MediaFile;
use Hyde\Framework\Features\BuildTasks\PreBuildTask;
Expand All @@ -19,11 +20,17 @@ public function handle(): void
{
$this->newLine();

if (MediaFile::all()->isEmpty()) {
$files = MediaFile::all();

if (Config::getBool('hyde.load_app_styles_from_cdn', false)) {
$files->forget('app.css');
}

if ($files->isEmpty()) {
$this->skip("No media files to transfer.\n");
}

$this->withProgressBar(MediaFile::all(), function (MediaFile $file): void {
$this->withProgressBar($files, function (MediaFile $file): void {
$sitePath = $file->getOutputPath();
$this->needsParentDirectory($sitePath);
Filesystem::putContents($sitePath, $file->getContents());
Expand Down
56 changes: 56 additions & 0 deletions packages/framework/tests/Feature/StaticSiteServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,60 @@ public function testSiteOutputDirectoryCanBeChangedInConfiguration()

File::deleteDirectory(Hyde::path('_site/build'));
}

public function testAppCssIsTransferredWhenLoadAppStylesFromCdnIsFalse()
{
config(['hyde.load_app_styles_from_cdn' => false]);

$this->artisan('build')->assertExitCode(0);

$this->assertFileExists(Hyde::path('_site/media/app.css'));
$this->assertFileEquals(Hyde::path('_media/app.css'), Hyde::path('_site/media/app.css'));
}

public function testAppCssIsNotTransferredWhenLoadAppStylesFromCdnIsTrue()
{
config(['hyde.load_app_styles_from_cdn' => true]);

$this->artisan('build')->assertExitCode(0);

$this->assertFileDoesNotExist(Hyde::path('_site/media/app.css'));
}

public function testOtherAssetsAreTransferredWhenLoadAppStylesFromCdnIsTrue()
{
config(['hyde.load_app_styles_from_cdn' => true]);
$this->file('_media/image.png', 'fake image data');

$this->artisan('build')->assertExitCode(0);

$this->assertFileDoesNotExist(Hyde::path('_site/media/app.css'));
$this->assertFileExists(Hyde::path('_site/media/image.png'));
$this->assertFileEquals(Hyde::path('_media/image.png'), Hyde::path('_site/media/image.png'));
}

public function testSkipMessageWhenOnlyAppCssExistsAndLoadAppStylesFromCdnIsTrue()
{
config(['hyde.load_app_styles_from_cdn' => true]);

$this->artisan('build')
->expectsOutputToContain('Transferring Media Assets... ')
->expectsOutputToContain('Skipped')
->expectsOutputToContain('> No media files to transfer.')
->assertExitCode(0);
}

public function testNormalTransferWhenMultipleAssetsExistAndLoadAppStylesFromCdnIsTrue()
{
config(['hyde.load_app_styles_from_cdn' => true]);
$this->file('_media/image.png', 'fake image data');

$this->artisan('build')
->expectsOutputToContain('Transferring Media Assets...')
->doesntExpectOutputToContain('Skipped')
->assertExitCode(0);

$this->assertFileDoesNotExist(Hyde::path('_site/media/app.css'));
$this->assertFileExists(Hyde::path('_site/media/image.png'));
}
}
Loading