Skip to content

Commit 8673653

Browse files
[4.x] Adds Laravel Breeze scaffolding (#253)
* Adds Laravel Breeze scaffolding * Update NewCommand.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent fd882ec commit 8673653

File tree

1 file changed

+100
-5
lines changed

1 file changed

+100
-5
lines changed

src/NewCommand.php

Lines changed: 100 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ protected function configure()
3030
->addOption('branch', null, InputOption::VALUE_REQUIRED, 'The branch that should be created for a new repository', $this->defaultBranch())
3131
->addOption('github', null, InputOption::VALUE_OPTIONAL, 'Create a new repository on GitHub', false)
3232
->addOption('organization', null, InputOption::VALUE_REQUIRED, 'The GitHub organization to create the new repository for')
33+
->addOption('breeze', null, InputOption::VALUE_NONE, 'Installs the Laravel Breeze scaffolding')
34+
->addOption('dark', null, InputOption::VALUE_NONE, 'Indicate whether Breeze should be scaffolded with dark mode support')
35+
->addOption('ssr', null, InputOption::VALUE_NONE, 'Indicate whether Breeze should be scaffolded with Inertia SSR support')
3336
->addOption('jet', null, InputOption::VALUE_NONE, 'Installs the Laravel Jetstream scaffolding')
34-
->addOption('stack', null, InputOption::VALUE_OPTIONAL, 'The Jetstream stack that should be installed')
37+
->addOption('stack', null, InputOption::VALUE_OPTIONAL, 'The Breeze / Jetstream stack that should be installed')
3538
->addOption('teams', null, InputOption::VALUE_NONE, 'Indicates whether Jetstream should be scaffolded with team support')
3639
->addOption('pest', null, InputOption::VALUE_NONE, 'Installs the Pest testing framework')
40+
->addOption('prompt-breeze', null, InputOption::VALUE_NONE, 'Issues a prompt to determine if Breeze should be installed')
3741
->addOption('prompt-jetstream', null, InputOption::VALUE_NONE, 'Issues a prompt to determine if Jetstream should be installed')
3842
->addOption('force', 'f', InputOption::VALUE_NONE, 'Forces install even if the directory already exists');
3943
}
@@ -47,18 +51,46 @@ protected function configure()
4751
*/
4852
protected function execute(InputInterface $input, OutputInterface $output)
4953
{
54+
$installBreeze = $input->getOption('breeze') ||
55+
($input->getOption('prompt-breeze') && (new SymfonyStyle($input, $output))->confirm('Would you like to install the Laravel Breeze application scaffolding?', false));
56+
5057
$installJetstream = $input->getOption('jet') ||
5158
($input->getOption('prompt-jetstream') && (new SymfonyStyle($input, $output))->confirm('Would you like to install the Laravel Jetstream application scaffolding?', false));
5259

53-
if ($installJetstream) {
60+
if ($installBreeze) {
61+
$output->write("<fg=blue> ____
62+
| __ ) _ __ ___ ___ _______
63+
| _ \| '__/ _ \/ _ \_ / _ \
64+
| |_) | | | __/ __// / __/
65+
|____/|_| \___|\___/___\___|</>".PHP_EOL.PHP_EOL);
66+
67+
$stack = $this->breezeStack($input, $output);
68+
$testingFramework = $this->testingFramework($input, $output);
69+
70+
$dark = false;
71+
72+
if (in_array($stack, ['blade', 'vue', 'react'])) {
73+
$dark = $input->getOption('dark') === true
74+
? (bool) $input->getOption('dark')
75+
: (new SymfonyStyle($input, $output))->confirm('Would you like to install dark mode support?', false);
76+
}
77+
78+
$ssr = false;
79+
80+
if (in_array($stack, ['vue', 'react'])) {
81+
$ssr = $input->getOption('ssr') === true
82+
? (bool) $input->getOption('ssr')
83+
: (new SymfonyStyle($input, $output))->confirm('Would you like to install Inertia SSR support?', false);
84+
}
85+
} elseif ($installJetstream) {
5486
$output->write(PHP_EOL." <fg=magenta>
5587
| | |
5688
|,---.|--- ,---.|--- ,---.,---.,---.,-.-.
5789
||---'| `---.| | |---',---|| | |
5890
`---'`---'`---'`---'`---'` `---'`---^` ' '</>".PHP_EOL.PHP_EOL);
5991

6092
$stack = $this->jetstreamStack($input, $output);
61-
$testingFramework = $this->jetstreamTestingFramework($input, $output);
93+
$testingFramework = $this->testingFramework($input, $output);
6294

6395
$teams = $input->getOption('teams') === true
6496
? (bool) $input->getOption('teams')
@@ -131,7 +163,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
131163
$this->createRepository($directory, $input, $output);
132164
}
133165

134-
if ($installJetstream) {
166+
if ($installBreeze) {
167+
$this->installBreeze($directory, $stack, $testingFramework, $dark, $ssr, $input, $output);
168+
} elseif ($installJetstream) {
135169
$this->installJetstream($directory, $stack, $testingFramework, $teams, $input, $output);
136170
} elseif ($input->getOption('pest')) {
137171
$this->installPest($directory, $input, $output);
@@ -164,6 +198,38 @@ protected function defaultBranch()
164198
return $process->isSuccessful() && $output ? $output : 'main';
165199
}
166200

201+
/**
202+
* Install Laravel Breeze into the application.
203+
*
204+
* @param string $directory
205+
* @param string $stack
206+
* @param string $testingFramework
207+
* @param bool $dark
208+
* @param bool $ssr
209+
* @param \Symfony\Component\Console\Input\InputInterface $input
210+
* @param \Symfony\Component\Console\Output\OutputInterface $output
211+
* @return void
212+
*/
213+
protected function installBreeze(string $directory, string $stack, string $testingFramework, bool $dark, bool $ssr, InputInterface $input, OutputInterface $output)
214+
{
215+
chdir($directory);
216+
217+
$commands = array_filter([
218+
$this->findComposer().' require laravel/breeze',
219+
trim(sprintf(
220+
PHP_BINARY.' artisan breeze:install %s %s %s %s',
221+
$stack,
222+
$testingFramework == 'pest' ? '--pest' : '',
223+
$dark ? '--dark' : '',
224+
$ssr ? '--ssr' : '',
225+
)),
226+
]);
227+
228+
$this->runCommands($commands, $input, $output);
229+
230+
$this->commitChanges('Install Breeze', $directory, $input, $output);
231+
}
232+
167233
/**
168234
* Install Laravel Jetstream into the application.
169235
*
@@ -194,6 +260,35 @@ protected function installJetstream(string $directory, string $stack, string $te
194260
$this->commitChanges('Install Jetstream', $directory, $input, $output);
195261
}
196262

263+
/**
264+
* Determine the stack for Breeze.
265+
*
266+
* @param \Symfony\Component\Console\Input\InputInterface $input
267+
* @param \Symfony\Component\Console\Output\OutputInterface $output
268+
* @return string
269+
*/
270+
protected function breezeStack(InputInterface $input, OutputInterface $output)
271+
{
272+
$stacks = [
273+
'blade',
274+
'react',
275+
'vue',
276+
'api',
277+
];
278+
279+
if ($input->getOption('stack') && in_array($input->getOption('stack'), $stacks)) {
280+
return $input->getOption('stack');
281+
}
282+
283+
$helper = $this->getHelper('question');
284+
285+
$question = new ChoiceQuestion('Which Breeze stack do you prefer?', $stacks);
286+
287+
$output->write(PHP_EOL);
288+
289+
return $helper->ask($input, new SymfonyStyle($input, $output), $question);
290+
}
291+
197292
/**
198293
* Determine the stack for Jetstream.
199294
*
@@ -228,7 +323,7 @@ protected function jetstreamStack(InputInterface $input, OutputInterface $output
228323
* @param \Symfony\Component\Console\Output\OutputInterface $output
229324
* @return string
230325
*/
231-
protected function jetstreamTestingFramework(InputInterface $input, OutputInterface $output)
326+
protected function testingFramework(InputInterface $input, OutputInterface $output)
232327
{
233328
if ($input->getOption('pest')) {
234329
return 'pest';

0 commit comments

Comments
 (0)