diff --git a/app/Listeners/CleanUpFrontEndLocaleFiles.php b/app/Listeners/CleanUpFrontEndLocaleFiles.php new file mode 100644 index 00000000..27487875 --- /dev/null +++ b/app/Listeners/CleanUpFrontEndLocaleFiles.php @@ -0,0 +1,27 @@ +filesystem = $filesystem; + } + + public function handle() + { + $files = $this->filesystem->allFiles(public_path('lang')); + array_walk($files, function (SplFileInfo $file) { + if ($file->getExtension() === 'js') { + $this->filesystem->delete($file->getPathname()); + } + }); + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 94fcdf1b..cdde149c 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -11,9 +11,11 @@ class EventServiceProvider extends ServiceProvider protected $listen = [ 'App\Events\PluginWasEnabled' => [ Listeners\CopyPluginAssets::class, + Listeners\CleanUpFrontEndLocaleFiles::class, ], 'plugin.versionChanged' => [ Listeners\CopyPluginAssets::class, + Listeners\CleanUpFrontEndLocaleFiles::class, ], 'App\Events\PluginBootFailed' => [ Listeners\NotifyFailedPlugin::class, diff --git a/tests/ListenersTest/CleanUpFrontEndLocaleFilesTest.php b/tests/ListenersTest/CleanUpFrontEndLocaleFilesTest.php new file mode 100644 index 00000000..a8953a75 --- /dev/null +++ b/tests/ListenersTest/CleanUpFrontEndLocaleFilesTest.php @@ -0,0 +1,27 @@ + 'fake']); + + $this->partialMock(\Illuminate\Filesystem\Filesystem::class, function ($mock) { + $dir = public_path('lang'); + $path = public_path('lang/en.js'); + $mock->shouldReceive('allFiles') + ->with($dir) + ->once() + ->andReturn([new SplFileInfo(public_path('lang/en.js'), 'en.js', 'en.js')]); + $mock->shouldReceive('delete') + ->with($path) + ->once(); + }); + + event('plugin.versionChanged', [$plugin]); + } +} diff --git a/tests/ListenersTest/CopyPluginAssetsTest.php b/tests/ListenersTest/CopyPluginAssetsTest.php index f2659b01..bc9b322d 100644 --- a/tests/ListenersTest/CopyPluginAssetsTest.php +++ b/tests/ListenersTest/CopyPluginAssetsTest.php @@ -8,7 +8,7 @@ class CopyPluginAssetsTest extends TestCase { $plugin = new \App\Services\Plugin('/path', ['name' => 'fake']); - $this->mock(\Illuminate\Filesystem\Filesystem::class, function ($mock) { + $this->partialMock(\Illuminate\Filesystem\Filesystem::class, function ($mock) { $dir = public_path('plugins/fake'); $mock->shouldReceive('deleteDirectory') ->with($dir)