commands and logs to the database

This commit is contained in:
2024-08-27 17:42:06 +03:00
parent 74d2fcc4fa
commit ae65ca47f6
16 changed files with 210 additions and 72 deletions
+20 -20
View File
@@ -3,51 +3,51 @@
use Carbon\Carbon;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use Lucent\Command\CommandService;
use Throwable;
class StaticGenerator
{
public function __construct(
public Writer $writer,
public Filesystem $filesystem
public Filesystem $filesystem,
public CommandService $commandService,
)
{
}
public function run(callable $callback): void
public function run(string $signature, callable $callback): void
{
echo "Start ".Carbon::now()->format("Y-m-d H:i:s").PHP_EOL;
$logWriter = $this->commandService->logWriter($signature);
$logWriter("Start " . Carbon::now()->format("Y-m-d H:i:s"));
$this->removeBuildDirectory();
echo "Removing previous data".PHP_EOL;
$logWriter("Removing previous data");
try {
$callback($this->writer);
}catch (Throwable $th){
echo "Finished with errors".Carbon::now()->format("Y-m-d H:i:s")." ".$th->getMessage().PHP_EOL;
$callback(new Writer($logWriter));
} catch (Throwable $th) {
$logWriter("Finished with errors" . Carbon::now()->format("Y-m-d H:i:s") . " " . $th->getMessage());
}
$this->copyBuildDirectory();
echo "Finished ".Carbon::now()->format("Y-m-d H:i:s").PHP_EOL;
$logWriter("Finished " . Carbon::now()->format("Y-m-d H:i:s"));
}
private function removeBuildDirectory() :void{
if(!file_exists(storage_path("lucent/build"))){
private function removeBuildDirectory(): void
{
if (!file_exists(storage_path("lucent/build"))) {
return;
}
$cmd = "rm -rf ".storage_path("lucent/build");
$cmd = "rm -rf " . storage_path("lucent/build");
exec($cmd);
}
private function copyBuildDirectory() :void{
if(file_exists(storage_path("lucent/live"))){
$cmd = "rm -rf ".storage_path("lucent/live");
private function copyBuildDirectory(): void
{
if (file_exists(storage_path("lucent/live"))) {
$cmd = "rm -rf " . storage_path("lucent/live");
exec($cmd);
}
$cmd = sprintf("cp -R %s %s",storage_path("lucent/build"),storage_path("lucent/live"));
$cmd = sprintf("cp -R %s %s", storage_path("lucent/build"), storage_path("lucent/live"));
exec($cmd);
}
+3 -5
View File
@@ -1,13 +1,10 @@
<?php namespace Lucent\StaticGenerator;
use Illuminate\Contracts\View\View;
class Writer
{
public function __construct()
public function __construct( private $logWriter)
{
}
@@ -27,7 +24,8 @@ class Writer
make_dir_r(pathinfo($filepath, PATHINFO_DIRNAME));
}
file_put_contents($filepath, $html);
echo "Path: $path" . PHP_EOL;
$logWriter = $this->logWriter;
$logWriter("Path: $path");
}