From 2928e0e8c079dda29fec9bfbf9b2f06325570431 Mon Sep 17 00:00:00 2001 From: Muhammad Umair Raza Date: Thu, 9 Nov 2023 13:38:44 +0500 Subject: [PATCH] add telescope install support --- src/NewCommand.php | 83 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/src/NewCommand.php b/src/NewCommand.php index 37477eff..725bdcb3 100644 --- a/src/NewCommand.php +++ b/src/NewCommand.php @@ -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'); @@ -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?', @@ -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(''); @@ -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. *