<?php

$hasPcntl = function_exists('pcntl_fork');

$commands = [
    'php artisan serve',
    'php artisan queue:listen --tries=1',
];

if ($hasPcntl) {
    $commands[] = 'php artisan pail --timeout=0';
    $colors = '#93c5fd,#c4b5fd,#fb7185,#fdba74';
    $names = 'server,queue,logs,vite';
} else {
    $colors = '#93c5fd,#c4b5fd,#fb7185';
    $names = 'server,queue,vite';
}

$commands[] = 'npm run dev';

$cmdString = '"' . implode('" "', $commands) . '"';
$command = sprintf(
    'npx concurrently -c "%s" %s --names=%s --kill-others',
    $colors,
    $cmdString,
    $names
);

passthru($command);

