wip setup guide
This commit is contained in:
@@ -37,6 +37,7 @@ final class Channel
|
||||
return match (config("filesystems.disks.lucent.driver")) {
|
||||
"s3" => config("filesystems.disks.lucent.endpoint") . "/" . config("filesystems.disks.lucent.bucket"),
|
||||
"local" => $this->url . "/storage" . config("filesystems.disks.lucent.endpoint"),
|
||||
default => ""
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Http\Controller;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\Session\Session;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Lucent\Account\AccountService;
|
||||
use Lucent\Channel\ChannelService;
|
||||
use Lucent\LucentException;
|
||||
use Lucent\Setup\Data\SetupStep;
|
||||
use Lucent\Setup\Setup;
|
||||
use Lucent\Setup\Step\ComposerStep;
|
||||
use Lucent\Setup\Step\IStep;
|
||||
use Lucent\Setup\Step\LucentConfigStep;
|
||||
use Lucent\Svelte\Svelte;
|
||||
use function Lucent\Response\fail;
|
||||
use function Lucent\Response\ok;
|
||||
|
||||
|
||||
class SetupController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AccountService $accountService,
|
||||
private readonly ChannelService $channelService,
|
||||
private readonly Svelte $svelte,
|
||||
private readonly Setup $setup,
|
||||
)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function setup(Request $request): View|RedirectResponse
|
||||
{
|
||||
if ($this->accountService->countUsers() > 0) {
|
||||
return redirect($this->channelService->channel->lucentUrl . "/login");
|
||||
}
|
||||
|
||||
$steps = array_reduce([
|
||||
new ComposerStep,
|
||||
new LucentConfigStep,
|
||||
],fn(array $carry, IStep $setupStep)=> array_merge($carry,[$setupStep()]) ,[]);
|
||||
|
||||
return $this->svelte->render(
|
||||
layout: "account",
|
||||
view: "setup",
|
||||
title: "Setup Lucent",
|
||||
data: [
|
||||
"steps" => $steps
|
||||
]
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function postRegister(Request $request): Response
|
||||
{
|
||||
|
||||
if ($this->accountService->countUsers() > 0) {
|
||||
abort(400);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->authService->registerAdmin(
|
||||
name: $request->input("name"),
|
||||
email: $request->input("email"),
|
||||
);
|
||||
} catch (LucentException $th) {
|
||||
return fail($th);
|
||||
}
|
||||
|
||||
return ok();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@ use Lucent\Http\Controller\HomeController;
|
||||
use Lucent\Http\Controller\MemberController;
|
||||
use Lucent\Http\Controller\RecordController;
|
||||
use Lucent\Http\Controller\RevisionController;
|
||||
use Lucent\Http\Controller\SetupController;
|
||||
|
||||
|
||||
Route::group([
|
||||
@@ -19,6 +20,7 @@ Route::group([
|
||||
|
||||
Route::middleware(['lucent.guest'])->group(function () {
|
||||
Route::get('/', [AuthController::class, 'login']);
|
||||
Route::get('/setup', [SetupController::class, 'setup']);
|
||||
Route::get('/register', [AuthController::class, 'register']);
|
||||
Route::post('/register', [AuthController::class, 'postRegister']);
|
||||
Route::get('/login', [AuthController::class, 'login']);
|
||||
|
||||
@@ -85,9 +85,10 @@ class LucentServiceProvider extends ServiceProvider
|
||||
|
||||
$this->publishes([
|
||||
__DIR__ . '/Config/main.php' => config_path('lucent.php'),
|
||||
]);
|
||||
],"lucent-config");
|
||||
|
||||
$this->publishes([
|
||||
__DIR__ . '/Config/main.php' => config_path('lucent.php'),
|
||||
__DIR__ . '/../front/dist' => public_path('vendor/lucent/dist'),
|
||||
__DIR__ . '/../front/public' => public_path('vendor/lucent/public'),
|
||||
], 'lucent');
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Setup\Data;
|
||||
|
||||
class SetupStep
|
||||
{
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $instructions,
|
||||
public SetupStepStatus $status,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public static function makeSuccess(string $name, string $instructions): self
|
||||
{
|
||||
return new self($name, $instructions, SetupStepStatus::SUCCESS);
|
||||
}
|
||||
|
||||
public static function makeFail(string $name, string $instructions): self
|
||||
{
|
||||
return new self($name, $instructions, SetupStepStatus::FAIL);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Setup\Data;
|
||||
|
||||
enum SetupStepStatus: string
|
||||
{
|
||||
case SUCCESS = "success";
|
||||
case FAIL = "fail";
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Setup;
|
||||
|
||||
use Lucent\Setup\Data\SetupStep;
|
||||
|
||||
class Setup
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Setup\Step;
|
||||
|
||||
use Lucent\Setup\Data\SetupStep;
|
||||
|
||||
class ComposerStep implements IStep
|
||||
{
|
||||
|
||||
public function __invoke(): SetupStep
|
||||
{
|
||||
|
||||
$composerFile = json_decode(file_get_contents(base_path("composer.json")), true);
|
||||
|
||||
$postAutoloadDumpList = data_get($composerFile, "scripts.post-autoload-dump", []);
|
||||
|
||||
$name = "Composer File";
|
||||
|
||||
$instructions = <<<EOD
|
||||
# Append this line in post-autoload-dump in your composer.json.:
|
||||
|
||||
"@php artisan vendor:publish --tag=lucent --force"
|
||||
|
||||
example:
|
||||
{
|
||||
"scripts": {
|
||||
"post-autoload-dump": [
|
||||
"@php artisan vendor:publish --tag=lucent --force"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
EOD;
|
||||
|
||||
|
||||
return match (in_array("@php artisan vendor:publish --tag=lucent --force", $postAutoloadDumpList)) {
|
||||
true => SetupStep::makeSuccess($name, $instructions),
|
||||
false => SetupStep::makeFail($name, $instructions),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Setup\Step;
|
||||
|
||||
use Lucent\Setup\Data\SetupStep;
|
||||
|
||||
interface IStep
|
||||
{
|
||||
public function __invoke(): SetupStep;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Setup\Step;
|
||||
|
||||
use Lucent\Setup\Data\SetupStep;
|
||||
|
||||
class LucentConfigStep implements IStep
|
||||
{
|
||||
|
||||
public function __invoke(): SetupStep
|
||||
{
|
||||
|
||||
$lucentConfig = config("lucent.schemasPath");
|
||||
|
||||
$name = "Generate Lucent config";
|
||||
|
||||
$instructions = <<<EOD
|
||||
# Run the following command to generate the configuration file:
|
||||
|
||||
php8.3 artisan vendor:publish --tag=lucent-config
|
||||
|
||||
# Choose "Lucent" from the prompted options.
|
||||
|
||||
A lucent.php file will be created in your config folder
|
||||
|
||||
EOD;
|
||||
|
||||
|
||||
return match (!empty($lucentConfig)) {
|
||||
true => SetupStep::makeSuccess($name, $instructions),
|
||||
false => SetupStep::makeFail($name, $instructions),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user