Skip to content

Commit

Permalink
Merge pull request #4 from davidhsianturi/feat-published-warn
Browse files Browse the repository at this point in the history
Show warning when manifest is outdated
  • Loading branch information
davidhsianturi authored Oct 12, 2019
2 parents 44c866f + 90499d8 commit 0e121ee
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
16 changes: 16 additions & 0 deletions resources/views/layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@
<sidebar-menu></sidebar-menu>

<main class="md:flex-1 md:overflow-x-hidden">
@if (! $assetsAreCurrent)
<div class="bg-blue-100 text-blue-900 px-4 py-3" role="alert">
<div class="flex">
<div class="py-1">
<svg class="fill-current h-6 w-6 text-blue-500 mr-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
<path d="M2.93 17.07A10 10 0 1 1 17.07 2.93 10 10 0 0 1 2.93 17.07zm12.73-1.41A8 8 0 1 0 4.34 4.34a8 8 0 0 0 11.32 11.32zM9 11V9h2v6H9v-4zm0-6h2v2H9V5z" />
</svg>
</div>
<div>
<p class="font-medium">The published Compass assets are not up-to-date with the installed version.</p>
<p class="text-sm">To update, run: <code class="ml-2">php artisan compass:publish</code></p>
</div>
</div>
</div>
@endif

<router-view :key="$route.path"></router-view>
</main>
</div>
Expand Down
20 changes: 20 additions & 0 deletions src/Compass.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Str;
use Illuminate\Routing\Route;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Route as RouteFacade;

final class Compass
Expand Down Expand Up @@ -140,4 +141,23 @@ public static function ignoreMigrations()

return new static;
}

/**
* Check if assets are up-to-date.
*
* src: https://github.com/laravel/telescope/pull/729
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
* @return bool
*/
public static function assetsAreCurrent()
{
$publishedPath = public_path('vendor/compass/mix-manifest.json');

if (! File::exists($publishedPath)) {
throw new \RuntimeException('The Compass assets are not published. Please run: php artisan compass:publish');
}

return File::get($publishedPath) === File::get(__DIR__.'/../public/mix-manifest.json');
}
}
1 change: 1 addition & 0 deletions src/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function __invoke()
{
return view('compass::layout', [
'compassScriptVariables' => Compass::scriptVariables(),
'assetsAreCurrent' => Compass::assetsAreCurrent(),
]);
}
}

0 comments on commit 0e121ee

Please sign in to comment.