Files
Bubberstation/tools/bootstrap/node_.ps1
SkyratBot 90fcd398ff [MIRROR] Creates a node compatibility mode (#27130)
* Creates a node compatibility mode (#82334)

## About The Pull Request
By default this will install node v20 LTS, but if a user is detected to
be using win 7 it's node v14

This lets us run higher node versions (with presumably more stable and
performant content) while allowing win 7 users to play

I should note that this is making clean tgui builds run at ~6.7sec which
is about a 6.9% speed increase (nice) from the previous #80310
## Why It's Good For The Game
Better tools
## Changelog
N/A nothing player facing

* Creates a node compatibility mode

---------

Co-authored-by: Jeremiah <42397676+jlsnow301@users.noreply.github.com>
2024-04-04 22:44:38 +02:00

72 lines
1.9 KiB
PowerShell

## bootstrap/node_.ps1
## Downloads a Node version to a cache directory and invokes it.
$ErrorActionPreference = "Stop"
function Extract-Variable {
param([string] $Path, [string] $Key)
foreach ($Line in Get-Content $Path) {
if ($Line.StartsWith("export $Key=")) {
return $Line.Substring("export $Key=".Length)
}
}
throw "Couldn't find value for $Key in $Path"
}
function Download-Node {
if (Test-Path $NodeTarget -PathType Leaf) {
return
}
Write-Output "Downloading Node v$NodeVersion (may take a while)"
New-Item $NodeTargetDir -ItemType Directory -ErrorAction silentlyContinue | Out-Null
$WebClient = New-Object Net.WebClient
$WebClient.DownloadFile($NodeSource, "$NodeTarget.downloading")
Rename-Item "$NodeTarget.downloading" $NodeTarget
}
## Convenience variables
$BaseDir = Split-Path $script:MyInvocation.MyCommand.Path
$Cache = "$BaseDir\.cache"
if ($Env:TG_BOOTSTRAP_CACHE) {
$Cache = $Env:TG_BOOTSTRAP_CACHE
}
# Get OS version
$OSVersion = (Get-WmiObject -Class Win32_OperatingSystem).Version
# Set Node version based on OS version
if ($OSVersion -gt 6.1) {
# Windows 7 is version 6.1
$NodeVersion = Extract-Variable -Path "$BaseDir\..\..\dependencies.sh" -Key "NODE_VERSION_COMPAT"
}
else {
$NodeVersion = Extract-Variable -Path "$BaseDir\..\..\dependencies.sh" -Key "NODE_VERSION_LTS"
}
$NodeSource = "https://nodejs.org/download/release/v$NodeVersion/win-x64/node.exe"
$NodeTargetDir = "$Cache\node-v$NodeVersion-x64"
$NodeTarget = "$NodeTargetDir\node.exe"
## Just print the path and exit
if ($Args.length -eq 1 -and $Args[0] -eq "Get-Path") {
Write-Output "$NodeTargetDir"
exit 0
}
## Just download node and exit
if ($Args.length -eq 1 -and $Args[0] -eq "Download-Node") {
Download-Node
exit 0
}
## Download node
Download-Node
## Set PATH so that recursive calls find it
$Env:PATH = "$NodeTargetDir;$ENV:Path"
## Invoke Node with all command-line arguments
$ErrorActionPreference = "Continue"
& "$NodeTarget" @Args
exit $LastExitCode