- 将 skill/SKILL.md 移动至根目录 SKILL.md - 更新 build.py 中的路径配置 - 更新 openspec/config.yaml 中的文档位置说明
135 lines
3.5 KiB
Python
135 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Skill 打包构建脚本
|
|
将 skill/SKILL.md 和 scripts/ 目录打包到 build/ 目录
|
|
"""
|
|
|
|
import os
|
|
import shutil
|
|
from datetime import datetime
|
|
|
|
|
|
def generate_timestamp() -> str:
|
|
"""
|
|
生成 YYYYMMDD_HHMMSS 格式的时间戳
|
|
|
|
Returns:
|
|
时间戳字符串
|
|
"""
|
|
return datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
|
|
|
def clean_and_create_build_dir(build_dir: str) -> None:
|
|
"""
|
|
删除旧 build 目录并创建新的空目录
|
|
|
|
Args:
|
|
build_dir: 构建目录路径
|
|
"""
|
|
if os.path.exists(build_dir):
|
|
print(f"清理旧构建目录: {build_dir}")
|
|
shutil.rmtree(build_dir)
|
|
os.makedirs(build_dir)
|
|
print(f"创建构建目录: {build_dir}")
|
|
|
|
|
|
def copy_skill_md(source_path: str, target_dir: str) -> None:
|
|
"""
|
|
复制 skill/SKILL.md 到 build/SKILL.md
|
|
|
|
Args:
|
|
source_path: 源 SKILL.md 路径
|
|
target_dir: 目标目录
|
|
"""
|
|
target_path = os.path.join(target_dir, "SKILL.md")
|
|
shutil.copy2(source_path, target_path)
|
|
print(f"复制: {source_path} -> {target_path}")
|
|
|
|
|
|
def copy_scripts_dir(source_dir: str, target_dir: str) -> int:
|
|
"""
|
|
递归复制 scripts/ 目录,仅复制 .py 文件
|
|
|
|
Args:
|
|
source_dir: 源目录
|
|
target_dir: 目标目录
|
|
|
|
Returns:
|
|
复制的文件数量
|
|
"""
|
|
file_count = 0
|
|
|
|
for root, dirs, files in os.walk(source_dir):
|
|
# 计算相对路径
|
|
rel_path = os.path.relpath(root, source_dir)
|
|
# 处理相对路径为 "." 的情况
|
|
if rel_path == ".":
|
|
target_root = target_dir
|
|
else:
|
|
target_root = os.path.join(target_dir, rel_path)
|
|
|
|
# 检查此目录下是否有 .py 文件需要复制
|
|
has_py_files = any(file.endswith(".py") for file in files)
|
|
|
|
# 只有当有 .py 文件需要复制时才创建目录并复制
|
|
if has_py_files:
|
|
if not os.path.exists(target_root):
|
|
os.makedirs(target_root)
|
|
|
|
# 只复制 .py 文件
|
|
for file in files:
|
|
if file.endswith(".py"):
|
|
source_file = os.path.join(root, file)
|
|
target_file = os.path.join(target_root, file)
|
|
shutil.copy2(source_file, target_file)
|
|
file_count += 1
|
|
print(f"复制: {source_file} -> {target_file}")
|
|
|
|
return file_count
|
|
|
|
|
|
def main() -> None:
|
|
"""
|
|
主函数:执行完整的打包流程
|
|
"""
|
|
print("=" * 60)
|
|
print("Skill 打包构建")
|
|
print("=" * 60)
|
|
|
|
# 路径配置
|
|
project_root = os.path.dirname(os.path.abspath(__file__))
|
|
skill_md_path = os.path.join(project_root, "SKILL.md")
|
|
scripts_source_dir = os.path.join(project_root, "scripts")
|
|
build_dir = os.path.join(project_root, "build")
|
|
scripts_target_dir = os.path.join(build_dir, "scripts")
|
|
|
|
# 生成时间戳
|
|
version = generate_timestamp()
|
|
print(f"版本号: {version}")
|
|
print()
|
|
|
|
# 清理并创建 build 目录
|
|
clean_and_create_build_dir(build_dir)
|
|
print()
|
|
|
|
# 复制 SKILL.md
|
|
copy_skill_md(skill_md_path, build_dir)
|
|
print()
|
|
|
|
# 复制 scripts 目录
|
|
print("复制 scripts/ 目录(仅 .py 文件):")
|
|
file_count = copy_scripts_dir(scripts_source_dir, scripts_target_dir)
|
|
print()
|
|
|
|
# 完成信息
|
|
print("=" * 60)
|
|
print("构建完成!")
|
|
print(f"版本号: {version}")
|
|
print(f"复制文件数: {file_count}")
|
|
print(f"输出目录: {build_dir}")
|
|
print("=" * 60)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|