urocibg a révisé ce gist . Aller à la révision
1 file changed, 1 insertion
setup-vscode-windows.ps1
| @@ -1,6 +1,7 @@ | |||
| 1 | 1 | # =================================================================== | |
| 2 | 2 | # PROFESSIONAL VS CODE + PYTHON + GIT + DOCKER SETUP FOR WINDOWS 11 | |
| 3 | 3 | # Run as Administrator | UTF-8 without BOM | |
| 4 | + | # Author: Федя Серафиев | |
| 4 | 5 | # =================================================================== | |
| 5 | 6 | ||
| 6 | 7 | $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) | |
urocibg a révisé ce gist . Aller à la révision
1 file changed, 197 insertions
setup-vscode-windows.ps1(fichier créé)
| @@ -0,0 +1,197 @@ | |||
| 1 | + | # =================================================================== | |
| 2 | + | # PROFESSIONAL VS CODE + PYTHON + GIT + DOCKER SETUP FOR WINDOWS 11 | |
| 3 | + | # Run as Administrator | UTF-8 without BOM | |
| 4 | + | # =================================================================== | |
| 5 | + | ||
| 6 | + | $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) | |
| 7 | + | if (-not $isAdmin) { | |
| 8 | + | Write-Host "ERROR: Run as Administrator!" -ForegroundColor Red | |
| 9 | + | pause | |
| 10 | + | exit 1 | |
| 11 | + | } | |
| 12 | + | ||
| 13 | + | Write-Host "`nStarting professional dev environment setup..." -ForegroundColor Green | |
| 14 | + | ||
| 15 | + | # --- 1. Ensure winget is available (Robust) --- | |
| 16 | + | function Install-Winget { | |
| 17 | + | if (Get-Command winget -ErrorAction SilentlyContinue) { return $true } | |
| 18 | + | ||
| 19 | + | Write-Host "winget not found. Installing App Installer..." -ForegroundColor Cyan | |
| 20 | + | try { | |
| 21 | + | # Try Microsoft Store (modern) | |
| 22 | + | Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe -ErrorAction SilentlyContinue | |
| 23 | + | Start-Sleep -Seconds 3 | |
| 24 | + | if (Get-Command winget -ErrorAction SilentlyContinue) { return $true } | |
| 25 | + | } catch {} | |
| 26 | + | ||
| 27 | + | # Fallback: Download .msixbundle from GitHub | |
| 28 | + | Write-Host "Downloading App Installer from GitHub..." -ForegroundColor Yellow | |
| 29 | + | $url = "https://aka.ms/getwinget" | |
| 30 | + | $out = "$env:TEMP\winget.msixbundle" | |
| 31 | + | Invoke-WebRequest -Uri $url -OutFile $out -UseBasicParsing | |
| 32 | + | Add-AppxPackage -Path $out -ErrorAction SilentlyContinue | |
| 33 | + | Remove-Item $out -Force | |
| 34 | + | Start-Sleep -Seconds 5 | |
| 35 | + | return (Get-Command winget -ErrorAction SilentlyContinue) | |
| 36 | + | } | |
| 37 | + | ||
| 38 | + | if (-not (Install-Winget)) { | |
| 39 | + | Write-Host "FAILED to install winget. Install manually: https://aka.ms/getwinget" -ForegroundColor Red | |
| 40 | + | pause | |
| 41 | + | exit 1 | |
| 42 | + | } | |
| 43 | + | ||
| 44 | + | # --- 2. Install VS Code --- | |
| 45 | + | Write-Host "`nInstalling VS Code..." -ForegroundColor Cyan | |
| 46 | + | if (-not (Get-Command code -ErrorAction SilentlyContinue)) { | |
| 47 | + | winget install -e --id Microsoft.VisualStudioCode --source winget --silent --accept-package-agreements --accept-source-agreements | |
| 48 | + | Start-Sleep -Seconds 10 # Wait for PATH update | |
| 49 | + | $env:PATH = [System.Environment]::GetEnvironmentVariable("PATH","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH","User") | |
| 50 | + | } | |
| 51 | + | if (Get-Command code -ErrorAction SilentlyContinue) { | |
| 52 | + | Write-Host "VS Code ready." -ForegroundColor Green | |
| 53 | + | } else { | |
| 54 | + | Write-Host "VS Code install failed." -ForegroundColor Red | |
| 55 | + | pause | |
| 56 | + | exit 1 | |
| 57 | + | } | |
| 58 | + | ||
| 59 | + | # --- 3. Install Python + pip upgrade --- | |
| 60 | + | Write-Host "`nInstalling Python 3.12..." -ForegroundColor Cyan | |
| 61 | + | if (-not (Get-Command python -ErrorAction SilentlyContinue)) { | |
| 62 | + | winget install -e --id Python.Python.3.12 --source winget --silent | |
| 63 | + | Start-Sleep -Seconds 10 | |
| 64 | + | } | |
| 65 | + | if (Get-Command python -ErrorAction SilentlyContinue) { | |
| 66 | + | Write-Host "Upgrading pip..." -ForegroundColor Cyan | |
| 67 | + | python -m pip install --upgrade pip --quiet | |
| 68 | + | Write-Host "Python ready." -ForegroundColor Green | |
| 69 | + | } | |
| 70 | + | ||
| 71 | + | # --- 4. Install Git --- | |
| 72 | + | Write-Host "`nInstalling Git..." -ForegroundColor Cyan | |
| 73 | + | if (-not (Get-Command git -ErrorAction SilentlyContinue)) { | |
| 74 | + | winget install -e --id Git.Git --source winget --silent | |
| 75 | + | } | |
| 76 | + | if (Get-Command git -ErrorAction SilentlyContinue) { | |
| 77 | + | Write-Host "Git ready." -ForegroundColor Green | |
| 78 | + | } | |
| 79 | + | ||
| 80 | + | # --- 5. Install Docker Desktop --- | |
| 81 | + | Write-Host "`nInstalling Docker Desktop..." -ForegroundColor Cyan | |
| 82 | + | if (-not (Get-Command docker -ErrorAction SilentlyContinue)) { | |
| 83 | + | winget install -e --id Docker.DockerDesktop --source winget --silent --accept-package-agreements | |
| 84 | + | Write-Host "Docker installed. Restart may be required." -ForegroundColor Yellow | |
| 85 | + | } | |
| 86 | + | ||
| 87 | + | # --- 6. Safe settings.json merge --- | |
| 88 | + | $settingsPath = "$env:APPDATA\Code\User\settings.json" | |
| 89 | + | $settingsDir = Split-Path $settingsPath -Parent | |
| 90 | + | if (-not (Test-Path $settingsDir)) { New-Item -ItemType Directory -Path $settingsDir -Force | Out-Null } | |
| 91 | + | ||
| 92 | + | $defaultSettings = @{ | |
| 93 | + | "editor.fontSize" = 14 | |
| 94 | + | "editor.tabSize" = 4 | |
| 95 | + | "editor.insertSpaces" = $true | |
| 96 | + | "files.autoSave" = "afterDelay" | |
| 97 | + | "files.autoSaveDelay" = 1000 | |
| 98 | + | "workbench.colorTheme" = "Default Dark+" | |
| 99 | + | "terminal.integrated.defaultProfile.windows" = "PowerShell" | |
| 100 | + | "python.defaultInterpreterPath" = "python" | |
| 101 | + | "python.terminal.activateEnvironment" = $true | |
| 102 | + | "git.autofetch" = $true | |
| 103 | + | "git.confirmSync" = $false | |
| 104 | + | "extensions.autoUpdate" = $true | |
| 105 | + | "telemetry.telemetryLevel" = "off" | |
| 106 | + | "workbench preferred language" = "bg" # Bulgarian | |
| 107 | + | } | |
| 108 | + | ||
| 109 | + | # Load existing or create new | |
| 110 | + | if (Test-Path $settingsPath) { | |
| 111 | + | try { | |
| 112 | + | $current = Get-Content $settingsPath -Raw | ConvertFrom-Json -ErrorAction Stop | |
| 113 | + | if ($current -isnot [PSCustomObject]) { $current = [PSCustomObject]@{} } | |
| 114 | + | } catch { | |
| 115 | + | Write-Host "Invalid settings.json - backing up and replacing..." -ForegroundColor Yellow | |
| 116 | + | Copy-Item $settingsPath "$settingsPath.bak" -Force | |
| 117 | + | $current = [PSCustomObject]@{} | |
| 118 | + | } | |
| 119 | + | } else { | |
| 120 | + | $current = [PSCustomObject]@{} | |
| 121 | + | } | |
| 122 | + | ||
| 123 | + | # Merge settings | |
| 124 | + | foreach ($key in $defaultSettings.Keys) { | |
| 125 | + | if (-not ($current.PSObject.Properties.Name -contains $key)) { | |
| 126 | + | Add-Member -InputObject $current -NotePropertyName $key -NotePropertyValue $defaultSettings[$key] | |
| 127 | + | } else { | |
| 128 | + | $current.$key = $defaultSettings[$key] | |
| 129 | + | } | |
| 130 | + | } | |
| 131 | + | ||
| 132 | + | $json = $current | ConvertTo-Json -Depth 10 | |
| 133 | + | [System.IO.File]::WriteAllText($settingsPath, $json, [System.Text.Encoding]::UTF8) | |
| 134 | + | Write-Host "settings.json updated safely!" -ForegroundColor Green | |
| 135 | + | ||
| 136 | + | # --- 7. Install Extensions --- | |
| 137 | + | Write-Host "`nInstalling VS Code extensions..." -ForegroundColor Cyan | |
| 138 | + | $extensions = @( | |
| 139 | + | "ms-python.python" | |
| 140 | + | "ms-python.vscode-pylance" | |
| 141 | + | "ms-toolsai.jupyter" | |
| 142 | + | "eamodio.gitlens" | |
| 143 | + | "GitHub.copilot" | |
| 144 | + | "ms-vscode.bulgarian-language-pack" | |
| 145 | + | "streetsidesoftware.code-spell-checker" | |
| 146 | + | "esbenp.prettier-vscode" | |
| 147 | + | "ms-vscode-remote.remote-wsl" | |
| 148 | + | "ms-azuretools.vscode-docker" | |
| 149 | + | ) | |
| 150 | + | ||
| 151 | + | foreach ($ext in $extensions) { | |
| 152 | + | if (-not (code --list-extensions | Where-Object { $_ -eq $ext })) { | |
| 153 | + | Write-Host " Installing: $ext" | |
| 154 | + | code --install-extension $ext --force | Out-Null | |
| 155 | + | } else { | |
| 156 | + | Write-Host " Already: $ext" -ForegroundColor DarkGray | |
| 157 | + | } | |
| 158 | + | } | |
| 159 | + | ||
| 160 | + | # --- 8. Activate Bulgarian Language --- | |
| 161 | + | Write-Host "`nActivating Bulgarian interface..." -ForegroundColor Cyan | |
| 162 | + | $localePath = "$env:APPDATA\Code\User\locale.json" | |
| 163 | + | $localeDir = Split-Path $localePath -Parent | |
| 164 | + | if (-not (Test-Path $localeDir)) { New-Item -ItemType Directory -Path $localeDir -Force | Out-Null } | |
| 165 | + | '{"locale":"bg"}' | Out-File -FilePath $localePath -Encoding UTF8 -Force | |
| 166 | + | Write-Host "Bulgarian language activated! Restart VS Code." -ForegroundColor Green | |
| 167 | + | ||
| 168 | + | # --- 9. WSL2 Check --- | |
| 169 | + | Write-Host "`nChecking WSL2..." -ForegroundColor Cyan | |
| 170 | + | if (Get-Command wsl -ErrorAction SilentlyContinue) { | |
| 171 | + | $distros = wsl --list --quiet | Where-Object { $_ -and $_.Trim() } | |
| 172 | + | if ($distros) { | |
| 173 | + | Write-Host "WSL2 active: $distros" -ForegroundColor Green | |
| 174 | + | } else { | |
| 175 | + | $ans = Read-Host "Install Ubuntu in WSL2? (y/n)" | |
| 176 | + | if ($ans -match "^[Yy]") { | |
| 177 | + | wsl --install -d Ubuntu | |
| 178 | + | Write-Host "Restart required after install!" -ForegroundColor Yellow | |
| 179 | + | } | |
| 180 | + | } | |
| 181 | + | } else { | |
| 182 | + | $ans = Read-Host "Enable WSL2? (y/n)" | |
| 183 | + | if ($ans -match "^[Yy]") { | |
| 184 | + | wsl --install | |
| 185 | + | Write-Host "Restart required!" -ForegroundColor Yellow | |
| 186 | + | } | |
| 187 | + | } | |
| 188 | + | ||
| 189 | + | # --- Final --- | |
| 190 | + | Write-Host "`nSETUP COMPLETE!" -ForegroundColor Green | |
| 191 | + | Write-Host " VS Code: code ." -ForegroundColor Cyan | |
| 192 | + | Write-Host " Python: python --version" -ForegroundColor Cyan | |
| 193 | + | Write-Host " Docker: docker --version" -ForegroundColor Cyan | |
| 194 | + | Write-Host " Restart VS Code to see Bulgarian UI!" -ForegroundColor Magenta | |
| 195 | + | Write-Host "`nTip: Restart PC if Docker/WSL/Python was installed.`n" | |
| 196 | + | ||
| 197 | + | pause | |