Skip to content

Commit

Permalink
Improve package resources (#1285)
Browse files Browse the repository at this point in the history
* [src/Console]: Improve abstract class PackageResource

* [src/Console]: Improve AssetsResource class

* [src/Console]: Fix Style CI in AssetsResource class

* [src/Console]: Rename AssetsResource to  AdminlteAssetsResoruce

* [src/Console]: Fix some issues detected on AdminLtePluginCommand class

* [src/Console]: Improve AuthViewsResource class

* [src/Console]: Improve BasicRoutesResource class

* [src/Console]: Fix Style CI in BasicRoutesResource class

* [src/Console]: Rename BasicRoutesResource to AuthRoutesResource

* [src/Console]: Remove BasicViewsResource

* [src/Console]: Improve ConfigResource class

* [src/Console]: Improve TranslationsResource class

* [src/Console]: Add some fixes to AdminlteAssetsResource class

* [src/Console]: Add some fixes to AuthRoutesResource class

* [src/Console]: Add some fixes to AuthViewsResource class

* [tests/Console]: Add fix when testing auth views resources

* [src/Console]: Add some fixes to ConfigResource class

* [src/Console]: Add some fixes to TranslationsResource class

* [src/Console]: Rework all logic in the MainViewsResource class

* [src/Console]: Rename MainViewsResource to LayoutViewsResource

* [src/Console]: Improve PluginsResource class

* [src/Console]: Fix method getSourceData() of PluginsResource class

* [src/Console]: Revert install/uninstall return boolean

There is no need to return boolean, it's better to let an exeption happen

* [src/Console]: Minor fix on method documentation of PluginsResource

* [src/Console] Solve some minor issues

* [src/Console] Improve console tests

* [tests/Console]: Minor improvements on the console tests
  • Loading branch information
dfsmania authored Jun 30, 2024
1 parent 3fd7820 commit cac45a5
Show file tree
Hide file tree
Showing 21 changed files with 581 additions and 622 deletions.
22 changes: 9 additions & 13 deletions src/Console/AdminLteInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
namespace JeroenNoten\LaravelAdminLte\Console;

use Illuminate\Console\Command;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\AssetsResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\AdminlteAssetsResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\AuthRoutesResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\AuthViewsResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\BasicRoutesResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\BasicViewsResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\ConfigResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\MainViewsResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\LayoutViewsResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\TranslationsResource;

class AdminLteInstallCommand extends Command
Expand All @@ -20,8 +19,8 @@ class AdminLteInstallCommand extends Command
*/
protected $signature = 'adminlte:install
{--type=basic : The installation type: basic (default), enhanced or full}
{--only=* : To install only specific resources: assets, config, translations, auth_views, basic_views, basic_routes or main_views. Can\'t be used with option --with}
{--with=* : To install with additional resources: auth_views, basic_views, basic_routes or main_views}
{--only=* : To install only specific resources: assets, config, translations, auth_views, basic_routes or main_views. Can\'t be used with option --with}
{--with=* : To install with additional resources: auth_views, basic_routes or main_views}
{--force : To force the overwrite of existing files}
{--interactive : The installation will guide you through the process}';

Expand Down Expand Up @@ -79,20 +78,19 @@ public function __construct()
// Fill the array with the package resources.

$this->pkgResources = [
'assets' => new AssetsResource(),
'assets' => new AdminlteAssetsResource(),
'config' => new ConfigResource(),
'translations' => new TranslationsResource(),
'main_views' => new MainViewsResource(),
'main_views' => new LayoutViewsResource(),
'auth_views' => new AuthViewsResource(),
'basic_views' => new BasicViewsResource(),
'basic_routes' => new BasicRoutesResource(),
'basic_routes' => new AuthRoutesResource(),
];

// Add the resources related to each available --type option.

$basic = ['assets', 'config', 'translations'];
$enhanced = array_merge($basic, ['auth_views']);
$full = array_merge($enhanced, ['basic_views', 'basic_routes']);
$full = array_merge($enhanced, ['basic_routes']);

$this->optTypeResources = [
'basic' => $basic,
Expand All @@ -108,7 +106,6 @@ public function __construct()
'translations' => ['translations'],
'main_views' => ['main_views'],
'auth_views' => ['auth_views'],
'basic_views' => ['basic_views'],
'basic_routes' => ['basic_routes'],
];

Expand All @@ -117,7 +114,6 @@ public function __construct()
$this->optWithResources = [
'main_views' => ['main_views'],
'auth_views' => ['auth_views'],
'basic_views' => ['basic_views'],
'basic_routes' => ['basic_routes'],
];
}
Expand Down
6 changes: 3 additions & 3 deletions src/Console/AdminLtePluginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ protected function installPlugin($pluginKey)
{
// Customize the output messages.

$confirmMsg = $this->plugins->getInstallMessage('install');
$overwriteMsg = $this->plugins->getInstallMessage('overwrite');
$confirmMsg = $this->plugins->getInstallMessage('install') ?? '';
$overwriteMsg = $this->plugins->getInstallMessage('overwrite') ?? '';

$confirmMsg = strtr($confirmMsg, [':plugin' => $pluginKey]);
$overwriteMsg = strtr($overwriteMsg, [':plugin' => $pluginKey]);
Expand Down Expand Up @@ -420,7 +420,7 @@ protected function removePlugin($pluginKey)
{
// Customize the output messages.

$confirmMsg = $this->plugins->getInstallMessage('remove');
$confirmMsg = $this->plugins->getInstallMessage('remove') ?? '';
$confirmMsg = strtr($confirmMsg, [':plugin' => $pluginKey]);

// Check if the plugin is valid.
Expand Down
14 changes: 6 additions & 8 deletions src/Console/AdminLteStatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
namespace JeroenNoten\LaravelAdminLte\Console;

use Illuminate\Console\Command;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\AssetsResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\AdminlteAssetsResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\AuthRoutesResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\AuthViewsResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\BasicRoutesResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\BasicViewsResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\ConfigResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\MainViewsResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\LayoutViewsResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\TranslationsResource;

class AdminLteStatusCommand extends Command
Expand Down Expand Up @@ -69,13 +68,12 @@ public function __construct()
// Fill the array with the package resources.

$this->pkgResources = [
'assets' => new AssetsResource(),
'assets' => new AdminlteAssetsResource(),
'config' => new ConfigResource(),
'translations' => new TranslationsResource(),
'main_views' => new MainViewsResource(),
'main_views' => new LayoutViewsResource(),
'auth_views' => new AuthViewsResource(),
'basic_views' => new BasicViewsResource(),
'basic_routes' => new BasicRoutesResource(),
'basic_routes' => new AuthRoutesResource(),
];
}

Expand Down
19 changes: 10 additions & 9 deletions src/Console/AdminLteUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace JeroenNoten\LaravelAdminLte\Console;

use Illuminate\Console\Command;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\MainViewsResource;
use JeroenNoten\LaravelAdminLte\Console\PackageResources\LayoutViewsResource;

class AdminLteUpdateCommand extends Command
{
Expand All @@ -27,9 +27,9 @@ class AdminLteUpdateCommand extends Command
*
* @var string
*/
protected $mainViewsWarn = '<fg=yellow>Outdated main views at %s</>
protected $layoutViewsWarn = '<fg=yellow>Outdated layout views at %s</>
<fg=cyan>
We detected that the package main views were previously published and they
We detected that the package layout views were previously published and they
differs from the ones currently available. Note this package may not work
correctly if you do not update those views manually in order to include the
latest changes. In the particular case you have recently changed those views
Expand All @@ -48,14 +48,15 @@ public function handle()

$this->call('adminlte:install', $options);

// When the main views were previously installed and they differs from
// the original ones, alarm the user that those views may require a
// manual update.
// When the layout views were previously published and they differs
// from the package default ones, alarm the user to notify that those
// views may require a manual update.

$mainViewsRes = new MainViewsResource();
$layoutViewsRes = new LayoutViewsResource();

if ($mainViewsRes->exists() && ! $mainViewsRes->installed()) {
$this->info(sprintf($this->mainViewsWarn, $mainViewsRes->target));
if ($layoutViewsRes->exists() && ! $layoutViewsRes->installed()) {
$msg = sprintf($this->layoutViewsWarn, $layoutViewsRes->target);
$this->info($msg);
}
}
}
Loading

0 comments on commit cac45a5

Please sign in to comment.