From 87b9ec6459ceaf47e4bd7b3d19c7613b3ace995c Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Wed, 8 Feb 2023 20:13:34 +0000 Subject: [PATCH 1/2] Adds Laravel Breeze scaffolding --- src/NewCommand.php | 105 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 100 insertions(+), 5 deletions(-) diff --git a/src/NewCommand.php b/src/NewCommand.php index 07fb64ba..0ffcbfa4 100644 --- a/src/NewCommand.php +++ b/src/NewCommand.php @@ -30,10 +30,14 @@ protected function configure() ->addOption('branch', null, InputOption::VALUE_REQUIRED, 'The branch that should be created for a new repository', $this->defaultBranch()) ->addOption('github', null, InputOption::VALUE_OPTIONAL, 'Create a new repository on GitHub', false) ->addOption('organization', null, InputOption::VALUE_REQUIRED, 'The GitHub organization to create the new repository for') + ->addOption('breeze', null, InputOption::VALUE_NONE, 'Installs the Laravel Breeze scaffolding') + ->addOption('dark', null, InputOption::VALUE_NONE, 'Indicate whether Breeze should be scaffolded with dark mode support') + ->addOption('ssr', null, InputOption::VALUE_NONE, 'Indicate whether Breeze should be scaffolded with Inertia SSR support') ->addOption('jet', null, InputOption::VALUE_NONE, 'Installs the Laravel Jetstream scaffolding') - ->addOption('stack', null, InputOption::VALUE_OPTIONAL, 'The Jetstream stack that should be installed') + ->addOption('stack', null, InputOption::VALUE_OPTIONAL, 'The Breeze/Jetstream stack that should be installed') ->addOption('teams', null, InputOption::VALUE_NONE, 'Indicates whether Jetstream should be scaffolded with team support') ->addOption('pest', null, InputOption::VALUE_NONE, 'Installs the Pest testing framework') + ->addOption('prompt-breeze', null, InputOption::VALUE_NONE, 'Issues a prompt to determine if Breeze should be installed') ->addOption('prompt-jetstream', null, InputOption::VALUE_NONE, 'Issues a prompt to determine if Jetstream should be installed') ->addOption('force', 'f', InputOption::VALUE_NONE, 'Forces install even if the directory already exists'); } @@ -47,10 +51,38 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $installBreeze = $input->getOption('breeze') || + ($input->getOption('prompt-breeze') && (new SymfonyStyle($input, $output))->confirm('Would you like to install the Laravel Breeze application scaffolding?', false)); + $installJetstream = $input->getOption('jet') || ($input->getOption('prompt-jetstream') && (new SymfonyStyle($input, $output))->confirm('Would you like to install the Laravel Jetstream application scaffolding?', false)); - if ($installJetstream) { + if ($installBreeze) { + $output->write(" ____ + | __ ) _ __ ___ ___ _______ + | _ \| '__/ _ \/ _ \_ / _ \ + | |_) | | | __/ __// / __/ + |____/|_| \___|\___/___\___|".PHP_EOL.PHP_EOL); + + $stack = $this->breezeStack($input, $output); + $testingFramework = $this->testingFramework($input, $output); + + $dark = false; + + if (in_array($stack, ['blade', 'vue', 'react'])) { + $dark = $input->getOption('dark') === true + ? (bool) $input->getOption('dark') + : (new SymfonyStyle($input, $output))->confirm('Would you like to install dark mode support?', false); + } + + $ssr = false; + + if (in_array($stack, ['vue', 'react'])) { + $ssr = $input->getOption('ssr') === true + ? (bool) $input->getOption('ssr') + : (new SymfonyStyle($input, $output))->confirm('Would you like to install Inertia SSR support?', false); + } + } elseif ($installJetstream) { $output->write(PHP_EOL." | | | |,---.|--- ,---.|--- ,---.,---.,---.,-.-. @@ -58,7 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output) `---'`---'`---'`---'`---'` `---'`---^` ' '".PHP_EOL.PHP_EOL); $stack = $this->jetstreamStack($input, $output); - $testingFramework = $this->jetstreamTestingFramework($input, $output); + $testingFramework = $this->testingFramework($input, $output); $teams = $input->getOption('teams') === true ? (bool) $input->getOption('teams') @@ -131,7 +163,9 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->createRepository($directory, $input, $output); } - if ($installJetstream) { + if ($installBreeze) { + $this->installBreeze($directory, $stack, $testingFramework, $dark, $ssr, $input, $output); + } elseif ($installJetstream) { $this->installJetstream($directory, $stack, $testingFramework, $teams, $input, $output); } elseif ($input->getOption('pest')) { $this->installPest($directory, $input, $output); @@ -164,6 +198,38 @@ protected function defaultBranch() return $process->isSuccessful() && $output ? $output : 'main'; } + /** + * Install Laravel Breeze into the application. + * + * @param string $directory + * @param string $stack + * @param string $testingFramework + * @param bool $dark + * @param bool $ssr + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Symfony\Component\Console\Output\OutputInterface $output + * @return void + */ + protected function installBreeze(string $directory, string $stack, string $testingFramework, bool $dark, bool $ssr, InputInterface $input, OutputInterface $output) + { + chdir($directory); + + $commands = array_filter([ + $this->findComposer().' require laravel/breeze', + trim(sprintf( + PHP_BINARY.' artisan breeze:install %s %s %s %s', + $stack, + $testingFramework == 'pest' ? '--pest' : '', + $dark ? '--dark' : '', + $ssr ? '--ssr' : '', + )), + ]); + + $this->runCommands($commands, $input, $output); + + $this->commitChanges('Install Breeze', $directory, $input, $output); + } + /** * Install Laravel Jetstream into the application. * @@ -194,6 +260,35 @@ protected function installJetstream(string $directory, string $stack, string $te $this->commitChanges('Install Jetstream', $directory, $input, $output); } + /** + * Determine the stack for Breeze. + * + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Symfony\Component\Console\Output\OutputInterface $output + * @return string + */ + protected function breezeStack(InputInterface $input, OutputInterface $output) + { + $stacks = [ + 'blade', + 'react', + 'vue', + 'api', + ]; + + if ($input->getOption('stack') && in_array($input->getOption('stack'), $stacks)) { + return $input->getOption('stack'); + } + + $helper = $this->getHelper('question'); + + $question = new ChoiceQuestion('Which Breeze stack do you prefer?', $stacks); + + $output->write(PHP_EOL); + + return $helper->ask($input, new SymfonyStyle($input, $output), $question); + } + /** * Determine the stack for Jetstream. * @@ -228,7 +323,7 @@ protected function jetstreamStack(InputInterface $input, OutputInterface $output * @param \Symfony\Component\Console\Output\OutputInterface $output * @return string */ - protected function jetstreamTestingFramework(InputInterface $input, OutputInterface $output) + protected function testingFramework(InputInterface $input, OutputInterface $output) { if ($input->getOption('pest')) { return 'pest'; From ddcf2c1d473407400a2ac8d4de470f998a935cfb Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 8 Feb 2023 14:30:11 -0600 Subject: [PATCH 2/2] Update NewCommand.php --- src/NewCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NewCommand.php b/src/NewCommand.php index 0ffcbfa4..8f4d8b0d 100644 --- a/src/NewCommand.php +++ b/src/NewCommand.php @@ -34,7 +34,7 @@ protected function configure() ->addOption('dark', null, InputOption::VALUE_NONE, 'Indicate whether Breeze should be scaffolded with dark mode support') ->addOption('ssr', null, InputOption::VALUE_NONE, 'Indicate whether Breeze should be scaffolded with Inertia SSR support') ->addOption('jet', null, InputOption::VALUE_NONE, 'Installs the Laravel Jetstream scaffolding') - ->addOption('stack', null, InputOption::VALUE_OPTIONAL, 'The Breeze/Jetstream stack that should be installed') + ->addOption('stack', null, InputOption::VALUE_OPTIONAL, 'The Breeze / Jetstream stack that should be installed') ->addOption('teams', null, InputOption::VALUE_NONE, 'Indicates whether Jetstream should be scaffolded with team support') ->addOption('pest', null, InputOption::VALUE_NONE, 'Installs the Pest testing framework') ->addOption('prompt-breeze', null, InputOption::VALUE_NONE, 'Issues a prompt to determine if Breeze should be installed')