install cmd
This commit is contained in:
parent
715de77a69
commit
027c680dc4
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BAG\Laravel\Console;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
|
|
||||||
|
#[AsCommand(name: 'bag:install')]
|
||||||
|
class Install extends ProxyCommand
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'bag:install';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Install required packages';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int|null
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
if (env('LARAVEL_SAIL')) {
|
||||||
|
$this->error("🐳 To install packages, please run 'php artisan bag:install' outside Sail.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->syncPackages();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function proxyHandle()
|
||||||
|
{
|
||||||
|
//ignored
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,16 +7,29 @@ use Illuminate\Support\Facades\Process;
|
||||||
|
|
||||||
abstract class ProxyCommand extends Command
|
abstract class ProxyCommand extends Command
|
||||||
{
|
{
|
||||||
|
const PACKAGES = [
|
||||||
|
'stack-laravel',
|
||||||
|
];
|
||||||
|
|
||||||
protected $base_path;
|
protected $base_path;
|
||||||
|
|
||||||
abstract protected function proxyHandle();
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->base_path = realpath(__DIR__ . '/../..');
|
||||||
|
}
|
||||||
|
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$this->base_path = realpath(__DIR__ . '/../..');
|
foreach (self::PACKAGES as $package) {
|
||||||
|
if (! is_dir("{$this->base_path}/packages/$package")) {
|
||||||
|
$this->error("🚨 Missing package bag/$package. Please run 'php artisan bag:install' first.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->syncPackages();
|
|
||||||
return $this->proxyHandle();
|
return $this->proxyHandle();
|
||||||
}
|
}
|
||||||
catch (\Exception $exception) {
|
catch (\Exception $exception) {
|
||||||
|
@ -25,9 +38,13 @@ abstract class ProxyCommand extends Command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract protected function proxyHandle();
|
||||||
|
|
||||||
protected function syncPackages(): void
|
protected function syncPackages(): void
|
||||||
{
|
{
|
||||||
$this->syncPackage('stack-laravel');
|
foreach (self::PACKAGES as $package) {
|
||||||
|
$this->syncPackage($package);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function syncPackage($package): void
|
protected function syncPackage($package): void
|
||||||
|
|
|
@ -28,6 +28,7 @@ class ServiceProvider extends \Illuminate\Support\ServiceProvider implements Def
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->commands([
|
$this->commands([
|
||||||
|
Console\Install::class,
|
||||||
Console\MakeMigrations::class,
|
Console\MakeMigrations::class,
|
||||||
//...
|
//...
|
||||||
]);
|
]);
|
||||||
|
@ -41,6 +42,7 @@ class ServiceProvider extends \Illuminate\Support\ServiceProvider implements Def
|
||||||
public function provides()
|
public function provides()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
Console\Install::class,
|
||||||
Console\MakeMigrations::class,
|
Console\MakeMigrations::class,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue