From 5f4ad85f0f3eac7dcb0c5a2a635886072e9524a3 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sat, 22 Aug 2020 18:10:37 +0800 Subject: [PATCH] fix front end i18n can't be updated fix bs-community/blessing-skin-plugins#74 --- app/Listeners/CleanUpFrontEndLocaleFiles.php | 27 +++++++++++++++++++ app/Providers/EventServiceProvider.php | 2 ++ .../CleanUpFrontEndLocaleFilesTest.php | 27 +++++++++++++++++++ tests/ListenersTest/CopyPluginAssetsTest.php | 2 +- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 app/Listeners/CleanUpFrontEndLocaleFiles.php create mode 100644 tests/ListenersTest/CleanUpFrontEndLocaleFilesTest.php 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)