diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f3a2258..f3b832bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,6 @@ All notable changes to `wireuse` will be documented in this file. -## v2.1.3 - 2024-07-24 - -**Full Changelog**: https://github.com/foxws/wireuse/compare/v2.1.2...v2.1.3 - ## v2.1.2 - 2024-07-20 **Full Changelog**: https://github.com/foxws/wireuse/compare/v2.1.1...v2.1.2 diff --git a/src/Scout/ComponentScout.php b/src/Scout/ComponentScout.php new file mode 100644 index 00000000..d967ce2e --- /dev/null +++ b/src/Scout/ComponentScout.php @@ -0,0 +1,74 @@ +getComponentStructures(); + + return Collection::make($scout->get()) + ->map(fn (DiscoveredStructure $class) => [ + 'class' => $class->getFcqn(), + 'name' => $this->componentName($class), + ]); + } + + protected function componentName(DiscoveredStructure $class): string + { + return str($class->name) + ->kebab() + ->prepend( + $this->componentPrefix(), + $this->componentNamespace($class) + ); + } + + protected function componentPrefix(): string + { + return str($this->prefix) + ->replace('\\', '.') + ->kebab(); + } + + protected function componentNamespace(DiscoveredStructure $class): string + { + return str($class->namespace) + ->after($this->namespace) + ->match('/(.*)\\\\/') + ->replace('\\', '.') + ->slug('.') + ->finish('.'); + } + + protected function getComponentStructures(): ComponentStructureScout + { + return ComponentStructureScout::create() + ->path($this->path) + ->prefix("blade-structures-{$this->prefix}"); + } +} diff --git a/src/Scout/LivewireScout.php b/src/Scout/LivewireScout.php new file mode 100644 index 00000000..c75aa83e --- /dev/null +++ b/src/Scout/LivewireScout.php @@ -0,0 +1,82 @@ +get(); + + $components->each(fn (array $component) => Livewire::component(...$component)); + } + + public function get(): Collection + { + $scout = $this->getLivewireStructures(); + + return Collection::make($scout->get()) + ->map(fn (DiscoveredStructure $class) => [ + 'class' => $class->getFcqn(), + 'name' => $this->componentName($class), + ]); + } + + protected function componentName(DiscoveredStructure $class): string + { + return str($class->name) + ->kebab() + ->prepend( + $this->componentPrefix(), + $this->componentNamespace($class) + ); + } + + protected function componentPrefix(): string + { + return str($this->prefix) + ->replace('\\', '.') + ->kebab(); + } + + protected function componentNamespace(DiscoveredStructure $class): string + { + return str($class->namespace) + ->after($this->namespace) + ->match('/(.*)\\\\/') + ->replace('\\', '.') + ->slug('.') + ->finish('.'); + } + + protected function getLivewireStructures(): LivewireStructureScout + { + return LivewireStructureScout::create() + ->path($this->path) + ->prefix("livewire-structures-{$this->prefix}"); + } +} diff --git a/src/Support/Discover/ComponentScout.php b/src/Support/Discover/ComponentStructureScout.php similarity index 95% rename from src/Support/Discover/ComponentScout.php rename to src/Support/Discover/ComponentStructureScout.php index 9dc90322..b4519438 100644 --- a/src/Support/Discover/ComponentScout.php +++ b/src/Support/Discover/ComponentStructureScout.php @@ -7,7 +7,7 @@ use Spatie\StructureDiscoverer\Discover; use Spatie\StructureDiscoverer\StructureScout; -class ComponentScout extends StructureScout +class ComponentStructureScout extends StructureScout { public ?string $path = null; diff --git a/src/Support/Discover/LivewireScout.php b/src/Support/Discover/LivewireStructureScout.php similarity index 83% rename from src/Support/Discover/LivewireScout.php rename to src/Support/Discover/LivewireStructureScout.php index 3dd7de32..dfa1f17b 100644 --- a/src/Support/Discover/LivewireScout.php +++ b/src/Support/Discover/LivewireStructureScout.php @@ -5,7 +5,7 @@ use Livewire\Component; use Spatie\StructureDiscoverer\Discover; -class LivewireScout extends ComponentScout +class LivewireStructureScout extends ComponentStructureScout { protected function definition(): Discover { diff --git a/src/WireUse.php b/src/WireUse.php index acb068c4..e091a83a 100755 --- a/src/WireUse.php +++ b/src/WireUse.php @@ -63,7 +63,7 @@ public static function componentName(DiscoveredStructure $class, string $namespa ); } - public static function componentPrefix(string $prefix): Stringable + public static function componentPrefix(string $prefix): string { return str($prefix) ->kebab() diff --git a/src/WireUseServiceProvider.php b/src/WireUseServiceProvider.php index 0afc1e25..e43c9215 100644 --- a/src/WireUseServiceProvider.php +++ b/src/WireUseServiceProvider.php @@ -2,7 +2,7 @@ namespace Foxws\WireUse; -use Spatie\LaravelPackageTools\Commands\InstallCommand; +use Foxws\WireUse\Scout\ComponentScout; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -12,21 +12,24 @@ public function configurePackage(Package $package): void { $package ->name('wireuse') - ->hasConfigFile() - ->hasViews() - ->hasInstallCommand(function (InstallCommand $command) { - $command - ->publishConfigFile(); - }); + ->hasConfigFile(); } - public function bootingPackage(): void + public function packageBooted(): void { $this ->registerFeatures() ->registerMixins(); } + public function packageRegistered(): void + { + $this->app->singleton( + ComponentScout::class, + fn () => new ComponentScout() + ); + } + protected function registerFeatures(): static { foreach ([