/[sudobot]/trunk/blazew.ps1
ViewVC logotype

Annotation of /trunk/blazew.ps1

Parent Directory Parent Directory | Revision Log Revision Log


Revision 629 - (hide annotations)
Sat Sep 7 14:55:53 2024 UTC (6 months, 3 weeks ago) by rakinar2
File size: 3226 byte(s)
chore: sync

1 rakinar2 575 #!/usr/bin/env powershell
2    
3 rakinar2 629 $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 rakinar2 575
9 rakinar2 629 enum LogLevel {
10     Info
11     Warn
12     Error
13     Debug
14 rakinar2 575 }
15    
16 rakinar2 629 function Write-Log {
17     param (
18     [string]$message,
19     [LogLevel]$type = [LogLevel]::Info
20     )
21 rakinar2 575
22 rakinar2 629 if ($type -eq [LogLevel]::Debug -and $env:BLAZEW_DEBUG -ne "1") {
23     return
24 rakinar2 575 }
25 rakinar2 629
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 rakinar2 575 }
45    
46 rakinar2 629 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 rakinar2 575
51 rakinar2 629 if (-not (Test-Path $tmp_dir)) {
52     New-Item -ItemType directory -Path $tmp_dir
53 rakinar2 575 }
54    
55 rakinar2 629 function Get-BlazeProperty {
56     param (
57     [string]$property
58     )
59 rakinar2 575
60 rakinar2 629 $properties = Get-Content $blazew_properties
61     $properties | ForEach-Object {
62     if ($_ -match "$property=(.*)") {
63     $matches[1]
64     }
65 rakinar2 575 }
66     }
67    
68 rakinar2 629 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 rakinar2 575
75     if ($LASTEXITCODE -ne 0) {
76 rakinar2 629 Write-Log "Failed to install Bun $bun_version" Error
77 rakinar2 575 exit 1
78     }
79     }
80    
81 rakinar2 629 function Check-Bun() {
82     $bun_version = Get-BlazeProperty "bun.version"
83 rakinar2 575
84 rakinar2 629 if (-not $bun_version) {
85     Write-Log "bun.version property could not be found in $blazew_properties."
86     exit 1
87     }
88 rakinar2 575
89 rakinar2 629 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 rakinar2 575 }
97 rakinar2 629 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 rakinar2 575 }
113    
114 rakinar2 629 Check-Bun
115 rakinar2 575
116 rakinar2 629 & $bun_path $blazew_dir/blaze_wrapper.js $args

Properties

Name Value
svn:executable *

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26