"""Design tokens CSS generator for VoIdeaAI. Reads docs/design-system/tokens.json and generates: - app/design-tokens/css/tokens.css """ import json from pathlib import Path TOKENS_PATH = Path(__file__).parent.parent.parent / "docs" / "design-system" / "tokens.json" OUTPUT_PATH = Path(__file__).parent / "css" / "tokens.css" def load_tokens() -> dict: if not TOKENS_PATH.exists(): return {} return json.loads(TOKENS_PATH.read_text(encoding="utf-8-sig")) def generate_css(tokens: dict) -> str: lines = [ "/* VoIdeaAI Design Tokens — auto-generated */", "/* Source: docs/design-system/tokens.json */", ":root {", ] for category, values in tokens.items(): if not isinstance(values, dict): continue for key, value in values.items(): if key == "$schema": continue if isinstance(value, dict): for mode, val in value.items(): if mode == "light": lines.append(f" --{category}-{key}: {val};") elif isinstance(value, (str, int, float)): lines.append(f" --{category}-{key}: {value};") lines.append("}") lines.append("") lines.append(".dark {") for category, values in tokens.items(): if not isinstance(values, dict): continue for key, value in values.items(): if key == "$schema": continue if isinstance(value, dict): for mode, val in value.items(): if mode == "dark": lines.append(f" --{category}-{key}: {val};") lines.append("}") return "\n".join(lines) def main(): tokens = load_tokens() if not tokens: print("tokens.json not found, skipping") return OUTPUT_PATH.parent.mkdir(parents=True, exist_ok=True) css = generate_css(tokens) OUTPUT_PATH.write_text(css, encoding="utf-8") print(f"Generated {OUTPUT_PATH} ({len(css)} bytes)") if __name__ == "__main__": main()