diff --git a/config.php b/config.php index 95b6dbd..92f6f27 100644 --- a/config.php +++ b/config.php @@ -77,7 +77,7 @@ | ], */ - 'stubs' => null, + 'stubs' => null, /* |-------------------------------------------------------------------------- @@ -90,5 +90,27 @@ | the presence of event discovery. */ - 'should_discover_events' => null, + 'should_discover_events' => null, + + /* + |-------------------------------------------------------------------------- + | Prevent automatic discovery of module components + |-------------------------------------------------------------------------- + | + | This package automatically discovers different componets from the modules + | like commands, routes, views, translations, blade and livewire + | components, and breadcrumbs. If you want to prevent automatic discovery + | of specific components you can list them here in the 'dont_discover' + | array. + */ + + 'dont_discover' => [ + // 'commands', + // 'routes', + // 'views', + // 'translations', + // 'blade_components', + // 'livewire_components', + // 'breadcrumbs', + ], ]; diff --git a/src/Support/ModularServiceProvider.php b/src/Support/ModularServiceProvider.php index 22120ca..5d88835 100644 --- a/src/Support/ModularServiceProvider.php +++ b/src/Support/ModularServiceProvider.php @@ -74,15 +74,35 @@ public function register(): void public function boot(): void { - $this->publishVendorFiles(); - $this->bootPackageCommands(); - - $this->bootRoutes(); - $this->bootBreadcrumbs(); - $this->bootViews(); - $this->bootBladeComponents(); - $this->bootTranslations(); - $this->bootLivewireComponents(); + $this->publishVendorFiles(); + + if ($this->shouldDiscover('commands')) { + $this->bootPackageCommands(); + } + + if ($this->shouldDiscover('routes')) { + $this->bootRoutes(); + } + + if ($this->shouldDiscover('breadcrumbs')) { + $this->bootBreadcrumbs(); + } + + if ($this->shouldDiscover('views')) { + $this->bootViews(); + } + + if ($this->shouldDiscover('blade_components')) { + $this->bootBladeComponents(); + } + + if ($this->shouldDiscover('translations')) { + $this->bootTranslations(); + } + + if ($this->shouldDiscover('livewire_components')) { + $this->bootLivewireComponents(); + } } protected function registry(): ModuleRegistry @@ -93,7 +113,12 @@ protected function registry(): ModuleRegistry protected function autoDiscoveryHelper(): AutoDiscoveryHelper { return $this->auto_discovery_helper ??= $this->app->make(AutoDiscoveryHelper::class); - } + } + + protected function shouldDiscover(string $component): bool + { + return ! in_array($component, config('app-modules.dont_discover', [])); + } protected function publishVendorFiles(): void { @@ -103,7 +128,7 @@ protected function publishVendorFiles(): void } protected function bootPackageCommands(): void - { + { if (! $this->app->runningInConsole()) { return; }