Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Prompts #295

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
98 changes: 59 additions & 39 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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)}
Expand All @@ -36,13 +40,6 @@ class InstallCommand extends Command
*/
protected $description = 'Install the Breeze controllers and resources';

/**
* The available stacks.
*
* @var array<int, string>
*/
protected $stacks = ['blade', 'react', 'vue', 'api'];

/**
* Execute the console command.
*
Expand All @@ -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.
*
Expand Down Expand Up @@ -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');
}
}