init_project.py 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. AI驱动的企业级软件开发工作流程 - 项目初始化脚本 (Python版本)
  5. 版本: 1.0
  6. 描述: 自动创建新项目的目录结构和固定文档
  7. """
  8. import os
  9. import sys
  10. import json
  11. import shutil
  12. import argparse
  13. import locale
  14. from datetime import datetime
  15. # 设置系统编码
  16. if sys.platform.startswith('win'):
  17. import codecs
  18. sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer)
  19. sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer)
  20. # 确保终端编码为UTF-8
  21. os.environ['PYTHONIOENCODING'] = 'utf-8'
  22. from pathlib import Path
  23. class Colors:
  24. """终端颜色定义"""
  25. RED = '\033[0;31m'
  26. GREEN = '\033[0;32m'
  27. YELLOW = '\033[1;33m'
  28. BLUE = '\033[0;34m'
  29. NC = '\033[0m' # No Color
  30. def print_message(color, message):
  31. """打印带颜色的消息"""
  32. print(f"{color}{message}{Colors.NC}")
  33. def print_success(message):
  34. print_message(Colors.GREEN, f"✓ {message}")
  35. def print_info(message):
  36. print_message(Colors.BLUE, f"ℹ {message}")
  37. def print_warning(message):
  38. print_message(Colors.YELLOW, f"⚠ {message}")
  39. def print_error(message):
  40. print_message(Colors.RED, f"✗ {message}")
  41. def get_user_input(prompt, default=""):
  42. """获取用户输入,支持默认值"""
  43. try:
  44. if default:
  45. user_input = input(f"{prompt} (默认: {default}): ").strip()
  46. return user_input if user_input else default
  47. else:
  48. return input(f"{prompt}: ").strip()
  49. except UnicodeDecodeError:
  50. print_error("输入编码错误,请确保终端支持UTF-8编码")
  51. return default if default else ""
  52. except KeyboardInterrupt:
  53. print_error("用户中断操作")
  54. sys.exit(1)
  55. except Exception as e:
  56. print_error(f"输入错误: {e}")
  57. return default if default else ""
  58. def get_yes_no_input(prompt, default_no=True):
  59. """获取是/否输入"""
  60. try:
  61. suffix = "(y/N)" if default_no else "(Y/n)"
  62. response = input(f"{prompt} {suffix}: ").strip().lower()
  63. if default_no:
  64. return response in ['y', 'yes', '是']
  65. else:
  66. return response not in ['n', 'no', '否']
  67. except UnicodeDecodeError:
  68. print_error("输入编码错误,请确保终端支持UTF-8编码")
  69. return not default_no
  70. except KeyboardInterrupt:
  71. print_error("用户中断操作")
  72. sys.exit(1)
  73. except Exception as e:
  74. print_error(f"输入错误: {e}")
  75. return not default_no
  76. def get_generation_mode_config():
  77. """获取用户选择的生成模式配置"""
  78. print_info("请选择生成模式:")
  79. print("1. fast - 快速验证模式(5页面,8-15个API,适合快速原型和测试)")
  80. print("2. full - 完整生产模式(10页面,15-35个API,适合正式申请和完整系统)")
  81. print()
  82. while True:
  83. choice = input("请输入选择 (1-2,默认为1): ").strip()
  84. if choice == "" or choice == "1":
  85. return {
  86. "generation_mode": "fast",
  87. "page_count": 5,
  88. "api_count_min": 8,
  89. "api_count_max": 15
  90. }
  91. elif choice == "2":
  92. return {
  93. "generation_mode": "full",
  94. "page_count": 10,
  95. "api_count_min": 15,
  96. "api_count_max": 35
  97. }
  98. else:
  99. print_warning("无效选择,请输入 1 或 2")
  100. def get_ui_design_style():
  101. """获取用户选择的UI设计风格"""
  102. print_info("请选择UI设计风格:")
  103. styles = [
  104. ("corporate", "企业商务风格(默认)", "企业管理系统、办公软件、政务系统、金融应用等", "专业稳重、通用性强、符合主流商务审美"),
  105. ("cyberpunk", "暗黑科技风格", "开发者工具、数据分析平台、科技产品、游戏相关应用等", "科技感强、适合夜间使用、吸引年轻用户群体"),
  106. ("minimal", "极简主义风格", "内容管理系统、阅读类应用、教育平台、专业工具等", "简洁优雅、专注内容、永恒的设计价值"),
  107. ("bauhaus", "包豪斯风格", "设计工具平台、建筑设计系统、艺术展览平台、学术研究工具", "功能至上、几何纯粹、理性秩序"),
  108. ("japanese", "日式极简风格", "冥想禅修应用、文化艺术平台、阅读写作工具、生活方式应用", "侘寂美学、间之道、静谧禅意"),
  109. ("scandinavian", "斯堪的纳维亚风格", "生活方式应用、健康养生平台、教育学习工具、家庭管理系统", "功能简约、温暖质感、自然和谐"),
  110. ("futuristic", "未来科技风格", "数据分析平台、开发者工具、网络安全系统、金融交易平台", "数字未来、HUD界面、信息密集"),
  111. ("elegant", "优雅复古风格", "文化教育平台、学术研究工具、图书馆系统、博物馆应用", "古典雅致、印刷美学、温暖怀旧"),
  112. ("bold", "大胆现代风格", "创意设计平台、时尚品牌网站、科技创新产品、营销活动平台", "大胆突破、现代前卫、视觉冲击"),
  113. ("artdeco", "艺术装饰风格", "奢侈品电商、高端酒店餐饮、艺术文化机构、金融投资平台", "装饰艺术、几何奢华、对称美学"),
  114. ("memphis", "孟菲斯风格", "创意设计平台、娱乐媒体应用、时尚潮流品牌、青年社交应用", "后现代反叛、色彩狂欢、几何拼贴"),
  115. ("popart", "波普艺术风格", "娱乐媒体平台、时尚购物平台、创意营销工具、社交娱乐应用", "大众文化、明亮色彩、商业美学")
  116. ]
  117. # 显示所有风格选项
  118. for i, (key, name, use_cases, features) in enumerate(styles, 1):
  119. print(f"{i:2d}. {key} - {name}")
  120. print(f" 适用于:{use_cases}")
  121. print(f" 特点:{features}")
  122. print()
  123. # 获取用户选择
  124. while True:
  125. choice = input(f"请输入选择 (1-{len(styles)},默认为1): ").strip()
  126. if choice == "" or choice == "1":
  127. return "corporate"
  128. try:
  129. choice_num = int(choice)
  130. if 1 <= choice_num <= len(styles):
  131. return styles[choice_num - 1][0]
  132. else:
  133. print_warning(f"无效选择,请输入 1 到 {len(styles)} 之间的数字")
  134. except ValueError:
  135. print_warning(f"无效输入,请输入 1 到 {len(styles)} 之间的数字")
  136. def create_directory_structure(project_dir):
  137. """创建项目目录结构"""
  138. directories = [
  139. "specs_docs/ui_design_specs",
  140. "specs_docs/tech_stack_specs",
  141. "system_prompts",
  142. "requires_docs",
  143. "process_docs",
  144. "output_docs",
  145. "output_sourcecode/front",
  146. "output_sourcecode/backend",
  147. "output_sourcecode/db",
  148. "scripts/generators",
  149. "scripts/validators"
  150. ]
  151. for directory in directories:
  152. os.makedirs(project_dir / directory, exist_ok=True)
  153. print_success("目录结构创建完成")
  154. def copy_fixed_documents(script_dir, project_dir, ui_design_style):
  155. """复制固定文档和系统提示词"""
  156. specs_source = script_dir / "specs_docs"
  157. if not specs_source.exists():
  158. print_error(f"源文件目录不存在: {specs_source}")
  159. print_info("请确保脚本在包含 specs_docs 目录的项目根目录中运行")
  160. sys.exit(1)
  161. # UI风格映射表
  162. ui_style_mapping = {
  163. "corporate": "01-UI设计规范_默认_Corporate.md",
  164. "cyberpunk": "02-UI设计规范_暗黑科技风格_Cyberpunk.md",
  165. "minimal": "03-UI设计规范_极简主义风格_Minimal.md",
  166. "bauhaus": "04-UI设计规范_包豪斯风格_Bauhaus.md",
  167. "japanese": "05-UI设计规范_日式极简风格_Japanese.md",
  168. "scandinavian": "06-UI设计规范_斯堪的纳维亚风格_Scandinavian.md",
  169. "futuristic": "07-UI设计规范_未来科技风格_Futuristic.md",
  170. "elegant": "08-UI设计规范_优雅复古风格_Elegant.md",
  171. "bold": "09-UI设计规范_大胆现代风格_Bold.md",
  172. "artdeco": "10-UI设计规范_艺术装饰风格_ArtDeco.md",
  173. "memphis": "11-UI设计规范_孟菲斯风格_Memphis.md",
  174. "popart": "12-UI设计规范_波普艺术风格_PopArt.md"
  175. }
  176. # 只复制选择的UI设计规范文档和默认的企业风格(作为备用参考)
  177. ui_design_files_to_copy = [ui_style_mapping[ui_design_style]]
  178. if ui_design_style != "corporate":
  179. ui_design_files_to_copy.append(ui_style_mapping["corporate"]) # 添加默认风格作为参考
  180. for file_name in ui_design_files_to_copy:
  181. src = specs_source / "ui_design_specs" / file_name
  182. dst = project_dir / "specs_docs" / "ui_design_specs" / file_name
  183. if src.exists():
  184. shutil.copy2(src, dst)
  185. print_info(f"复制UI设计规范: {file_name}")
  186. # 复制技术栈规范文档
  187. tech_stack_file = "技术栈说明文档_默认.md"
  188. src = specs_source / "tech_stack_specs" / tech_stack_file
  189. dst = project_dir / "specs_docs" / "tech_stack_specs" / tech_stack_file
  190. if src.exists():
  191. shutil.copy2(src, dst)
  192. # 复制系统提示词
  193. system_prompt_src = script_dir / "system_prompts"
  194. system_prompt_dst = project_dir / "system_prompts"
  195. if system_prompt_src.exists():
  196. for file_path in system_prompt_src.glob("*.md"):
  197. shutil.copy2(file_path, system_prompt_dst / file_path.name)
  198. # 复制scripts目录(生成和验证脚本)
  199. scripts_src = script_dir / "scripts"
  200. scripts_dst = project_dir / "scripts"
  201. if scripts_src.exists():
  202. # 复制generators目录下的所有脚本
  203. generators_src = scripts_src / "generators"
  204. generators_dst = scripts_dst / "generators"
  205. if generators_src.exists():
  206. for file_path in generators_src.iterdir():
  207. if file_path.is_file():
  208. shutil.copy2(file_path, generators_dst / file_path.name)
  209. print_info(f"复制生成脚本: {file_path.name}")
  210. # 复制validators目录下的所有脚本
  211. validators_src = scripts_src / "validators"
  212. validators_dst = scripts_dst / "validators"
  213. if validators_src.exists():
  214. for file_path in validators_src.iterdir():
  215. if file_path.is_file():
  216. shutil.copy2(file_path, validators_dst / file_path.name)
  217. print_info(f"复制验证脚本: {file_path.name}")
  218. # 复制工作流程文档和执行计划文档
  219. workflow_files = [
  220. "工作流程.md",
  221. "执行计划.md"
  222. ]
  223. for workflow_file in workflow_files:
  224. src = script_dir / workflow_file
  225. if src.exists():
  226. shutil.copy2(src, project_dir / workflow_file)
  227. else:
  228. print_warning(f"工作流程文档不存在: {src}")
  229. print_success("固定文档复制完成")
  230. def create_config_file(project_dir, config):
  231. """创建配置文件"""
  232. # UI风格映射到文件路径
  233. ui_style_file_mapping = {
  234. "corporate": "specs_docs/ui_design_specs/01-UI设计规范_默认_Corporate.md",
  235. "cyberpunk": "specs_docs/ui_design_specs/02-UI设计规范_暗黑科技风格_Cyberpunk.md",
  236. "minimal": "specs_docs/ui_design_specs/03-UI设计规范_极简主义风格_Minimal.md",
  237. "bauhaus": "specs_docs/ui_design_specs/04-UI设计规范_包豪斯风格_Bauhaus.md",
  238. "japanese": "specs_docs/ui_design_specs/05-UI设计规范_日式极简风格_Japanese.md",
  239. "scandinavian": "specs_docs/ui_design_specs/06-UI设计规范_斯堪的纳维亚风格_Scandinavian.md",
  240. "futuristic": "specs_docs/ui_design_specs/07-UI设计规范_未来科技风格_Futuristic.md",
  241. "elegant": "specs_docs/ui_design_specs/08-UI设计规范_优雅复古风格_Elegant.md",
  242. "bold": "specs_docs/ui_design_specs/09-UI设计规范_大胆现代风格_Bold.md",
  243. "artdeco": "specs_docs/ui_design_specs/10-UI设计规范_艺术装饰风格_ArtDeco.md",
  244. "memphis": "specs_docs/ui_design_specs/11-UI设计规范_孟菲斯风格_Memphis.md",
  245. "popart": "specs_docs/ui_design_specs/12-UI设计规范_波普艺术风格_PopArt.md"
  246. }
  247. config_data = {
  248. "_comment_init": "=== 项目初始化配置(用户设置) ===",
  249. "front": config['front_tech'],
  250. "backend": config['backend_tech'],
  251. "title": config['system_title'],
  252. "short_title": config['system_short_title'],
  253. "requirements_description": "requires_docs/需求文档.md",
  254. "dev_tech_stack": config['tech_stack_path'],
  255. "ui_design_spec": ui_style_file_mapping[config['ui_design_style']],
  256. "ui_design_style": config['ui_design_style'],
  257. "_comment_generation": "=== 生成配置(可调整) ===",
  258. "page_count_fast": 5,
  259. "page_count_full": 10,
  260. "api_count_min": config['api_count_min'],
  261. "api_count_max": config['api_count_max'],
  262. "generation_mode": config['generation_mode'],
  263. "_comment_usage": "=== 使用说明 ===",
  264. "_usage_note_1": "1. 请务必修改上方的 title 和 short_title 为您的实际项目名称",
  265. "_usage_note_2": "2. front 和 backend 可根据实际技术栈修改(如 React, Vue, Python, Node.js 等)",
  266. "_usage_note_3": "3. UI设计风格已设置为 " + config['ui_design_style'] + ",可修改为 corporate(企业商务)、cyberpunk(暗黑科技)、minimal(极简主义)、bauhaus(包豪斯)、japanese(日式极简)、scandinavian(斯堪的纳维亚)、futuristic(未来科技)、elegant(优雅复古)、bold(大胆现代)、artdeco(艺术装饰)、memphis(孟菲斯)、popart(波普艺术)",
  267. "_usage_note_4": "4. 生成配置已设置为 " + config['generation_mode'] + " 模式,可调整:generation_mode(fast快速验证/full完整生产),page_count_fast/full(各模式页面数量),api_count_min/max(API数量范围)",
  268. "_usage_note_5": "5. 详细填写 requires_docs/需求文档.md 文件(必需)",
  269. "_usage_note_6": "6. 可选填写 requires_docs/技术栈说明文档.md 和 requires_docs/UI设计规范.md(如提供自定义UI规范,需手动修改ui_design_spec路径)",
  270. "_usage_note_7": "7. 最后按照 工作流程.md 或 01-快速开始.md 执行八阶段生成流程",
  271. "_comment_fixed": "=== 固定配置(请勿修改) ===",
  272. "system_prompt_dir": "system_prompts",
  273. "ui_design_spec_default": "specs_docs/ui_design_specs/01-UI设计规范_默认_Corporate.md",
  274. "_comment_generated": "=== 流程生成配置(自动生成) ===",
  275. "framework_design": f"process_docs/{config['system_title']}_框架设计文档.md",
  276. "page_list": "process_docs/页面清单.md",
  277. "database_schema": "output_sourcecode/db/database_schema.sql",
  278. "copyright_application": f"output_docs/{config['system_title']}_软件著作权登记信息表.md"
  279. }
  280. config_file = project_dir / "ai-copyright-config.json"
  281. with open(config_file, 'w', encoding='utf-8') as f:
  282. json.dump(config_data, f, ensure_ascii=False, indent=2)
  283. print_success("配置文件创建完成")
  284. def create_readme(project_dir, config):
  285. """创建 README.md 文件"""
  286. readme_content = f"""# {config['system_title']}
  287. 这是一个使用AI驱动的企业级软件开发工作流程创建的项目。
  288. ## 项目信息
  289. - **系统名称**: {config['system_title']}
  290. - **系统简称**: {config['system_short_title']}
  291. - **前端技术**: {config['front_tech']}
  292. - **后端技术**: {config['backend_tech']}
  293. - **创建时间**: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
  294. ## 目录结构
  295. ```
  296. {config['project_name']}/
  297. ├── ai-copyright-config.json # 项目全局配置文件
  298. ├── workflow.md # 工作流程文档
  299. ├── specs_docs/ # 固定规范文档目录
  300. │ ├── ui_design_specs/ # UI设计规范子目录
  301. │ │ └── [选择的UI设计风格文档] # 根据用户选择的UI风格复制相应文档
  302. │ └── tech_stack_specs/ # 技术栈规范子目录
  303. │ └── 技术栈说明文档_默认.md # 默认技术栈说明模板
  304. ├── system_prompts/ # 系统提示词目录(固定不变)
  305. ├── scripts/ # 生成和验证脚本目录
  306. │ ├── generators/ # 代码生成和合并脚本
  307. │ └── validators/ # 项目验证脚本
  308. ├── requires_docs/ # 输入文档目录
  309. │ └── 需求文档.md # 核心业务需求规格说明(待创建)
  310. ├── process_docs/ # 流程中间文档目录
  311. ├── output_docs/ # 最终交付文档目录
  312. └── output_sourcecode/ # 生成代码目录
  313. ├── front/ # 前端页面代码
  314. ├── backend/ # 后端项目代码
  315. └── db/ # 数据库相关文件
  316. ```
  317. ## 下一步操作
  318. 1. **创建需求文档**: 在 `requires_docs/` 目录下创建您的需求文档
  319. 2. **技术栈配置**: 如果需要自定义技术栈,请创建 `requires_docs/技术栈说明文档.md`
  320. 3. **开始开发**: 按照 `workflow.md` 中的八阶段开发流程执行
  321. ## 工作流程
  322. 详细的开发流程请参考 `workflow.md` 文档,包含以下阶段:
  323. 1. 项目初始化和框架设计
  324. 2. 系统提示词体系建设
  325. 3. 前端页面设计和开发
  326. 4. 数据库和后端开发
  327. 5. 文档生成
  328. 6. 项目整理和交付
  329. ## 支持
  330. 如有问题,请参考 `workflow.md` 中的详细说明。
  331. """
  332. readme_file = project_dir / "README.md"
  333. with open(readme_file, 'w', encoding='utf-8') as f:
  334. f.write(readme_content)
  335. def create_requirements_template(project_dir, config):
  336. """创建需求文档模板"""
  337. requirements_content = f"""# {config['system_title']} 需求文档
  338. ## 项目背景
  339. 请在此描述项目的背景和目标。
  340. ## 功能需求
  341. ### 核心功能
  342. 1. 功能一
  343. - 详细描述
  344. - 业务规则
  345. - 用户角色
  346. 2. 功能二
  347. - 详细描述
  348. - 业务规则
  349. - 用户角色
  350. ### 非功能需求
  351. - 性能要求
  352. - 安全要求
  353. - 可用性要求
  354. ## 技术要求
  355. - 前端技术: {config['front_tech']}
  356. - 后端技术: {config['backend_tech']}
  357. - 其他技术要求
  358. ## 用户角色
  359. - 角色一: 描述
  360. - 角色二: 描述
  361. ## 业务流程
  362. 请描述主要的业务流程。
  363. ---
  364. *请根据实际项目需求完善此文档内容*
  365. """
  366. requirements_file = project_dir / "requires_docs" / "需求文档.md"
  367. with open(requirements_file, 'w', encoding='utf-8') as f:
  368. f.write(requirements_content)
  369. def create_ui_design_template(project_dir, config):
  370. """创建UI设计规范模板"""
  371. ui_design_content = f"""# UI设计规范 - {config['system_title']}
  372. > 📝 **使用说明**:本文档为可选输入文档。如不提供,系统将使用默认的UI设计规范。
  373. >
  374. > 🎯 **目的**:定义本软件项目的专属UI设计理念、风格和规范,体现软件的独特性和创新性。
  375. ## 项目设计定位
  376. ### 设计理念
  377. <!-- 请描述本软件的设计理念,例如:现代简约、科技感、专业商务、友好亲民等 -->
  378. ### 目标用户群体
  379. <!-- 请描述主要用户群体,设计风格应该符合用户群体的审美和使用习惯 -->
  380. ### 设计创新点
  381. <!-- 请描述本软件在UI设计方面的创新点和特色功能 -->
  382. ## 色彩系统
  383. ### 主色调
  384. <!-- 请定义软件的主品牌色彩,建议提供具体的色值 -->
  385. - 主色:#[请填写]
  386. - 辅助色:#[请填写]
  387. ### 功能色彩
  388. <!-- 定义成功、警告、错误等状态的色彩 -->
  389. - 成功色:#[请填写]
  390. - 警告色:#[请填写]
  391. - 错误色:#[请填写]
  392. ### 中性色
  393. <!-- 定义文字、背景、边框等中性色彩 -->
  394. - 背景色:#[请填写]
  395. - 文字色:#[请填写]
  396. - 边框色:#[请填写]
  397. ## 设计风格
  398. ### 整体风格
  399. <!-- 选择设计风格:扁平化、拟物化、毛玻璃、渐变、极简等 -->
  400. ### 圆角规范
  401. <!-- 定义按钮、卡片等元素的圆角大小 -->
  402. ### 阴影效果
  403. <!-- 定义卡片、弹窗等元素的阴影样式 -->
  404. ### 字体规范
  405. <!-- 定义标题、正文、说明文字的字体大小和样式 -->
  406. ## 组件设计规范
  407. ### 按钮设计
  408. <!-- 描述主按钮、次要按钮、文字按钮的设计规范 -->
  409. ### 表单设计
  410. <!-- 描述输入框、下拉框、复选框等表单元素的设计 -->
  411. ### 导航设计
  412. <!-- 描述顶部导航、侧边栏、面包屑等导航元素的设计 -->
  413. ### 数据展示
  414. <!-- 描述表格、图表、卡片等数据展示组件的设计 -->
  415. ## 页面布局规范
  416. ### 栅格系统
  417. <!-- 定义页面的栅格布局规则 -->
  418. ### 间距规范
  419. <!-- 定义元素间的间距标准 -->
  420. ### 响应式设计
  421. <!-- 描述在不同屏幕尺寸下的适配方案 -->
  422. ## 交互设计
  423. ### 动效设计
  424. <!-- 描述页面切换、元素交互的动效规范 -->
  425. ### 反馈机制
  426. <!-- 描述加载状态、操作反馈的设计规范 -->
  427. ### 错误处理
  428. <!-- 描述错误提示、空状态页面的设计 -->
  429. ## 特色功能设计
  430. ### 创新交互
  431. <!-- 描述本软件独有的交互方式或界面元素 -->
  432. ### 用户体验优化
  433. <!-- 描述针对特定业务场景的UX优化设计 -->
  434. ## 设计资源
  435. ### 图标风格
  436. <!-- 描述使用的图标库或自定义图标风格 -->
  437. ### 插图风格
  438. <!-- 如使用插图,描述插图的风格和应用场景 -->
  439. ---
  440. **注意**:
  441. 1. 请根据您的软件项目特点填写具体内容
  442. 2. 这些设计规范将影响前端页面的生成效果
  443. 3. 建议体现软件的独特性和创新性,有助于软著申请
  444. 4. 如不提供此文档,系统将使用通用的默认设计规范
  445. """
  446. ui_design_file = project_dir / "requires_docs" / "UI设计规范.md"
  447. with open(ui_design_file, 'w', encoding='utf-8') as f:
  448. f.write(ui_design_content)
  449. def create_gitignore(project_dir):
  450. """创建 .gitignore 文件"""
  451. gitignore_content = """# OS generated files
  452. .DS_Store
  453. .DS_Store?
  454. ._*
  455. .Spotlight-V100
  456. .Trashes
  457. ehthumbs.db
  458. Thumbs.db
  459. # IDE files
  460. .vscode/
  461. .idea/
  462. *.swp
  463. *.swo
  464. # Temporary files
  465. *.tmp
  466. *.temp
  467. .temp/
  468. # Logs
  469. *.log
  470. logs/
  471. # Node modules (if applicable)
  472. node_modules/
  473. # Java compiled files
  474. *.class
  475. target/
  476. # Python
  477. __pycache__/
  478. *.py[cod]
  479. *$py.class
  480. *.so
  481. .Python
  482. env/
  483. venv/
  484. .venv/
  485. # Backup files
  486. *.backup
  487. *.bak
  488. """
  489. gitignore_file = project_dir / ".gitignore"
  490. with open(gitignore_file, 'w', encoding='utf-8') as f:
  491. f.write(gitignore_content)
  492. def validate_project_integrity(project_dir, config):
  493. """初始化后完整性验证"""
  494. print_info("开始项目完整性验证...")
  495. validation_results = []
  496. # 1. 验证目录结构
  497. required_dirs = [
  498. "specs_docs/ui_design_specs",
  499. "specs_docs/tech_stack_specs",
  500. "system_prompts",
  501. "requires_docs",
  502. "process_docs",
  503. "output_docs",
  504. "output_sourcecode/front",
  505. "output_sourcecode/backend",
  506. "output_sourcecode/db",
  507. "scripts/generators",
  508. "scripts/validators"
  509. ]
  510. for directory in required_dirs:
  511. dir_path = project_dir / directory
  512. if dir_path.exists():
  513. validation_results.append(f"✓ 目录存在: {directory}")
  514. else:
  515. validation_results.append(f"✗ 目录缺失: {directory}")
  516. print_error(f"关键目录缺失: {directory}")
  517. # 2. 验证配置文件
  518. config_file = project_dir / "ai-copyright-config.json"
  519. if config_file.exists():
  520. try:
  521. with open(config_file, 'r', encoding='utf-8') as f:
  522. config_data = json.load(f)
  523. # 检查关键配置项
  524. required_keys = ['title', 'ui_design_style', 'generation_mode', 'ui_design_spec']
  525. for key in required_keys:
  526. if key in config_data:
  527. validation_results.append(f"✓ 配置项存在: {key}")
  528. else:
  529. validation_results.append(f"✗ 配置项缺失: {key}")
  530. # 验证UI设计规范文件存在
  531. ui_spec_path = project_dir / config_data.get('ui_design_spec', '')
  532. if ui_spec_path.exists():
  533. validation_results.append(f"✓ UI设计规范文件存在")
  534. else:
  535. validation_results.append(f"✗ UI设计规范文件缺失: {config_data.get('ui_design_spec', '')}")
  536. except json.JSONDecodeError:
  537. validation_results.append("✗ 配置文件JSON格式错误")
  538. print_error("配置文件JSON格式错误")
  539. except Exception as e:
  540. validation_results.append(f"✗ 配置文件验证失败: {str(e)}")
  541. else:
  542. validation_results.append("✗ 配置文件不存在")
  543. print_error("配置文件不存在")
  544. # 3. 验证系统提示词
  545. prompt_dir = project_dir / "system_prompts"
  546. expected_prompts = [
  547. "01-软著框架系统提示词.md",
  548. "02-页面规划系统提示词.md",
  549. "03-界面设计系统提示词.md",
  550. "04-网页代码生成系统提示词.md",
  551. "05-数据库代码生成系统提示词.md",
  552. "06-后端代码生成系统提示词.md",
  553. "07-用户手册系统提示词.md",
  554. "08-软件著作权登记信息表系统提示词.md"
  555. ]
  556. for prompt_file in expected_prompts:
  557. prompt_path = prompt_dir / prompt_file
  558. if prompt_path.exists():
  559. validation_results.append(f"✓ 系统提示词存在: {prompt_file}")
  560. else:
  561. validation_results.append(f"✗ 系统提示词缺失: {prompt_file}")
  562. # 4. 验证脚本权限和可执行性
  563. script_dir = project_dir / "scripts" / "generators"
  564. if script_dir.exists():
  565. bash_scripts = list(script_dir.glob("*.sh"))
  566. if bash_scripts:
  567. validation_results.append(f"✓ 发现 {len(bash_scripts)} 个Bash脚本")
  568. # 检查脚本权限
  569. for script in bash_scripts[:3]: # 检查前几个即可
  570. if os.access(script, os.X_OK):
  571. validation_results.append(f"✓ 脚本可执行: {script.name}")
  572. else:
  573. validation_results.append(f"⚠ 脚本需要执行权限: {script.name}")
  574. # 自动修复权限
  575. try:
  576. script.chmod(0o755)
  577. validation_results.append(f"✓ 已修复执行权限: {script.name}")
  578. except:
  579. validation_results.append(f"✗ 权限修复失败: {script.name}")
  580. else:
  581. validation_results.append("✗ 未发现生成脚本")
  582. # 5. 生成验证报告
  583. error_count = len([r for r in validation_results if r.startswith('✗')])
  584. warning_count = len([r for r in validation_results if r.startswith('⚠')])
  585. success_count = len([r for r in validation_results if r.startswith('✓')])
  586. print()
  587. print_info("=== 项目完整性验证报告 ===")
  588. for result in validation_results:
  589. if result.startswith('✓'):
  590. print_success(result[2:])
  591. elif result.startswith('⚠'):
  592. print_warning(result[2:])
  593. elif result.startswith('✗'):
  594. print_error(result[2:])
  595. print()
  596. print_info(f"验证统计: 成功 {success_count} | 警告 {warning_count} | 错误 {error_count}")
  597. if error_count == 0:
  598. print_success("项目初始化验证通过!")
  599. return True
  600. else:
  601. print_error(f"发现 {error_count} 个严重问题,请检查修复后重新验证")
  602. return False
  603. def print_directory_tree(project_dir):
  604. """打印目录结构"""
  605. print_info("项目目录结构:")
  606. def print_tree(directory, prefix=""):
  607. """递归打印目录树"""
  608. items = sorted(directory.iterdir())
  609. for i, item in enumerate(items):
  610. is_last_item = i == len(items) - 1
  611. current_prefix = "└── " if is_last_item else "├── "
  612. print(f"{prefix}{current_prefix}{item.name}")
  613. if item.is_dir() and not item.name.startswith('.'):
  614. extension = " " if is_last_item else "│ "
  615. print_tree(item, prefix + extension)
  616. print_tree(project_dir)
  617. def main():
  618. """主函数"""
  619. parser = argparse.ArgumentParser(description='AI驱动的企业级软件开发工作流程 - 项目初始化脚本')
  620. parser.add_argument('project_name', help='项目名称')
  621. parser.add_argument('--force', '-f', action='store_true', help='强制覆盖现有目录')
  622. args = parser.parse_args()
  623. project_name = args.project_name
  624. script_dir = Path(__file__).parent.parent.parent.absolute() # 回到项目根目录
  625. project_dir = Path.cwd() / project_name
  626. print_info(f"开始初始化项目: {project_name}")
  627. print_info(f"项目目录: {project_dir}")
  628. # 检查目录是否已存在
  629. if project_dir.exists():
  630. if not args.force:
  631. print_warning(f"目录 {project_dir} 已存在")
  632. if not get_yes_no_input("是否继续并覆盖现有内容?"):
  633. print_info("操作已取消")
  634. sys.exit(1)
  635. shutil.rmtree(project_dir)
  636. # 创建项目目录
  637. project_dir.mkdir(parents=True, exist_ok=True)
  638. print_info("创建目录结构...")
  639. create_directory_structure(project_dir)
  640. # 获取用户输入
  641. print()
  642. print_info("请输入项目配置信息:")
  643. system_title = get_user_input("系统完整名称")
  644. if not system_title:
  645. print_error("系统名称不能为空")
  646. sys.exit(1)
  647. system_short_title = get_user_input("系统简称 (可选)", system_title)
  648. front_tech = get_user_input("前端技术", "JavaScript")
  649. backend_tech = get_user_input("后端技术", "Java")
  650. # 询问是否使用自定义技术栈文档
  651. print()
  652. use_custom_tech_stack = get_yes_no_input("是否使用自定义技术栈文档?")
  653. if use_custom_tech_stack:
  654. tech_stack_path = "requires_docs/技术栈说明文档.md"
  655. print_info(f"请将您的技术栈说明文档放在: {tech_stack_path}")
  656. else:
  657. tech_stack_path = "specs_docs/tech_stack_specs/技术栈说明文档_默认.md"
  658. # 选择UI设计风格
  659. print()
  660. ui_design_style = get_ui_design_style()
  661. print_success(f"已选择UI设计风格: {ui_design_style}")
  662. # 选择生成模式配置
  663. print()
  664. generation_config = get_generation_mode_config()
  665. print_success(f"已选择生成模式: {generation_config['generation_mode']} ({generation_config['page_count']}页面,{generation_config['api_count_min']}-{generation_config['api_count_max']}个API)")
  666. print_info("复制固定文档和系统提示词...")
  667. copy_fixed_documents(script_dir, project_dir, ui_design_style)
  668. print_info("创建配置文件...")
  669. # 配置对象
  670. config = {
  671. 'project_name': project_name,
  672. 'system_title': system_title,
  673. 'system_short_title': system_short_title,
  674. 'front_tech': front_tech,
  675. 'backend_tech': backend_tech,
  676. 'tech_stack_path': tech_stack_path,
  677. 'ui_design_style': ui_design_style,
  678. 'generation_mode': generation_config['generation_mode'],
  679. 'page_count': generation_config['page_count'],
  680. 'api_count_min': generation_config['api_count_min'],
  681. 'api_count_max': generation_config['api_count_max']
  682. }
  683. create_config_file(project_dir, config)
  684. print_info("创建项目文档...")
  685. create_readme(project_dir, config)
  686. create_requirements_template(project_dir, config)
  687. create_ui_design_template(project_dir, config)
  688. create_gitignore(project_dir)
  689. print_success("项目文档创建完成")
  690. print()
  691. print_success("项目初始化完成!")
  692. print()
  693. print_info(f"项目位置: {project_dir}")
  694. print_info(f"配置文件: {project_dir}/ai-copyright-config.json")
  695. print()
  696. print_info("下一步操作:")
  697. print(f" 1. cd {project_name}")
  698. print(" 2. 编辑 requires_docs/需求文档.md 添加您的项目需求")
  699. print(" 3. 如需自定义技术栈,创建 requires_docs/技术栈说明文档.md")
  700. print(" 4. 参考 workflow.md 开始开发流程")
  701. print()
  702. # 执行完整性验证
  703. print()
  704. validation_success = validate_project_integrity(project_dir, config)
  705. # 显示项目结构
  706. print()
  707. print_directory_tree(project_dir)
  708. print()
  709. if validation_success:
  710. print_success("项目初始化完成并通过验证!")
  711. print_info("建议下一步: 详细填写 requires_docs/需求文档.md")
  712. else:
  713. print_error("项目初始化完成但验证发现问题,请修复后继续")
  714. print_success("初始化脚本执行完成!")
  715. if __name__ == "__main__":
  716. main()