#!/usr/bin/env python3 """Writes BaseKit's Resources/Colophon.json: every open-source project and font the apps ship, what each is, who made it, its licence and the licence's full text (Help → Colophon). Names, URLs and licence texts are kept verbatim there; what each one is and what Base uses it for are copy, so the JSON holds their catalog keys (native.colophon..blurb, .usage) and this writes their text into Localizable.xcstrings, where copy review's words live and check-strings.py holds them. native/scripts/colophon.py [path/to/estilo] Descriptions come from estilo's catalog (colophon/projects.json, read from its origin/main) where it has the project; the four it doesn't have yet (KeyboardShortcuts, swift-cmark, Timeless Sans, DM Sans) are described in EXTRA below until estilo adds them. Licence texts are read from the pinned checkouts (apple/.build/checkouts, after `swift package resolve`) and the fonts' own files. Timeless Sans's licence is a PDF (the Timeless Free Font License 1.2); its entry links it. """ import json, os, pathlib, subprocess, sys native = pathlib.Path(__file__).resolve().parent.parent repo = native.parent checkouts = native / "apple/.build/checkouts" estilo = pathlib.Path(sys.argv[1] if len(sys.argv) > 1 else os.path.expanduser("~/amadan.net/oficina/estilo")) out = native / "apple/Sources/BaseKit/Resources/Colophon.json" catalog_path = native / "apple/Sources/BaseKit/Resources/Localizable.xcstrings" catalog = json.loads(subprocess.check_output(["git", "-C", str(estilo), "show", "origin/main:colophon/projects.json"])) by_id = {p["id"]: p for p in catalog["projects"]} def text(path): return pathlib.Path(path).read_text(encoding="utf-8") def from_estilo(id, usage, licence_file): p = by_id[id] return {"id": id, "name": p["name"], "blurb": p["blurb"], "usage": usage, "author": p["author"], "licence": p["licence"], "home": p["home"], "source": p["source"], "licenceText": text(licence_file)} EXTRA = [ {"section": "typefaces", "id": "timeless-sans", "name": "Timeless Sans", "blurb": "A sans serif typeface by Timeless, with two styles: Grotesk for headings and Sans for text.", "usage": "Base's typeface, as on the web.", "author": "Timeless", "licence": {"spdx": "LicenseRef-Timeless-Free-Font-1.2", "name": "Timeless Free Font License 1.2"}, "home": "https://timeless.co/", "source": "https://media.timeless.co/type/Timeless-Type-Family-1.094.zip", "licenceText": "The Timeless Free Font License 1.2 comes with the fonts as LICENSE.pdf, in the family's download above."}, {"section": "typefaces", "id": "dm-sans", "name": "DM Sans", "blurb": "A sans serif typeface made by Colophon Foundry for DeepMind, designed to stay clear at small sizes.", "usage": "The face Base falls back to where Timeless Sans isn't bundled.", "author": "The DM Sans Project Authors", "licence": {"spdx": "OFL-1.1", "name": "SIL Open Font License 1.1"}, "home": "https://fonts.google.com/specimen/DM+Sans", "source": "https://github.com/googlefonts/dm-fonts", "licenceText": text(repo / "internal/look/static/fonts/dm-sans/OFL.txt")}, {"section": "swift", "id": "keyboardshortcuts", "name": "KeyboardShortcuts", "blurb": "A Swift package for Mac keyboard shortcuts, with a recorder so you can choose your own.", "usage": "The Mac app's shortcut for Ask Base.", "author": "Sindre Sorhus", "licence": {"spdx": "MIT", "name": "MIT License"}, "home": "https://github.com/sindresorhus/KeyboardShortcuts", "source": "https://github.com/sindresorhus/KeyboardShortcuts", "licenceText": text(checkouts / "KeyboardShortcuts/license"), "platforms": ["mac"]}, {"section": "swift", "id": "swift-cmark", "name": "swift-cmark", "blurb": "GitHub's CommonMark parser in C, packaged for Swift.", "usage": "Formats the Assistant's replies.", "author": "John MacFarlane, GitHub and others", "licence": {"spdx": "BSD-2-Clause", "name": "BSD 2-Clause License"}, "home": "https://github.com/swiftlang/swift-cmark", "source": "https://github.com/swiftlang/swift-cmark", "licenceText": text(checkouts / "swift-cmark/COPYING")}, ] sections = {"typefaces": [], "swift": []} for e in EXTRA: sections[e.pop("section")].append(e) sections["swift"].append(from_estilo("rastrillo-native", "Signs Base in with Oficina ID, and its shared parts.", checkouts / "native/LICENSE")) sparkle = from_estilo("sparkle", "The Mac app updates itself with it.", checkouts / "Sparkle/LICENSE") sparkle["platforms"] = ["mac"] sections["swift"].append(sparkle) for s in sections.values(): s.sort(key=lambda e: e["name"].lower()) # The words go to the catalog; the JSON keeps their keys. strings = json.loads(catalog_path.read_text()) for entries in sections.values(): for e in entries: for field, what in (("blurb", "What it is"), ("usage", "What Base uses it for")): key = f"native.colophon.{e['id']}.{field}" strings["strings"][key] = {"comment": f"Colophon: {what} ({e['name']}).", "extractionState": "manual", "localizations": {"en": {"stringUnit": {"state": "translated", "value": e.pop(field)}}}} e[field + "Key"] = key strings["strings"] = dict(sorted(strings["strings"].items())) catalog_path.write_text(json.dumps(strings, indent=2, ensure_ascii=False) + "\n") out.write_text(json.dumps({"sections": [{"id": k, "entries": v} for k, v in sections.items()]}, indent=2, ensure_ascii=False) + "\n") print(f"colophon: wrote {out.relative_to(repo)}")