This commit is contained in:
2025-04-07 12:16:11 +01:00
parent ce8b201a1c
commit e15a80163b
62 changed files with 149 additions and 131 deletions

View File

@@ -11,6 +11,7 @@ use Illuminate\Console\Command;
class CreateServiceCommand extends Command
{
protected $signature = 'service:create';
protected $description = 'Create a service';
public function handle()
@@ -18,17 +19,18 @@ class CreateServiceCommand extends Command
$serverId = $this->components->ask('Enter the server ID');
$server = Server::find($serverId);
if (!$server) {
if (! $server) {
$this->components->error('Server not found');
return;
}
$serviceType = $this->components->choice('select the service you want to install', [
'postgres-17'
'postgres-17',
]);
$serviceName = $this->components->ask('Enter the service name');
list ($type, $version) = explode('-', $serviceType);
[$type, $version] = explode('-', $serviceType);
$service = app(CreateService::class)->execute(
server: $server,

View File

@@ -40,10 +40,10 @@ class GenerateJSEnums extends Command
}
foreach ((new Finder)->in($paths)->files() as $enum) {
$enum = 'App\\' . str_replace(
$enum = 'App\\'.str_replace(
['/', '.php'],
['\\', ''],
Str::after($enum->getRealPath(), realpath(app_path()) . DIRECTORY_SEPARATOR)
Str::after($enum->getRealPath(), realpath(app_path()).DIRECTORY_SEPARATOR)
);
if (! class_exists($enum)) {
@@ -51,36 +51,36 @@ class GenerateJSEnums extends Command
}
$js = "// This is a generated file. \n";
$js .= '// Published at ' . now()->format('Y-m-d H:i:s') . "\n";
$js .= '// Published at '.now()->format('Y-m-d H:i:s')."\n";
$js .= "\n";
$js .= 'export default ';
$js .= json_encode($enum::toArray(), JSON_PRETTY_PRINT) . "\n";
$js .= json_encode($enum::toArray(), JSON_PRETTY_PRINT)."\n";
$js .= "\n";
if (method_exists($enum, 'getLabels')) {
$labels = $enum::getLabels();
$js .= 'export const LabelMap = ';
$js .= json_encode($labels, JSON_PRETTY_PRINT) . "\n";
$js .= json_encode($labels, JSON_PRETTY_PRINT)."\n";
$js .= "\n";
$labelSelect = array_map(fn($key) => ['title' => $labels[$key], 'id' => $key], array_keys($labels));
$labelSelect = array_map(fn ($key) => ['title' => $labels[$key], 'id' => $key], array_keys($labels));
$js .= 'export const LabelSelectMap = ';
$js .= json_encode($labelSelect, JSON_PRETTY_PRINT) . "\n";
$js .= json_encode($labelSelect, JSON_PRETTY_PRINT)."\n";
$js .= "\n";
}
if (method_exists($enum, 'getDescription')) {
$values = $enum::toArray();
$descriptions = array_map(fn($key) => $enum::getDescription($key), $values);
$descriptions = array_map(fn ($key) => $enum::getDescription($key), $values);
$js .= 'export const DescriptionMap = ';
$js .= json_encode($descriptions, JSON_PRETTY_PRINT) . "\n";
$js .= json_encode($descriptions, JSON_PRETTY_PRINT)."\n";
$js .= "\n";
}
if (method_exists($enum, 'colours')) {
$colours = $enum::colours();
$js .= 'export const ColourMap = ';
$js .= json_encode($colours, JSON_PRETTY_PRINT) . "\n";
$js .= json_encode($colours, JSON_PRETTY_PRINT)."\n";
$js .= "\n";
}
@@ -88,10 +88,10 @@ class GenerateJSEnums extends Command
// Skip format, JS date formats are different to PHP ones.
if ($name !== 'Format') {
file_put_contents(base_path('resources/js/Enums/' . $name . '.js'), $js);
$this->info('Stored ' . $enum);
file_put_contents(base_path('resources/js/Enums/'.$name.'.js'), $js);
$this->info('Stored '.$enum);
} else {
$this->info('Skipped ' . $name . 's');
$this->info('Skipped '.$name.'s');
}
}
}

View File

@@ -8,27 +8,30 @@ use Illuminate\Support\Facades\Process;
class GenerateSshKey extends Command
{
protected $signature = 'setup:generate-ssh-key';
protected $description = 'Generates an SSH key pair for the application.';
public function handle()
{
if (file_exists(storage_path('app/private/ssh/id_ed25519'))) {
$this->components->info('SSH key pair already exists.');
return;
}
$this->components->info('Generating SSH key pair...');
if (!file_exists(storage_path('app/private/ssh'))) {
if (! file_exists(storage_path('app/private/ssh'))) {
$this->components->info('ssh directory does not exist. Creating it now...');
mkdir(storage_path('app/private/ssh'), 0755, true);
}
$result = Process::run(['ssh-keygen', '-t', 'ed25519', '-f', storage_path('app/private/ssh/id_ed25519'), '-N', '']);
if (!$result->successful()) {
if (! $result->successful()) {
$this->components->error('Failed to generate SSH key pair.');
$this->line($result->output());
$this->line($result->errorOutput());
return;
}

View File

@@ -7,6 +7,7 @@ use Illuminate\Console\Command;
class Setup extends Command
{
protected $signature = 'setup';
protected $description = 'Initialize the application.';
public function handle()