feat(script): check-deps will prompt user to install dependencies (#165)

This commit is contained in:
sigoden
2025-02-13 09:24:55 +08:00
committed by GitHub
parent 42c827e556
commit f5c3071fbc
+19 -9
View File
@@ -12,7 +12,8 @@ set -e
main() {
script_path="$argc_script_path"
if [[ ! -f "$script_path" ]]; then
_exit "✗ not found $script_path"
echo "✗ not found $script_path"
exit 0
fi
ext="${script_path##*.}"
if [[ "$script_path" == tools/* ]]; then
@@ -39,7 +40,7 @@ check_sh_dependencies() {
fi
done
if [[ -n "${missing_deps}" ]]; then
_exit "✗ missing tools: ${missing_deps[*]}"
echo "✗ missing tools: ${missing_deps[*]}"
fi
}
@@ -47,7 +48,14 @@ check_agent_js_dependencies() {
agent_dir="$(dirname "$script_path")"
if [[ -f "$agent_dir/package.json" ]]; then
npm ls --prefix="$agent_dir" --depth=0 --silent >/dev/null 2>&1 || \
_exit "✗ missing node modules, FIX: cd $agent_dir && npm install"
{
cmd="cd $agent_dir && npm install"
echo "✗ missing node modules"
read -p "? run \`$cmd\` to fix [Y/n] " choice
if [[ "$choice" == "Y" || "$choice" == "y" || -z "$choice" ]]; then
(eval "$cmd")
fi
}
fi
}
@@ -55,14 +63,16 @@ check_agent_py_dependencies() {
agent_dir="$(dirname "$script_path")"
if [[ -f "$agent_dir/requirements.txt" ]]; then
python <(cat "$agent_dir/requirements.txt" | sed -E -n 's/^([A-Za-z_]+).*/import \1/p') >/dev/null 2>&1 || \
_exit "✗ missing python modules, FIX: cd $agent_dir && pip install -r requirements.txt"
{
cmd="cd $agent_dir && pip install -r requirements.txt"
echo "✗ missing python modules"
read -p "? run \`$cmd\` to fix [Y/n] " choice
if [[ "$choice" == "Y" || "$choice" == "y" || -z "$choice" ]]; then
(eval "$cmd")
fi
}
fi
}
_exit() {
echo "$*" >&2
exit 0
}
# See more details at https://github.com/sigoden/argc
eval "$(argc --argc-eval "$0" "$@")"