from __future__ import annotations import json import sys from pathlib import Path VALID_TYPES = {"app", "script", "script_pack", "watchface", "theme", "plugin"} def create_template(package_type: str, package_id: str, name: str) -> None: if package_type not in VALID_TYPES: raise SystemExit(f"Invalid package type. Use one of: {', '.join(sorted(VALID_TYPES))}") root = Path("beeos") / "sideload" / package_id root.mkdir(parents=True, exist_ok=True) entry = "app.py" if package_type == "theme": entry = "theme.json" elif package_type == "watchface": entry = "face.py" elif package_type in {"script", "script_pack"}: entry = "script.py" elif package_type == "plugin": entry = "plugin.py" manifest = { "id": package_id, "name": name, "type": package_type, "version": "0.1.0", "author": "Local Developer", "description": f"A local BeeOS {package_type} package.", "entry": entry, "permissions": ["display", "storage"], "repository": "", "category": package_type, "color": "#ffcc00", "icon": "⬢", "curated": False, } (root / "manifest.json").write_text(json.dumps(manifest, indent=2), encoding="utf-8") if package_type == "app": app_code = f"""class BeeApp: def __init__(self, ctx): self.ctx = ctx def on_open(self): launches = self.ctx.storage.get("launches", 0) + 1 self.ctx.storage.set("launches", launches) def on_draw(self, display): display.title({name!r}) display.card("BeeOS App", "Created from the Phase 5 template.") display.list_item("Launches", str(self.ctx.storage.get("launches", 0))) display.list_item("Touches", str(self.ctx.storage.get("touches", 0))) display.progress("Battery", self.ctx.battery_percent()) def on_touch(self, event): touches = self.ctx.storage.get("touches", 0) + 1 self.ctx.storage.set("touches", touches) def on_close(self): self.ctx.notify({name!r}, "Session closed") """ (root / entry).write_text(app_code, encoding="utf-8") elif package_type == "theme": (root / entry).write_text(json.dumps({"accent": "#ffcc00", "background": "#000000"}, indent=2), encoding="utf-8") else: script_code = f"""def main(ctx): ctx.display.title({name!r}) ctx.display.text("Hello from a BeeOS {package_type} package.") ctx.notify({name!r}, "Package ran through BeeOS Runtime.") """ (root / entry).write_text(script_code, encoding="utf-8") print(f"Created BeeOS package template: {root}") def main() -> None: if len(sys.argv) < 4: print("Usage: py tools/create_package_template.py ") print("Example: py tools/create_package_template.py app local.test.app \"Test App\"") raise SystemExit(1) create_template(sys.argv[1], sys.argv[2], " ".join(sys.argv[3:])) if __name__ == "__main__": main()