Skip to content

Commit

Permalink
Merge pull request #466 from hydephp/build-manifest
Browse files Browse the repository at this point in the history
Update build manifest generation
  • Loading branch information
caendesilva authored Sep 6, 2022
2 parents 2ca777c + 3c0cfa8 commit c8fc2ae
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
use Illuminate\Console\OutputStyle;
use Illuminate\Support\Collection;

/**
* @see \Hyde\Framework\Testing\Unit\GenerateBuildManifestTest
*/
class GenerateBuildManifest extends AbstractBuildTask
{
public static string $description = 'Generating build manifest';

public function __construct(?OutputStyle $output = null)
{
parent::__construct($output);
Expand All @@ -23,13 +28,18 @@ public function run(): void
foreach (Hyde::pages() as $page) {
$manifest->push([
'page' => $page->getSourcePath(),
'source_hash' => md5(Hyde::path($page->getSourcePath())),
'output_hash' => md5(Hyde::path($page->getOutputPath())),
'source_hash' => md5_file(Hyde::path($page->getSourcePath())),
'output_hash' => $this->hashOutputPath(Hyde::getSiteOutputPath($page->getOutputPath())),
]);
}

file_put_contents(Hyde::path(config('hyde.build_manifest_path',
'storage/framework/cache/build-manifest.json')
), $manifest->toJson());
}

protected function hashOutputPath(string $path): ?string
{
return file_exists($path) ? md5_file($path) : null;
}
}
32 changes: 32 additions & 0 deletions packages/framework/tests/Unit/GenerateBuildManifestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Hyde\Framework\Testing\Unit;

use Hyde\Framework\Actions\PostBuildTasks\GenerateBuildManifest;
use Hyde\Framework\Hyde;
use Hyde\Testing\TestCase;

/**
* @covers \Hyde\Framework\Actions\PostBuildTasks\GenerateBuildManifest
*/
class GenerateBuildManifestTest extends TestCase
{
public function test_action_generates_build_manifest()
{
(new GenerateBuildManifest())->run();

$this->assertFileExists(Hyde::path('storage/framework/cache/build-manifest.json'));

$manifest = json_decode(file_get_contents(Hyde::path('storage/framework/cache/build-manifest.json')), true);

$this->assertIsArray($manifest);
$this->assertCount(2, $manifest);

$this->assertArrayHasKey('page', $manifest[0]);
$this->assertArrayHasKey('source_hash', $manifest[0]);
$this->assertArrayHasKey('output_hash', $manifest[0]);

$this->assertStringContainsString('_pages/404.blade.php', $manifest[0]['page']);
$this->assertStringContainsString('_pages/index.blade.php', $manifest[1]['page']);
}
}

0 comments on commit c8fc2ae

Please sign in to comment.