From 824842b3ab0ea47572850ae9641ab0b977f05ec2 Mon Sep 17 00:00:00 2001 From: antoine Date: Wed, 11 Feb 2026 13:25:59 +0100 Subject: [PATCH] Clear assets public directory on publish --- src/SharpInternalServiceProvider.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/SharpInternalServiceProvider.php b/src/SharpInternalServiceProvider.php index 6105db7c2..90395da4e 100644 --- a/src/SharpInternalServiceProvider.php +++ b/src/SharpInternalServiceProvider.php @@ -39,14 +39,17 @@ use Code16\Sharp\Utils\SharpUtil; use Code16\Sharp\Utils\Uploads\SharpUploadManager; use Code16\Sharp\View\Components\Content; -use Code16\Sharp\View\Components\File; +use Code16\Sharp\View\Components\File as FileComponent; use Code16\Sharp\View\Components\Image; use Illuminate\Auth\AuthenticationException; use Illuminate\Auth\Notifications\ResetPassword; +use Illuminate\Console\Events\CommandStarting; use Illuminate\Contracts\Debug\ExceptionHandler; use Illuminate\Session\TokenMismatchException; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Blade; +use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\File; use Illuminate\Support\ServiceProvider; use Inertia\ServiceProvider as InertiaServiceProvider; use Laravel\Octane\Events\RequestReceived; @@ -77,10 +80,12 @@ public function boot() 'sharp-views' ); + $this->clearAssetsPublicDirectoryOnPublish(); + Blade::componentNamespace('Code16\\Sharp\\View\\Components', 'sharp'); Blade::componentNamespace('Code16\\Sharp\\View\\Components\\Content', 'sharp-content'); Blade::component(Content::class, 'sharp-content'); - Blade::component(File::class, 'sharp-file'); + Blade::component(FileComponent::class, 'sharp-file'); Blade::component(Image::class, 'sharp-image'); $this->registerViewExceptionMapper(); @@ -200,6 +205,20 @@ protected function registerViewExceptionMapper(): void }); } + protected function clearAssetsPublicDirectoryOnPublish(): void + { + Event::listen(CommandStarting::class, function (CommandStarting $event) { + if ($event->command === 'vendor:publish' + && $event->input->getOption('tag') + && in_array('sharp-assets', $event->input->getOption('tag')) + ) { + if (File::exists(public_path('vendor/sharp'))) { + File::deleteDirectory(public_path('vendor/sharp')); + } + } + }); + } + public function loadRoutes(): void { $this->loadRoutesFrom(__DIR__.'/routes/web.php');