|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Set up the dev environment from a fresh clone of totk-vscode. |
| 4 | +.DESCRIPTION |
| 5 | + 1. Initializes git submodules |
| 6 | + 2. Installs Node dependencies (root) |
| 7 | + 3. Creates a Python venv and installs Python dependencies |
| 8 | +.PARAMETER PythonPath |
| 9 | + Explicit path to a Python 3.10+ interpreter. If omitted, tries py, python3, python. |
| 10 | +#> |
| 11 | +param( |
| 12 | + [string]$PythonPath |
| 13 | +) |
| 14 | + |
| 15 | +$ErrorActionPreference = 'Stop' |
| 16 | +$root = Split-Path -Parent $PSScriptRoot |
| 17 | + |
| 18 | +Push-Location $root |
| 19 | +try { |
| 20 | + # ── 1. Git submodules ────────────────────────────────────────────── |
| 21 | + Write-Host "`n=== Initializing git submodules ===" -ForegroundColor Cyan |
| 22 | + git submodule update --init --recursive |
| 23 | + if ($LASTEXITCODE -ne 0) { throw "git submodule update failed" } |
| 24 | + |
| 25 | + # ── 2. Node dependencies ─────────────────────────────────────────── |
| 26 | + Write-Host "`n=== Installing Node dependencies (root) ===" -ForegroundColor Cyan |
| 27 | + npm install |
| 28 | + if ($LASTEXITCODE -ne 0) { throw "npm install failed" } |
| 29 | + |
| 30 | + # ── 3. Python venv ───────────────────────────────────────────────── |
| 31 | + Write-Host "`n=== Setting up Python virtual environment ===" -ForegroundColor Cyan |
| 32 | + |
| 33 | + if ($PythonPath) { |
| 34 | + $py = $PythonPath |
| 35 | + } else { |
| 36 | + $py = $null |
| 37 | + foreach ($candidate in @('py -3', 'python3', 'python')) { |
| 38 | + $parts = $candidate -split ' ' |
| 39 | + $exe = $parts[0] |
| 40 | + $args = if ($parts.Length -gt 1) { $parts[1..($parts.Length-1)] } else { @() } |
| 41 | + try { |
| 42 | + $ver = & $exe @args --version 2>&1 |
| 43 | + if ($ver -match 'Python 3\.(\d+)' -and [int]$Matches[1] -ge 10) { |
| 44 | + $py = $candidate |
| 45 | + Write-Host " Found: $ver ($candidate)" -ForegroundColor Green |
| 46 | + break |
| 47 | + } |
| 48 | + } catch {} |
| 49 | + } |
| 50 | + if (-not $py) { throw "Python 3.10+ not found. Install it or pass -PythonPath." } |
| 51 | + } |
| 52 | + |
| 53 | + $venvDir = Join-Path $root '.venv' |
| 54 | + if (-not (Test-Path $venvDir)) { |
| 55 | + Write-Host " Creating venv at $venvDir" |
| 56 | + $parts = $py -split ' ' |
| 57 | + $exe = $parts[0] |
| 58 | + $args = if ($parts.Length -gt 1) { $parts[1..($parts.Length-1)] } else { @() } |
| 59 | + & $exe @args -m venv $venvDir |
| 60 | + if ($LASTEXITCODE -ne 0) { throw "venv creation failed" } |
| 61 | + } else { |
| 62 | + Write-Host " venv already exists at $venvDir" |
| 63 | + } |
| 64 | + |
| 65 | + $pip = Join-Path $venvDir 'Scripts' 'pip.exe' |
| 66 | + Write-Host " Installing Python dependencies" |
| 67 | + & $pip install $root --quiet |
| 68 | + if ($LASTEXITCODE -ne 0) { throw "pip install failed" } |
| 69 | + |
| 70 | + Write-Host "`n=== Dev Environment Setup complete ===" -ForegroundColor Green |
| 71 | +} finally { |
| 72 | + Pop-Location |
| 73 | +} |
0 commit comments