build
This commit is contained in:
File diff suppressed because one or more lines are too long
Vendored
+171
File diff suppressed because one or more lines are too long
Vendored
-172
File diff suppressed because one or more lines are too long
Vendored
+3
-3
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"main.js": {
|
||||
"file": "assets/main.c3dc0395.js",
|
||||
"file": "assets/main.aacd1b62.js",
|
||||
"src": "main.js",
|
||||
"isEntry": true,
|
||||
"css": [
|
||||
"assets/main.778ffe0f.css"
|
||||
"assets/main.632850b9.css"
|
||||
]
|
||||
},
|
||||
"main.css": {
|
||||
"file": "assets/main.778ffe0f.css",
|
||||
"file": "assets/main.632850b9.css",
|
||||
"src": "main.css"
|
||||
}
|
||||
}
|
||||
@@ -7,14 +7,7 @@
|
||||
const channel = getContext("channel");
|
||||
const user = getContext("user");
|
||||
|
||||
function buildWebsite(e) {
|
||||
e.preventDefault();
|
||||
|
||||
axios.post(channel.lucentUrl + "/build").then(response => {
|
||||
window.location.href = channel.lucentUrl + "/build-report"
|
||||
})
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<nav class="lx-nav">
|
||||
@@ -27,7 +20,7 @@
|
||||
<a class="nav-item" href="{channel.lucentUrl}/members">Members</a>
|
||||
|
||||
{#if channel.generateCommand}
|
||||
<button on:click={buildWebsite} class="btn btn-outline-primary btn-sm">Build website</button>
|
||||
<a href="{channel.lucentUrl}/build-report" class="btn btn-outline-primary btn-sm">Build website</a>
|
||||
{/if}
|
||||
</div>
|
||||
<div>
|
||||
|
||||
@@ -8,25 +8,39 @@
|
||||
|
||||
const channel = getContext("channel");
|
||||
export let title;
|
||||
$: output = "";
|
||||
const eventSource = new EventSource(channel.lucentUrl + "/build-report-source");
|
||||
$: date = "";
|
||||
$: logs = "";
|
||||
|
||||
|
||||
function buildWebsite(e) {
|
||||
e.preventDefault();
|
||||
|
||||
axios.post(channel.lucentUrl + "/build").then(response => {
|
||||
const eventSource = new EventSource(channel.lucentUrl + "/build-report-source");
|
||||
|
||||
eventSource.onmessage = function(event) {
|
||||
const data = JSON.parse(event.data);
|
||||
date = data.date;
|
||||
logs = data.logs;
|
||||
}
|
||||
eventSource.onerror = (e)=>{
|
||||
console.log(e)
|
||||
}
|
||||
})
|
||||
|
||||
console.log("heklko")
|
||||
eventSource.onmessage = function(event) {
|
||||
const data = JSON.parse(event.data);
|
||||
console.log(data)
|
||||
output = output + "message: " + data.time;
|
||||
}
|
||||
eventSource.onerror = (e)=>{
|
||||
console.log(e)
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<div class="wrapper-tiny transparent mb-5">
|
||||
<div class="lx-card mt-5">
|
||||
|
||||
<h3 class="header-small mb-5">{title}</h3>
|
||||
|
||||
{output}
|
||||
<button on:click={buildWebsite} class="btn btn-outline-primary btn-sm mb-3">Start Build</button>
|
||||
|
||||
<div class="mb-3">{date}</div>
|
||||
|
||||
<pre>{logs}</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -22,7 +22,13 @@ class BuildController extends Controller
|
||||
|
||||
public function build()
|
||||
{
|
||||
exec("cd ".base_path(). " && php8.2 artisan {$this->channelService->channel->generateCommand} > /dev/null 2>&1 & echo $!",$op);
|
||||
|
||||
$buildLogFile = storage_path("build.log");
|
||||
if(file_exists($buildLogFile)){
|
||||
unlink($buildLogFile);
|
||||
}
|
||||
|
||||
exec("cd " . base_path() . " && php8.2 artisan {$this->channelService->channel->generateCommand} > " . $buildLogFile . " 2>&1 & echo $!", $op);
|
||||
$pid = (int)$op[0];
|
||||
return redirect($this->channelService->channel->lucentUrl . "/build-report");
|
||||
}
|
||||
@@ -41,17 +47,25 @@ class BuildController extends Controller
|
||||
{
|
||||
return response()->stream(function () {
|
||||
while (true) {
|
||||
$curDate = time();
|
||||
echo 'data: {"time": "' . $curDate . '"}';
|
||||
$data["date"] = date("Y-m-d H:i:s");
|
||||
$data["logs"] = file_get_contents(storage_path("build.log"));
|
||||
$lines = explode("\n",$data["logs"]);
|
||||
|
||||
echo 'data: ' .json_encode($data);
|
||||
echo "\n\n";
|
||||
logger( $curDate);
|
||||
|
||||
ob_flush();
|
||||
flush();
|
||||
|
||||
if(in_array("Finito",$lines)){
|
||||
break;
|
||||
}
|
||||
|
||||
// Break the loop if the client aborted the connection (closed the page)
|
||||
if (connection_aborted()) {break;}
|
||||
sleep(2); // 50ms
|
||||
if (connection_aborted()) {
|
||||
break;
|
||||
}
|
||||
sleep(1); // 50ms
|
||||
}
|
||||
}, 200, [
|
||||
'Cache-Control' => 'no-cache',
|
||||
|
||||
@@ -1,51 +1,23 @@
|
||||
<?php namespace Lucent\StaticGenerator;
|
||||
|
||||
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class StaticGenerator
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
public Writer $writer,
|
||||
public Filesystem $filesystem
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public function save(string $path, string $html): void
|
||||
public function run(callable $callback): void
|
||||
{
|
||||
$path = trim($path, "/");
|
||||
|
||||
$filepath = public_path($path . "/index.html");
|
||||
|
||||
if (!file_exists(pathinfo($filepath, PATHINFO_DIRNAME))) {
|
||||
make_dir_r(pathinfo($filepath, PATHINFO_DIRNAME));
|
||||
}
|
||||
|
||||
file_put_contents($filepath, $html);
|
||||
}
|
||||
|
||||
public function recordIterator(callable $query, callable $parser, int $skip = 0): int
|
||||
{
|
||||
$limit = 100;
|
||||
// logger("fetching $skip");
|
||||
|
||||
$records = $query($limit, $skip);
|
||||
$parser($records);
|
||||
|
||||
if ($records->hasResults()) {
|
||||
return $this->recordIterator($query, $parser, $skip + $limit);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function createRedirect(string $from, string $to, string $title = "Redirecting", string $message = "Redirecting Soon..."): void
|
||||
{
|
||||
$html = view("lucent::redirect", [
|
||||
"to" => $to,
|
||||
"title" => $title,
|
||||
"message" => $message,
|
||||
])->render();
|
||||
$this->save($from, $html);
|
||||
echo "Start".PHP_EOL;
|
||||
$callback($this->writer);
|
||||
echo "Finito".PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php namespace Lucent\StaticGenerator;
|
||||
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class Writer
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public function save(string $path, string $html): void
|
||||
{
|
||||
$path = trim($path, "/");
|
||||
|
||||
$filepath = public_path($path . "/index.html");
|
||||
|
||||
if (!file_exists(pathinfo($filepath, PATHINFO_DIRNAME))) {
|
||||
make_dir_r(pathinfo($filepath, PATHINFO_DIRNAME));
|
||||
}
|
||||
|
||||
file_put_contents($filepath, $html);
|
||||
echo "Path: /$path".PHP_EOL;
|
||||
}
|
||||
|
||||
public function recordIterator(callable $query, callable $parser, int $skip = 0): int
|
||||
{
|
||||
$limit = 100;
|
||||
// logger("fetching $skip");
|
||||
|
||||
$records = $query($limit, $skip);
|
||||
$parser($records);
|
||||
|
||||
if ($records->hasResults()) {
|
||||
return $this->recordIterator($query, $parser, $skip + $limit);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function createRedirect(string $from, string $to, string $title = "Redirecting", string $message = "Redirecting Soon..."): void
|
||||
{
|
||||
$html = view("lucent::redirect", [
|
||||
"to" => $to,
|
||||
"title" => $title,
|
||||
"message" => $message,
|
||||
])->render();
|
||||
$this->save($from, $html);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user