diff --git a/scripts/setup-windows-dev.ps1 b/scripts/setup-windows-dev.ps1 new file mode 100644 index 0000000..f17a678 --- /dev/null +++ b/scripts/setup-windows-dev.ps1 @@ -0,0 +1,121 @@ +#Requires -Version 5.1 +<# +.SYNOPSIS + Non-elevated WABOX development setup for Windows 11 24H2+. + +.DESCRIPTION + Installs npm deps, creates .env from template, builds TypeScript, and runs + preflight checks. For MXC host prep (one-time, elevated), run: + .\scripts\setup-mxc-host.ps1 + +.USAGE + # PowerShell from repo root: + .\scripts\setup-windows-dev.ps1 + .\scripts\setup-windows-dev.ps1 -SkipWarmup + .\scripts\setup-windows-dev.ps1 -RunIntegration +#> +param( + [switch] $SkipWarmup, + [switch] $RunIntegration, + [switch] $RunExample +) + +$ErrorActionPreference = 'Stop' +$RepoRoot = Split-Path -Parent $PSScriptRoot +Set-Location $RepoRoot + +function Write-Step([string]$Message) { + Write-Host "`n=== $Message ===" -ForegroundColor Cyan +} + +function Assert-Command([string]$Name) { + if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) { + throw "$Name is not on PATH. Install it and retry." + } +} + +Write-Step 'Checking prerequisites' +Assert-Command node +Assert-Command npm + +$nodeMajor = [int]((node -p "process.versions.node.split('.')[0]")) +if ($nodeMajor -lt 18) { + throw "Node.js >= 18 required; found $(node -v)" +} + +if ($env:OS -ne 'Windows_NT') { + throw 'WABOX requires Windows. Use Cursor My Machines or a Windows devbox.' +} + +$build = [System.Environment]::OSVersion.Version +if ($build.Major -lt 10 -or ($build.Major -eq 10 -and $build.Build -lt 26100)) { + Write-Warning "Windows 11 24H2+ (build 26100+) is recommended. Current build: $($build.Build)" +} + +Write-Step 'Installing npm dependencies' +npm install +if ($LASTEXITCODE -ne 0) { throw 'npm install failed' } + +Write-Step 'Creating .env from template' +$envFile = Join-Path $RepoRoot '.env' +$envExample = Join-Path $RepoRoot '.env.example' +if (-not (Test-Path $envFile)) { + Copy-Item $envExample $envFile +} +$workspace = ($RepoRoot -replace '\\', '/') +$content = Get-Content $envFile -Raw +$content = $content -replace 'WABOX_WORKSPACE_PATH=.*', "WABOX_WORKSPACE_PATH=$workspace" +if ($content -notmatch 'WABOX_WORKSPACE_PATH=') { + $content += "`nWABOX_WORKSPACE_PATH=$workspace`n" +} +Set-Content -Path $envFile -Value $content.TrimEnd() -NoNewline +Write-Host "WABOX_WORKSPACE_PATH=$workspace" + +Write-Step 'Building TypeScript' +npm run build +if ($LASTEXITCODE -ne 0) { throw 'npm run build failed' } + +Write-Step 'Running unit tests' +npm test +if ($LASTEXITCODE -ne 0) { throw 'npm test failed' } + +$hostPrep = Join-Path $RepoRoot 'node_modules\@microsoft\mxc-sdk\bin\x64\wxc-host-prep.exe' +if (Test-Path $hostPrep) { + Write-Step 'MXC host prep reminder' + Write-Host 'If diagnose/warmup hang or fail, run elevated once:' + Write-Host ' .\scripts\setup-mxc-host.ps1' -ForegroundColor Yellow +} else { + Write-Warning 'wxc-host-prep not found after npm install' +} + +if (-not $SkipWarmup) { + Write-Step 'Warming up MXC (first spawn can be slow)' + npm run warmup + if ($LASTEXITCODE -ne 0) { + Write-Warning 'warmup failed — try elevated setup-mxc-host.ps1 then npm run warmup' + } +} + +Write-Step 'Running diagnose preflight' +npm run diagnose +if ($LASTEXITCODE -ne 0) { + Write-Warning 'diagnose reported issues — see .wabox/diagnostics/latest.json' +} + +if ($RunExample) { + Write-Step 'Running minimal example' + npm run example + if ($LASTEXITCODE -ne 0) { throw 'npm run example failed' } +} + +if ($RunIntegration) { + Write-Step 'Running integration tests' + $env:WABOX_INTEGRATION = '1' + npm run test:integration + if ($LASTEXITCODE -ne 0) { throw 'npm run test:integration failed' } +} + +Write-Host "`nDone. Next steps:" -ForegroundColor Green +Write-Host ' npm run example # smoke test sandbox exec' +Write-Host ' npm run diagnose # full MXC preflight' +Write-Host ' npm run test:integration # set WABOX_INTEGRATION=1 on Windows'