diff --git a/composer.json b/composer.json index 045d61567..e4317a4fd 100644 --- a/composer.json +++ b/composer.json @@ -15,10 +15,10 @@ ], "require": { "php": "^8.1.0", - "illuminate/console": "^10.0", - "illuminate/filesystem": "^10.0", - "illuminate/support": "^10.0", - "illuminate/validation": "^10.0" + "illuminate/console": "^10.17", + "illuminate/filesystem": "^10.17", + "illuminate/support": "^10.17", + "illuminate/validation": "^10.17" }, "autoload": { "psr-4": { diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index 328f37630..76d930603 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -3,6 +3,7 @@ namespace Laravel\Breeze\Console; use Illuminate\Console\Command; +use Illuminate\Contracts\Console\PromptsForMissingInput; use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Str; use RuntimeException; @@ -12,7 +13,11 @@ use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Process; -class InstallCommand extends Command +use function Laravel\Prompts\confirm; +use function Laravel\Prompts\multiselect; +use function Laravel\Prompts\select; + +class InstallCommand extends Command implements PromptsForMissingInput { use InstallsApiStack, InstallsBladeStack, InstallsInertiaStacks; @@ -23,7 +28,6 @@ class InstallCommand extends Command */ protected $signature = 'breeze:install {stack : The development stack that should be installed (blade,react,vue,api)} {--dark : Indicate that dark mode support should be installed} - {--inertia : Indicate that the Vue Inertia stack should be installed (Deprecated)} {--pest : Indicate that Pest should be installed} {--ssr : Indicates if Inertia SSR support should be installed} {--typescript : Indicates if TypeScript is preferred for the Inertia stack (Experimental)} @@ -36,13 +40,6 @@ class InstallCommand extends Command */ protected $description = 'Install the Breeze controllers and resources'; - /** - * The available stacks. - * - * @var array - */ - protected $stacks = ['blade', 'react', 'vue', 'api']; - /** * Execute the console command. * @@ -65,36 +62,6 @@ public function handle() return 1; } - /** - * Interact with the user to prompt them when the stack argument is missing. - * - * @param \Symfony\Component\Console\Input\InputInterface $input - * @param \Symfony\Component\Console\Output\OutputInterface $output - * @return void - */ - protected function interact(InputInterface $input, OutputInterface $output) - { - if ($this->argument('stack') === null && $this->option('inertia')) { - $input->setArgument('stack', 'vue'); - } - - if ($this->argument('stack')) { - return; - } - - $input->setArgument('stack', $this->components->choice('Which stack would you like to install?', $this->stacks)); - - $input->setOption('dark', $this->components->confirm('Would you like to install dark mode support?')); - - if (in_array($input->getArgument('stack'), ['vue', 'react'])) { - $input->setOption('typescript', $this->components->confirm('Would you like TypeScript support? (Experimental)')); - - $input->setOption('ssr', $this->components->confirm('Would you like to install Inertia SSR support?')); - } - - $input->setOption('pest', $this->components->confirm('Would you prefer Pest tests instead of PHPUnit?')); - } - /** * Install Breeze's tests. * @@ -312,4 +279,57 @@ protected function removeDarkClasses(Finder $finder) file_put_contents($file->getPathname(), preg_replace('/\sdark:[^\s"\']+/', '', $file->getContents())); } } + + /** + * Prompt for missing input arguments using the returned questions. + * + * @return array + */ + protected function promptForMissingArgumentsUsing() + { + return [ + 'stack' => fn () => select( + label: 'Which Breeze stack would you like to install?', + options: [ + 'blade' => 'Blade', + 'react' => 'React with Inertia', + 'vue' => 'Vue with Inertia', + 'api' => 'API only', + ] + ), + ]; + } + + /** + * Interact further with the user if they were prompted for missing arguments. + * + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Symfony\Component\Console\Output\OutputInterface $output + * @return void + */ + protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output) + { + $stack = $input->getArgument('stack'); + + if (in_array($stack, ['react', 'vue'])) { + collect(multiselect( + label: 'Would you like any optional features?', + options: [ + 'dark' => 'Dark mode', + 'ssr' => 'Inertia SSR', + 'typescript' => 'TypeScript (experimental)', + ] + ))->each(fn ($option) => $input->setOption($option, true)); + } elseif ($stack === 'blade') { + $input->setOption('dark', confirm( + label: 'Would you like dark mode support?', + default: false + )); + } + + $input->setOption('pest', select( + label: 'Which testing framework do you prefer?', + options: ['PHPUnit', 'Pest'], + ) === 'Pest'); + } }