Skip to content

Commit

Permalink
add telescope install support
Browse files Browse the repository at this point in the history
  • Loading branch information
umairparacha00 committed Nov 9, 2023
1 parent 18c134c commit 2928e0e
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ protected function configure()
->addOption('verification', null, InputOption::VALUE_NONE, 'Indicates whether Jetstream should be scaffolded with email verification support')
->addOption('pest', null, InputOption::VALUE_NONE, 'Installs the Pest testing framework')
->addOption('phpunit', null, InputOption::VALUE_NONE, 'Installs the PHPUnit testing framework')
->addOption('telescope', null, InputOption::VALUE_NONE, 'Installs Laravel Telescope')
->addOption('telescope-local', null, InputOption::VALUE_NONE, 'Installs Laravel Telescope locally')
->addOption('prompt-breeze', null, InputOption::VALUE_NONE, 'Issues a prompt to determine if Breeze should be installed (Deprecated)')
->addOption('prompt-jetstream', null, InputOption::VALUE_NONE, 'Issues a prompt to determine if Jetstream should be installed (Deprecated)')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Forces install even if the directory already exists');
Expand Down Expand Up @@ -114,6 +116,20 @@ protected function interact(InputInterface $input, OutputInterface $output)
$this->promptForJetstreamOptions($input);
}

if (!$input->getOption('telescope') && !$input->getOption('telescope-local')) {
match (select(
label: 'Would you like to install Laravel Telescope?',
options: [
'telescope' => 'Laravel Telescope',
'telescope-local' => 'Laravel Telescope (local)',
],
)) {
'telescope' => $input->setOption('telescope', true),
'telescope-local' => $input->setOption('telescope-local', true),
default => null,
};
}

if (! $input->getOption('phpunit') && ! $input->getOption('pest')) {
$input->setOption('pest', select(
label: 'Which testing framework do you prefer?',
Expand Down Expand Up @@ -196,6 +212,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->installPest($directory, $input, $output);
}

if ($input->getOption('telescope') || $input->getOption('telescope-local')) {
$this->installTelescope($directory, $input, $output);
}

if ($input->getOption('github') !== false) {
$this->pushToGitHub($name, $directory, $input, $output);
$output->writeln('');
Expand Down Expand Up @@ -324,6 +344,69 @@ protected function installBreeze(string $directory, InputInterface $input, Outpu
$this->commitChanges('Install Breeze', $directory, $input, $output);
}

/**
* Install Laravel Telescope into the application.
*
* @param string $directory
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return void
*/
protected function installTelescope(string $directory, InputInterface $input, OutputInterface $output)
{
$commands = array_filter([
trim(sprintf(
$this->findComposer().' require laravel/telescope %s',
$input->getOption('telescope-local') ? '--dev' : '',
)),
$this->phpBinary().' artisan telescope:install',
]);

$this->runCommands($commands, $input, $output, workingPath: $directory);


if ($input->getOption('telescope-local')) {
$this->replaceInFile(
' App\Providers\TelescopeServiceProvider::class,',
'',
$directory.'/config/app.php',
);

$this->replaceInFile(
'"extra": {
"laravel": {
"dont-discover": []
}
},',
'"extra": {
"laravel": {
"dont-discover": [
"laravel/telescope"
]
}
},',
$directory.'/composer.json',
);

$this->replaceInFile(
'public function register(): void
{
//
}',
'public function register(): void
{
if ($this->app->environment(\'local\')) {
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
$this->app->register(TelescopeServiceProvider::class);
}
}',
$directory.'/app/Providers/AppServiceProvider.php',
);
}

$this->commitChanges('Install Telescope', $directory, $input, $output);
}

/**
* Install Laravel Jetstream into the application.
*
Expand Down

0 comments on commit 2928e0e

Please sign in to comment.