⚠️ Mandatory execution rules
The following command must be executed; no other operations are permitted:
cp ~/.claude/templates/ruanzhu/generate_docx.py ./generate_docx.py && python3 generate_docx.py $ARGUMENTS && rm generate_docx.py
Prohibited items
- ❌ Writing your own generation script
- ❌ Creating any
.pyfile in the project - ❌ Checking whether python-docx is installed
- ❌ Creating a venv or manually installing dependencies
- ❌ Searching for files in the project
- ❌ Executing any existing script in the project
The only permitted operation
✅ Execute the bash command above (one command, joined with &&)
State after execution
- ✅ Generated
docs/ruanzhu/{软件名称}{版本}-源代码.docx - ✅ When using
--different, generate{软件名称}{版本}-源代码-2.docx(numbering increments) - ✅ In the projectthere should not be any newly added .py files
- ✅ The temporary script
./generate_docx.pyhas been deleted
Reference information (for understanding only; do not implement it yourself)
The following content has been implemented by the generate_docx.py script,no manual handling is required:
Project information detection
Read the project name and version by priority:
# 优先级 1: CLAUDE.md
# 查找 "# {项目名}" 或 "## 项目概述" 下的内容
# 版本:查找 "版本:" 或 "version:"
# 优先级 2: package.json
{
"name": "project-name",
"version": "1.0.0"
}
# 优先级 3: pom.xml
<artifactId>project-name</artifactId>
<version>1.0.0</version>
# 优先级 4: 用户输入
2. Detect the project language
Determine based on file existence:
| Detection file | Language |
|---|---|
pom.xml or build.gradle |
Java |
package.json |
JavaScript/TypeScript |
Cargo.toml |
Rust |
Gemfile |
Ruby |
go.mod |
Go |
*.cpp or CMakeLists.txt |
C++ |
requirements.txt or pyproject.toml |
Python |
3. Source code scanning rules
Java
优先目录:
- src/main/java/**/controller/
- src/main/java/**/service/
- src/main/java/**/entity/
- src/main/java/**/repository/
- src/main/java/**/config/
- src/main/java/**/security/
- src/main/java/**/dto/
- src/main/java/**/
排除:
- *Test.java
- *IT.java
- *Tests.java
- target/
TypeScript/Vue/React
优先目录:
- src/api/
- src/stores/
- src/pages/
- src/views/
- src/components/
- src/hooks/
- src/utils/
- src/layouts/
- frontend/src/
排除:
- *.spec.ts
- *.test.ts
- *.test.tsx
- *.d.ts
- node_modules/
- dist/
C++
优先目录:
- src/
- include/
- lib/
排除:
- *_test.cpp
- *_test.cc
- test/
- tests/
- build/
Ruby
优先目录:
- app/controllers/
- app/models/
- app/services/
- lib/
排除:
- *_spec.rb
- *_test.rb
- spec/
- test/
Rust
优先目录:
- src/
排除:
- tests/
- *_test.rs
- target/
Go
优先目录:
- cmd/
- internal/
- pkg/
- ./
排除:
- *_test.go
- vendor/
Python
优先目录:
- src/
- app/
- lib/
- ./
排除:
- test_*.py
- *_test.py
- tests/
- __pycache__/
- .venv/
4. Page count control
Fixed page count mode (default 60 pages)
- About 57 rendered lines per page (taking long line wrapping into account)
- Scan by priority and stop after reaching the target line count
- If insufficient, output all
Automatic mode (auto)
- Total pages ≤ 60: output all
- Total pages > 60: output the first 30 pages + the last 30 pages, with an omission note in the middle
5. Rendered line count calculation
def estimate_rendered_lines(text, usable_width_cm=15.5):
"""估算一行文本在Word中渲染需要的行数"""
if len(text) == 0:
return 1
width = 0
for ch in text:
if ord(ch) > 127: # 中文字符
width += 0.35
else: # 英文/符号
width += 0.18
return max(1, int(width / usable_width_cm) + (1 if width % usable_width_cm > 0.1 else 0))
6. DOCX format specification
页面:A4 (21cm x 29.7cm)
边距:上2.5cm, 下2.5cm, 左3.0cm, 右2.5cm
字体:宋体 + Courier New, 10pt
行距:单倍行距
页眉:
- 左侧:{软件名称} {版本}(加粗)
- 居中:第 X 页共 Y 页
- 底部:下划线
页脚:
- 居中:第 X 页
7. Output
- Directory:
docs/ruanzhu/(create if it does not exist) - File name:
{软件名称}{版本}-源代码.docx - Example:
贸易订单管理系统V1.0-源代码.docx
Error handling
| Error | Handling |
|---|---|
| Unable to detect project information | Prompt the user for input |
| No source code detected | Report an error and list the supported languages |
| python-docx is not installed | Automatically install with pip install |
| Insufficient code volume | Warn and output all |