fix: show actual hapi install path when already installed via npm in quick mode
This commit is contained in:
+23
-2
@@ -219,6 +219,18 @@ function Detect-Installed {
|
||||
$script:INSTALLED_VERSION = (Get-Content $script:VERSION_FILE -Raw).Trim()
|
||||
}
|
||||
}
|
||||
|
||||
# 如果 hapi 命令未找到,尝试通过 npm list -g 检测
|
||||
if (-not $hapiCmd -and (Get-Command "npm" -ErrorAction SilentlyContinue)) {
|
||||
$npmPkg = (& npm list -g $script:NPM_PACKAGE --depth=0 2>$null) | Select-String -Pattern '@twsxtd/hapi@'
|
||||
if ($npmPkg) {
|
||||
$verMatch = $npmPkg | Select-String -Pattern '\d+\.\d+\.\d+'
|
||||
if ($verMatch) {
|
||||
$script:INSTALLED_VERSION = $verMatch.Matches.Value
|
||||
$script:INSTALLED_SOURCE = "npm"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────
|
||||
@@ -227,8 +239,11 @@ function Detect-Installed {
|
||||
function Get-RemoteNpmVersion {
|
||||
if (-not (Get-Command "npm" -ErrorAction SilentlyContinue)) { return $null }
|
||||
try {
|
||||
$regArg = if ($script:NPM_REGISTRY -and $script:NPM_REGISTRY -ne "https://registry.npmjs.org") { "--registry=$($script:NPM_REGISTRY)" } else { "" }
|
||||
$ver = (& npm view $script:NPM_PACKAGE version $regArg 2>$null).Trim()
|
||||
$npmArgs = @("view", $script:NPM_PACKAGE, "version")
|
||||
if ($script:NPM_REGISTRY -and $script:NPM_REGISTRY -ne "https://registry.npmjs.org") {
|
||||
$npmArgs += "--registry=$($script:NPM_REGISTRY)"
|
||||
}
|
||||
$ver = (& npm @npmArgs 2>$null).Trim()
|
||||
if ($ver) { return $ver }
|
||||
} catch {}
|
||||
return $null
|
||||
@@ -1165,6 +1180,12 @@ if ($Upgrade -or $Force -or $Source -or $SkipHub -or $InstallDir -or $isIexExecu
|
||||
Write-Host "║ HAPI 快速模式 ║" -ForegroundColor White
|
||||
Write-Host "╚══════════════════════════════════════════════════════════════════╝" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Detect-Installed
|
||||
if ($script:INSTALLED_VERSION) {
|
||||
$srcDisplay = $script:INSTALLED_SOURCE
|
||||
if ($srcDisplay -like "github:*") { $srcDisplay = $srcDisplay.Substring(7) }
|
||||
Write-Info "检测到已安装 HAPI CLI v$($script:INSTALLED_VERSION) (来源: $srcDisplay, 路径: $((Get-Command hapi -ErrorAction SilentlyContinue).Source))"
|
||||
}
|
||||
Setup-InstallDir
|
||||
Check-Prerequisites
|
||||
Run-QuickMode
|
||||
|
||||
@@ -1390,6 +1390,16 @@ check_prerequisites() {
|
||||
# 快速模式:向后兼容的命令行参数
|
||||
# ─────────────────────────────────────────
|
||||
run_quick_mode() {
|
||||
detect_installed
|
||||
|
||||
if [[ -n "$INSTALLED_VERSION" ]]; then
|
||||
local actual_path
|
||||
actual_path=$(command -v hapi 2>/dev/null || true)
|
||||
local src_display="$INSTALLED_SOURCE"
|
||||
[[ "$src_display" == github:* ]] && src_display="${src_display#github:}"
|
||||
info "检测到已安装 HAPI CLI v$INSTALLED_VERSION (来源: $src_display, 路径: $actual_path)"
|
||||
fi
|
||||
|
||||
setup_install_dir
|
||||
check_prerequisites
|
||||
|
||||
|
||||
Reference in New Issue
Block a user