|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Assemble the slim Claude Code plugin tree published on the `plugin-dist` branch. |
| 3 | +
|
| 4 | +The repo root is ~30 MB of gallery renders, showcase props and history; the |
| 5 | +plugin needs ~1 MB of it. This copies only what the plugin uses into --out, |
| 6 | +as a self-contained marketplace (its marketplace.json points at "./"): |
| 7 | +
|
| 8 | + skills/ claude/ rules/ snippets/ templates/ LICENSE files |
| 9 | + .claude-plugin/plugin.json + marketplace.json, and a short README |
| 10 | +
|
| 11 | + python scripts/build_plugin_dist.py --out DIR # build |
| 12 | + python scripts/build_plugin_dist.py --check # build to a temp dir, verify, report size |
| 13 | +
|
| 14 | +release.yml force-pushes the built tree as a single orphan commit to |
| 15 | +`plugin-dist` on every release, so the branch never accumulates history. |
| 16 | +Users add it with `/plugin marketplace add TMHSDigital/Blender-Developer-Tools@plugin-dist`. |
| 17 | +""" |
| 18 | +from __future__ import annotations |
| 19 | + |
| 20 | +import argparse |
| 21 | +import json |
| 22 | +import shutil |
| 23 | +import sys |
| 24 | +import tempfile |
| 25 | +from pathlib import Path |
| 26 | + |
| 27 | +ROOT = Path(__file__).resolve().parent.parent |
| 28 | +DIRS = ("skills", "claude", "rules", "snippets", "templates") |
| 29 | +FILES = ("LICENSE", ".claude-plugin/plugin.json") |
| 30 | +MAX_BYTES = 2_000_000 |
| 31 | +IGNORE = shutil.ignore_patterns("__pycache__", "*.pyc") |
| 32 | + |
| 33 | +DIST_README = """# Blender Developer Tools (Claude Code plugin build) |
| 34 | +
|
| 35 | +Generated from https://github.com/TMHSDigital/Blender-Developer-Tools by |
| 36 | +`scripts/build_plugin_dist.py` on every release. Do not edit this branch; it |
| 37 | +is force-pushed. It carries only what the plugin loads: skills, the |
| 38 | +`blender-rules` skill generated from `rules/`, snippets, templates and licenses. |
| 39 | +Examples, the showcase and the gallery live on `main`. |
| 40 | +
|
| 41 | +```text |
| 42 | +/plugin marketplace add TMHSDigital/Blender-Developer-Tools@plugin-dist |
| 43 | +/plugin install blender-developer-tools@blender-developer-tools |
| 44 | +``` |
| 45 | +""" |
| 46 | + |
| 47 | + |
| 48 | +def build(out: Path) -> int: |
| 49 | + if out.exists(): |
| 50 | + shutil.rmtree(out) |
| 51 | + out.mkdir(parents=True) |
| 52 | + for d in DIRS: |
| 53 | + shutil.copytree(ROOT / d, out / d, ignore=IGNORE) |
| 54 | + for f in FILES: |
| 55 | + (out / f).parent.mkdir(parents=True, exist_ok=True) |
| 56 | + shutil.copy2(ROOT / f, out / f) |
| 57 | + market = json.loads((ROOT / ".claude-plugin" / "marketplace.json").read_text(encoding="utf-8")) |
| 58 | + for entry in market["plugins"]: |
| 59 | + entry["source"] = "./" |
| 60 | + (out / ".claude-plugin" / "marketplace.json").write_text( |
| 61 | + json.dumps(market, indent=2) + "\n", encoding="utf-8", newline="\n") |
| 62 | + (out / "README.md").write_text(DIST_README, encoding="utf-8", newline="\n") |
| 63 | + return sum(p.stat().st_size for p in out.rglob("*") if p.is_file()) |
| 64 | + |
| 65 | + |
| 66 | +def verify(out: Path, size: int) -> list[str]: |
| 67 | + errors = [] |
| 68 | + plugin = json.loads((out / ".claude-plugin" / "plugin.json").read_text(encoding="utf-8")) |
| 69 | + skill_dirs = [out / "skills"] + [out / s for s in plugin.get("skills", [])] |
| 70 | + for d in skill_dirs: |
| 71 | + if not any(d.glob("*/SKILL.md")): |
| 72 | + errors.append(f"{d.relative_to(out)} has no SKILL.md") |
| 73 | + if not (out / "claude" / "skills" / "blender-rules" / "SKILL.md").is_file(): |
| 74 | + errors.append("blender-rules skill missing") |
| 75 | + if size > MAX_BYTES: |
| 76 | + errors.append(f"dist is {size} bytes, over the {MAX_BYTES} budget") |
| 77 | + return errors |
| 78 | + |
| 79 | + |
| 80 | +def main(argv=None) -> int: |
| 81 | + ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) |
| 82 | + ap.add_argument("--out", type=Path) |
| 83 | + ap.add_argument("--check", action="store_true") |
| 84 | + a = ap.parse_args(argv) |
| 85 | + if not a.out and not a.check: |
| 86 | + ap.error("give --out DIR or --check") |
| 87 | + with tempfile.TemporaryDirectory() as td: |
| 88 | + out = a.out or Path(td) / "dist" |
| 89 | + size = build(out) |
| 90 | + errors = verify(out, size) |
| 91 | + n = sum(1 for p in out.rglob("*") if p.is_file()) |
| 92 | + for e in errors: |
| 93 | + print(f"::error::{e}", file=sys.stderr) |
| 94 | + print(f"plugin dist: {n} files, {size / 1e6:.2f} MB" + ("" if errors else " ok")) |
| 95 | + return 1 if errors else 0 |
| 96 | + |
| 97 | + |
| 98 | +if __name__ == "__main__": |
| 99 | + sys.exit(main()) |
0 commit comments