Files

45 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""发布打包辅助(开发工具,`_` 前缀运行时不会被插件扫描加载)。
把本插件压成 dist-plugin/xq0031_xq0032_v<版本>.zip,
包根布局与 sb_person_change 一致:plugin.json / 各 .py / ui/ 直接位于 zip 根。
排除项:ui-src(前端源码与 node_modules)、__pycache__、debug、本脚本、*.pyc。
用法(desktop/ 下执行):
../.venv/Scripts/python.exe ../plugins/XQ0001-0100/XQ0031_XQ0032 物料收发与采购订单导出/_pack.py
随后发布:
.venv\\Scripts\\python.exe tools\\agent_cli.py publish \
dist-plugin\\xq0031_xq0032_v1.0.0.zip --id xq0031_xq0032 --version 1.0.0
"""
import json
import sys
import zipfile
from pathlib import Path
_HERE = Path(__file__).resolve().parent
# 仓库根 = plugins/XQ0001-0100/<插件目录>/ 的 parents[2],统一出包位置
_OUT_DIR = _HERE.parents[2] / "dist-plugin"
_EXCLUDE_DIRS = {"ui-src", "__pycache__", "debug", ".sessions"}
_EXCLUDE_FILES = {"_pack.py", "_test_both_export.py"}
def main():
manifest = json.loads((_HERE / "plugin.json").read_text(encoding="utf-8"))
pid, ver = manifest["id"], manifest["version"]
if not (_HERE / "ui" / "index.html").is_file():
sys.exit("缺少 ui/index.html:请先在 ui-src 下执行 npm install && npm run build")
_OUT_DIR.mkdir(exist_ok=True)
out = _OUT_DIR / f"{pid}_v{ver}.zip"
with zipfile.ZipFile(out, "w", zipfile.ZIP_DEFLATED) as zf:
for p in sorted(_HERE.rglob("*")):
rel = p.relative_to(_HERE)
if set(rel.parts) & _EXCLUDE_DIRS or p.name in _EXCLUDE_FILES or p.suffix == ".pyc":
continue
if p.is_file():
zf.write(p, str(rel))
print(f"已打包: {out}({out.stat().st_size / 1024:.0f} KB)")
if __name__ == "__main__":
main()