Skip to content

Commit e5036c4

Browse files
authored
Merge pull request #706 from code16/clear-assets-dir-on-publish
Clear assets public directory on publish
2 parents 41166a6 + 824842b commit e5036c4

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/SharpInternalServiceProvider.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@
3939
use Code16\Sharp\Utils\SharpUtil;
4040
use Code16\Sharp\Utils\Uploads\SharpUploadManager;
4141
use Code16\Sharp\View\Components\Content;
42-
use Code16\Sharp\View\Components\File;
42+
use Code16\Sharp\View\Components\File as FileComponent;
4343
use Code16\Sharp\View\Components\Image;
4444
use Illuminate\Auth\AuthenticationException;
4545
use Illuminate\Auth\Notifications\ResetPassword;
46+
use Illuminate\Console\Events\CommandStarting;
4647
use Illuminate\Contracts\Debug\ExceptionHandler;
4748
use Illuminate\Session\TokenMismatchException;
4849
use Illuminate\Support\Carbon;
4950
use Illuminate\Support\Facades\Blade;
51+
use Illuminate\Support\Facades\Event;
52+
use Illuminate\Support\Facades\File;
5053
use Illuminate\Support\ServiceProvider;
5154
use Inertia\ServiceProvider as InertiaServiceProvider;
5255
use Laravel\Octane\Events\RequestReceived;
@@ -77,10 +80,12 @@ public function boot()
7780
'sharp-views'
7881
);
7982

83+
$this->clearAssetsPublicDirectoryOnPublish();
84+
8085
Blade::componentNamespace('Code16\\Sharp\\View\\Components', 'sharp');
8186
Blade::componentNamespace('Code16\\Sharp\\View\\Components\\Content', 'sharp-content');
8287
Blade::component(Content::class, 'sharp-content');
83-
Blade::component(File::class, 'sharp-file');
88+
Blade::component(FileComponent::class, 'sharp-file');
8489
Blade::component(Image::class, 'sharp-image');
8590

8691
$this->registerViewExceptionMapper();
@@ -200,6 +205,20 @@ protected function registerViewExceptionMapper(): void
200205
});
201206
}
202207

208+
protected function clearAssetsPublicDirectoryOnPublish(): void
209+
{
210+
Event::listen(CommandStarting::class, function (CommandStarting $event) {
211+
if ($event->command === 'vendor:publish'
212+
&& $event->input->getOption('tag')
213+
&& in_array('sharp-assets', $event->input->getOption('tag'))
214+
) {
215+
if (File::exists(public_path('vendor/sharp'))) {
216+
File::deleteDirectory(public_path('vendor/sharp'));
217+
}
218+
}
219+
});
220+
}
221+
203222
public function loadRoutes(): void
204223
{
205224
$this->loadRoutesFrom(__DIR__.'/routes/web.php');

0 commit comments

Comments
 (0)