diff --git a/tools/bootstrap/node.bat b/tools/bootstrap/node.bat index 2055c4fb0d8..5e721641463 100644 --- a/tools/bootstrap/node.bat +++ b/tools/bootstrap/node.bat @@ -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" %* diff --git a/tools/bootstrap/node_.ps1 b/tools/bootstrap/node_.ps1 index 6730975370b..91be4e07a3d 100644 --- a/tools/bootstrap/node_.ps1 +++ b/tools/bootstrap/node_.ps1 @@ -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' @@ -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 diff --git a/tools/build/cbt/task.js b/tools/build/cbt/task.js index f074ec0b8b7..8b2ccbf3bb8 100644 --- a/tools/build/cbt/task.js +++ b/tools/build/cbt/task.js @@ -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();