1 |
rakinar2 |
575 |
#!/usr/bin/env powershell |
2 |
|
|
|
3 |
rakinar2 |
630 |
$blazeDir = (Join-Path (Get-Location) ".blaze").Replace("\", "/") |
4 |
|
|
$blazewDir = (Join-Path (Get-Location) "blaze/wrapper").Replace("\", "/") |
5 |
|
|
$propertiesFile = Join-Path $blazewDir "blaze_wrapper.properties" |
6 |
|
|
$wrapperJSFile = Join-Path $blazewDir "blaze_wrapper.js" |
7 |
|
|
$bunBinDir = Join-Path $blazeDir "bun/bin" |
8 |
|
|
$bunPath = Join-Path $bunBinDir "bun.exe" |
9 |
|
|
$debugMode = $false |
10 |
rakinar2 |
575 |
|
11 |
rakinar2 |
630 |
if ($env:BLAZEW_DEBUG -eq "1") { |
12 |
|
|
$debugMode = $true |
13 |
rakinar2 |
575 |
} |
14 |
|
|
|
15 |
rakinar2 |
630 |
function Debug-Log { |
16 |
|
|
param([string]$message) |
17 |
rakinar2 |
575 |
|
18 |
rakinar2 |
630 |
if ($debugMode) { |
19 |
|
|
Write-Host "[debug] $message" |
20 |
rakinar2 |
575 |
} |
21 |
|
|
} |
22 |
|
|
|
23 |
rakinar2 |
630 |
function Get-Property { |
24 |
|
|
param([string]$key) |
25 |
rakinar2 |
575 |
|
26 |
rakinar2 |
630 |
$value = Get-Content $propertiesFile | Select-String -Pattern "$key=" | ForEach-Object { $_ -replace "$key=" } |
27 |
|
|
return $value |
28 |
rakinar2 |
575 |
} |
29 |
|
|
|
30 |
rakinar2 |
630 |
function Start-Blaze { |
31 |
|
|
if (-not (Test-Path $blazeDir)) { |
32 |
|
|
Debug-Log "Creating .blaze/ directory" |
33 |
|
|
New-Item -ItemType Directory -Path $blazeDir | Out-Null |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
if (-not (Test-Path $blazewDir)) { |
37 |
|
|
Write-Error "blaze/wrapper/ directory not found. Please run this script from the root of a BlazeBuild project." |
38 |
|
|
exit 1 |
39 |
|
|
} |
40 |
rakinar2 |
575 |
|
41 |
rakinar2 |
630 |
if (-not (Test-Path $propertiesFile)) { |
42 |
|
|
Write-Error "blaze_wrapper.properties file not found. Please run this script from the root of a BlazeBuild project." |
43 |
|
|
exit 1 |
44 |
rakinar2 |
575 |
} |
45 |
|
|
} |
46 |
|
|
|
47 |
rakinar2 |
630 |
# These checks were taken from the Bun installation script. |
48 |
|
|
function Test-Bun { |
49 |
|
|
$bunRevision = "$(& "${bunPath}" --revision)" |
50 |
rakinar2 |
575 |
|
51 |
rakinar2 |
630 |
if ($LASTEXITCODE -eq 1073741795) { |
52 |
|
|
# STATUS_ILLEGAL_INSTRUCTION |
53 |
|
|
Write-Output "Install Failed - bun.exe is not compatible with your CPU. This should have been detected before downloading.`n" |
54 |
|
|
exit 1 |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
if (($LASTEXITCODE -eq 3221225781) -or ($LASTEXITCODE -eq -1073741515)) { |
58 |
|
|
# STATUS_DLL_NOT_FOUND |
59 |
|
|
Write-Output "Install Failed - You are missing a DLL required to run bun.exe" |
60 |
|
|
Write-Output "This can be solved by installing the Visual C++ Redistributable from Microsoft:`nSee https://learn.microsoft.com/cpp/windows/latest-supported-vc-redist`nDirect Download -> https://aka.ms/vs/17/release/vc_redist.x64.exe`n`n" |
61 |
|
|
Write-Output "The command '${bunPath} --revision' exited with code ${LASTEXITCODE}`n" |
62 |
|
|
exit 1 |
63 |
|
|
} |
64 |
|
|
|
65 |
rakinar2 |
575 |
if ($LASTEXITCODE -ne 0) { |
66 |
rakinar2 |
630 |
Write-Output "Install Failed - could not verify bun.exe" |
67 |
|
|
Write-Output "The command '${bunPath} --revision' exited with code ${LASTEXITCODE}`n" |
68 |
rakinar2 |
575 |
exit 1 |
69 |
|
|
} |
70 |
rakinar2 |
630 |
|
71 |
|
|
return $bunRevision |
72 |
rakinar2 |
575 |
} |
73 |
|
|
|
74 |
rakinar2 |
630 |
Start-Blaze |
75 |
rakinar2 |
575 |
|
76 |
rakinar2 |
630 |
$bunVersion = Get-Property "bun.version" |
77 |
rakinar2 |
575 |
|
78 |
rakinar2 |
630 |
if (-not $bunVersion) { |
79 |
|
|
Write-Error "bun.version property not found or is empty in blaze_wrapper.properties file." |
80 |
|
|
exit 1 |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
if (Test-Path $bunPath) { |
84 |
|
|
Write-Host "Found bun installation at $bunPath" |
85 |
|
|
Test-Bun |
86 |
|
|
|
87 |
|
|
$version = & $bunPath --version |
88 |
|
|
|
89 |
|
|
if ($version -eq $bunVersion) { |
90 |
|
|
Write-Host "Bun is up to date" |
91 |
|
|
# TODO |
92 |
|
|
exit 0 |
93 |
rakinar2 |
575 |
} |
94 |
|
|
} |
95 |
|
|
|
96 |
rakinar2 |
630 |
if (-not (Get-Command Get-CimInstance -ErrorAction SilentlyContinue)) { |
97 |
|
|
Write-Output "Cannot Install Bun" |
98 |
|
|
Write-Output "Bun for Windows requires PowerShell 3.0 or later.`n" |
99 |
|
|
exit 1 |
100 |
|
|
} |
101 |
rakinar2 |
575 |
|
102 |
rakinar2 |
630 |
if (-not ((Get-CimInstance Win32_ComputerSystem)).SystemType -match "x64-based") { |
103 |
|
|
Write-Output "Cannot Install Bun" |
104 |
|
|
Write-Output "Bun for Windows is currently only available for x86 64-bit Windows.`n" |
105 |
|
|
exit 1 |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
$bunDownloadURL = "https://github.com/oven-sh/bun/releases/download/bun-v$bunVersion/bun-windows-x64.zip" |
109 |
|
|
$zipPath = Join-Path $blazeDir "bun.zip" |
110 |
|
|
|
111 |
|
|
if (Test-Path $zipPath) { |
112 |
|
|
Remove-Item -Force $zipPath |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
Write-Host "Downloading Bun from $bunDownloadURL" |
116 |
|
|
Invoke-WebRequest -Uri $bunDownloadURL -OutFile $zipPath |
117 |
|
|
|
118 |
|
|
$bunInstallPath = Join-Path $blazeDir "bun" |
119 |
|
|
|
120 |
|
|
if (Test-Path $bunInstallPath) { |
121 |
|
|
Remove-Item -Recurse -Force $bunInstallPath |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
Write-Host "Installing Bun to $bunInstallPath" |
125 |
|
|
Expand-Archive -Path $zipPath -DestinationPath $bunInstallPath |
126 |
|
|
Remove-Item -Force $zipPath |
127 |
|
|
Rename-Item -Path (Join-Path $bunInstallPath "bun-windows-x64") -NewName $bunBinDir |
128 |
|
|
|
129 |
|
|
Test-Bun |
130 |
|
|
|
131 |
|
|
Write-Host "Bun installed successfully" |
132 |
|
|
|
133 |
|
|
# Prepare and execute the BlazeBuild wrapper |
134 |
|
|
|
135 |
|
|
if (-not (Test-Path $wrapperJSFile)) { |
136 |
|
|
Write-Error "blaze_wrapper.js file not found. Please run this script from the root of a BlazeBuild project." |
137 |
|
|
exit 1 |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
$env:Path = "$bunBinDir;$env:Path" |
141 |
|
|
|
142 |
|
|
$blazeBuildArgs = $args -join " " |
143 |
|
|
Debug-Log "Executing BlazeBuild with arguments: $blazeBuildArgs" |
144 |
|
|
& $bunPath run $wrapperJSFile $args |
145 |
|
|
exit $LASTEXITCODE |