refactor: 统一构建/发布脚本输出样式,更简约
- 添加 build.sh 调用脚本 - 移除装饰性分隔线和标题 - 移除进度输出,只保留必要的错误提示 - 使用 >>> 前缀标识脚本步骤
This commit is contained in:
66
build.py
66
build.py
@@ -58,27 +58,17 @@ def get_git_user_info() -> tuple[str, str]:
|
||||
try:
|
||||
name = get_git_config("user.name")
|
||||
except subprocess.CalledProcessError:
|
||||
print("""
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
错误: git user.name 未设置
|
||||
|
||||
请先配置 git 用户名:
|
||||
git config --global user.name "Your Name"
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
""")
|
||||
print("错误: git user.name 未设置")
|
||||
print("请先配置 git 用户名:")
|
||||
print(' git config --global user.name "Your Name"')
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
email = get_git_config("user.email")
|
||||
except subprocess.CalledProcessError:
|
||||
print("""
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
错误: git user.email 未设置
|
||||
|
||||
请先配置 git 邮箱:
|
||||
git config --global user.email "your@email.com"
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
""")
|
||||
print("错误: git user.email 未设置")
|
||||
print("请先配置 git 邮箱:")
|
||||
print(' git config --global user.email "your@email.com"')
|
||||
sys.exit(1)
|
||||
|
||||
return name, email
|
||||
@@ -92,10 +82,8 @@ def clean_and_create_build_dir(build_dir: str) -> None:
|
||||
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, version: str, author: str) -> None:
|
||||
@@ -203,8 +191,6 @@ def copy_skill_md(source_path: str, target_dir: str, version: str, author: str)
|
||||
with open(target_path, "w", encoding="utf-8") as f:
|
||||
f.write(new_content)
|
||||
|
||||
print(f"生成: {target_path} (version: {version}, author: {author})")
|
||||
|
||||
|
||||
def obfuscate_scripts_dir(source_dir: str, target_dir: str) -> None:
|
||||
"""
|
||||
@@ -218,16 +204,9 @@ def obfuscate_scripts_dir(source_dir: str, target_dir: str) -> None:
|
||||
try:
|
||||
__import__("pyarmor")
|
||||
except ImportError:
|
||||
print("""
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
错误: PyArmor 未安装
|
||||
|
||||
请使用以下命令:
|
||||
|
||||
uv run --with pyarmor python build.py
|
||||
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
""")
|
||||
print("错误: PyArmor 未安装")
|
||||
print("请使用以下命令:")
|
||||
print(" uv run --with pyarmor python build.py")
|
||||
sys.exit(1)
|
||||
|
||||
# 临时目录
|
||||
@@ -246,8 +225,6 @@ def obfuscate_scripts_dir(source_dir: str, target_dir: str) -> None:
|
||||
source_dir
|
||||
]
|
||||
|
||||
print(f" 执行: {' '.join(cmd)}")
|
||||
|
||||
try:
|
||||
result = subprocess.run(
|
||||
cmd,
|
||||
@@ -256,7 +233,7 @@ def obfuscate_scripts_dir(source_dir: str, target_dir: str) -> None:
|
||||
text=True
|
||||
)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"\nPyArmor 混淆失败:")
|
||||
print("错误: PyArmor 混淆失败")
|
||||
print(f" 返回码: {e.returncode}")
|
||||
print(f" 标准输出: {e.stdout}")
|
||||
print(f" 错误输出: {e.stderr}")
|
||||
@@ -294,16 +271,11 @@ def obfuscate_scripts_dir(source_dir: str, target_dir: str) -> None:
|
||||
# 清理临时目录
|
||||
os.rmdir(temp_dir)
|
||||
|
||||
print(" 混淆完成")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""
|
||||
主函数:执行完整的混淆打包流程
|
||||
"""
|
||||
print("=" * 60)
|
||||
print("Skill 打包构建 (混淆模式)")
|
||||
print("=" * 60)
|
||||
|
||||
# 路径配置
|
||||
project_root = os.path.dirname(os.path.abspath(__file__))
|
||||
@@ -313,37 +285,19 @@ def main() -> None:
|
||||
|
||||
# 生成版本号
|
||||
version = generate_timestamp()
|
||||
print(f"版本号: {version}")
|
||||
|
||||
# 读取 git 用户信息
|
||||
git_name, git_email = get_git_user_info()
|
||||
author = f"{git_name} <{git_email}>"
|
||||
print(f"作者: {author}")
|
||||
print()
|
||||
|
||||
# 清理并创建 build 目录
|
||||
clean_and_create_build_dir(build_dir)
|
||||
print()
|
||||
|
||||
# 复制 SKILL.md(动态注入元数据)
|
||||
copy_skill_md(skill_md_path, build_dir, version, author)
|
||||
print()
|
||||
|
||||
# 混淆代码
|
||||
print("────────────────────────────────────────")
|
||||
print(" 使用 PyArmor 混淆代码 (Normal Mode)")
|
||||
print("────────────────────────────────────────")
|
||||
obfuscate_scripts_dir(scripts_source_dir, build_dir)
|
||||
print()
|
||||
|
||||
# 完成信息
|
||||
print("=" * 60)
|
||||
print("构建完成!")
|
||||
print(f"版本号: {version}")
|
||||
print(f"作者: {author}")
|
||||
print("混淆模式: 已生成 .pyx 和 pyarmor_runtime")
|
||||
print(f"输出目录: {build_dir}")
|
||||
print("=" * 60)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user