Files
his/.husky/pre-commit
guanyu 986510278b feat: 配置Husky pre-commit钩子 - 提交前自动执行前端构建检查
- 创建.husky/pre-commit文件
- 配置提交前自动执行npm run build:dev检查语法
- 添加node_modules存在性校验
- 预留ESLint检查接口(待赵云配置后启用)
- 更新openhis-ui-vue3/package.json添加lint-staged配置

【关羽】构建门禁第一步落地
2026-04-24 18:02:27 +08:00

52 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
# ============================================================
# Husky Pre-commit Hook - HIS项目
# 配置: 关羽 | 日期: 2026-04-24
# 功能: 提交前自动检查前端构建
# ============================================================
echo "========================================"
echo "🔍 [Pre-commit] HIS项目提交检查"
echo "========================================"
# 检查前端目录是否存在
if [ ! -d "openhis-ui-vue3" ]; then
echo "⚠️ [Pre-commit] 未找到openhis-ui-vue3目录跳过前端检查"
exit 0
fi
cd openhis-ui-vue3
# 检查node_modules是否存在
if [ ! -d "node_modules" ]; then
echo "⚠️ [Pre-commit] node_modules未安装请先执行 npm install"
echo " 提示: 首次使用或依赖变更后需要安装依赖"
exit 1
fi
# 执行lint检查ESLint配置由赵云下周完善后启用
if grep -q '"lint"' package.json 2>/dev/null; then
echo "📋 [Pre-commit] 执行Lint检查..."
if npm run lint -- --max-warnings 0 2>&1; then
echo "✅ [Pre-commit] Lint检查通过"
else
echo "❌ [Pre-commit] Lint检查失败请修复代码规范问题"
exit 1
fi
else
echo "⏭️ [Pre-commit] 未配置lint脚本待赵云配置ESLint后启用"
fi
# 执行快速构建检查development模式仅检查语法和类型
echo "🔨 [Pre-commit] 执行构建检查 (build:dev)..."
if timeout 120 npm run build:dev 2>&1; then
echo "✅ [Pre-commit] 构建检查通过"
else
echo "❌ [Pre-commit] 构建检查失败!请修复编译错误后重新提交"
exit 1
fi
echo "========================================"
echo "✅ [Pre-commit] 所有检查通过,允许提交"
echo "========================================"