wip setup guide
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import Login from "./account/Login.svelte";
|
||||
import Verify from "./account/Verify.svelte";
|
||||
import Profile from "./account/Profile.svelte";
|
||||
import SetupIndex from "./setup/Index.svelte";
|
||||
import {setContext} from "svelte";
|
||||
|
||||
const components = {
|
||||
@@ -10,6 +11,7 @@
|
||||
login: Login,
|
||||
verify: Verify,
|
||||
profile: Profile,
|
||||
setup: SetupIndex,
|
||||
};
|
||||
|
||||
export let title;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<script>
|
||||
import Step from "./Step.svelte"
|
||||
export let steps;
|
||||
|
||||
console.log(steps);
|
||||
</script>
|
||||
<div class="wrapper-tiny">
|
||||
|
||||
{#each steps as step}
|
||||
<Step {step}></Step>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -0,0 +1,67 @@
|
||||
<script>
|
||||
import Icon from "../common/Icon.svelte"
|
||||
|
||||
export let step;
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
<div class="step step-{step.status}">
|
||||
<div class="step-icon">
|
||||
{#if step.status === "success"}
|
||||
<Icon icon="check"></Icon>
|
||||
{:else}
|
||||
<Icon icon="close"></Icon>
|
||||
{/if}
|
||||
</div>
|
||||
<div style="width:100%">
|
||||
<h4>{step.name}</h4>
|
||||
<details>
|
||||
<summary>Instuctions</summary>
|
||||
<code class="instructions">{step.instructions}</code>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.step-success .step-icon{
|
||||
background: var(--suc10);
|
||||
color: var(--suc100);
|
||||
}
|
||||
|
||||
.step-fail .step-icon{
|
||||
background: var(--err10);
|
||||
color: var(--err100);
|
||||
}
|
||||
|
||||
.step-icon{
|
||||
padding: 12px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.step {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: start;
|
||||
gap: 10px;
|
||||
justify-content: space-between;
|
||||
|
||||
padding: 12px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
details {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.instructions {
|
||||
margin-top: 20px;
|
||||
padding: 12px;
|
||||
border-radius: 12px;
|
||||
background: var(--p10);
|
||||
white-space: break-spaces;
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
@@ -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