Files
syops/.githooks/_common.sh
T
2026-05-21 11:38:54 +08:00

46 lines
1.1 KiB
Bash

# shellcheck shell=bash
# 供 pre-commit / pre-push 引用;勿直接执行。
hook_should_skip() {
[[ "${SKIP_GIT_HOOKS:-}" == "1" ]] || [[ "${SKIP_FRONTEND_HOOKS:-}" == "1" ]]
}
frontend_paths_in() {
local file_list="${1:-}"
echo "${file_list}" | grep -qE '^frontend/'
}
ensure_frontend_deps() {
local frontend_dir="${1}/frontend"
if [[ ! -d "${frontend_dir}/node_modules" ]]; then
echo "[git-hook] frontend/node_modules 不存在,请先执行:"
echo " cd frontend && npm install"
return 1
fi
return 0
}
run_frontend_typecheck() {
local root_dir="${1}"
echo "[pre-commit] 检测到 frontend/ 变更,运行 vue-tsc 类型检查..."
if ! ensure_frontend_deps "${root_dir}"; then
return 1
fi
(
cd "${root_dir}/frontend"
npx vue-tsc -b --pretty false
)
}
run_frontend_build() {
local root_dir="${1}"
echo "[pre-push] 检测到将要推送的提交包含 frontend/ 变更,运行 npm run build..."
if ! ensure_frontend_deps "${root_dir}"; then
return 1
fi
(
cd "${root_dir}/frontend"
npm run build
)
}