fix: remove npm version/source file writes, infer from path instead
npm installs to global node_modules, so writing .hapi-version and .hapi-source under /opt/hapi (or C:\hapi) is unnecessary and fails when that directory doesn't exist yet. - Stop writing VERSION_FILE and SOURCE_FILE in install_from_npm - Infer "npm" source from hapi path in print_result when files absent - Sync both install.sh and install.ps1 via [HAPI](https://hapi.run) Co-Authored-By: HAPI <[email protected]>
This commit is contained in:
+13
-4
@@ -413,9 +413,6 @@ function Install-FromNpm {
|
|||||||
$installedVer = ((& hapi --version 2>$null) | Select-String -Pattern '\d+\.\d+\.\d+' | ForEach-Object { $_.Matches.Value } | Select-Object -First 1)
|
$installedVer = ((& hapi --version 2>$null) | Select-String -Pattern '\d+\.\d+\.\d+' | ForEach-Object { $_.Matches.Value } | Select-Object -First 1)
|
||||||
if (-not $installedVer) { $installedVer = "unknown" }
|
if (-not $installedVer) { $installedVer = "unknown" }
|
||||||
|
|
||||||
$installedVer | Set-Content $script:VERSION_FILE -Encoding UTF8
|
|
||||||
"npm" | Set-Content $script:SOURCE_FILE -Encoding UTF8
|
|
||||||
|
|
||||||
Write-Ok "HAPI CLI v$installedVer 安装成功 (来源: npm, 路径: $($hapi.Source))"
|
Write-Ok "HAPI CLI v$installedVer 安装成功 (来源: npm, 路径: $($hapi.Source))"
|
||||||
return $true
|
return $true
|
||||||
}
|
}
|
||||||
@@ -855,7 +852,19 @@ function Print-Result {
|
|||||||
} else {
|
} else {
|
||||||
(Get-Content $VERSION_FILE -Raw).Trim()
|
(Get-Content $VERSION_FILE -Raw).Trim()
|
||||||
}
|
}
|
||||||
$hapiSource = if (Test-Path $SOURCE_FILE) { (Get-Content $SOURCE_FILE -Raw).Trim() } else { "unknown" }
|
$hapiSource = if (Test-Path $SOURCE_FILE) {
|
||||||
|
(Get-Content $SOURCE_FILE -Raw).Trim()
|
||||||
|
} elseif ($script:INSTALLED_SOURCE) {
|
||||||
|
$script:INSTALLED_SOURCE
|
||||||
|
} else {
|
||||||
|
$currentHapi = (Get-Command hapi -ErrorAction SilentlyContinue).Source
|
||||||
|
if ($currentHapi -and $currentHapi -notlike "$script:HAPI_BIN_DIR*") {
|
||||||
|
$npmPrefix = (& npm config get prefix 2>$null).Trim()
|
||||||
|
if ($currentHapi -like "$npmPrefix*") { "npm" } else { "unknown" }
|
||||||
|
} else {
|
||||||
|
"unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host "╔══════════════════════════════════════════════════════════════════╗" -ForegroundColor Green
|
Write-Host "╔══════════════════════════════════════════════════════════════════╗" -ForegroundColor Green
|
||||||
|
|||||||
+19
-1
@@ -1106,7 +1106,25 @@ print_result() {
|
|||||||
echo -e "${GREEN}║${NC} ${BOLD}HAPI 安装完成${NC} ${GREEN}║${NC}"
|
echo -e "${GREEN}║${NC} ${BOLD}HAPI 安装完成${NC} ${GREEN}║${NC}"
|
||||||
echo -e "${GREEN}╚══════════════════════════════════════════════════════════════════╝${NC}"
|
echo -e "${GREEN}╚══════════════════════════════════════════════════════════════════╝${NC}"
|
||||||
echo ""
|
echo ""
|
||||||
echo -e " ${BOLD}HAPI CLI:${NC} v$hapi_ver (来源: $(cat "$SOURCE_FILE" 2>/dev/null || echo unknown))"
|
|
||||||
|
local hapi_source
|
||||||
|
if [[ -f "$SOURCE_FILE" ]]; then
|
||||||
|
hapi_source=$(cat "$SOURCE_FILE" 2>/dev/null)
|
||||||
|
else
|
||||||
|
hapi_source="$INSTALLED_SOURCE"
|
||||||
|
if [[ -z "$hapi_source" || "$hapi_source" == "unknown" ]]; then
|
||||||
|
local current_hapi_path
|
||||||
|
current_hapi_path=$(command -v hapi 2>/dev/null || true)
|
||||||
|
if [[ -n "$current_hapi_path" && "$current_hapi_path" != "$HAPI_BIN_DIR"* ]]; then
|
||||||
|
local npm_prefix
|
||||||
|
npm_prefix=$(npm config get prefix 2>/dev/null || echo "/usr/local")
|
||||||
|
[[ "$current_hapi_path" == "$npm_prefix"* ]] && hapi_source="npm"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
[[ -z "$hapi_source" ]] && hapi_source="unknown"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e " ${BOLD}HAPI CLI:${NC} v$hapi_ver (来源: $hapi_source)"
|
||||||
echo -e " ${BOLD}CLI 路径:${NC} $hapi_path"
|
echo -e " ${BOLD}CLI 路径:${NC} $hapi_path"
|
||||||
echo -e " ${BOLD}Hub 地址:${NC} http://${public_ip}:3006"
|
echo -e " ${BOLD}Hub 地址:${NC} http://${public_ip}:3006"
|
||||||
echo -e " ${BOLD}Token:${NC} ${YELLOW}$CLI_TOKEN${NC}"
|
echo -e " ${BOLD}Token:${NC} ${YELLOW}$CLI_TOKEN${NC}"
|
||||||
|
|||||||
Reference in New Issue
Block a user