fix front end i18n can't be updated

fix bs-community/blessing-skin-plugins#74
This commit is contained in:
Pig Fang 2020-08-22 18:10:37 +08:00
parent 10d5b95358
commit 5f4ad85f0f
No known key found for this signature in database
GPG Key ID: A8198F548DADA9E2
4 changed files with 57 additions and 1 deletions

View File

@ -0,0 +1,27 @@
<?php
namespace App\Listeners;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Finder\SplFileInfo;
class CleanUpFrontEndLocaleFiles
{
/** @var Filesystem */
protected $filesystem;
public function __construct(Filesystem $filesystem)
{
$this->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());
}
});
}
}

View File

@ -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,

View File

@ -0,0 +1,27 @@
<?php
namespace Tests;
use Symfony\Component\Finder\SplFileInfo;
class CleanUpFrontEndLocaleFilesTest extends TestCase
{
public function testHandle()
{
$plugin = new \App\Services\Plugin('/path', ['name' => '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]);
}
}

View File

@ -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)