From 6640fbacac72e9e924916b775babf59023344128 Mon Sep 17 00:00:00 2001 From: JasperTey Date: Sat, 9 Nov 2024 16:59:28 +0000 Subject: [PATCH] Fix styling --- src/Commands/PublishCommand.php | 2 - src/Commands/StubCommand.php | 131 ++++++++++++++++---------------- 2 files changed, 64 insertions(+), 69 deletions(-) diff --git a/src/Commands/PublishCommand.php b/src/Commands/PublishCommand.php index 875afde..f1c8c70 100644 --- a/src/Commands/PublishCommand.php +++ b/src/Commands/PublishCommand.php @@ -3,9 +3,7 @@ namespace Lunarstorm\LaravelDDD\Commands; use Illuminate\Console\Command; -use Lunarstorm\LaravelDDD\Support\DomainResolver; use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Process\Process; use function Laravel\Prompts\multiselect; diff --git a/src/Commands/StubCommand.php b/src/Commands/StubCommand.php index a0a9d98..82bb60d 100644 --- a/src/Commands/StubCommand.php +++ b/src/Commands/StubCommand.php @@ -7,14 +7,11 @@ use Illuminate\Foundation\Console\StubPublishCommand; use Illuminate\Foundation\Events\PublishingStubs; use Illuminate\Support\Str; -use Lunarstorm\LaravelDDD\Support\DomainResolver; use ReflectionClass; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Process\Process; use function Laravel\Prompts\multisearch; -use function Laravel\Prompts\multiselect; use function Laravel\Prompts\select; class StubCommand extends Command @@ -41,84 +38,84 @@ protected function getOptions() protected function getNativeLaravelStubs() { - $laravelStubCommand = new ReflectionClass(new StubPublishCommand()); + $laravelStubCommand = new ReflectionClass(new StubPublishCommand); $dir = dirname($laravelStubCommand->getFileName()); return [ - $dir . '/stubs/cast.inbound.stub' => 'cast.inbound.stub', - $dir . '/stubs/cast.stub' => 'cast.stub', - $dir . '/stubs/class.stub' => 'class.stub', - $dir . '/stubs/class.invokable.stub' => 'class.invokable.stub', - $dir . '/stubs/console.stub' => 'console.stub', - $dir . '/stubs/enum.stub' => 'enum.stub', - $dir . '/stubs/enum.backed.stub' => 'enum.backed.stub', - $dir . '/stubs/event.stub' => 'event.stub', - $dir . '/stubs/job.queued.stub' => 'job.queued.stub', - $dir . '/stubs/job.stub' => 'job.stub', - $dir . '/stubs/listener.typed.queued.stub' => 'listener.typed.queued.stub', - $dir . '/stubs/listener.queued.stub' => 'listener.queued.stub', - $dir . '/stubs/listener.typed.stub' => 'listener.typed.stub', - $dir . '/stubs/listener.stub' => 'listener.stub', - $dir . '/stubs/mail.stub' => 'mail.stub', - $dir . '/stubs/markdown-mail.stub' => 'markdown-mail.stub', - $dir . '/stubs/markdown-notification.stub' => 'markdown-notification.stub', - $dir . '/stubs/model.pivot.stub' => 'model.pivot.stub', - $dir . '/stubs/model.stub' => 'model.stub', - $dir . '/stubs/notification.stub' => 'notification.stub', - $dir . '/stubs/observer.plain.stub' => 'observer.plain.stub', - $dir . '/stubs/observer.stub' => 'observer.stub', - $dir . '/stubs/pest.stub' => 'pest.stub', - $dir . '/stubs/pest.unit.stub' => 'pest.unit.stub', - $dir . '/stubs/policy.plain.stub' => 'policy.plain.stub', - $dir . '/stubs/policy.stub' => 'policy.stub', - $dir . '/stubs/provider.stub' => 'provider.stub', - $dir . '/stubs/request.stub' => 'request.stub', - $dir . '/stubs/resource.stub' => 'resource.stub', - $dir . '/stubs/resource-collection.stub' => 'resource-collection.stub', - $dir . '/stubs/rule.stub' => 'rule.stub', - $dir . '/stubs/scope.stub' => 'scope.stub', - $dir . '/stubs/test.stub' => 'test.stub', - $dir . '/stubs/test.unit.stub' => 'test.unit.stub', - $dir . '/stubs/trait.stub' => 'trait.stub', - $dir . '/stubs/view-component.stub' => 'view-component.stub', + $dir.'/stubs/cast.inbound.stub' => 'cast.inbound.stub', + $dir.'/stubs/cast.stub' => 'cast.stub', + $dir.'/stubs/class.stub' => 'class.stub', + $dir.'/stubs/class.invokable.stub' => 'class.invokable.stub', + $dir.'/stubs/console.stub' => 'console.stub', + $dir.'/stubs/enum.stub' => 'enum.stub', + $dir.'/stubs/enum.backed.stub' => 'enum.backed.stub', + $dir.'/stubs/event.stub' => 'event.stub', + $dir.'/stubs/job.queued.stub' => 'job.queued.stub', + $dir.'/stubs/job.stub' => 'job.stub', + $dir.'/stubs/listener.typed.queued.stub' => 'listener.typed.queued.stub', + $dir.'/stubs/listener.queued.stub' => 'listener.queued.stub', + $dir.'/stubs/listener.typed.stub' => 'listener.typed.stub', + $dir.'/stubs/listener.stub' => 'listener.stub', + $dir.'/stubs/mail.stub' => 'mail.stub', + $dir.'/stubs/markdown-mail.stub' => 'markdown-mail.stub', + $dir.'/stubs/markdown-notification.stub' => 'markdown-notification.stub', + $dir.'/stubs/model.pivot.stub' => 'model.pivot.stub', + $dir.'/stubs/model.stub' => 'model.stub', + $dir.'/stubs/notification.stub' => 'notification.stub', + $dir.'/stubs/observer.plain.stub' => 'observer.plain.stub', + $dir.'/stubs/observer.stub' => 'observer.stub', + $dir.'/stubs/pest.stub' => 'pest.stub', + $dir.'/stubs/pest.unit.stub' => 'pest.unit.stub', + $dir.'/stubs/policy.plain.stub' => 'policy.plain.stub', + $dir.'/stubs/policy.stub' => 'policy.stub', + $dir.'/stubs/provider.stub' => 'provider.stub', + $dir.'/stubs/request.stub' => 'request.stub', + $dir.'/stubs/resource.stub' => 'resource.stub', + $dir.'/stubs/resource-collection.stub' => 'resource-collection.stub', + $dir.'/stubs/rule.stub' => 'rule.stub', + $dir.'/stubs/scope.stub' => 'scope.stub', + $dir.'/stubs/test.stub' => 'test.stub', + $dir.'/stubs/test.unit.stub' => 'test.unit.stub', + $dir.'/stubs/trait.stub' => 'trait.stub', + $dir.'/stubs/view-component.stub' => 'view-component.stub', // realpath($dir . '/../../Database/Console/Factories/stubs/factory.stub') => 'factory.stub', - realpath($dir . '/../../Database/Console/Seeds/stubs/seeder.stub') => 'seeder.stub', - realpath($dir . '/../../Database/Migrations/stubs/migration.create.stub') => 'migration.create.stub', - realpath($dir . '/../../Database/Migrations/stubs/migration.stub') => 'migration.stub', - realpath($dir . '/../../Database/Migrations/stubs/migration.update.stub') => 'migration.update.stub', - realpath($dir . '/../../Routing/Console/stubs/controller.api.stub') => 'controller.api.stub', - realpath($dir . '/../../Routing/Console/stubs/controller.invokable.stub') => 'controller.invokable.stub', - realpath($dir . '/../../Routing/Console/stubs/controller.model.api.stub') => 'controller.model.api.stub', - realpath($dir . '/../../Routing/Console/stubs/controller.model.stub') => 'controller.model.stub', - realpath($dir . '/../../Routing/Console/stubs/controller.nested.api.stub') => 'controller.nested.api.stub', - realpath($dir . '/../../Routing/Console/stubs/controller.nested.singleton.api.stub') => 'controller.nested.singleton.api.stub', - realpath($dir . '/../../Routing/Console/stubs/controller.nested.singleton.stub') => 'controller.nested.singleton.stub', - realpath($dir . '/../../Routing/Console/stubs/controller.nested.stub') => 'controller.nested.stub', - realpath($dir . '/../../Routing/Console/stubs/controller.plain.stub') => 'controller.plain.stub', - realpath($dir . '/../../Routing/Console/stubs/controller.singleton.api.stub') => 'controller.singleton.api.stub', - realpath($dir . '/../../Routing/Console/stubs/controller.singleton.stub') => 'controller.singleton.stub', - realpath($dir . '/../../Routing/Console/stubs/controller.stub') => 'controller.stub', - realpath($dir . '/../../Routing/Console/stubs/middleware.stub') => 'middleware.stub', + realpath($dir.'/../../Database/Console/Seeds/stubs/seeder.stub') => 'seeder.stub', + realpath($dir.'/../../Database/Migrations/stubs/migration.create.stub') => 'migration.create.stub', + realpath($dir.'/../../Database/Migrations/stubs/migration.stub') => 'migration.stub', + realpath($dir.'/../../Database/Migrations/stubs/migration.update.stub') => 'migration.update.stub', + realpath($dir.'/../../Routing/Console/stubs/controller.api.stub') => 'controller.api.stub', + realpath($dir.'/../../Routing/Console/stubs/controller.invokable.stub') => 'controller.invokable.stub', + realpath($dir.'/../../Routing/Console/stubs/controller.model.api.stub') => 'controller.model.api.stub', + realpath($dir.'/../../Routing/Console/stubs/controller.model.stub') => 'controller.model.stub', + realpath($dir.'/../../Routing/Console/stubs/controller.nested.api.stub') => 'controller.nested.api.stub', + realpath($dir.'/../../Routing/Console/stubs/controller.nested.singleton.api.stub') => 'controller.nested.singleton.api.stub', + realpath($dir.'/../../Routing/Console/stubs/controller.nested.singleton.stub') => 'controller.nested.singleton.stub', + realpath($dir.'/../../Routing/Console/stubs/controller.nested.stub') => 'controller.nested.stub', + realpath($dir.'/../../Routing/Console/stubs/controller.plain.stub') => 'controller.plain.stub', + realpath($dir.'/../../Routing/Console/stubs/controller.singleton.api.stub') => 'controller.singleton.api.stub', + realpath($dir.'/../../Routing/Console/stubs/controller.singleton.stub') => 'controller.singleton.stub', + realpath($dir.'/../../Routing/Console/stubs/controller.stub') => 'controller.stub', + realpath($dir.'/../../Routing/Console/stubs/middleware.stub') => 'middleware.stub', ]; } protected function resolveSelectedStubs(array $names = []) { $stubs = [ - realpath(__DIR__ . '/../../stubs/action.stub') => 'action.stub', - realpath(__DIR__ . '/../../stubs/dto.stub') => 'dto.stub', - realpath(__DIR__ . '/../../stubs/value-object.stub') => 'value-object.stub', - realpath(__DIR__ . '/../../stubs/view-model.stub') => 'view-model.stub', - realpath(__DIR__ . '/../../stubs/base-view-model.stub') => 'base-view-model.stub', - realpath(__DIR__ . '/../../stubs/factory.stub') => 'factory.stub', + realpath(__DIR__.'/../../stubs/action.stub') => 'action.stub', + realpath(__DIR__.'/../../stubs/dto.stub') => 'dto.stub', + realpath(__DIR__.'/../../stubs/value-object.stub') => 'value-object.stub', + realpath(__DIR__.'/../../stubs/view-model.stub') => 'view-model.stub', + realpath(__DIR__.'/../../stubs/base-view-model.stub') => 'base-view-model.stub', + realpath(__DIR__.'/../../stubs/factory.stub') => 'factory.stub', ...$this->getNativeLaravelStubs(), ]; if ($names) { return collect($stubs) ->filter( - fn($stub, $path) => in_array($stub, $names) + fn ($stub, $path) => in_array($stub, $names) || in_array(str($stub)->replaceEnd('.stub', '')->toString(), $names) ) ->all(); @@ -127,8 +124,8 @@ protected function resolveSelectedStubs(array $names = []) return multisearch( label: 'Which stub should be published?', placeholder: 'Search for a stub...', - options: fn(string $value) => strlen($value) > 0 - ? collect($stubs)->filter(fn($stub, $path) => str($stub)->contains($value))->all() + options: fn (string $value) => strlen($value) > 0 + ? collect($stubs)->filter(fn ($stub, $path) => str($stub)->contains($value))->all() : $stubs, required: true ); @@ -175,7 +172,7 @@ public function handle(): int $this->laravel['events']->dispatch($event = new PublishingStubs($stubs)); foreach ($event->stubs as $from => $to) { - $to = $stubsPath . DIRECTORY_SEPARATOR . ltrim($to, DIRECTORY_SEPARATOR); + $to = $stubsPath.DIRECTORY_SEPARATOR.ltrim($to, DIRECTORY_SEPARATOR); $relativePath = Str::after($to, $this->laravel->basePath());