setup complete

This commit is contained in:
2024-09-06 23:30:12 +03:00
parent a73ee21568
commit 6fc0a65b6f
22 changed files with 351 additions and 330 deletions
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace Lucent\Setup\Step;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\DB;
use Lucent\Setup\Data\SetupStep;
class DatabaseSetupStep implements IStep
{
public function __invoke(): SetupStep
{
$name = "Database Connection";
$databaseConfig = config('database.connections.lucentdb');
if(empty($databaseConfig)) {
$instructions = <<<EOD
# You need to setup a database connection for lucentdb in database.php config. You can choose either sqlite or pgsql
# example:
'connections' => [
'lucentdb' => [
'driver' => 'sqlite',
'url' => env('LUCENT_DATABASE_URL'),
'database' => env('LUCENT_DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
EOD;
return SetupStep::makeFail($name, $instructions);
}
try {
DB::connection("lucentdb")->table("records")->get();
}catch (QueryException $e) {
$instructions = <<<EOD
# Make sure you run:
php artisan lucent:setup-db
EOD;
return SetupStep::makeFail($name, $instructions);
}
return SetupStep::makeSuccess($name, "Database Connection successfully created");
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace Lucent\Setup\Step;
use Lucent\Setup\Data\SetupStep;
class LaravelEnvStep implements IStep
{
public function __invoke(): SetupStep
{
$name = "Laravel ENV";
$instructions = <<<EOD
# Make sure in your env that you APP_URL is the same as the one in your browser right now. Or the other way round.
EOD;
return match (config("lucent.url") === request()->getSchemeAndHttpHost()) {
true => SetupStep::makeSuccess($name, $instructions),
false => SetupStep::makeFail($name, $instructions),
};
}
}
+2 -2
View File
@@ -10,14 +10,14 @@ class LucentConfigStep implements IStep
public function __invoke(): SetupStep
{
$lucentConfig = config("lucent.schemasPath");
$lucentConfig = config("lucent.schemas_path");
$name = "Generate Lucent config";
$instructions = <<<EOD
# Run the following command to generate the configuration file:
php8.3 artisan vendor:publish --tag=lucent-config
php artisan vendor:publish --tag=lucent-config
# A lucent.php file will be created in your config folder
+39
View File
@@ -0,0 +1,39 @@
<?php
namespace Lucent\Setup\Step;
use Lucent\Setup\Data\SetupStep;
class StorageLinkSetupStep implements IStep
{
public function __invoke(): SetupStep
{
$storageDriver = config("filesystems.disks.lucent.driver");
$name = "Storage Link";
$instructions = <<<EOD
# If you have chosen to store your file locally then you have to generate a link to the public folder
# run:
php artisan storage:link
EOD;
if($storageDriver !== "local"){
return SetupStep::makeSuccess($name, $instructions);
}
$storageLinks = config("filesystems.links");
$allLinksExist = array_reduce(array_keys($storageLinks),fn(bool $carry, string $link) => !$carry ? false : is_link($link) , true);
return match ($allLinksExist) {
true => SetupStep::makeSuccess($name, $instructions),
false => SetupStep::makeFail($name, $instructions),
};
}
}
+42
View File
@@ -0,0 +1,42 @@
<?php
namespace Lucent\Setup\Step;
use Lucent\Setup\Data\SetupStep;
class StorageSetupStep implements IStep
{
public function __invoke(): SetupStep
{
$storage = config("filesystems.disks.lucent");
$name = "Storage setup";
$instructions = <<<EOD
# You can use your local filesystem or s3 compatible storage. Lucent expects you to have a valid configuration inside config/filesystems.php
# example:
return [
'disks' => [
'lucent' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => true,
],
],
];
EOD;
return match (!empty($storage)) {
true => SetupStep::makeSuccess($name, $instructions),
false => SetupStep::makeFail($name, $instructions),
};
}
}