Skip to content

Commit 8ab3502

Browse files
committed
add jetstream install support
1 parent ce9a329 commit 8ab3502

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

src/NewCommand.php

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Symfony\Component\Console\Input\InputInterface;
99
use Symfony\Component\Console\Input\InputOption;
1010
use Symfony\Component\Console\Output\OutputInterface;
11+
use Symfony\Component\Console\Question\ChoiceQuestion;
12+
use Symfony\Component\Console\Question\ConfirmationQuestion;
13+
use Symfony\Component\Console\Style\SymfonyStyle;
1114
use Symfony\Component\Process\Process;
1215

1316
class NewCommand extends Command
@@ -24,6 +27,7 @@ protected function configure()
2427
->setDescription('Create a new Laravel application')
2528
->addArgument('name', InputArgument::OPTIONAL)
2629
->addOption('dev', null, InputOption::VALUE_NONE, 'Installs the latest "development" release')
30+
->addOption('jet', null, InputOption::VALUE_NONE, 'Installs the Laravel Jetstream scaffolding')
2731
->addOption('force', 'f', InputOption::VALUE_NONE, 'Forces install even if the directory already exists');
2832
}
2933

@@ -36,12 +40,33 @@ protected function configure()
3640
*/
3741
protected function execute(InputInterface $input, OutputInterface $output)
3842
{
39-
$output->write(PHP_EOL.'<fg=red> _ _
43+
if ($input->getOption('jet')) {
44+
$output->write(PHP_EOL."<fg=magenta>
45+
| | |
46+
|,---.|--- ,---.|--- ,---.,---.,---.,-.-.
47+
||---'| `---.| | |---',---|| | |
48+
`---'`---'`---'`---'`---'` `---'`---^` ' '</>".PHP_EOL.PHP_EOL);
49+
50+
$helper = $this->getHelper('question');
51+
52+
$question = new ChoiceQuestion('Which Jetstream stack do you prefer?', [
53+
'livewire',
54+
'inertia',
55+
]);
56+
57+
$output->write(PHP_EOL);
58+
59+
$stack = $helper->ask($input, new SymfonyStyle($input, $output), $question);
60+
61+
$teams = (new SymfonyStyle($input, $output))->confirm('Will your application use teams?', false);
62+
} else {
63+
$output->write(PHP_EOL.'<fg=red> _ _
4064
| | | |
4165
| | __ _ _ __ __ ___ _____| |
4266
| | / _` | \'__/ _` \ \ / / _ \ |
4367
| |___| (_| | | | (_| |\ V / __/ |
4468
|______\__,_|_| \__,_| \_/ \___|_|'.PHP_EOL.PHP_EOL);
69+
}
4570

4671
sleep(1);
4772

@@ -83,12 +108,40 @@ protected function execute(InputInterface $input, OutputInterface $output)
83108
$directory.'/.env'
84109
);
85110

111+
if ($input->getOption('jet')) {
112+
$this->installJetstream($directory, $stack, $teams, $input, $output);
113+
}
114+
86115
$output->writeln(PHP_EOL.'<comment>Application ready! Build something amazing.</comment>');
87116
}
88117

89118
return 0;
90119
}
91120

121+
/**
122+
* Install Laravel Jetstream into the application.
123+
*
124+
* @param string $directory
125+
* @param string $stack
126+
* @param bool $teams
127+
* @param \Symfony\Component\Console\Input\InputInterface $input
128+
* @param \Symfony\Component\Console\Output\OutputInterface $output
129+
* @return void
130+
*/
131+
protected function installJetstream(string $directory, string $stack, bool $teams, InputInterface $input, OutputInterface $output)
132+
{
133+
chdir($directory);
134+
135+
$commands = array_filter([
136+
$this->findComposer().' require laravel/jetstream',
137+
trim(sprintf(PHP_BINARY.' artisan jetstream:install %s %s', $stack, $teams ? '--teams' : '')),
138+
$stack === 'inertia' ? 'npm install && npm run dev' : null,
139+
PHP_BINARY.' artisan storage:link',
140+
]);
141+
142+
$this->runCommands($commands, $input, $output);
143+
}
144+
92145
/**
93146
* Verify that the application does not already exist.
94147
*

0 commit comments

Comments
 (0)