|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * This file is part of Laravel Harbor. |
| 7 | + * |
| 8 | + * (c) Mehran Rasulian <[email protected]> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view the LICENSE |
| 11 | + * file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace App\Services\Forge\Pipeline; |
| 15 | + |
| 16 | +use App\Services\Forge\ForgeService; |
| 17 | +use App\Traits\Outputifier; |
| 18 | +use Closure; |
| 19 | + |
| 20 | +class EnableInertiaSupport |
| 21 | +{ |
| 22 | + use Outputifier; |
| 23 | + |
| 24 | + public function __invoke(ForgeService $service, Closure $next) |
| 25 | + { |
| 26 | + if (! $service->setting->inertiaSsrEnabled) { |
| 27 | + return $next($service); |
| 28 | + } |
| 29 | + |
| 30 | + if (! $service->siteNewlyMade) { |
| 31 | + return $next($service); |
| 32 | + } |
| 33 | + |
| 34 | + $this->addDaemonToStartInertiaSsr($service); |
| 35 | + |
| 36 | + $this->addCommandToStopInertiaOnReDeploy($service); |
| 37 | + |
| 38 | + return $next($service); |
| 39 | + } |
| 40 | + |
| 41 | + protected function addDaemonToStartInertiaSsr(ForgeService $service): void |
| 42 | + { |
| 43 | + $this->information('Create a daemon for Inertia.js SSR.'); |
| 44 | + |
| 45 | + $service->forge->createDaemon($service->server->id, [ |
| 46 | + 'command' => 'php artisan inertia:start-ssr', |
| 47 | + 'user' => 'forge', |
| 48 | + 'directory' => $service->siteDirectory() |
| 49 | + ]); |
| 50 | + } |
| 51 | + |
| 52 | + protected function addCommandToStopInertiaOnReDeploy(ForgeService $service): void |
| 53 | + { |
| 54 | + $script = $service->forge->siteDeploymentScript($service->server->id, $service->site->id); |
| 55 | + |
| 56 | + if (!str_contains($script, $command = 'php artisan inertia:stop-ssr')) { |
| 57 | + $this->information('Including stop command for Inertia SSR in deploy script.'); |
| 58 | + |
| 59 | + $service->forge->updateSiteDeploymentScript( |
| 60 | + $service->server->id, |
| 61 | + $service->site->id, |
| 62 | + $script . "\n\n$command" |
| 63 | + ); |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments