Skip to content

Commit

Permalink
Revert "Simplify Node bootstrapping (tgstation#56713)" (tgstation#56747)
Browse files Browse the repository at this point in the history
This reverts commit 917d5d4.
  • Loading branch information
Cyberboss authored Feb 7, 2021
1 parent 3451522 commit f7cf0e4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 38 deletions.
10 changes: 1 addition & 9 deletions tools/bootstrap/node.bat
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
@echo off
where node.exe >nul 2>nul
if errorlevel 0 (
echo | set /p printed_str="Using system-wide Node "
call node.exe --version
call node.exe %*
) else (
call powershell.exe -NoLogo -ExecutionPolicy Bypass -File "%~dp0\node_.ps1" %*
)
@call powershell.exe -NoLogo -ExecutionPolicy Bypass -File "%~dp0\node_.ps1" %*
72 changes: 44 additions & 28 deletions tools/bootstrap/node_.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
## bootstrap/node_.ps1
##
## Node bootstrapping script for Windows.
##
## Automatically downloads a Node version to a cache directory and invokes it.
##
## The underscore in the name is so that typing `bootstrap/node` into
## PowerShell finds the `.bat` file first, which ensures this script executes
## regardless of ExecutionPolicy.

#Requires -Version 4.0

$Host.ui.RawUI.WindowTitle = "starting :: node $Args"
# bootstrap/node_.ps1
#
# Node bootstrapping script for Windows.
#
# Automatically downloads a Node version to a cache directory and invokes it.
#
# The underscore in the name is so that typing `bootstrap/node` into
# PowerShell finds the `.bat` file first, which ensures this script executes
# regardless of ExecutionPolicy.
$host.ui.RawUI.WindowTitle = "starting :: node $args"
$ErrorActionPreference = "Stop"
Add-Type -AssemblyName System.IO.Compression.FileSystem

## This forces UTF-8 encoding across all powershell built-ins
# This forces UTF-8 encoding across all powershell built-ins
$OutputEncoding = [System.Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$PSDefaultParameterValues['*:Encoding'] = 'utf8'

Expand All @@ -27,31 +27,47 @@ function ExtractVersion {
throw "Couldn't find value for $Key in $Path"
}

## Convenience variables
$BaseDir = Split-Path $script:MyInvocation.MyCommand.Path
$Cache = "$BaseDir/.cache"
# Convenience variables
$Bootstrap = Split-Path $script:MyInvocation.MyCommand.Path
$Cache = "$Bootstrap/.cache"
if ($Env:TG_BOOTSTRAP_CACHE) {
$Cache = $Env:TG_BOOTSTRAP_CACHE
}
$NodeVersion = ExtractVersion -Path "$BaseDir/../../dependencies.sh" -Key "NODE_VERSION_PRECISE"
$NodeDir = "$Cache/node-v$NodeVersion"
$NodeVersion = ExtractVersion -Path "$Bootstrap/../../dependencies.sh" -Key "NODE_VERSION_PRECISE"
$NodeFullVersion = "node-v$NodeVersion-win-x64"
$NodeDir = "$Cache/$NodeFullVersion"
$NodeExe = "$NodeDir/node.exe"
$Log = "$Cache/last-command.log"

## Download and unzip Node
# Download and unzip Node
if (!(Test-Path $NodeExe -PathType Leaf)) {
$Host.ui.RawUI.WindowTitle = "Downloading Node $NodeVersion..."
New-Item $NodeDir -ItemType Directory -ErrorAction silentlyContinue | Out-Null
$host.ui.RawUI.WindowTitle = "Downloading Node $NodeVersion..."
New-Item $Cache -ItemType Directory -ErrorAction silentlyContinue | Out-Null

$Archive = "$Cache/node-v$NodeVersion.zip"
Invoke-WebRequest `
"https://nodejs.org/download/release/v$NodeVersion/win-x86/node.exe" `
-OutFile $NodeExe `
"https://nodejs.org/download/release/v$NodeVersion/$NodeFullVersion.zip" `
-OutFile $Archive `
-ErrorAction Stop
$tmp = "$Cache/tmp"
if (Test-Path $tmp) {
Remove-Item $tmp -Recurse
}
[System.IO.Compression.ZipFile]::ExtractToDirectory($Archive, $tmp)
Move-Item $tmp/node-* $Cache
Remove-Item $tmp
Remove-Item $Archive
}

## Set PATH so that recursive calls find it
$Env:PATH = "$NodeDir;$ENV:Path"

## Invoke Node with all command-line arguments
$Host.ui.RawUI.WindowTitle = "node $Args"
# Invoke Node with all command-line arguments
Write-Output $NodeExe | Out-File -Encoding utf8 $Log
[System.String]::Join([System.Environment]::NewLine, $args) | Out-File -Encoding utf8 -Append $Log
Write-Output "---" | Out-File -Encoding utf8 -Append $Log
$Env:PATH = "$NodeDir;$ENV:Path" # Set PATH so that recursive calls find it
$host.ui.RawUI.WindowTitle = "node $args"
$ErrorActionPreference = "Continue"
& "$NodeExe" @Args
& $NodeExe $args 2>&1 | ForEach-Object {
"$_" | Out-File -Encoding utf8 -Append $Log
"$_" | Out-Host
}
exit $LastExitCode
2 changes: 1 addition & 1 deletion tools/build/cbt/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Task {
if (!this.script) {
return;
}
console.warn(` => Starting '${this.name}'`);
console.warn(` => Starting '${this.name}': ${needsRebuild}`);
const startedAt = Date.now();
// Run the script
await this.script();
Expand Down

0 comments on commit f7cf0e4

Please sign in to comment.