remove static generator
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
<?php namespace Lucent\StaticGenerator;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
use Lucent\Command\CommandService;
|
||||
use Throwable;
|
||||
|
||||
class StaticGenerator
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
public Filesystem $filesystem,
|
||||
public CommandService $commandService,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public function run(string $signature, callable $callback): void
|
||||
{
|
||||
$logWriter = $this->commandService->logWriter($signature);
|
||||
$logWriter("Start " . Carbon::now()->format("Y-m-d H:i:s"));
|
||||
$this->removeBuildDirectory();
|
||||
$logWriter("Removing previous data");
|
||||
try {
|
||||
$callback(new Writer($logWriter));
|
||||
} catch (Throwable $th) {
|
||||
$logWriter("Finished with errors" . Carbon::now()->format("Y-m-d H:i:s") . " " . $th->getMessage());
|
||||
}
|
||||
|
||||
$this->copyBuildDirectory();
|
||||
$logWriter("Finished " . Carbon::now()->format("Y-m-d H:i:s"));
|
||||
}
|
||||
|
||||
private function removeBuildDirectory(): void
|
||||
{
|
||||
if (!file_exists(storage_path("lucent/build"))) {
|
||||
return;
|
||||
}
|
||||
$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");
|
||||
exec($cmd);
|
||||
}
|
||||
$cmd = sprintf("cp -R %s %s", storage_path("lucent/build"), storage_path("lucent/live"));
|
||||
exec($cmd);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
<?php namespace Lucent\StaticGenerator;
|
||||
|
||||
class Writer
|
||||
{
|
||||
|
||||
public function __construct( private $logWriter)
|
||||
{
|
||||
}
|
||||
|
||||
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, string $extension = "html"): void
|
||||
{
|
||||
$filepath = $this->buildPath($path. "/index.$extension");
|
||||
|
||||
if (!file_exists(pathinfo($filepath, PATHINFO_DIRNAME))) {
|
||||
make_dir_r(pathinfo($filepath, PATHINFO_DIRNAME));
|
||||
}
|
||||
file_put_contents($filepath, $html);
|
||||
$logWriter = $this->logWriter;
|
||||
$logWriter("Path: $path");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function recordIterator(callable $query, callable $parser, int $skip = 0, $limit = 100): int
|
||||
{
|
||||
$records = $query($limit, $skip);
|
||||
$parser($records, $limit, $skip);
|
||||
|
||||
if ($records->count() > 0) {
|
||||
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