Dockerized for dev purposes
This commit is contained in:
64
app/Console/Commands/InitializeApp.php
Normal file
64
app/Console/Commands/InitializeApp.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class InitializeApp extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:initialize-app';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('🚀 Initializing application...');
|
||||
|
||||
// Composer install
|
||||
$this->info('📦 Installing Composer dependencies...');
|
||||
$this->runProcess(['composer', 'install', '--no-interaction']);
|
||||
|
||||
// NPM install
|
||||
$this->info('📦 Installing NPM dependencies...');
|
||||
$this->runProcess(['npm', 'install']);
|
||||
|
||||
// Generate key
|
||||
$this->info('🔑 Generating application key...');
|
||||
Artisan::call('key:generate', [], $this->output);
|
||||
|
||||
// Migrate and seed
|
||||
$this->info('🗄️ Running migrations and seeders...');
|
||||
Artisan::call('migrate:fresh', ['--seed' => true], $this->output);
|
||||
|
||||
$this->info('✅ Application initialized successfully!');
|
||||
}
|
||||
|
||||
private function runProcess(array $command)
|
||||
{
|
||||
$process = new Process($command);
|
||||
$process->setTimeout(300); // 5 minutes
|
||||
$process->run(function ($type, $buffer) {
|
||||
echo $buffer;
|
||||
});
|
||||
|
||||
if (!$process->isSuccessful()) {
|
||||
$this->error("Failed to run: " . implode(' ', $command));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user