From c66e2f5c618e9d9bc57b405ae56b32755effaf8f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 8 Dec 2024 19:51:41 +0100 Subject: [PATCH] Extract helper methods --- .../src/Console/Commands/ServeCommand.php | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/framework/src/Console/Commands/ServeCommand.php b/packages/framework/src/Console/Commands/ServeCommand.php index b2b85548d05..18d94199d30 100644 --- a/packages/framework/src/Console/Commands/ServeCommand.php +++ b/packages/framework/src/Console/Commands/ServeCommand.php @@ -70,17 +70,7 @@ public function safeHandle(): int $this->runServerProcess($command); - while ($this->server->running()) { - if (isset($this->vite) && $this->vite->running()) { - $output = $this->vite->latestOutput(); - - if ($output) { - $this->output->write($output); - } - } - - Sleep::usleep(100000); // 100ms - } + $this->handleRunningProcesses(); return Command::SUCCESS; } @@ -209,6 +199,26 @@ protected function runViteProcess(): void $this->vite = Process::forever()->start('npm run dev'); } + protected function handleRunningProcesses(): void + { + while ($this->server->running()) { + $this->handleViteOutput(); + + Sleep::usleep(100000); // 100ms + } + } + + protected function handleViteOutput(): void + { + if (isset($this->vite) && $this->vite->running()) { + $output = $this->vite->latestOutput(); + + if ($output) { + $this->output->write($output); + } + } + } + /** @experimental This feature may be removed before the final release. */ protected function isPortAvailable(int $port): bool {