generate_all_sourcecode.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. 统一源代码文档生成脚本
  5. 一次性生成前端、后端和数据库的所有源代码文档
  6. """
  7. import os
  8. import subprocess
  9. import sys
  10. from datetime import datetime
  11. def run_script(script_name, description):
  12. """
  13. 运行指定的脚本
  14. """
  15. print(f"\n{'='*60}")
  16. print(f"正在执行: {description}")
  17. print(f"脚本: {script_name}")
  18. print(f"{'='*60}")
  19. try:
  20. # 检查脚本是否存在
  21. if not os.path.exists(script_name):
  22. print(f"❌ 错误:脚本文件不存在 {script_name}")
  23. return False
  24. # 运行脚本
  25. result = subprocess.run([sys.executable, script_name],
  26. capture_output=True,
  27. text=True,
  28. encoding='utf-8')
  29. if result.returncode == 0:
  30. print(result.stdout)
  31. print(f"✅ {description} 执行成功!")
  32. return True
  33. else:
  34. print(f"❌ {description} 执行失败!")
  35. print("错误信息:")
  36. print(result.stderr)
  37. return False
  38. except Exception as e:
  39. print(f"❌ 执行 {description} 时出错: {e}")
  40. return False
  41. def main():
  42. """
  43. 主函数
  44. """
  45. print("="*80)
  46. print("统一源代码文档生成脚本")
  47. print("="*80)
  48. print(f"开始时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
  49. # 定义要执行的脚本
  50. scripts = [
  51. ("generate_frontend_sourcecode.py", "前端源代码文档生成"),
  52. ("generate_backend_sourcecode.py", "后端源代码文档生成"),
  53. ]
  54. success_count = 0
  55. total_count = len(scripts)
  56. # 逐个执行脚本
  57. for script_name, description in scripts:
  58. if run_script(script_name, description):
  59. success_count += 1
  60. # 输出总结
  61. print(f"\n{'='*80}")
  62. print("执行总结")
  63. print(f"{'='*80}")
  64. print(f"总脚本数: {total_count}")
  65. print(f"成功执行: {success_count}")
  66. print(f"失败数量: {total_count - success_count}")
  67. print(f"完成时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
  68. if success_count == total_count:
  69. print("\n🎉 所有源代码文档生成完成!")
  70. print("\n📁 生成的文档:")
  71. print(" - output_docs/前端源代码.txt")
  72. print(" - output_docs/后端源代码.txt")
  73. print("\n💡 注意:数据库代码.txt 需要通过系统提示词在AI生成阶段直接创建")
  74. return 0
  75. else:
  76. print(f"\n⚠️ 有 {total_count - success_count} 个脚本执行失败,请检查错误信息")
  77. return 1
  78. if __name__ == "__main__":
  79. exit(main())