diff --git a/src/Console/InstallsApiStack.php b/src/Console/InstallsApiStack.php index f88f73cf..7a302143 100644 --- a/src/Console/InstallsApiStack.php +++ b/src/Console/InstallsApiStack.php @@ -47,15 +47,35 @@ protected function installApiStack() // Configuration... $files->copyDirectory(__DIR__.'/../../stubs/api/config', config_path()); + // Sail... + $dockerComposePath = base_path('docker-compose.yml'); + $isSail = $files->exists($dockerComposePath); + if ($isSail) { + $dockerComposeContent = file_get_contents($dockerComposePath); + if (! empty($dockerComposeContent)) { + $dockerComposeContent = preg_replace('/\s*- \'\${VITE_PORT:-5173}:\${VITE_PORT:-5173}\'/', '', $dockerComposeContent); + file_put_contents($dockerComposePath, $dockerComposeContent); + } + } + // Environment... if (! $files->exists(base_path('.env'))) { copy(base_path('.env.example'), base_path('.env')); } - file_put_contents( - base_path('.env'), - preg_replace('/APP_URL=(.*)/', 'APP_URL=http://localhost:8000'.PHP_EOL.'FRONTEND_URL=http://localhost:3000', file_get_contents(base_path('.env'))) - ); + foreach (['.env', '.env.example'] as $envFile) { + $envPath = base_path($envFile); + $envContent = file_get_contents($envPath); + if (! empty($envContent)) { + $envVars = 'APP_URL=http://localhost:8000'.PHP_EOL.'FRONTEND_URL=http://localhost:3000'; + if ($isSail) { + $envVars = 'APP_PORT=8000'.PHP_EOL.$envVars; + } + $envContent = preg_replace('/APP_URL=.*/', $envVars, $envContent); + $envContent = preg_replace('/VITE_APP_NAME=.*\n\n?/', '', $envContent); + file_put_contents($envPath, $envContent); + } + } // Tests... if (! $this->installTests()) {