From 0fc9330e2e33895d74796dcede6ae99660444bd4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Dec 2024 10:15:40 +0100 Subject: [PATCH] Wip --- .../Console/Commands/PublishViewsCommand.php | 7 +++++- .../InteractivePublishCommandHelper.php | 25 ++++++++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/framework/src/Console/Commands/PublishViewsCommand.php b/packages/framework/src/Console/Commands/PublishViewsCommand.php index 19c16b6e1b9..4557a5ca618 100644 --- a/packages/framework/src/Console/Commands/PublishViewsCommand.php +++ b/packages/framework/src/Console/Commands/PublishViewsCommand.php @@ -9,6 +9,7 @@ use Hyde\Hyde; use Illuminate\Support\Facades\Artisan; +use function Laravel\Prompts\multiselect; use function str_replace; use function sprintf; use function strstr; @@ -114,7 +115,11 @@ protected function handleInteractivePublish(string $selected): void $group = $this->options[$selected]['group']; $publisher = new InteractivePublishCommandHelper($group); - $message = $publisher->handle(); + $choices = $publisher->getFileChoices(); + + $selectedFiles = multiselect('Select the files you want to publish (CTRL+A to toggle all)', $choices, [], 10, 'required', hint: 'Navigate with arrow keys, space to select, enter to confirm.'); + + $message = $publisher->handle($selectedFiles); $this->infoComment($message); } } diff --git a/packages/framework/src/Console/Helpers/InteractivePublishCommandHelper.php b/packages/framework/src/Console/Helpers/InteractivePublishCommandHelper.php index 496b269e2b6..c75e90ad7ad 100644 --- a/packages/framework/src/Console/Helpers/InteractivePublishCommandHelper.php +++ b/packages/framework/src/Console/Helpers/InteractivePublishCommandHelper.php @@ -25,18 +25,26 @@ class InteractivePublishCommandHelper protected readonly string $source; protected readonly string $target; + /** @var \Illuminate\Support\Collection Map of source files to target files */ + protected readonly Collection $publishableFilesMap; + public function __construct(string $group) { $this->group = $group; } - public function handle(): string + public function getFileChoices(): Collection { - $publishableFilesMap = $this->mapPublishableFiles($this->findAllFilesForTag()); + $this->publishableFilesMap = $this->mapPublishableFiles($this->findAllFilesForTag()); + + return $this->publishableFilesMap->mapWithKeys(/** @return array */ function (string $source): array { + return [$source => Str::after($source, basename($this->target) . '/')]; + }); + } - $choices = $this->getFileChoices($publishableFilesMap); - $selectedFiles = multiselect('Select the files you want to publish (CTRL+A to toggle all)', $choices, [], 10, 'required', hint: 'Navigate with arrow keys, space to select, enter to confirm.'); - $filesToPublish = $publishableFilesMap->filter(fn (string $file): bool => in_array($file, $selectedFiles)); + public function handle(array $selectedFiles): string + { + $filesToPublish = $this->publishableFilesMap->filter(fn (string $file): bool => in_array($file, $selectedFiles)); $this->publishFiles($filesToPublish); @@ -74,11 +82,4 @@ protected function getPublishedFilesForOutput(Collection $selectedFiles): string { return collect($selectedFiles)->map(fn (string $file): string => Str::after($file, basename($this->source).'/'))->implode(', '); } - - public function getFileChoices(Collection $publishableFilesMap): Collection - { - return $publishableFilesMap->mapWithKeys(/** @return array */ function (string $source): array { - return [$source => Str::after($source, basename($this->target) . '/')]; - }); - } }