1 |
rakinar2 |
575 |
#!/usr/bin/env powershell |
2 |
|
|
|
3 |
|
|
$projectdir = Split-Path -parent $MyInvocation.MyCommand.Definition |
4 |
|
|
$tmp_dir = $projectdir + "/.blaze" |
5 |
|
|
$blazew_dir = $projectdir + "/blaze/wrapper" |
6 |
|
|
$blazew_properties = $blazew_dir + "/blaze_wrapper.properties" |
7 |
|
|
$bun_path = $tmp_dir + "/bun/bin/bun" |
8 |
|
|
|
9 |
|
|
enum LogLevel { |
10 |
|
|
Info |
11 |
|
|
Warn |
12 |
|
|
Error |
13 |
|
|
Debug |
14 |
|
|
} |
15 |
|
|
|
16 |
|
|
function Write-Log { |
17 |
|
|
param ( |
18 |
|
|
[string]$message, |
19 |
|
|
[LogLevel]$type = [LogLevel]::Info |
20 |
|
|
) |
21 |
|
|
|
22 |
|
|
if ($type -eq [LogLevel]::Debug -and $env:BLAZEW_DEBUG -ne "1") { |
23 |
|
|
return |
24 |
|
|
} |
25 |
|
|
|
26 |
|
|
switch ($type) { |
27 |
|
|
Info { |
28 |
|
|
Write-Host "info " -NoNewline -ForegroundColor Green |
29 |
|
|
Write-Host "$message" |
30 |
|
|
} |
31 |
|
|
Warn { |
32 |
|
|
Write-Host "warn " -NoNewline -ForegroundColor Yellow |
33 |
|
|
Write-Warning "$message" |
34 |
|
|
} |
35 |
|
|
Error { |
36 |
|
|
Write-Host "error " -NoNewline -ForegroundColor Red |
37 |
|
|
Write-Error "$message" |
38 |
|
|
} |
39 |
|
|
Debug { |
40 |
|
|
Write-Host "debug " -NoNewline -ForegroundColor Cyan |
41 |
|
|
Write-Verbose "$message" |
42 |
|
|
} |
43 |
|
|
} |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
if (-not (Test-Path $blazew_properties)) { |
47 |
|
|
Write-Log "blaze_wrapper.properties file could not be found in $blazew_dir. Are you sure this is BlazeBuild project?" |
48 |
|
|
exit 1 |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
if (-not (Test-Path $tmp_dir)) { |
52 |
|
|
New-Item -ItemType directory -Path $tmp_dir |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
function Get-BlazeProperty { |
56 |
|
|
param ( |
57 |
|
|
[string]$property |
58 |
|
|
) |
59 |
|
|
|
60 |
|
|
$properties = Get-Content $blazew_properties |
61 |
|
|
$properties | ForEach-Object { |
62 |
|
|
if ($_ -match "$property=(.*)") { |
63 |
|
|
$matches[1] |
64 |
|
|
} |
65 |
|
|
} |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
function Install-Bun() { |
69 |
|
|
Write-Log "Installing Bun $bun_version" |
70 |
|
|
$env:BUN_INSTALL = $tmp_dir + "/bun" |
71 |
|
|
$env:SHELL = "blazew" |
72 |
|
|
$env:PATH = $tmp_dir + "/bun/bin" + ";" + $env:PATH + ";" + $tmp_dir + "/bun/bin" |
73 |
|
|
& ([scriptblock]::Create((irm bun.sh/install.ps1))) -Version $bun_version -NoPathUpdate -NoRegisterInstallation -NoCompletions -DownloadWithoutCurl |
74 |
|
|
|
75 |
|
|
if ($LASTEXITCODE -ne 0) { |
76 |
|
|
Write-Log "Failed to install Bun $bun_version" Error |
77 |
|
|
exit 1 |
78 |
|
|
} |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
function Check-Bun() { |
82 |
|
|
$bun_version = Get-BlazeProperty "bun.version" |
83 |
|
|
|
84 |
|
|
if (-not $bun_version) { |
85 |
|
|
Write-Log "bun.version property could not be found in $blazew_properties." |
86 |
|
|
exit 1 |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
Write-Log "Checking if Bun is already installed" Debug |
90 |
|
|
|
91 |
|
|
if (-not (Test-Path $tmp_dir/bun/bin)) { |
92 |
|
|
Write-Log "Could not find Bun installation" |
93 |
|
|
Install-Bun |
94 |
|
|
$current_version = & $bun_path --version |
95 |
|
|
Write-Log "Installed Bun $current_version" |
96 |
|
|
} |
97 |
|
|
else { |
98 |
|
|
$current_version = & $bun_path --version |
99 |
|
|
|
100 |
|
|
if ($current_version -ne $bun_version) { |
101 |
|
|
Write-Log "Bun $current_version is installed, but required version is $bun_version" Warn |
102 |
|
|
Write-log "Reinstalling Bun $bun_version" Info |
103 |
|
|
Remove-Item -Recurse $tmp_dir/bun |
104 |
|
|
Install-Bun |
105 |
|
|
$current_version = & $bun_path --version |
106 |
|
|
Write-Log "Installed Bun $current_version" |
107 |
|
|
} |
108 |
|
|
else { |
109 |
|
|
Write-Log "Bun $current_version is already installed and meets the requirements" Debug |
110 |
|
|
} |
111 |
|
|
} |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
Check-Bun |
115 |
|
|
|
116 |
|
|
& $bun_path $blazew_dir/blaze_wrapper.js $args |