Skip to content

Commit

Permalink
Merge pull request #1449 from hydephp/fancy-serve-command
Browse files Browse the repository at this point in the history
Fancy serve command cleanup
  • Loading branch information
caendesilva authored Nov 11, 2023
2 parents d325a10 + afca62e commit e13e215
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/framework/src/Console/Commands/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
class ServeCommand extends Command
{
/** @var string */
protected $signature = 'serve {--host= : <comment>[default: "localhost"]</comment>}} {--port= : <comment>[default: 8080]</comment>}';
protected $signature = 'serve
{--host= : <comment>[default: "localhost"]</comment>}}
{--port= : <comment>[default: 8080]</comment>}
';

/** @var string */
protected $description = 'Start the realtime compiler server.';
Expand Down
14 changes: 12 additions & 2 deletions packages/realtime-compiler/src/Http/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public function __construct()
{
$this->title = config('hyde.name').' - Dashboard';
$this->request = Request::capture();
$this->console = new ConsoleOutput();

if (((bool) env('HYDE_RC_REQUEST_OUTPUT', false)) === true) {
$this->console = new ConsoleOutput();
}

$this->loadFlashData();

Expand Down Expand Up @@ -355,7 +358,7 @@ protected function createPage(): void
$this->abort($exception->getCode(), $exception->getMessage());
}

$this->console->printMessage("Created file '$path'", 'dashboard@createPage');
$this->writeToConsole("Created file '$path'", 'dashboard@createPage');

$this->flash('justCreatedPage', RouteKey::fromPage($pageClass, $pageClass::pathToIdentifier($path))->get());
$this->setJsonResponse(201, "Created file '$path'!");
Expand Down Expand Up @@ -510,4 +513,11 @@ protected function hasAsyncHeaders(): bool
{
return (getallheaders()['X-RC-Handler'] ?? getallheaders()['x-rc-handler'] ?? null) === 'Async';
}

protected function writeToConsole(string $message, string $context = 'dashboard'): void
{
if (isset($this->console)) {
$this->console->printMessage($message, $context);
}
}
}

0 comments on commit e13e215

Please sign in to comment.