dymokomi/luce-ui
Source of release 0.19.3
#!/usr/bin/env python3
"""Embed every luciaos-assets rounded SVG into src/icon_assets.lucb.
Icons are looked up by their file name ("brush-tool", "layer-mask", ...); the
SVG source is inlined (whitespace collapsed, quotes escaped) so applications have
no runtime dependency on the assets repo. Re-run when the icon set changes."""
import re
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
ASSETS = ROOT.parent / "luciaos-assets" / "rounded" / "icons"
# Legacy IconKind names that differ from the asset file names.
ALIASES = {"folder_open": "folder-open"}
def load(path: Path) -> str:
text = re.sub(r"\s+", " ", path.read_text()).strip()
return text.replace('"', '\\"')
icons = {}
for path in sorted(ASSETS.rglob("*.svg")):
name = path.stem
if name in icons:
raise SystemExit(f"duplicate icon name {name}: {path} and {icons[name][0]}")
icons[name] = (path, load(path))
lines = [
"## Generated by tools/icons.py from luciaos-assets — do not edit by hand.",
"## Rounded icons by Dy Mokomi (luciaos-assets), CC BY 4.0.",
"",
f"## The SVG source for one of the {len(icons)} icon names, or empty when unknown.",
"pub func source(name: str) -> str:",
" var key = name",
]
for alias, target in ALIASES.items():
lines.append(f' if key == "{alias}":')
lines.append(f' key = "{target}"')
for name, (path, source) in icons.items():
lines.append(f' if key == "{name}":')
lines.append(f' return "{source}"')
lines.append(' return ""')
lines.append("")
lines.append("## Every icon name, for pickers and tests.")
lines.append(f"pub let names: str[{len(icons)}] = [{', '.join(chr(34) + n + chr(34) for n in icons)}]")
out = ROOT / "src/icon_assets.lucb"
out.write_text("\n".join(lines) + "\n")
print("wrote", out, "with", len(icons), "icons")