2023-10-04 23:48:12 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Lucent\Http\Controller;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
use Illuminate\Support\Facades\Artisan;
|
|
|
|
|
use Lucent\Channel\ChannelService;
|
|
|
|
|
use Lucent\Svelte\Svelte;
|
|
|
|
|
use function Lucent\Response\ok;
|
|
|
|
|
|
|
|
|
|
class BuildController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
public readonly Svelte $svelte,
|
|
|
|
|
public readonly ChannelService $channelService,
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function build()
|
|
|
|
|
{
|
2023-10-05 13:03:17 +03:00
|
|
|
|
2023-10-16 13:42:06 +03:00
|
|
|
$buildLogFile = storage_path("lucent/build.log");
|
2023-10-05 13:03:17 +03:00
|
|
|
if(file_exists($buildLogFile)){
|
|
|
|
|
unlink($buildLogFile);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-23 17:29:08 +03:00
|
|
|
exec("cd " . base_path() . " && php8.3 artisan {$this->channelService->channel->generateCommand} > " . $buildLogFile . " 2>&1 & echo $!", $op);
|
2023-10-04 23:48:12 +03:00
|
|
|
$pid = (int)$op[0];
|
|
|
|
|
return redirect($this->channelService->channel->lucentUrl . "/build-report");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function report(): View
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return $this->svelte->render(
|
|
|
|
|
layout: "channel",
|
|
|
|
|
view: "buildReport",
|
|
|
|
|
title: "Build Report",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function reportSource()
|
|
|
|
|
{
|
|
|
|
|
return response()->stream(function () {
|
|
|
|
|
while (true) {
|
2023-10-16 18:30:00 +03:00
|
|
|
// sleep(1); // 50ms
|
2023-10-05 13:03:17 +03:00
|
|
|
$data["date"] = date("Y-m-d H:i:s");
|
2023-10-16 13:42:06 +03:00
|
|
|
$data["logs"] = file_get_contents(storage_path("lucent/build.log"));
|
2023-10-16 18:30:00 +03:00
|
|
|
// $lines = explode("\n",$data["logs"]);
|
2023-10-05 13:03:17 +03:00
|
|
|
|
|
|
|
|
echo 'data: ' .json_encode($data);
|
2023-10-04 23:48:12 +03:00
|
|
|
echo "\n\n";
|
|
|
|
|
|
|
|
|
|
ob_flush();
|
|
|
|
|
flush();
|
|
|
|
|
|
2023-10-16 18:30:00 +03:00
|
|
|
if(str_contains($data["logs"],"Finito")){
|
2023-10-05 13:03:17 +03:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-17 20:21:45 +02:00
|
|
|
if(str_contains($data["logs"],"Exception")){
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-04 23:48:12 +03:00
|
|
|
// Break the loop if the client aborted the connection (closed the page)
|
2023-10-05 13:03:17 +03:00
|
|
|
if (connection_aborted()) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
sleep(1); // 50ms
|
2023-10-04 23:48:12 +03:00
|
|
|
}
|
|
|
|
|
}, 200, [
|
|
|
|
|
'Cache-Control' => 'no-cache',
|
|
|
|
|
'X-Accel-Buffering' => 'no',
|
|
|
|
|
'Content-Type' => 'text/event-stream',
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|