From a582080e5c19d7a5b825489f0292fc2c33863b73 Mon Sep 17 00:00:00 2001 From: stephenjude Date: Thu, 29 Feb 2024 22:26:31 +0100 Subject: [PATCH] install jetstream from command line --- src/Commands/FilamentJetstreamCommand.php | 34 +++++++++++------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/Commands/FilamentJetstreamCommand.php b/src/Commands/FilamentJetstreamCommand.php index 2078b38..0670c2d 100644 --- a/src/Commands/FilamentJetstreamCommand.php +++ b/src/Commands/FilamentJetstreamCommand.php @@ -20,17 +20,15 @@ public function handle(): int { $this->info('Filament Jetstream scaffolding...'); - if (! $this->installComposerPackages()) { + if (!$this->installComposerPackages()) { return self::FAILURE; } - $this->call('jetstream:install', [ - 'stack' => 'livewire', - '--verification' => true, - '--dark' => true, - '--teams' => $this->option('teams'), - '--api' => $this->option('api'), - ]); + $options = array_filter(['--teams' => $this->option('teams'), '--api' => $this->option('api'),]); + + $options = implode(' ', (array_keys($options))); + + $this->runCommands(["php artisan jetstream:install livewire --verification --dark $options"]); $this->configureUser(); @@ -58,11 +56,11 @@ public function handle(): int */ protected function installComposerPackages(): bool { - if (! $this->hasComposerPackage('filament/filament')) { + if (!$this->hasComposerPackage('filament/filament')) { return $this->requireComposerPackages('filament/filament:^3.2'); } - if (! $this->hasComposerPackage('laravel/jetstream')) { + if (!$this->hasComposerPackage('laravel/jetstream')) { return $this->requireComposerPackages('laravel/jetstream:^4.2'); } @@ -196,15 +194,15 @@ protected function configurePanel() { $filesystem = (new Filesystem); - if (! $filesystem->isEmptyDirectory(app_path('Providers/Filament'))) { + if (!$filesystem->isEmptyDirectory(app_path('Providers/Filament'))) { collect($filesystem->files(app_path('Providers/Filament'))) - ->map(fn (\SplFileInfo $fileInfo) => str($fileInfo->getFilename()) + ->map(fn(\SplFileInfo $fileInfo) => str($fileInfo->getFilename()) ->before('.php') ->prepend("App\Providers\Filament") ->append('::class,') ->toString()) ->each( - fn ($value) => $this->replaceInFile(search: $value, replace: '', path: config_path('app.php')) + fn($value) => $this->replaceInFile(search: $value, replace: '', path: config_path('app.php')) ); $filesystem->deleteDirectory(app_path('Providers/Filament')); @@ -297,7 +295,7 @@ protected function replaceInFile(string $search, string $replace, string $path): /** * Run the given commands. */ - protected function runCommands($commands): void + protected function runCommands(array $commands): void { $process = Process::fromShellCommandline(implode(' && ', $commands), null, null, null, null); @@ -305,12 +303,12 @@ protected function runCommands($commands): void try { $process->setTty(true); } catch (\RuntimeException $e) { - $this->output->writeln(' WARN ' . $e->getMessage() . PHP_EOL); + $this->output->writeln(' WARN '.$e->getMessage().PHP_EOL); } } $process->run(function ($type, $line) { - $this->output->write(' ' . $line); + $this->output->write(' '.$line); }); } @@ -328,14 +326,14 @@ protected function hasComposerPackage(string $package): bool /** * Installs the given Composer Packages into the application. */ - protected function requireComposerPackages(array | string $packages): bool + protected function requireComposerPackages(array|string $packages): bool { $command = array_merge( ['composer', 'require'], is_array($packages) ? $packages : func_get_args() ); - return ! (new Process($command, base_path(), ['COMPOSER_MEMORY_LIMIT' => '-1'])) + return !(new Process($command, base_path(), ['COMPOSER_MEMORY_LIMIT' => '-1'])) ->setTimeout(null) ->run(function ($type, $output) { $this->output->write($output);