fix front end i18n can't be updated
fix bs-community/blessing-skin-plugins#74
This commit is contained in:
parent
10d5b95358
commit
5f4ad85f0f
27
app/Listeners/CleanUpFrontEndLocaleFiles.php
Normal file
27
app/Listeners/CleanUpFrontEndLocaleFiles.php
Normal 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());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,9 +11,11 @@ class EventServiceProvider extends ServiceProvider
|
||||||
protected $listen = [
|
protected $listen = [
|
||||||
'App\Events\PluginWasEnabled' => [
|
'App\Events\PluginWasEnabled' => [
|
||||||
Listeners\CopyPluginAssets::class,
|
Listeners\CopyPluginAssets::class,
|
||||||
|
Listeners\CleanUpFrontEndLocaleFiles::class,
|
||||||
],
|
],
|
||||||
'plugin.versionChanged' => [
|
'plugin.versionChanged' => [
|
||||||
Listeners\CopyPluginAssets::class,
|
Listeners\CopyPluginAssets::class,
|
||||||
|
Listeners\CleanUpFrontEndLocaleFiles::class,
|
||||||
],
|
],
|
||||||
'App\Events\PluginBootFailed' => [
|
'App\Events\PluginBootFailed' => [
|
||||||
Listeners\NotifyFailedPlugin::class,
|
Listeners\NotifyFailedPlugin::class,
|
||||||
|
|
|
||||||
27
tests/ListenersTest/CleanUpFrontEndLocaleFilesTest.php
Normal file
27
tests/ListenersTest/CleanUpFrontEndLocaleFilesTest.php
Normal 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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ class CopyPluginAssetsTest extends TestCase
|
||||||
{
|
{
|
||||||
$plugin = new \App\Services\Plugin('/path', ['name' => 'fake']);
|
$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');
|
$dir = public_path('plugins/fake');
|
||||||
$mock->shouldReceive('deleteDirectory')
|
$mock->shouldReceive('deleteDirectory')
|
||||||
->with($dir)
|
->with($dir)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user