Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the artisan commands #1293

Merged
merged 7 commits into from
Jul 5, 2024
52 changes: 27 additions & 25 deletions src/Console/AdminLteInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ class AdminLteInstallCommand extends Command
* @var string
*/
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_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}';
{--type=basic : The installation type: basic, basic_with_auth, basic_with_views or full}
{--only=* : To install only specific resources: assets, config, translations, auth_views, auth_routes or main_views. Can\'t be mixed with option --with}
{--with=* : To install with additional resources: auth_views, auth_routes or main_views}
{--force : To force the overwrite of existing files during the installation process}
{--interactive : To allow the installation process guide you through it}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Install all the required files for AdminLTE, and additional resources';
protected $description = 'Publishes the required files, and other resources, for use the AdminLTE template';

/**
* Array with all the available package resources.
Expand Down Expand Up @@ -75,26 +75,28 @@ public function __construct()
{
parent::__construct();

// Fill the array with the package resources.
// Fill the array with the available package resources.

$this->pkgResources = [
'assets' => new AdminlteAssetsResource(),
'config' => new ConfigResource(),
'translations' => new TranslationsResource(),
'main_views' => new LayoutViewsResource(),
'auth_views' => new AuthViewsResource(),
'basic_routes' => new AuthRoutesResource(),
'auth_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_routes']);
$basicWithAuth = array_merge($basic, ['auth_views', 'auth_routes']);
$basicWithViews = array_merge($basic, ['main_views']);
$full = array_merge($basicWithAuth, ['main_views']);

$this->optTypeResources = [
'basic' => $basic,
'enhanced' => $enhanced,
'basic_with_auth' => $basicWithAuth,
'basic_with_views' => $basicWithViews,
'full' => $full,
];

Expand All @@ -106,15 +108,15 @@ public function __construct()
'translations' => ['translations'],
'main_views' => ['main_views'],
'auth_views' => ['auth_views'],
'basic_routes' => ['basic_routes'],
'auth_routes' => ['auth_routes'],
];

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

$this->optWithResources = [
'main_views' => ['main_views'],
'auth_views' => ['auth_views'],
'basic_routes' => ['basic_routes'],
'auth_routes' => ['auth_routes'],
];
}

Expand All @@ -129,8 +131,8 @@ public function handle()

$this->installedResources = [];

// Check if option --only is used. In this case, install the specified
// parts and return.
// Check if option --only is used. In this case, install only the
// specified resources and finish.

if ($optValues = $this->option('only')) {
$this->handleOptions($optValues, $this->optOnlyResources, 'only');
Expand All @@ -144,8 +146,8 @@ public function handle()
$optValue = $this->option('type');
$this->handleOption($optValue, $this->optTypeResources, 'type');

// Check if option --with is used. In this case, also install the
// specified parts.
// Check if option --with is used. In this case, we also need to install
// the specified additional resources.

if ($optValues = $this->option('with')) {
$this->handleOptions($optValues, $this->optWithResources, 'with');
Expand All @@ -155,7 +157,7 @@ public function handle()
}

/**
* Handle multiple option values.
* Handles multiple option values.
*
* @param array $values An array with the option values
* @param array $resources An array with the resources of each option
Expand All @@ -170,7 +172,7 @@ protected function handleOptions($values, $resources, $opt)
}

/**
* Handle an option value.
* Handles an option value.
*
* @param string $value A string with the option value
* @param array $resources An array with the resources of each option
Expand All @@ -191,16 +193,16 @@ protected function handleOption($value, $resources, $opt)
}

/**
* Install multiple packages resources.
* Installs multiple packages resources.
*
* @param string $resources The resources to install
* @return void
*/
protected function exportPackageResources(...$resources)
{
foreach ($resources as $resource) {
// Check if resource was already installed on the current command
// execution. This can happen, for example, when using:
// Check if the resource was already installed on the current
// command execution. This can happen, for example, when using:
// php artisan --type=full --with=auth_views

if (isset($this->installedResources[$resource])) {
Expand All @@ -213,7 +215,7 @@ protected function exportPackageResources(...$resources)
}

/**
* Install a package resource.
* Installs a package resource.
*
* @param string $resource The keyword of the resource to install
* @return void
Expand All @@ -233,9 +235,9 @@ protected function exportPackageResource($resource)

// Check for overwrite warning.

$isOverwrite = ! $this->option('force') && $resource->exists();
$shouldWarnOverwrite = ! $this->option('force') && $resource->exists();

if ($isOverwrite && ! $this->confirm($overwriteMsg)) {
if ($shouldWarnOverwrite && ! $this->confirm($overwriteMsg)) {
return;
}

Expand Down
Loading