Última actividad 1761361722

Revisión a732a445b23af85904c14509ece3fe7479809dc6

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