oficina / base Public

Clone
git clone https://amadan.net/oficina/base

Plain git — no account needed to clone.

Download

Download this file

1#!/usr/bin/env python3
2"""Writes BaseKit's Resources/Colophon.json: every open-source project and
3font the apps ship, what each is, who made it, its licence and the licence's
4full text (Help → Colophon). Names, URLs and licence texts are kept
5verbatim there; what each one is and what Base uses it for are copy, so
6the JSON holds their catalog keys (native.colophon.<id>.blurb, .usage) and
7this writes their text into Localizable.xcstrings, where copy review's
8words live and check-strings.py holds them.
9
10 native/scripts/colophon.py [path/to/estilo]
11
12Descriptions come from estilo's catalog (colophon/projects.json, read from
13its origin/main) where it has the project; the four it doesn't have yet
14(KeyboardShortcuts, swift-cmark, Timeless Sans, DM Sans) are described in
15EXTRA below until estilo adds them. Licence texts are read from the pinned
16checkouts (apple/.build/checkouts, after `swift package resolve`) and the
17fonts' own files. Timeless Sans's licence is a PDF (the Timeless Free Font
18License 1.2); its entry links it.
19"""
20import json, os, pathlib, subprocess, sys
21
22native = pathlib.Path(__file__).resolve().parent.parent
23repo = native.parent
24checkouts = native / "apple/.build/checkouts"
25estilo = pathlib.Path(sys.argv[1] if len(sys.argv) > 1 else os.path.expanduser("~/amadan.net/oficina/estilo"))
26out = native / "apple/Sources/BaseKit/Resources/Colophon.json"
27catalog_path = native / "apple/Sources/BaseKit/Resources/Localizable.xcstrings"
28
29catalog = json.loads(subprocess.check_output(["git", "-C", str(estilo), "show", "origin/main:colophon/projects.json"]))
30by_id = {p["id"]: p for p in catalog["projects"]}
31
32def text(path):
33 return pathlib.Path(path).read_text(encoding="utf-8")
34
35def from_estilo(id, usage, licence_file):
36 p = by_id[id]
37 return {"id": id, "name": p["name"], "blurb": p["blurb"], "usage": usage, "author": p["author"],
38 "licence": p["licence"], "home": p["home"], "source": p["source"], "licenceText": text(licence_file)}
39
40EXTRA = [
41 {"section": "typefaces", "id": "timeless-sans", "name": "Timeless Sans",
42 "blurb": "A sans serif typeface by Timeless, with two styles: Grotesk for headings and Sans for text.",
43 "usage": "Base's typeface, as on the web.", "author": "Timeless",
44 "licence": {"spdx": "LicenseRef-Timeless-Free-Font-1.2", "name": "Timeless Free Font License 1.2"},
45 "home": "https://timeless.co/", "source": "https://media.timeless.co/type/Timeless-Type-Family-1.094.zip",
46 "licenceText": "The Timeless Free Font License 1.2 comes with the fonts as LICENSE.pdf, in the family's download above."},
47 {"section": "typefaces", "id": "dm-sans", "name": "DM Sans",
48 "blurb": "A sans serif typeface made by Colophon Foundry for DeepMind, designed to stay clear at small sizes.",
49 "usage": "The face Base falls back to where Timeless Sans isn't bundled.", "author": "The DM Sans Project Authors",
50 "licence": {"spdx": "OFL-1.1", "name": "SIL Open Font License 1.1"},
51 "home": "https://fonts.google.com/specimen/DM+Sans", "source": "https://github.com/googlefonts/dm-fonts",
52 "licenceText": text(repo / "internal/look/static/fonts/dm-sans/OFL.txt")},
53 {"section": "swift", "id": "keyboardshortcuts", "name": "KeyboardShortcuts",
54 "blurb": "A Swift package for Mac keyboard shortcuts, with a recorder so you can choose your own.",
55 "usage": "The Mac app's shortcut for Ask Base.", "author": "Sindre Sorhus",
56 "licence": {"spdx": "MIT", "name": "MIT License"},
57 "home": "https://github.com/sindresorhus/KeyboardShortcuts", "source": "https://github.com/sindresorhus/KeyboardShortcuts",
58 "licenceText": text(checkouts / "KeyboardShortcuts/license"), "platforms": ["mac"]},
59 {"section": "swift", "id": "swift-cmark", "name": "swift-cmark",
60 "blurb": "GitHub's CommonMark parser in C, packaged for Swift.",
61 "usage": "Formats the Assistant's replies.", "author": "John MacFarlane, GitHub and others",
62 "licence": {"spdx": "BSD-2-Clause", "name": "BSD 2-Clause License"},
63 "home": "https://github.com/swiftlang/swift-cmark", "source": "https://github.com/swiftlang/swift-cmark",
64 "licenceText": text(checkouts / "swift-cmark/COPYING")},
65]
66
67sections = {"typefaces": [], "swift": []}
68for e in EXTRA:
69 sections[e.pop("section")].append(e)
70sections["swift"].append(from_estilo("rastrillo-native", "Signs Base in with Oficina ID, and its shared parts.", checkouts / "native/LICENSE"))
71sparkle = from_estilo("sparkle", "The Mac app updates itself with it.", checkouts / "Sparkle/LICENSE")
72sparkle["platforms"] = ["mac"]
73sections["swift"].append(sparkle)
74for s in sections.values():
75 s.sort(key=lambda e: e["name"].lower())
76# The words go to the catalog; the JSON keeps their keys.
77strings = json.loads(catalog_path.read_text())
78for entries in sections.values():
79 for e in entries:
80 for field, what in (("blurb", "What it is"), ("usage", "What Base uses it for")):
81 key = f"native.colophon.{e['id']}.{field}"
82 strings["strings"][key] = {"comment": f"Colophon: {what} ({e['name']}).", "extractionState": "manual",
83 "localizations": {"en": {"stringUnit": {"state": "translated", "value": e.pop(field)}}}}
84 e[field + "Key"] = key
85strings["strings"] = dict(sorted(strings["strings"].items()))
86catalog_path.write_text(json.dumps(strings, indent=2, ensure_ascii=False) + "\n")
87out.write_text(json.dumps({"sections": [{"id": k, "entries": v} for k, v in sections.items()]}, indent=2, ensure_ascii=False) + "\n")
88print(f"colophon: wrote {out.relative_to(repo)}")
89