#!/usr/bin/env powershell # Environment Configuration Helper Script # This script helps you switch between development and production API endpoints param( [Parameter(Mandatory = $false)] [ValidateSet("dev", "development", "prod", "production", "local")] [string]$Environment = "dev", [switch]$Show ) $EnvFile = ".env" $EnvExampleFile = ".env.example" function Show-CurrentConfig { Write-Host "Current Environment Configuration:" -ForegroundColor Green Write-Host "=================================" -ForegroundColor Green if (Test-Path $EnvFile) { $content = Get-Content $EnvFile foreach ($line in $content) { if ($line -match "VITE_API_BASE_URL=(.+)") { Write-Host "API Base URL: " -NoNewline -ForegroundColor Yellow Write-Host $matches[1] -ForegroundColor White } if ($line -match "NODE_ENV=(.+)") { Write-Host "Node Environment: " -NoNewline -ForegroundColor Yellow Write-Host $matches[1] -ForegroundColor White } } } else { Write-Host "No .env file found. Using default configuration." -ForegroundColor Red Write-Host "API Base URL: " -NoNewline -ForegroundColor Yellow Write-Host "http://localhost:8000 (development default)" -ForegroundColor White } Write-Host "" } function Set-Environment { param([string]$Env) $apiUrl = "" $nodeEnv = "" switch ($Env.ToLower()) { { $_ -in @("dev", "development", "local") } { $apiUrl = "http://localhost:8000" $nodeEnv = "development" Write-Host "Configuring for DEVELOPMENT environment..." -ForegroundColor Green } { $_ -in @("prod", "production") } { $apiUrl = "https://api.pennyzo.com/api/v1/general" $nodeEnv = "production" Write-Host "Configuring for PRODUCTION environment..." -ForegroundColor Green } default { Write-Host "Unknown environment: $Env" -ForegroundColor Red return } } # Create .env content $debugValue = if ($nodeEnv -eq "development") { "true" } else { "false" } $logLevel = if ($nodeEnv -eq "development") { "INFO" } else { "WARN" } $envContent = @" # Environment Configuration - Auto-generated # Generated on: $(Get-Date -Format "yyyy-MM-dd HH:mm:ss") # API Base URL VITE_API_BASE_URL=$apiUrl # Environment NODE_ENV=$nodeEnv # Debug settings DEBUG=$debugValue LOG_LEVEL=$logLevel # API Status Checker Credentials (optional) # PENNYZO_TEST_EMAIL=your-test-email@example.com # PENNYZO_TEST_PASSWORD=your-test-password "@ # Write to .env file $envContent | Out-File -FilePath $EnvFile -Encoding UTF8 Write-Host "Environment configured successfully!" -ForegroundColor Green Write-Host "API Base URL set to: " -NoNewline -ForegroundColor Yellow Write-Host $apiUrl -ForegroundColor White Write-Host "" } # Main execution if ($Show) { Show-CurrentConfig } else { Set-Environment -Env $Environment Show-CurrentConfig Write-Host "Usage Examples:" -ForegroundColor Cyan Write-Host " .\scripts\set-env.ps1 dev # Set development environment" -ForegroundColor Gray Write-Host " .\scripts\set-env.ps1 prod # Set production environment" -ForegroundColor Gray Write-Host " .\scripts\set-env.ps1 -Show # Show current configuration" -ForegroundColor Gray Write-Host "" Write-Host "Restart your development server for changes to take effect." -ForegroundColor Yellow }