Skip to content

Commit 3bdd094

Browse files
Make MSI packaging generate WiX launcher cmd files
1 parent 838c9a4 commit 3bdd094

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

scripts/release/msi.ps1

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,76 @@ function Convert-TagToMsiVersion([string]$Tag) {
7373
return "$major.$minor.$build"
7474
}
7575

76+
function Ensure-WixBinLaunchers([string]$RepoRoot) {
77+
$binDir = Join-Path $RepoRoot "installer\\wix\\bin"
78+
New-Item -ItemType Directory -Force -Path $binDir | Out-Null
79+
80+
$cliLauncher = Join-Path $binDir "buffaly-codex.cmd"
81+
$webLauncher = Join-Path $binDir "buffaly-codex-web.cmd"
82+
83+
$cliContent = @'
84+
@echo off
85+
setlocal
86+
set "ROOT=%~dp0.."
87+
set "TARGET=%ROOT%\apps\cli\Buffaly.CodexEmbedded.Cli.exe"
88+
if not exist "%TARGET%" (
89+
echo Missing executable: "%TARGET%"
90+
exit /b 1
91+
)
92+
for %%I in ("%TARGET%") do set "APPDIR=%%~dpI"
93+
pushd "%APPDIR%" >nul
94+
"%TARGET%" %*
95+
set "EXITCODE=%ERRORLEVEL%"
96+
popd >nul
97+
exit /b %EXITCODE%
98+
'@
99+
100+
$webContent = @'
101+
@echo off
102+
setlocal
103+
set "ROOT=%~dp0.."
104+
set "TARGET=%ROOT%\apps\web\Buffaly.CodexEmbedded.Web.exe"
105+
if not exist "%TARGET%" (
106+
echo Missing executable: "%TARGET%"
107+
exit /b 1
108+
)
109+
110+
set "WEB_CONFIG_PATH=%ROOT%\apps\web\appsettings.json"
111+
set "BUFFALY_WEB_CONFIG=%WEB_CONFIG_PATH%"
112+
for /f "usebackq delims=" %%U in (`powershell -NoProfile -ExecutionPolicy Bypass -Command "$default='http://127.0.0.1:5170/'; $u=$env:BUFFALY_CODEX_WEB_URL; if([string]::IsNullOrWhiteSpace($u) -and (Test-Path $env:BUFFALY_WEB_CONFIG)){ try { $json=Get-Content -Raw $env:BUFFALY_WEB_CONFIG | ConvertFrom-Json; $u=[string]$json.WebLaunchUrl } catch {} }; if([string]::IsNullOrWhiteSpace($u)){ $u=$default }; $u=$u.Trim(); $parsed=$null; if(-not [Uri]::TryCreate($u,[UriKind]::Absolute,[ref]$parsed)){ $u=$default }; if(($u -notlike 'http://*') -and ($u -notlike 'https://*')){ $u=$default }; if(-not $u.EndsWith('/')){ $u=$u + '/' }; $u"`) do set "WEB_URL=%%U"
113+
if "%WEB_URL%"=="" set "WEB_URL=http://127.0.0.1:5170/"
114+
set "BIND_URL=%WEB_URL%"
115+
if "%BIND_URL:~-1%"=="/" set "BIND_URL=%BIND_URL:~0,-1%"
116+
117+
set "BUFFALY_WEB_URL=%WEB_URL%"
118+
powershell -NoProfile -ExecutionPolicy Bypass -Command "try { Invoke-WebRequest -Uri $env:BUFFALY_WEB_URL -UseBasicParsing -TimeoutSec 1 | Out-Null; exit 0 } catch { exit 1 }" >nul 2>nul
119+
if %ERRORLEVEL%==0 (
120+
start "" "%WEB_URL%"
121+
exit /b 0
122+
)
123+
124+
echo Starting Buffaly Codex Embedded Web UI...
125+
set "ASPNETCORE_URLS=%BIND_URL%"
126+
start "" powershell -NoProfile -ExecutionPolicy Bypass -Command "$u=$env:BUFFALY_WEB_URL; for($i=0; $i -lt 80; $i++){ try { Invoke-WebRequest -Uri $u -UseBasicParsing -TimeoutSec 1 | Out-Null; Start-Process $u; exit 0 } catch { Start-Sleep -Milliseconds 500 } }; Start-Process $u"
127+
128+
for %%I in ("%TARGET%") do set "APPDIR=%%~dpI"
129+
pushd "%APPDIR%" >nul
130+
"%TARGET%" %*
131+
set "EXITCODE=%ERRORLEVEL%"
132+
popd >nul
133+
if not "%EXITCODE%"=="0" (
134+
echo.
135+
echo Buffaly Codex Embedded Web exited with code %EXITCODE%.
136+
echo Check logs under "%LOCALAPPDATA%\Buffaly.CodexEmbedded\logs\Buffaly.CodexEmbedded.Web".
137+
pause
138+
)
139+
exit /b %EXITCODE%
140+
'@
141+
142+
Set-Content -Path $cliLauncher -Value $cliContent -Encoding ascii
143+
Set-Content -Path $webLauncher -Value $webContent -Encoding ascii
144+
}
145+
76146
function Build-DirectoryTree([string[]]$DirectoryPaths) {
77147
$tree = @{}
78148
foreach ($dir in $DirectoryPaths) {
@@ -243,6 +313,7 @@ $binWxs = Join-Path $repoRoot "installer\\wix\\Bin.wxs"
243313

244314
if (-not (Test-Path $productTemplate)) { throw "Missing WiX template: $productTemplate" }
245315
if (-not (Test-Path $binWxs)) { throw "Missing WiX file: $binWxs" }
316+
Ensure-WixBinLaunchers -RepoRoot $repoRoot
246317

247318
$productXml = Get-Content -Raw -Path $productTemplate
248319
if ($productXml -notmatch "__PRODUCT_VERSION__") {

0 commit comments

Comments
 (0)