This commit is contained in:
2023-10-16 13:16:22 +03:00
parent 96c2204939
commit 5adeaeb2bd
7 changed files with 94 additions and 100 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"main.js": { "main.js": {
"file": "assets/main.e9ef6ca6.js", "file": "assets/main.6a78412a.js",
"src": "main.js", "src": "main.js",
"isEntry": true, "isEntry": true,
"css": [ "css": [
+2 -2
View File
@@ -63,7 +63,7 @@
</div> </div>
</div> </div>
</div> </div>
{#if otherSchemas} {#if otherSchemas.length > 0}
<div class="accordion-item"> <div class="accordion-item">
<h2 class="accordion-header" id="panelsStayOpen-headingOther"> <h2 class="accordion-header" id="panelsStayOpen-headingOther">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
@@ -83,7 +83,7 @@
</div> </div>
</div> </div>
{/if} {/if}
{#if fileSchemas} {#if fileSchemas.length > 0}
<div class="accordion-item"> <div class="accordion-item">
<h2 class="accordion-header" id="panelsStayOpen-headingFS"> <h2 class="accordion-header" id="panelsStayOpen-headingFS">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
+1 -2
View File
@@ -63,10 +63,9 @@
{/if} {/if}
{#if !inProgress && logs} {#if !inProgress && logs}
<span class="badge text-bg-info"> <span class="badge text-bg-info">
Build completed at Build completed
</span> </span>
{/if} {/if}
<span class="badge text-bg-light"> {date}</span>
</div> </div>
+2 -1
View File
@@ -47,6 +47,7 @@ class BuildController extends Controller
{ {
return response()->stream(function () { return response()->stream(function () {
while (true) { while (true) {
sleep(1); // 50ms
$data["date"] = date("Y-m-d H:i:s"); $data["date"] = date("Y-m-d H:i:s");
$data["logs"] = file_get_contents(storage_path("build.log")); $data["logs"] = file_get_contents(storage_path("build.log"));
$lines = explode("\n",$data["logs"]); $lines = explode("\n",$data["logs"]);
@@ -57,7 +58,7 @@ class BuildController extends Controller
ob_flush(); ob_flush();
flush(); flush();
if(in_array("Finito",$lines)){ if(str_contains("Finito",$lines)){
break; break;
} }
+16 -27
View File
@@ -1,6 +1,7 @@
<?php namespace Lucent\StaticGenerator; <?php namespace Lucent\StaticGenerator;
use Carbon\Carbon;
use Illuminate\Contracts\Filesystem\Filesystem; use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
@@ -8,10 +9,6 @@ use Illuminate\Support\Facades\Storage;
class StaticGenerator class StaticGenerator
{ {
/**
* @var array<string> $directoriesIndex
*/
public array $directoriesIndex = [];
public function __construct( public function __construct(
public Writer $writer, public Writer $writer,
@@ -23,37 +20,29 @@ class StaticGenerator
public function run(callable $callback): void public function run(callable $callback): void
{ {
echo "Start".PHP_EOL; echo "Start ".Carbon::now()->format("Y-m-d H:i:s").PHP_EOL;
$this->removePreviousDirectories(); $this->removeBuildDirectory();
echo "Removing previous data".PHP_EOL; echo "Removing previous data".PHP_EOL;
$callback($this->writer); $callback($this->writer);
echo "Finito".PHP_EOL; $this->copyBuildDirectory();
echo "Finito ".Carbon::now()->format("Y-m-d H:i:s").PHP_EOL;
} }
private function removePreviousDirectories() :void{ private function removeBuildDirectory() :void{
if(!file_exists(storage_path("lucent/directories.log"))){ if(!file_exists(storage_path("lucent/build"))){
return; return;
} }
$directories = file_get_contents(storage_path("lucent/directories.log")); $cmd = "rm -rf ".storage_path("lucent/build");
$directoriesArr = array_reverse(explode(PHP_EOL,$directories)); exec($cmd);
foreach ($directoriesArr as $directory){ }
if(empty($directory) || $directory === "/") {
continue;
}
if(!file_exists(public_path($directory."/index.html"))){ private function copyBuildDirectory() :void{
if(file_exists(public_path($directory))){ if(file_exists(storage_path("lucent/live"))){
rmdir(public_path($directory)); $cmd = "rm -rf ".storage_path("lucent/live");
} exec($cmd);
continue;
}
unlink(public_path($directory."/index.html"));
rmdir(public_path($directory));
} }
if(file_exists(public_path("index.html"))){ $cmd = sprintf("cp -R %s %s",storage_path("lucent/build"),storage_path("lucent/live"));
unlink(public_path("index.html")); exec($cmd);
}
unlink(storage_path("lucent/directories.log"));
} }
+13 -8
View File
@@ -6,24 +6,29 @@ use Illuminate\Contracts\View\View;
class Writer class Writer
{ {
public function __construct(
) public function __construct()
{ {
} }
private function buildPath(string $path): string
{
if (!file_exists(storage_path("lucent/build"))) {
mkdir(storage_path("lucent/build"));
}
return storage_path("lucent/build/" . ltrim($path, "/"));
}
public function save(string $path, string $html): void public function save(string $path, string $html): void
{ {
$path = trim($path, "/");
$filepath = public_path($path . "/index.html"); $filepath = $this->buildPath($path. "/index.html");
if (!file_exists(pathinfo($filepath, PATHINFO_DIRNAME))) { if (!file_exists(pathinfo($filepath, PATHINFO_DIRNAME))) {
make_dir_r(pathinfo($filepath, PATHINFO_DIRNAME)); make_dir_r(pathinfo($filepath, PATHINFO_DIRNAME));
} }
file_put_contents($filepath, $html); file_put_contents($filepath, $html);
file_put_contents(storage_path("lucent/directories.log"), $path.PHP_EOL, FILE_APPEND); echo "Path: $path" . PHP_EOL;
echo "Path: /$path".PHP_EOL;
} }
@@ -32,7 +37,7 @@ class Writer
// logger("fetching $skip"); // logger("fetching $skip");
$records = $query($limit, $skip); $records = $query($limit, $skip);
$parser($records,$limit, $skip); $parser($records, $limit, $skip);
if ($records->count() > 0) { if ($records->count() > 0) {
return $this->recordIterator($query, $parser, $skip + $limit); return $this->recordIterator($query, $parser, $skip + $limit);