From 027c680dc4bcc7284d762f06942179150e2690f0 Mon Sep 17 00:00:00 2001 From: Maxime Renou Date: Mon, 8 Apr 2024 17:11:35 +0200 Subject: [PATCH] install cmd --- src/Console/Install.php | 37 +++++++++++++++++++++++++++++++++++++ src/Console/ProxyCommand.php | 25 +++++++++++++++++++++---- src/ServiceProvider.php | 2 ++ 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 src/Console/Install.php diff --git a/src/Console/Install.php b/src/Console/Install.php new file mode 100644 index 0000000..27a2c57 --- /dev/null +++ b/src/Console/Install.php @@ -0,0 +1,37 @@ +error("🐳 To install packages, please run 'php artisan bag:install' outside Sail."); + return 0; + } + + $this->syncPackages(); + } + + protected function proxyHandle() + { + //ignored + } +} diff --git a/src/Console/ProxyCommand.php b/src/Console/ProxyCommand.php index d855194..b7b156b 100644 --- a/src/Console/ProxyCommand.php +++ b/src/Console/ProxyCommand.php @@ -7,16 +7,29 @@ use Illuminate\Support\Facades\Process; abstract class ProxyCommand extends Command { + const PACKAGES = [ + 'stack-laravel', + ]; + protected $base_path; - abstract protected function proxyHandle(); + public function __construct() + { + parent::__construct(); + + $this->base_path = realpath(__DIR__ . '/../..'); + } 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 { - $this->syncPackages(); return $this->proxyHandle(); } catch (\Exception $exception) { @@ -25,9 +38,13 @@ abstract class ProxyCommand extends Command } } + abstract protected function proxyHandle(); + protected function syncPackages(): void { - $this->syncPackage('stack-laravel'); + foreach (self::PACKAGES as $package) { + $this->syncPackage($package); + } } protected function syncPackage($package): void diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index af04a05..480a2bf 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -28,6 +28,7 @@ class ServiceProvider extends \Illuminate\Support\ServiceProvider implements Def } $this->commands([ + Console\Install::class, Console\MakeMigrations::class, //... ]); @@ -41,6 +42,7 @@ class ServiceProvider extends \Illuminate\Support\ServiceProvider implements Def public function provides() { return [ + Console\Install::class, Console\MakeMigrations::class, ]; }