check_project.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. #!/bin/bash
  2. # AI驱动软件著作权申请材料生成系统 - 项目完整性检查脚本 (Shell版本)
  3. # 版本: 1.0
  4. # 描述: 快速检查项目文件完整性和基本配置
  5. set -e
  6. # 颜色定义
  7. RED='\033[0;31m'
  8. GREEN='\033[0;32m'
  9. YELLOW='\033[1;33m'
  10. BLUE='\033[0;34m'
  11. PURPLE='\033[0;35m'
  12. CYAN='\033[0;36m'
  13. NC='\033[0m' # No Color
  14. # 计数器
  15. SUCCESS_COUNT=0
  16. WARNING_COUNT=0
  17. ERROR_COUNT=0
  18. # 打印函数
  19. print_colored() {
  20. local color=$1
  21. local message=$2
  22. echo -e "${color}${message}${NC}"
  23. }
  24. print_header() {
  25. local title=$1
  26. echo
  27. print_colored $CYAN "============================================================"
  28. print_colored $CYAN "🔍 $title"
  29. print_colored $CYAN "============================================================"
  30. }
  31. print_success() {
  32. local message=$1
  33. print_colored $GREEN "✅ $message"
  34. ((SUCCESS_COUNT++))
  35. }
  36. print_warning() {
  37. local message=$1
  38. print_colored $YELLOW "⚠️ $message"
  39. ((WARNING_COUNT++))
  40. }
  41. print_error() {
  42. local message=$1
  43. print_colored $RED "❌ $message"
  44. ((ERROR_COUNT++))
  45. }
  46. print_info() {
  47. local message=$1
  48. print_colored $BLUE "ℹ️ $message"
  49. }
  50. # 检查文件是否存在
  51. check_file() {
  52. local file_path=$1
  53. local required=${2:-true}
  54. local description=${3:-$file_path}
  55. if [ -f "$file_path" ]; then
  56. print_success "文件存在: $description"
  57. return 0
  58. else
  59. if [ "$required" = "true" ]; then
  60. print_error "必需文件缺失: $description"
  61. else
  62. print_warning "可选文件缺失: $description"
  63. fi
  64. return 1
  65. fi
  66. }
  67. # 检查目录是否存在
  68. check_directory() {
  69. local dir_path=$1
  70. local required=${2:-true}
  71. local description=${3:-$dir_path}
  72. if [ -d "$dir_path" ]; then
  73. print_success "目录存在: $description"
  74. return 0
  75. else
  76. if [ "$required" = "true" ]; then
  77. print_error "必需目录缺失: $description"
  78. else
  79. print_warning "可选目录缺失: $description"
  80. fi
  81. return 1
  82. fi
  83. }
  84. # 检查核心文件
  85. check_core_files() {
  86. print_header "核心文件完整性检查"
  87. # 配置文件
  88. check_file "ai-copyright-config.json" true "项目配置文件"
  89. # 初始化脚本
  90. check_file "init_project.py" true "Python初始化脚本"
  91. check_file "init_project.sh" true "Shell初始化脚本"
  92. check_file "create-copyright-project" true "全局创建脚本"
  93. # 生成脚本
  94. check_file "generate_all_sourcecode.py" true "Python全代码生成脚本"
  95. check_file "generate_frontend_sourcecode.py" true "Python前端生成脚本"
  96. check_file "generate_backend_sourcecode.py" true "Python后端生成脚本"
  97. check_file "generate_all_sourcecode.sh" true "Shell全代码生成脚本"
  98. check_file "generate_frontend_sourcecode.sh" true "Shell前端生成脚本"
  99. check_file "generate_backend_sourcecode.sh" true "Shell后端生成脚本"
  100. # 文档文件
  101. check_file "README.md" true "项目说明文档"
  102. check_file "01-快速开始.md" true "快速开始指南"
  103. check_file "02-安装指南.md" true "安装指南"
  104. check_file "03-使用说明.md" true "使用说明"
  105. check_file "04-故障排除.md" true "故障排除指南"
  106. check_file "05-FAQ.md" true "常见问题文档"
  107. check_file "CLAUDE.md" true "Claude指导文档"
  108. check_file "CLAUDE_zh.md" true "Claude中文指导文档"
  109. check_file "ROADMAP.md" true "发展路线图"
  110. check_file "工作流程.md" true "工作流程文档"
  111. check_file "执行计划.md" true "执行计划文档"
  112. check_file "项目检查指南.md" true "项目检查指南文档"
  113. # 检查脚本自身
  114. check_file "check_project.py" true "Python检查脚本"
  115. }
  116. # 检查目录结构
  117. check_directory_structure() {
  118. print_header "目录结构完整性检查"
  119. check_directory "specs_docs" true "规范文档目录"
  120. check_directory "specs_docs/ui_design_specs" true "UI设计规范目录"
  121. check_directory "specs_docs/tech_stack_specs" true "技术栈规范目录"
  122. check_directory "system_prompts" true "AI提示词目录"
  123. check_directory "requires_docs" true "输入文档目录"
  124. check_directory "process_docs" true "流程文档目录"
  125. check_directory "output_docs" true "输出文档目录"
  126. check_directory "output_sourcecode" true "生成代码目录"
  127. check_directory "output_sourcecode/front" true "前端代码目录"
  128. check_directory "output_sourcecode/backend" true "后端代码目录"
  129. }
  130. # 检查UI设计规范
  131. check_ui_design_specs() {
  132. print_header "UI设计规范文件检查"
  133. check_file "specs_docs/ui_design_specs/01-UI设计规范_默认_Corporate.md" true "企业商务风格规范"
  134. check_file "specs_docs/ui_design_specs/02-UI设计规范_暗黑科技风格_Cyberpunk.md" true "暗黑科技风格规范"
  135. check_file "specs_docs/ui_design_specs/03-UI设计规范_极简主义风格_Minimal.md" true "极简主义风格规范"
  136. check_file "specs_docs/tech_stack_specs/技术栈说明文档_默认.md" true "默认技术栈说明"
  137. }
  138. # 检查AI系统提示词
  139. check_system_prompts() {
  140. print_header "AI系统提示词完整性检查"
  141. check_file "system_prompts/01-软著框架系统提示词.md" true "框架设计提示词"
  142. check_file "system_prompts/02-页面规划系统提示词.md" true "页面规划提示词"
  143. check_file "system_prompts/03-界面设计系统提示词.md" true "界面设计提示词"
  144. check_file "system_prompts/04-网页代码生成系统提示词.md" true "前端代码生成提示词"
  145. check_file "system_prompts/05-数据库代码生成系统提示词.md" true "数据库生成提示词"
  146. check_file "system_prompts/06-后端代码生成系统提示词.md" true "后端代码生成提示词"
  147. check_file "system_prompts/07-用户手册系统提示词.md" true "用户手册生成提示词"
  148. check_file "system_prompts/08-软件著作权登记信息表系统提示词.md" true "软著信息表生成提示词"
  149. }
  150. # 检查配置文件内容
  151. check_config_file() {
  152. print_header "配置文件内容检查"
  153. if [ ! -f "ai-copyright-config.json" ]; then
  154. print_error "配置文件 ai-copyright-config.json 不存在"
  155. return
  156. fi
  157. # 检查JSON格式
  158. if command -v jq >/dev/null 2>&1; then
  159. if jq empty ai-copyright-config.json >/dev/null 2>&1; then
  160. print_success "配置文件JSON格式正确"
  161. else
  162. print_error "配置文件JSON格式错误"
  163. return
  164. fi
  165. # 检查关键字段
  166. local fields=("front" "backend" "title" "short_title" "ui_design_style")
  167. for field in "${fields[@]}"; do
  168. if jq -e ".$field" ai-copyright-config.json >/dev/null 2>&1; then
  169. print_success "配置字段存在: $field"
  170. else
  171. print_error "配置字段缺失: $field"
  172. fi
  173. done
  174. # 检查UI设计风格值
  175. local ui_style=$(jq -r '.ui_design_style' ai-copyright-config.json 2>/dev/null)
  176. case "$ui_style" in
  177. "corporate"|"cyberpunk"|"minimal"|"bauhaus"|"japanese"|"scandinavian"|"futuristic"|"elegant"|"bold"|"artdeco"|"memphis"|"popart")
  178. print_success "UI设计风格有效: $ui_style"
  179. ;;
  180. *)
  181. print_warning "UI设计风格可能无效: $ui_style"
  182. ;;
  183. esac
  184. else
  185. print_warning "未安装jq,跳过JSON内容检查"
  186. # 简单检查文件是否包含基本字段
  187. if grep -q '"front"' ai-copyright-config.json && grep -q '"backend"' ai-copyright-config.json; then
  188. print_success "配置文件包含基本字段"
  189. else
  190. print_warning "配置文件可能缺少基本字段"
  191. fi
  192. fi
  193. }
  194. # 检查脚本语法
  195. check_script_syntax() {
  196. print_header "脚本语法检查"
  197. # 检查Python脚本语法
  198. local python_scripts=("init_project.py" "generate_all_sourcecode.py" "generate_frontend_sourcecode.py" "generate_backend_sourcecode.py" "check_project.py")
  199. for script in "${python_scripts[@]}"; do
  200. if [ -f "$script" ]; then
  201. if python3 -m py_compile "$script" 2>/dev/null; then
  202. print_success "Python脚本语法正确: $script"
  203. else
  204. print_error "Python脚本语法错误: $script"
  205. fi
  206. fi
  207. done
  208. # 检查Shell脚本语法
  209. local shell_scripts=("init_project.sh" "generate_all_sourcecode.sh" "generate_frontend_sourcecode.sh" "generate_backend_sourcecode.sh" "create-copyright-project")
  210. for script in "${shell_scripts[@]}"; do
  211. if [ -f "$script" ]; then
  212. if bash -n "$script" 2>/dev/null; then
  213. print_success "Shell脚本语法正确: $script"
  214. else
  215. print_error "Shell脚本语法错误: $script"
  216. fi
  217. fi
  218. done
  219. }
  220. # 检查文档引用一致性
  221. check_document_references() {
  222. print_header "文档引用一致性检查"
  223. local docs=("README.md" "01-快速开始.md" "03-使用说明.md" "工作流程.md" "04-故障排除.md" "05-FAQ.md" "CLAUDE.md" "CLAUDE_zh.md")
  224. local old_refs=0
  225. local new_refs=0
  226. local problematic_docs=0
  227. for doc in "${docs[@]}"; do
  228. if [ -f "$doc" ]; then
  229. # 检查旧配置文件引用(不包括 ai-copyright-config.json)
  230. # 查找独立的 config.json 引用,不包括 ai-copyright-config.json
  231. if grep -q "config\.json" "$doc"; then
  232. # 计算总的 config.json 出现次数
  233. local total_config=$(grep -c "config\.json" "$doc")
  234. # 计算 ai-copyright-config.json 出现次数
  235. local ai_config=$(grep -c "ai-copyright-config\.json" "$doc" 2>/dev/null || echo 0)
  236. # 独立的 config.json 引用 = 总数 - ai-copyright-config.json数量
  237. local isolated_matches=$((total_config - ai_config))
  238. if [ "$isolated_matches" -gt 0 ]; then
  239. # 检查是否是说明性文本(更名说明)
  240. if grep -q -E "(从.*config\.json.*更名|已从.*config\.json.*更名|config\.json.*更名为|配置文件.*从.*config\.json|原.*config\.json|旧.*config\.json|之前.*config\.json)" "$doc"; then
  241. print_success "文档包含配置文件更名说明: $doc"
  242. else
  243. old_refs=$((old_refs + isolated_matches))
  244. problematic_docs=$((problematic_docs + 1))
  245. print_warning "文档包含旧配置文件引用: $doc"
  246. fi
  247. fi
  248. fi
  249. # 检查新配置文件引用
  250. if grep -q "ai-copyright-config\.json" "$doc"; then
  251. local count=$(grep -c "ai-copyright-config\.json" "$doc")
  252. new_refs=$((new_refs + count))
  253. print_success "文档使用新配置文件名: $doc"
  254. fi
  255. fi
  256. done
  257. if [ $old_refs -eq 0 ]; then
  258. print_success "所有文档已更新为新配置文件名"
  259. else
  260. print_error "发现 $old_refs 处旧配置文件引用需要更新(在 $problematic_docs 个文档中)"
  261. fi
  262. }
  263. # 检查Git配置
  264. check_git_configuration() {
  265. print_header "Git配置检查"
  266. # 检查.gitignore
  267. if [ -f ".gitignore" ]; then
  268. print_success ".gitignore文件存在"
  269. # 检查关键忽略项
  270. local ignores=("ai-copyright-config_local.json" ".DS_Store" "__pycache__" "node_modules" "*.log")
  271. for ignore in "${ignores[@]}"; do
  272. if grep -q "$ignore" .gitignore; then
  273. print_success "包含忽略项: $ignore"
  274. else
  275. print_warning "缺少忽略项: $ignore"
  276. fi
  277. done
  278. else
  279. print_warning ".gitignore文件不存在"
  280. fi
  281. # 检查Git仓库
  282. if [ -d ".git" ]; then
  283. print_success "Git仓库已初始化"
  284. else
  285. print_warning "未初始化Git仓库"
  286. fi
  287. }
  288. # 生成检查报告
  289. generate_report() {
  290. print_header "检查报告汇总"
  291. local total=$((SUCCESS_COUNT + WARNING_COUNT + ERROR_COUNT))
  292. print_colored $CYAN "📊 检查统计:"
  293. print_colored $GREEN " ✅ 成功: $SUCCESS_COUNT"
  294. print_colored $YELLOW " ⚠️ 警告: $WARNING_COUNT"
  295. print_colored $RED " ❌ 错误: $ERROR_COUNT"
  296. print_colored $BLUE " 📋 总计: $total"
  297. # 计算健康度分数
  298. if [ $total -gt 0 ]; then
  299. local health_score=$(( (SUCCESS_COUNT * 100) / total ))
  300. print_colored $PURPLE " 💯 健康度: ${health_score}%"
  301. fi
  302. echo
  303. echo "============================================================"
  304. if [ $ERROR_COUNT -eq 0 ]; then
  305. if [ $WARNING_COUNT -eq 0 ]; then
  306. print_colored $GREEN "🎉 项目检查完全通过!系统可以正常使用。"
  307. return 0
  308. else
  309. print_colored $YELLOW "✅ 项目检查基本通过,有一些警告需要注意。"
  310. return 1
  311. fi
  312. else
  313. print_colored $RED "❌ 项目检查发现错误,需要修复后才能正常使用。"
  314. print_colored $RED "🔧 请运行 Python 版本获取详细错误信息: python3 check_project.py"
  315. return 2
  316. fi
  317. }
  318. # 主函数
  319. main() {
  320. local project_dir=${1:-.}
  321. local quick_mode=${2:-false}
  322. # 切换到项目目录
  323. if [ ! -d "$project_dir" ]; then
  324. print_colored $RED "❌ 项目目录不存在: $project_dir"
  325. exit 1
  326. fi
  327. cd "$project_dir"
  328. print_colored $PURPLE "🚀 开始AI软著申请材料生成系统完整性检查 (Shell版本)"
  329. print_colored $BLUE "📁 检查目录: $(pwd)"
  330. if [ "$quick_mode" = "true" ]; then
  331. print_colored $YELLOW "⚡ 快速检查模式"
  332. fi
  333. # 执行检查
  334. check_core_files
  335. check_directory_structure
  336. check_ui_design_specs
  337. check_system_prompts
  338. check_config_file
  339. check_document_references
  340. check_git_configuration
  341. if [ "$quick_mode" != "true" ]; then
  342. check_script_syntax
  343. fi
  344. # 生成报告
  345. generate_report
  346. return $?
  347. }
  348. # 显示帮助信息
  349. show_help() {
  350. echo "AI驱动软件著作权申请材料生成系统 - 项目完整性检查工具 (Shell版本)"
  351. echo
  352. echo "用法:"
  353. echo " $0 [项目目录] [选项]"
  354. echo
  355. echo "参数:"
  356. echo " 项目目录 项目目录路径(默认为当前目录)"
  357. echo
  358. echo "选项:"
  359. echo " --quick 快速检查模式(跳过语法检查)"
  360. echo " --help 显示此帮助信息"
  361. echo
  362. echo "示例:"
  363. echo " $0 # 检查当前目录"
  364. echo " $0 /path/to/project # 检查指定目录"
  365. echo " $0 . --quick # 快速检查当前目录"
  366. echo
  367. }
  368. # 处理命令行参数
  369. if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
  370. show_help
  371. exit 0
  372. fi
  373. if [ "$2" = "--quick" ] || [ "$1" = "--quick" ]; then
  374. if [ "$1" = "--quick" ]; then
  375. main "." true
  376. else
  377. main "$1" true
  378. fi
  379. else
  380. main "$1" false
  381. fi
  382. exit $?