-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from mehrancodes/add-support-for-inertia-ssr
Added support for Inertia SSR
- Loading branch information
Showing
9 changed files
with
371 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of Laravel Harbor. | ||
* | ||
* (c) Mehran Rasulian <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace App\Services\Forge\Pipeline; | ||
|
||
use App\Services\Forge\ForgeService; | ||
use App\Traits\Outputifier; | ||
use Closure; | ||
|
||
class EnableInertiaSupport | ||
{ | ||
use Outputifier; | ||
|
||
public function __invoke(ForgeService $service, Closure $next) | ||
{ | ||
if (! $service->setting->inertiaSsrEnabled) { | ||
return $next($service); | ||
} | ||
|
||
if (! $service->siteNewlyMade) { | ||
return $next($service); | ||
} | ||
|
||
$this->addDaemonToStartInertiaSsr($service); | ||
|
||
$this->addCommandToStopInertiaOnReDeploy($service); | ||
|
||
return $next($service); | ||
} | ||
|
||
protected function addDaemonToStartInertiaSsr(ForgeService $service): void | ||
{ | ||
$this->information('Create a daemon for Inertia.js SSR.'); | ||
|
||
$service->forge->createDaemon($service->server->id, [ | ||
'command' => 'php artisan inertia:start-ssr', | ||
'user' => 'forge', | ||
'directory' => $service->siteDirectory() | ||
]); | ||
} | ||
|
||
protected function addCommandToStopInertiaOnReDeploy(ForgeService $service): void | ||
{ | ||
$script = $service->forge->siteDeploymentScript($service->server->id, $service->site->id); | ||
|
||
if (!str_contains($script, $command = 'php artisan inertia:stop-ssr')) { | ||
$this->information('Including stop command for Inertia SSR in deploy script.'); | ||
|
||
$service->forge->updateSiteDeploymentScript( | ||
$service->server->id, | ||
$service->site->id, | ||
$script . "\n\n$command" | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of Laravel Harbor. | ||
* | ||
* (c) Mehran Rasulian <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace App\Services\Forge\Pipeline; | ||
|
||
use App\Services\Forge\ForgeService; | ||
use App\Traits\Outputifier; | ||
use Closure; | ||
use Illuminate\Support\Arr; | ||
use Laravel\Forge\Resources\Daemon; | ||
|
||
class RemoveInertiaSupport | ||
{ | ||
use Outputifier; | ||
|
||
public function __invoke(ForgeService $service, Closure $next) | ||
{ | ||
if (! $service->setting->inertiaSsrEnabled) { | ||
return $next($service); | ||
} | ||
|
||
if ($daemon = $this->getInertiaDaemon($service)) { | ||
$this->information('Removing the daemon for Inertia.js SSR command.'); | ||
|
||
$service->forge->deleteDaemon($service->server->id, $daemon->id); | ||
} | ||
|
||
return $next($service); | ||
} | ||
|
||
protected function getInertiaDaemon(ForgeService $service): ?Daemon | ||
{ | ||
$daemons = $service->forge->daemons($service->server->id); | ||
$command = 'php artisan inertia:start-ssr'; | ||
|
||
return Arr::first( | ||
$daemons, | ||
fn ($daemon) => $daemon->directory == $service->siteDirectory() && $daemon->command == $command | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.