Files
pkg/tools/install-deps.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

74 lines
2.4 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
# install-deps.sh — 重新解析並安裝專案的相依套件。
# 用法:install-deps.sh <ecosystem> <project-dir>
# ecosystem:nodejs | python | dotnet
# 對應動作:
# nodejs → npm install
# python → pip install -r requirements.txt(優先)或 pip install -e .(pyproject.toml)
# dotnet → dotnet restore
# 輸出:底層指令的原始輸出。
# 檢查順序:先確認相依來源檔案存在,才檢查指令存在。順序顛倒會把「沒有來源檔案」報成「指令不存在」。
# 結束碼(慣例見 README「工具」章的結束碼總表):
# 0 安裝成功
# 1 參數個數不對
# 2 ecosystem 不認識
# 3 該 ecosystem 沒有相依來源檔案——呼叫方跳過這個 ecosystem
# 4 需要的指令不存在(npm、pip、dotnet)
# 6 找不到專案目錄——呼叫方停手,不要當成跳過
# 其他 底層指令的結束碼,代表安裝失敗
set -u
if [ "$#" -ne 2 ]; then
echo "用法:install-deps.sh <ecosystem> <project-dir>" >&2
exit 1
fi
eco="$1"
DIR="$2"
[ -d "$DIR" ] || { echo "project dir not found: $DIR" >&2; exit 6; }
case "$eco" in
nodejs)
[ -f "$DIR/package.json" ] || { echo "package.json not found in $DIR" >&2; exit 3; }
command -v npm >/dev/null 2>&1 || { echo "npm not found" >&2; exit 4; }
( cd "$DIR" && npm install )
exit $?
;;
python)
if [ -f "$DIR/requirements.txt" ]; then
target="-r requirements.txt"
elif [ -f "$DIR/pyproject.toml" ]; then
target="-e ."
else
echo "requirements.txt or pyproject.toml not found in $DIR" >&2
exit 3
fi
pip=""
for c in pip3 pip; do
if command -v "$c" >/dev/null 2>&1; then pip="$c"; break; fi
done
if [ -z "$pip" ]; then
if command -v python3 >/dev/null 2>&1 && python3 -m pip --version >/dev/null 2>&1; then
pip="python3 -m pip"
else
echo "pip not found" >&2
exit 4
fi
fi
( cd "$DIR" && $pip install $target )
exit $?
;;
dotnet)
projs=$(find "$DIR" -maxdepth 3 \( -name '*.csproj' -o -name '*.sln' \) 2>/dev/null)
[ -n "$projs" ] || { echo "*.csproj or *.sln not found in $DIR" >&2; exit 3; }
command -v dotnet >/dev/null 2>&1 || { echo "dotnet not found" >&2; exit 4; }
( cd "$DIR" && dotnet restore )
exit $?
;;
*) echo "unknown ecosystem: $eco" >&2; exit 2 ;;
esac