feat: 根目录文档、脚本、gitignore
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
DOC_MAP = {
|
||||
"prd": "prd.md",
|
||||
"frd": "frd.md",
|
||||
"dar": "dar.md",
|
||||
}
|
||||
|
||||
|
||||
def now_ts():
|
||||
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
|
||||
def read_template(doc_type: str) -> str:
|
||||
ref_name = DOC_MAP[doc_type]
|
||||
ref_path = Path(__file__).resolve().parent.parent / "references" / ref_name
|
||||
if ref_path.exists():
|
||||
return ref_path.read_text(encoding="utf-8")
|
||||
return f"# {doc_type.upper()}\n\n> 模板缺失,请手动补充。\n"
|
||||
|
||||
|
||||
def write_file(path: Path, content: str, force: bool = False) -> bool:
|
||||
if path.exists() and not force:
|
||||
return False
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(content, encoding="utf-8")
|
||||
return True
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Initialize pmassist session workspace")
|
||||
parser.add_argument("--path", required=True, help="Work directory path")
|
||||
parser.add_argument("--doc", required=True, choices=["prd", "frd", "dar"], help="Document type")
|
||||
parser.add_argument("--alias", default="", help="Project alias (short name)")
|
||||
parser.add_argument("--title", default="", help="Document title")
|
||||
parser.add_argument("--desc", default="", help="Raw requirement description")
|
||||
parser.add_argument("--force", action="store_true", help="Overwrite existing files")
|
||||
parser.add_argument("--enable-prototype", action="store_true", help="Enable prototype design phase")
|
||||
args = parser.parse_args()
|
||||
|
||||
workdir = Path(args.path).resolve()
|
||||
workdir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Directories
|
||||
base_dirs = ["materials", "rounds", "questions", "outputs"]
|
||||
proto_dirs = [
|
||||
"materials/prototypes",
|
||||
"materials/prototypes/reference",
|
||||
"materials/prototypes/analysis",
|
||||
"prototypes",
|
||||
"prototypes/screenshots",
|
||||
"prototypes/webapp"
|
||||
]
|
||||
|
||||
dirs_to_create = base_dirs + (proto_dirs if args.enable_prototype else [])
|
||||
for d in dirs_to_create:
|
||||
(workdir / d).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
ts = now_ts()
|
||||
alias = args.alias or ""
|
||||
title = args.title or ""
|
||||
raw_desc = args.desc or ""
|
||||
|
||||
desc_md = f"""# 需求描述\n\n## 元信息\n- 创建时间: {ts}\n- 最后更新: {ts}\n- 文档类型: {args.doc.upper()}\n- 项目简称: {alias}\n- 标题: {title}\n\n## 原始输入\n{raw_desc if raw_desc else '[待补充原始需求]'}\n\n## WWH 分析\n### What - 做什么\n[待补充]\n\n### Why - 为什么\n[待补充]\n\n### How - 怎么做\n[待补充]\n"""
|
||||
|
||||
# Build prototype section if enabled
|
||||
proto_section = ""
|
||||
if args.enable_prototype:
|
||||
proto_section = """
|
||||
prototype:
|
||||
enabled: true
|
||||
status: "proto_pending"
|
||||
proto_round: 0
|
||||
tech_stack: []
|
||||
outputs: []
|
||||
unresolved_proto_questions: []
|
||||
"""
|
||||
|
||||
session_yaml = f"""project_alias: "{alias}"
|
||||
doc_type: "{args.doc}"
|
||||
title: "{title}"
|
||||
created_at: "{ts}"
|
||||
updated_at: "{ts}"
|
||||
round: 0
|
||||
status: "init"
|
||||
unresolved_questions: []
|
||||
last_output: ""
|
||||
materials: []{proto_section}
|
||||
"""
|
||||
|
||||
summary_md = f"""# 会话摘要\n\n- {ts} 初始化会话\n"""
|
||||
|
||||
decision_log_md = """# 决策记录\n\n| 时间 | 事项 | 决策 | 依据 |\n|---|---|---|---|\n"""
|
||||
|
||||
materials_index_md = """# 资料索引\n\n| ID | 标题 | 类型 | 来源/路径 | 摘要 | 日期 |\n|---|---|---|---|---|---|\n"""
|
||||
|
||||
output_template = read_template(args.doc)
|
||||
|
||||
wrote = []
|
||||
if write_file(workdir / "desc.md", desc_md, args.force):
|
||||
wrote.append("desc.md")
|
||||
if write_file(workdir / "session.yaml", session_yaml, args.force):
|
||||
wrote.append("session.yaml")
|
||||
if write_file(workdir / "summary.md", summary_md, args.force):
|
||||
wrote.append("summary.md")
|
||||
if write_file(workdir / "decision_log.md", decision_log_md, args.force):
|
||||
wrote.append("decision_log.md")
|
||||
if write_file(workdir / "materials_index.md", materials_index_md, args.force):
|
||||
wrote.append("materials_index.md")
|
||||
|
||||
output_name = DOC_MAP[args.doc]
|
||||
if write_file(workdir / "outputs" / output_name, output_template, args.force):
|
||||
wrote.append(f"outputs/{output_name}")
|
||||
|
||||
if wrote:
|
||||
print("[OK] Created/updated:")
|
||||
for f in wrote:
|
||||
print(" -", f)
|
||||
else:
|
||||
print("[SKIP] No files changed. Use --force to overwrite.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user