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:
i
2026-06-01 23:18:11 +08:00
co-authored by HAPI
parent 8cb35598af
commit 65c6e960a9
2 changed files with 32 additions and 5 deletions
+19 -1
View File
@@ -1106,7 +1106,25 @@ print_result() {
echo -e "${GREEN}║${NC} ${BOLD}HAPI 安装完成${NC} ${GREEN}║${NC}"
echo -e "${GREEN}╚══════════════════════════════════════════════════════════════════╝${NC}"
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}Hub 地址:${NC} http://${public_ip}:3006"
echo -e " ${BOLD}Token:${NC} ${YELLOW}$CLI_TOKEN${NC}"