lasthourcloud/app/Console/Commands/Dev.php

63 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2023-12-13 10:35:53 +00:00
<?php
namespace App\Console\Commands;
use App\Models\InstanceSettings;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Process;
class Dev extends Command
{
2024-07-06 12:33:59 +00:00
protected $signature = 'dev {--init} {--generate-openapi}';
2024-06-10 20:43:34 +00:00
2024-07-06 12:33:59 +00:00
protected $description = 'Helper commands for development.';
2023-12-13 10:35:53 +00:00
public function handle()
2024-07-06 12:33:59 +00:00
{
if ($this->option('init')) {
$this->init();
return;
}
if ($this->option('generate-openapi')) {
$this->generateOpenApi();
return;
}
}
public function generateOpenApi()
{
// Generate OpenAPI documentation
echo "Generating OpenAPI documentation.\n";
$process = Process::run(['/var/www/html/vendor/bin/openapi', 'app', '-o', 'openapi.yaml']);
$error = $process->errorOutput();
$error = preg_replace('/^.*an object literal,.*$/m', '', $error);
$error = preg_replace('/^\h*\v+/m', '', $error);
echo $error;
echo $process->output();
}
public function init()
2023-12-13 10:35:53 +00:00
{
// Generate APP_KEY if not exists
2024-07-06 12:33:59 +00:00
2023-12-13 10:35:53 +00:00
if (empty(env('APP_KEY'))) {
echo "Generating APP_KEY.\n";
Artisan::call('key:generate');
}
// Seed database if it's empty
$settings = InstanceSettings::find(0);
2024-06-10 20:43:34 +00:00
if (! $settings) {
2023-12-13 10:35:53 +00:00
echo "Initializing instance, seeding database.\n";
Artisan::call('migrate --seed');
} else {
echo "Instance already initialized.\n";
}
// Set permissions
Process::run(['chmod', '-R', 'o+rwx', '.']);
}
}