feat(installer): migrate shims to runtime-managed targets

This commit is contained in:
ZenchantLive 2026-03-02 20:42:35 -08:00
parent 205f9500ec
commit 7945ee8d3c
6 changed files with 271 additions and 1 deletions

64
install/install.ps1 Normal file
View file

@ -0,0 +1,64 @@
$ErrorActionPreference = 'Stop'
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$RepoRoot = Split-Path -Parent $ScriptDir
$InstallHome = if ($env:BB_INSTALL_HOME) { $env:BB_INSTALL_HOME } else { $HOME }
$BbHome = Join-Path $InstallHome '.beadboard'
$TargetDir = Join-Path $BbHome 'bin'
$RuntimeDir = Join-Path $BbHome 'runtime'
$CurrentJson = Join-Path $RuntimeDir 'current.json'
$Version = if ($env:BB_RUNTIME_VERSION) { $env:BB_RUNTIME_VERSION } else { '0.1.0' }
New-Item -ItemType Directory -Path $TargetDir -Force | Out-Null
New-Item -ItemType Directory -Path $RuntimeDir -Force | Out-Null
$BeadboardShim = Join-Path $TargetDir 'beadboard.cmd'
$BbShim = Join-Path $TargetDir 'bb.cmd'
$runtimeMetadata = @{
version = $Version
runtimeRoot = $RepoRoot
installMode = 'repo-shim-fallback'
shimTarget = (Join-Path $RepoRoot 'install\beadboard.mjs')
} | ConvertTo-Json -Depth 4
[System.IO.File]::WriteAllText($CurrentJson, "$runtimeMetadata`n")
$beadboardContent = @"
@echo off
setlocal
set "BB_HOME=%BB_INSTALL_HOME%"
if "%BB_HOME%"=="" set "BB_HOME=%USERPROFILE%"
set "CURRENT_JSON=%BB_HOME%\.beadboard\runtime\current.json"
set "RUNTIME_ROOT="
for /f "usebackq delims=" %%I in (`powershell -NoProfile -Command "$p='%CURRENT_JSON%'; if (Test-Path $p) { try { (Get-Content -Raw $p | ConvertFrom-Json).runtimeRoot } catch {} }"`) do set "RUNTIME_ROOT=%%I"
if "%RUNTIME_ROOT%"=="" set "RUNTIME_ROOT=$RepoRoot"
node "%RUNTIME_ROOT%\install\beadboard.mjs" %*
"@
$bbContent = @"
@echo off
setlocal
set "BB_HOME=%BB_INSTALL_HOME%"
if "%BB_HOME%"=="" set "BB_HOME=%USERPROFILE%"
set "CURRENT_JSON=%BB_HOME%\.beadboard\runtime\current.json"
set "RUNTIME_ROOT="
for /f "usebackq delims=" %%I in (`powershell -NoProfile -Command "$p='%CURRENT_JSON%'; if (Test-Path $p) { try { (Get-Content -Raw $p | ConvertFrom-Json).runtimeRoot } catch {} }"`) do set "RUNTIME_ROOT=%%I"
if "%RUNTIME_ROOT%"=="" set "RUNTIME_ROOT=$RepoRoot"
npx --yes tsx "%RUNTIME_ROOT%\tools\bb.ts" %*
"@
$beadboardTemp = "$BeadboardShim.tmp"
$bbTemp = "$BbShim.tmp"
[System.IO.File]::WriteAllText($beadboardTemp, $beadboardContent)
[System.IO.File]::WriteAllText($bbTemp, $bbContent)
Move-Item -Path $beadboardTemp -Destination $BeadboardShim -Force
Move-Item -Path $bbTemp -Destination $BbShim -Force
Write-Output "Installed BeadBoard shims:"
Write-Output "- $BeadboardShim"
Write-Output "- $BbShim"
Write-Output "- $CurrentJson"
Write-Output ""
Write-Output "Add to PATH if needed:"
Write-Output " setx PATH ""$TargetDir;%PATH%"""

81
install/install.sh Normal file
View file

@ -0,0 +1,81 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd -- "${SCRIPT_DIR}/.." && pwd)"
INSTALL_HOME="${BB_INSTALL_HOME:-$HOME}"
BB_HOME="${INSTALL_HOME}/.beadboard"
TARGET_DIR="${BB_HOME}/bin"
RUNTIME_DIR="${BB_HOME}/runtime"
CURRENT_JSON="${RUNTIME_DIR}/current.json"
VERSION="${BB_RUNTIME_VERSION:-0.1.0}"
write_file_atomic() {
local target="$1"
local tmp="${target}.tmp.$$"
cat > "${tmp}"
mv "${tmp}" "${target}"
}
mkdir -p "${TARGET_DIR}" "${RUNTIME_DIR}"
write_file_atomic "${CURRENT_JSON}" <<EOF
{
"version": "${VERSION}",
"runtimeRoot": "${REPO_ROOT}",
"installMode": "repo-shim-fallback",
"shimTarget": "${REPO_ROOT}/install/beadboard.mjs"
}
EOF
write_file_atomic "${TARGET_DIR}/beadboard" <<EOF
#!/usr/bin/env bash
set -euo pipefail
BB_HOME="\${BB_INSTALL_HOME:-\$HOME}/.beadboard"
CURRENT_JSON="\${BB_HOME}/runtime/current.json"
resolve_runtime_root() {
if [ -f "\${CURRENT_JSON}" ]; then
local root
root="\$(node -e "const fs=require('fs');try{const j=JSON.parse(fs.readFileSync(process.argv[1],'utf8'));if(j&&typeof j.runtimeRoot==='string')process.stdout.write(j.runtimeRoot)}catch{}" "\${CURRENT_JSON}")"
if [ -n "\${root}" ]; then
printf '%s' "\${root}"
return 0
fi
fi
printf '%s' "${REPO_ROOT}"
}
RUNTIME_ROOT="\$(resolve_runtime_root)"
exec node "\${RUNTIME_ROOT}/install/beadboard.mjs" "\$@"
EOF
write_file_atomic "${TARGET_DIR}/bb" <<EOF
#!/usr/bin/env bash
set -euo pipefail
BB_HOME="\${BB_INSTALL_HOME:-\$HOME}/.beadboard"
CURRENT_JSON="\${BB_HOME}/runtime/current.json"
resolve_runtime_root() {
if [ -f "\${CURRENT_JSON}" ]; then
local root
root="\$(node -e "const fs=require('fs');try{const j=JSON.parse(fs.readFileSync(process.argv[1],'utf8'));if(j&&typeof j.runtimeRoot==='string')process.stdout.write(j.runtimeRoot)}catch{}" "\${CURRENT_JSON}")"
if [ -n "\${root}" ]; then
printf '%s' "\${root}"
return 0
fi
fi
printf '%s' "${REPO_ROOT}"
}
RUNTIME_ROOT="\$(resolve_runtime_root)"
exec npx --yes tsx "\${RUNTIME_ROOT}/tools/bb.ts" "\$@"
EOF
chmod +x "${TARGET_DIR}/beadboard" "${TARGET_DIR}/bb"
cat <<MSG
Installed BeadBoard shims:
- ${TARGET_DIR}/beadboard
- ${TARGET_DIR}/bb
- ${CURRENT_JSON}
Add to PATH if needed:
export PATH="${TARGET_DIR}:\$PATH"
MSG