refactor: unify build scripts to Python 3

This commit is contained in:
FlipWind
2026-08-09 00:53:55 +08:00
parent 7c76365942
commit 9b171ed169
13 changed files with 173 additions and 466 deletions
+60
View File
@@ -0,0 +1,60 @@
#!/usr/bin/env python3
"""SFCraft 文档构建入口: 先同步物品贴图, 再执行 hugo 构建。
贴图同步失败(有物品找不到)时终止构建。
用法:
python scripts/build.py [hugo 参数...]
"""
import os
import subprocess
import sys
from pathlib import Path
SCRIPTS = Path(__file__).resolve().parent
def find_hugo():
"""按 HUGO 环境变量、PATH、winget 安装目录依次查找 hugo。"""
env = os.environ.get("HUGO")
if env and Path(env).is_file():
return env
name = "hugo.exe" if os.name == "nt" else "hugo"
for d in os.environ.get("PATH", "").split(os.pathsep):
if d:
cand = Path(d) / name
if cand.is_file():
return str(cand)
local = os.environ.get("LOCALAPPDATA")
if local:
base = Path(local) / "Microsoft" / "WinGet" / "Packages"
if base.is_dir():
for p in sorted(base.glob("*/hugo.exe")):
return str(p)
return None
def main():
print("\n[1/2] 同步物品贴图")
r = subprocess.run([sys.executable, str(SCRIPTS / "sync-items.py")])
if r.returncode != 0:
print("[构建终止] 物品贴图同步失败, 未执行 hugo 构建。", file=sys.stderr)
sys.exit(r.returncode)
hugo = find_hugo()
if not hugo:
print(
"[错误] 未找到 hugo, 请安装 Hugo、将其加入 PATH, 或设置环境变量 HUGO。",
file=sys.stderr,
)
sys.exit(1)
print("\n[2/2] hugo 构建")
sys.exit(subprocess.run([hugo, *sys.argv[1:]]).returncode)
if __name__ == "__main__":
main()