Files
pkg/tools/latest-version.sh
jiantw83andClaude Opus 5 ea11ca0590 fix(pkg): 補齊稽核缺失並修掉護欄失效
What:依 jsc-meta:skill-check 的稽核結果修正技能與工具——補上每個步驟的可檢核完成條件、
把留在內文的標準輸入輸出流程下放 tools/、修正查表與退碼路由造成的誤判。

Why:稽核發現這些缺失會讓技能在實際執行時走錯分支或靜默通過。
完成條件缺漏是最常被違反的一項;退碼誤判與查表錯誤則會讓良性狀況被當成失敗。

How:逐項對照 references/guidelines.md 的審核檢查清單修正,新增的工具都有
documented exit codes,並以真實執行驗證每條路徑。

Who:jsc-meta:skill-check 例行稽核(2026-08-25)。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-25 14:58:54 +08:00

48 lines
1.7 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env sh
# latest-version.sh — 查詢套件最新且穩定的版本號。
# 用法:latest-version.sh <ecosystem> <name>
# ecosystem:nodejs | python | dotnet
# 輸出:版本號一行。
# 結束碼(慣例見 README「工具」章的結束碼總表):
# 0 查到版本號
# 1 參數個數不對
# 2 ecosystem 不認識
# 4 登錄站上查不到這個套件——呼叫方跳過這個套件
# 5 需要的指令不存在(curl、python3)
# 本工具不收專案目錄,所以沒有 6。
set -u
if [ "$#" -ne 2 ]; then
echo "用法:latest-version.sh <ecosystem> <name>" >&2
exit 1
fi
eco="$1"
name="$2"
# 回應靠 curl 取得、靠 python3 解析。少了任一支會解出空字串,被誤判成查不到套件,所以先擋。
for c in curl python3; do
command -v "$c" >/dev/null 2>&1 || { echo "$c not found" >&2; exit 5; }
done
case "$eco" in
nodejs)
v=$(curl -sSf "https://registry.npmjs.org/$name/latest" 2>/dev/null \
| python3 2>/dev/null -c 'import json,sys;print(json.load(sys.stdin).get("version",""))') ;;
python)
v=$(curl -sSf "https://pypi.org/pypi/$name/json" 2>/dev/null \
| python3 2>/dev/null -c 'import json,sys;print(json.load(sys.stdin)["info"]["version"])') ;;
dotnet)
lname=$(printf '%s' "$name" | tr '[:upper:]' '[:lower:]')
v=$(curl -sSf "https://api.nuget.org/v3-flatcontainer/$lname/index.json" 2>/dev/null \
| python3 2>/dev/null -c '
import json,sys,re
vs=json.load(sys.stdin).get("versions",[])
stable=[x for x in vs if re.match(r"^[0-9]+(\.[0-9]+)*$",x)]
print((stable or vs)[-1] if (stable or vs) else "")') ;;
*) echo "unknown ecosystem: $eco" >&2; exit 2 ;;
esac
[ -n "${v:-}" ] || { echo "not found: $eco/$name" >&2; exit 4; }
printf '%s\n' "$v"