@flipova/foundation 1.14.0 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +175 -0
- package/README.md +53 -178
- package/components/ui/accordion/ANIMATION_CUSTOMIZATION.md +162 -0
- package/components/ui/accordion/AccordionAnimatedHeight.tsx +56 -0
- package/components/ui/accordion/AccordionAnimatedIcon.tsx +41 -0
- package/components/ui/accordion/AnimatedHeight.tsx +56 -0
- package/components/ui/accordion/AnimatedIcon.tsx +41 -0
- package/components/ui/accordion/MIGRATION_SUMMARY.md +250 -0
- package/components/ui/accordion/USAGE_EXAMPLE.tsx +179 -0
- package/components/ui/accordion/animation-config.ts +32 -0
- package/components/ui/accordion/index.tsx +253 -0
- package/components/ui/actionsheet/index.tsx +511 -0
- package/components/ui/alert/index.tsx +158 -0
- package/components/ui/alert-dialog/index.tsx +254 -0
- package/components/ui/avatar/index.tsx +139 -0
- package/components/ui/badge/index.tsx +163 -0
- package/components/ui/bottomsheet/index.tsx +477 -0
- package/components/ui/box/index.tsx +19 -0
- package/components/ui/box/index.web.tsx +19 -0
- package/components/ui/box/styles.tsx +10 -0
- package/components/ui/button/index.tsx +264 -0
- package/components/ui/calendar/creator.tsx +366 -0
- package/components/ui/calendar/index.tsx +462 -0
- package/components/ui/calendar/styles.tsx +140 -0
- package/components/ui/card/index.tsx +23 -0
- package/components/ui/card/index.web.tsx +26 -0
- package/components/ui/card/styles.tsx +16 -0
- package/components/ui/center/index.tsx +22 -0
- package/components/ui/center/index.web.tsx +20 -0
- package/components/ui/center/styles.tsx +8 -0
- package/components/ui/checkbox/index.tsx +184 -0
- package/components/ui/date-time-picker/creator.tsx +109 -0
- package/components/ui/date-time-picker/index.tsx +585 -0
- package/components/ui/date-time-picker/index.web.tsx +217 -0
- package/components/ui/date-time-picker/styles.tsx +56 -0
- package/components/ui/divider/index.tsx +40 -0
- package/components/ui/drawer/index.tsx +362 -0
- package/components/ui/fab/index.tsx +215 -0
- package/components/ui/flat-list/index.tsx +21 -0
- package/components/ui/form-control/index.tsx +352 -0
- package/components/ui/gluestack-ui-provider/config.ts +72 -0
- package/components/ui/gluestack-ui-provider/index.tsx +47 -0
- package/components/ui/gluestack-ui-provider/index.web.tsx +96 -0
- package/components/ui/gluestack-ui-provider/script.ts +19 -0
- package/components/ui/gluestack-ui-provider/tokens.d.ts +17 -0
- package/components/ui/gluestack-ui-provider/tokens.js +188 -0
- package/components/ui/gluestack-ui-provider/useGluestackColors.ts +82 -0
- package/components/ui/grid/index.tsx +283 -0
- package/components/ui/grid/index.web.tsx +66 -0
- package/components/ui/grid/styles.tsx +15 -0
- package/components/ui/heading/index.tsx +220 -0
- package/components/ui/heading/index.web.tsx +202 -0
- package/components/ui/heading/styles.tsx +43 -0
- package/components/ui/hstack/index.tsx +27 -0
- package/components/ui/hstack/index.web.tsx +26 -0
- package/components/ui/hstack/styles.tsx +25 -0
- package/components/ui/icon/index.tsx +1588 -0
- package/components/ui/icon/index.web.tsx +1573 -0
- package/components/ui/image/index.tsx +48 -0
- package/components/ui/image-background/index.tsx +25 -0
- package/components/ui/image-viewer/index.tsx +743 -0
- package/components/ui/image-viewer/index.web.tsx +302 -0
- package/components/ui/index.ts +58 -0
- package/components/ui/input/index.tsx +125 -0
- package/components/ui/input-accessory-view/index.tsx +2 -0
- package/components/ui/keyboard-avoiding-view/index.tsx +2 -0
- package/components/ui/link/index.tsx +102 -0
- package/components/ui/liquid-glass/index.tsx +74 -0
- package/components/ui/menu/index.tsx +186 -0
- package/components/ui/modal/index.tsx +237 -0
- package/components/ui/popover/index.tsx +272 -0
- package/components/ui/portal/index.tsx +17 -0
- package/components/ui/pressable/index.tsx +39 -0
- package/components/ui/progress/index.tsx +83 -0
- package/components/ui/radio/index.tsx +217 -0
- package/components/ui/refresh-control/index.tsx +2 -0
- package/components/ui/safe-area-view/index.tsx +2 -0
- package/components/ui/scroll-view/index.tsx +2 -0
- package/components/ui/section-list/index.tsx +2 -0
- package/components/ui/select/index.tsx +277 -0
- package/components/ui/select/select-actionsheet.tsx +562 -0
- package/components/ui/skeleton/index.tsx +105 -0
- package/components/ui/skeleton/index.web.tsx +103 -0
- package/components/ui/skeleton/styles.tsx +35 -0
- package/components/ui/slider/index.tsx +181 -0
- package/components/ui/spinner/index.tsx +40 -0
- package/components/ui/status-bar/index.tsx +2 -0
- package/components/ui/switch/index.tsx +41 -0
- package/components/ui/table/index.tsx +210 -0
- package/components/ui/table/index.web.tsx +157 -0
- package/components/ui/table/styles.tsx +44 -0
- package/components/ui/tabs/TabsAnimatedIndicator.tsx +160 -0
- package/components/ui/tabs/animation-config.ts +3 -0
- package/components/ui/tabs/creator.tsx +206 -0
- package/components/ui/tabs/index.tsx +484 -0
- package/components/ui/text/index.tsx +48 -0
- package/components/ui/text/index.web.tsx +45 -0
- package/components/ui/text/styles.tsx +47 -0
- package/components/ui/textarea/index.tsx +94 -0
- package/components/ui/toast/index.tsx +252 -0
- package/components/ui/tooltip/index.tsx +131 -0
- package/components/ui/view/index.tsx +2 -0
- package/components/ui/virtualized-list/index.tsx +2 -0
- package/components/ui/vstack/index.tsx +28 -0
- package/components/ui/vstack/index.web.tsx +27 -0
- package/components/ui/vstack/styles.tsx +25 -0
- package/design/canonical.index.txt +53 -0
- package/design/documentation.xml +519 -0
- package/design/manifest.xml +90 -0
- package/design/schema.xsd +639 -0
- package/design/themes.xml +204 -0
- package/design/tokens.xml +510 -0
- package/design/tools/design.js +165 -0
- package/design/tools/npm.js +65 -0
- package/design/tools/requirements.txt +35 -0
- package/design/tools/sources/.checker/__init__.py +81 -0
- package/design/tools/sources/.checker/checks.py +198 -0
- package/design/tools/sources/.checker/cli.py +154 -0
- package/design/tools/sources/.checker/io.py +242 -0
- package/design/tools/sources/.checker/model.py +144 -0
- package/design/tools/sources/.checker/registry.py +115 -0
- package/design/tools/sources/.checker/report.py +21 -0
- package/design/tools/sources/.docgen/__init__.py +45 -0
- package/design/tools/sources/.docgen/cli.py +101 -0
- package/design/tools/sources/.docgen/model.py +147 -0
- package/design/tools/sources/.docgen/reference.py +97 -0
- package/design/tools/sources/.docgen/site.py +145 -0
- package/design/tools/sources/.docgen/xsddoc.py +329 -0
- package/design/tools/sources/.generate/__init__.py +35 -0
- package/design/tools/sources/.generate/cli.py +76 -0
- package/design/tools/sources/.generate/common.py +33 -0
- package/design/tools/sources/.generate/config.py +119 -0
- package/design/tools/sources/.generate/model.py +51 -0
- package/design/tools/sources/.generate/tokens.py +141 -0
- package/design/tools/sources/.linter/__init__.py +9 -0
- package/design/tools/sources/.linter/cli.py +44 -0
- package/design/tools/sources/.linter/discovery.py +30 -0
- package/design/tools/sources/.linter/errors.py +45 -0
- package/design/tools/sources/.linter/linter.py +68 -0
- package/design/tools/sources/.xmleditor/__init__.py +74 -0
- package/design/tools/sources/.xmleditor/blocks.py +185 -0
- package/design/tools/sources/.xmleditor/cli.py +141 -0
- package/design/tools/sources/.xmleditor/editor.py +906 -0
- package/design/tools/sources/.xmleditor/model.py +708 -0
- package/design/tools/sources/.xmleditor/widgets.py +1832 -0
- package/design/tools/sources/.xmleditor/xsdmodel.py +753 -0
- package/design/tools/sources/checker.py +55 -0
- package/design/tools/sources/docgen.py +66 -0
- package/design/tools/sources/generate.py +48 -0
- package/design/tools/sources/linter.py +54 -0
- package/design/tools/sources/ruff.toml +12 -0
- package/design/tools/sources/xmleditor.py +62 -0
- package/design/tools/unix/_venv_python.sh +16 -0
- package/design/tools/unix/check.sh +13 -0
- package/design/tools/unix/doc.sh +14 -0
- package/design/tools/unix/gen.sh +14 -0
- package/design/tools/unix/lint.sh +10 -0
- package/design/tools/unix/run.sh +20 -0
- package/design/tools/unix/verify.sh +12 -0
- package/design/tools/unix/xmledit.sh +12 -0
- package/design/tools/windows/check.cmd +12 -0
- package/design/tools/windows/doc.cmd +12 -0
- package/design/tools/windows/gen.cmd +11 -0
- package/design/tools/windows/lint.cmd +9 -0
- package/design/tools/windows/run.cmd +26 -0
- package/design/tools/windows/verify.cmd +10 -0
- package/design/tools/windows/xmledit.cmd +10 -0
- package/dist/chunk-LV4UIEQN.js +9730 -0
- package/dist/chunk-LV4UIEQN.js.map +1 -0
- package/dist/chunk-WNVU3BM2.mjs +9401 -0
- package/dist/chunk-WNVU3BM2.mjs.map +1 -0
- package/dist/index.d.mts +40 -10
- package/dist/index.d.ts +40 -10
- package/dist/index.js +726 -414
- package/dist/index.mjs +1 -5
- package/dist/ui/index.d.mts +6931 -3070
- package/dist/ui/index.d.ts +6931 -3070
- package/dist/ui/index.js +779 -352
- package/dist/ui/index.mjs +1 -2
- package/package.json +66 -149
- package/dist/chunk-2XORADW6.js +0 -24552
- package/dist/chunk-2XORADW6.js.map +0 -1
- package/dist/chunk-52BHHF5M.js +0 -46
- package/dist/chunk-52BHHF5M.js.map +0 -1
- package/dist/chunk-5647JY7Z.mjs +0 -100
- package/dist/chunk-5647JY7Z.mjs.map +0 -1
- package/dist/chunk-5N5HC4ZA.mjs +0 -3
- package/dist/chunk-5N5HC4ZA.mjs.map +0 -1
- package/dist/chunk-7QFZMGL6.js +0 -8583
- package/dist/chunk-7QFZMGL6.js.map +0 -1
- package/dist/chunk-ASZEP37D.js +0 -423
- package/dist/chunk-ASZEP37D.js.map +0 -1
- package/dist/chunk-BH5SU2JQ.mjs +0 -8282
- package/dist/chunk-BH5SU2JQ.mjs.map +0 -1
- package/dist/chunk-BO65GO53.mjs +0 -422
- package/dist/chunk-BO65GO53.mjs.map +0 -1
- package/dist/chunk-BSVXX52E.mjs +0 -413
- package/dist/chunk-BSVXX52E.mjs.map +0 -1
- package/dist/chunk-DNV5UBNF.mjs +0 -3
- package/dist/chunk-DNV5UBNF.mjs.map +0 -1
- package/dist/chunk-EDTAMUO2.js +0 -8310
- package/dist/chunk-EDTAMUO2.js.map +0 -1
- package/dist/chunk-IJTI6EX4.js +0 -4
- package/dist/chunk-IJTI6EX4.js.map +0 -1
- package/dist/chunk-M3YLASM2.js +0 -428
- package/dist/chunk-M3YLASM2.js.map +0 -1
- package/dist/chunk-OXKOGLXE.js +0 -4
- package/dist/chunk-OXKOGLXE.js.map +0 -1
- package/dist/chunk-RQXQK3ZO.mjs +0 -8486
- package/dist/chunk-RQXQK3ZO.mjs.map +0 -1
- package/dist/chunk-SR25V4EA.mjs +0 -40
- package/dist/chunk-SR25V4EA.mjs.map +0 -1
- package/dist/chunk-UB34WFEQ.js +0 -106
- package/dist/chunk-UB34WFEQ.js.map +0 -1
- package/dist/chunk-ZBRWXKDF.mjs +0 -24431
- package/dist/chunk-ZBRWXKDF.mjs.map +0 -1
- package/dist/cli/ds.d.mts +0 -1
- package/dist/cli/ds.d.ts +0 -1
- package/dist/cli/ds.js +0 -602
- package/dist/cli/ds.js.map +0 -1
- package/dist/cli/ds.mjs +0 -579
- package/dist/cli/ds.mjs.map +0 -1
- package/dist/cli/flipova.d.mts +0 -1
- package/dist/cli/flipova.d.ts +0 -1
- package/dist/cli/flipova.js +0 -161
- package/dist/cli/flipova.js.map +0 -1
- package/dist/cli/flipova.mjs +0 -154
- package/dist/cli/flipova.mjs.map +0 -1
- package/dist/config/index.d.mts +0 -123
- package/dist/config/index.d.ts +0 -123
- package/dist/config/index.js +0 -28
- package/dist/config/index.js.map +0 -1
- package/dist/config/index.mjs +0 -3
- package/dist/config/index.mjs.map +0 -1
- package/dist/createTheme-DQeX3s0I.d.mts +0 -78
- package/dist/createTheme-Y4jfz4-u.d.ts +0 -78
- package/dist/index-CuaJA3gM.d.mts +0 -78
- package/dist/index-CuaJA3gM.d.ts +0 -78
- package/dist/registry/index.d.mts +0 -10160
- package/dist/registry/index.d.ts +0 -10160
- package/dist/registry/index.js +0 -392
- package/dist/registry/index.js.map +0 -1
- package/dist/registry/index.mjs +0 -3
- package/dist/registry/index.mjs.map +0 -1
- package/dist/theme/index.d.mts +0 -35
- package/dist/theme/index.d.ts +0 -35
- package/dist/theme/index.js +0 -28
- package/dist/theme/index.js.map +0 -1
- package/dist/theme/index.mjs +0 -3
- package/dist/theme/index.mjs.map +0 -1
- package/dist/tokens/index.d.mts +0 -423
- package/dist/tokens/index.d.ts +0 -423
- package/dist/tokens/index.js +0 -44
- package/dist/tokens/index.js.map +0 -1
- package/dist/tokens/index.mjs +0 -3
- package/dist/tokens/index.mjs.map +0 -1
- package/dist/types/index.d.mts +0 -202
- package/dist/types/index.d.ts +0 -202
- package/dist/types/index.js +0 -4
- package/dist/types/index.js.map +0 -1
- package/dist/types/index.mjs +0 -3
- package/dist/types/index.mjs.map +0 -1
- package/dist/web/index.d.mts +0 -316
- package/dist/web/index.d.ts +0 -316
- package/dist/web/index.js +0 -1500
- package/dist/web/index.js.map +0 -1
- package/dist/web/index.mjs +0 -1396
- package/dist/web/index.mjs.map +0 -1
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
import re
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from lxml import etree
|
|
9
|
+
|
|
10
|
+
from .model import (
|
|
11
|
+
Diagnostic,
|
|
12
|
+
RegistryModel,
|
|
13
|
+
natural_key,
|
|
14
|
+
parse_rules,
|
|
15
|
+
q,
|
|
16
|
+
resolve_reference,
|
|
17
|
+
)
|
|
18
|
+
from .registry import expand_targets
|
|
19
|
+
from .report import Report
|
|
20
|
+
|
|
21
|
+
# ---------------------------------------------------------------------------
|
|
22
|
+
# Model building (manifest.xml -> RegistryModel)
|
|
23
|
+
# ---------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def build_model(root: Path, manifest_path: Path) -> RegistryModel:
|
|
27
|
+
manifest_dir = manifest_path.resolve().parent
|
|
28
|
+
tree = etree.parse(str(manifest_path))
|
|
29
|
+
mroot = tree.getroot()
|
|
30
|
+
|
|
31
|
+
# The registers are exactly the <index> register names (tokens, themes):
|
|
32
|
+
# the manifest no longer carries a uiElement nomenclature/contract.
|
|
33
|
+
registers = [
|
|
34
|
+
(el.get("name") or "").strip()
|
|
35
|
+
for el in mroot.findall(q("index") + "/" + q("register"))
|
|
36
|
+
]
|
|
37
|
+
reserves: list[str] = []
|
|
38
|
+
index: dict[str, list[str]] = {}
|
|
39
|
+
for reg_el in mroot.findall(q("index") + "/" + q("register")):
|
|
40
|
+
index[reg_el.get("name")] = [
|
|
41
|
+
(item.text or "").strip() for item in reg_el.findall(q("item"))
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
catalog_files: dict[str, Path] = {}
|
|
45
|
+
for catalog in mroot.findall(q("catalogs") + "/" + q("catalog")):
|
|
46
|
+
reg = catalog.get("register")
|
|
47
|
+
file_el = catalog.find(q("file"))
|
|
48
|
+
if file_el is not None and file_el.text:
|
|
49
|
+
catalog_files[reg] = (manifest_dir / file_el.text.strip()).resolve()
|
|
50
|
+
|
|
51
|
+
token_values: dict[str, dict[str, str]] = {}
|
|
52
|
+
theme_roles: dict[str, dict[str, str]] = {}
|
|
53
|
+
for path in catalog_files.values():
|
|
54
|
+
if not path.exists():
|
|
55
|
+
continue
|
|
56
|
+
doc = etree.parse(str(path))
|
|
57
|
+
for token in doc.iter(q("token")):
|
|
58
|
+
tid = token.get("id")
|
|
59
|
+
values = {}
|
|
60
|
+
for value in token.iter(q("value")):
|
|
61
|
+
values[value.get("id")] = (value.text or "").strip()
|
|
62
|
+
token_values[tid] = values
|
|
63
|
+
for theme in doc.iter(q("theme")):
|
|
64
|
+
tid = theme.get("id")
|
|
65
|
+
roles = {}
|
|
66
|
+
for role in theme.iter(q("role")):
|
|
67
|
+
ref_el = role.find(q("ref"))
|
|
68
|
+
roles[role.get("id")] = (ref_el.text or "").strip() if ref_el is not None else ""
|
|
69
|
+
theme_roles[tid] = roles
|
|
70
|
+
|
|
71
|
+
# The ONE version of this repository: the root package.json, i.e. exactly
|
|
72
|
+
# what gets published. The registry stores no copy on purpose -- a second
|
|
73
|
+
# copy drifts silently (e.g. `changeset version` bumps package.json only).
|
|
74
|
+
version = ""
|
|
75
|
+
package_json = Path(root) / "package.json"
|
|
76
|
+
if package_json.exists():
|
|
77
|
+
try:
|
|
78
|
+
version = json.loads(package_json.read_text(encoding="utf-8")).get("version", "") or ""
|
|
79
|
+
except (ValueError, OSError):
|
|
80
|
+
version = ""
|
|
81
|
+
return RegistryModel(
|
|
82
|
+
root=Path(root),
|
|
83
|
+
manifest_path=manifest_path.resolve(),
|
|
84
|
+
registers=registers,
|
|
85
|
+
reserves=reserves,
|
|
86
|
+
index=index,
|
|
87
|
+
catalog_files=catalog_files,
|
|
88
|
+
token_values=token_values,
|
|
89
|
+
theme_roles=theme_roles,
|
|
90
|
+
rules=parse_rules(mroot),
|
|
91
|
+
version=version,
|
|
92
|
+
schema_id=mroot.get("schema") or "",
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# ---------------------------------------------------------------------------
|
|
97
|
+
# Canonical index (the deterministic artifact)
|
|
98
|
+
# ---------------------------------------------------------------------------
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def canonical_payload(ctx: RegistryModel) -> tuple:
|
|
102
|
+
"""Deterministic canonical view: entries sorted by (register, id), refs resolved."""
|
|
103
|
+
entries: list[str] = []
|
|
104
|
+
register_names = sorted(ctx.registers, key=natural_key)
|
|
105
|
+
for reg in register_names:
|
|
106
|
+
if reg in ctx.catalog_files and ctx.catalog_files[reg].exists():
|
|
107
|
+
if reg == "tokens":
|
|
108
|
+
ids = sorted(ctx.token_values.keys(), key=natural_key)
|
|
109
|
+
elif reg == "themes":
|
|
110
|
+
ids = sorted(ctx.theme_roles.keys(), key=natural_key)
|
|
111
|
+
else:
|
|
112
|
+
ids = sorted(ctx.index.get(reg, []), key=natural_key)
|
|
113
|
+
else:
|
|
114
|
+
ids = sorted(ctx.index.get(reg, []), key=natural_key)
|
|
115
|
+
for ident in ids:
|
|
116
|
+
entries.append(f"{reg}/{ident}")
|
|
117
|
+
|
|
118
|
+
refs: dict[str, str] = {}
|
|
119
|
+
for path in ctx.catalog_files.values():
|
|
120
|
+
if not path.exists():
|
|
121
|
+
continue
|
|
122
|
+
doc = etree.parse(str(path))
|
|
123
|
+
for elem in doc.iter(q("ref")):
|
|
124
|
+
ref = (elem.text or "").strip()
|
|
125
|
+
if ref and resolve_reference(ctx, ref):
|
|
126
|
+
refs[ref] = resolve_reference_value(ctx, ref)
|
|
127
|
+
ref_lines = [f"{ref} -> {refs[ref]}" for ref in sorted(refs, key=natural_key)]
|
|
128
|
+
return entries, ref_lines
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def resolve_reference_value(ctx: RegistryModel, ref: str) -> str:
|
|
132
|
+
|
|
133
|
+
parts = ref.split(".")
|
|
134
|
+
if ref.startswith("$ref."):
|
|
135
|
+
parts = ref[len("$ref."):].split(".")
|
|
136
|
+
if parts and parts[0] in ctx.registers:
|
|
137
|
+
parts = parts[1:]
|
|
138
|
+
item_id = parts[0]
|
|
139
|
+
path = parts[1:]
|
|
140
|
+
if item_id in ctx.token_values:
|
|
141
|
+
return ctx.token_values[item_id].get(".".join(path), "?")
|
|
142
|
+
return "?"
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def canonical_document(ctx: RegistryModel) -> str:
|
|
146
|
+
entries, ref_lines = canonical_payload(ctx)
|
|
147
|
+
body = "\n".join(entries)
|
|
148
|
+
digest = hashlib.sha256(body.encode("utf-8")).hexdigest()
|
|
149
|
+
lines = [
|
|
150
|
+
"# Flipova Foundation — canonical registry index (deterministic artifact)",
|
|
151
|
+
"# generated by design/tools/sources/checker.py --emit-canonical",
|
|
152
|
+
"# commit this file: --verify-canonical fails the build when the registry drifts.",
|
|
153
|
+
"",
|
|
154
|
+
"# entries (register/id) — canonical sort by (register, id)",
|
|
155
|
+
*entries,
|
|
156
|
+
"",
|
|
157
|
+
"## references (resolved, never dangling)",
|
|
158
|
+
*ref_lines,
|
|
159
|
+
"",
|
|
160
|
+
"## sha256",
|
|
161
|
+
digest,
|
|
162
|
+
]
|
|
163
|
+
return "\n".join(lines) + "\n"
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _root_start_tag(data: bytes) -> int | None:
|
|
167
|
+
"""Byte offset of the root element start tag ('<' not inside prolog/comment)."""
|
|
168
|
+
idx = 0
|
|
169
|
+
while True:
|
|
170
|
+
idx = data.find(b"<", idx)
|
|
171
|
+
if idx == -1:
|
|
172
|
+
return None
|
|
173
|
+
head = data[idx:idx + 4]
|
|
174
|
+
if head.startswith(b"<?"):
|
|
175
|
+
idx = data.find(b"?>", idx) + 1
|
|
176
|
+
elif head.startswith(b"<!--"):
|
|
177
|
+
idx = data.find(b"-->", idx) + 3
|
|
178
|
+
elif head.startswith(b"<!"):
|
|
179
|
+
idx = data.find(b">", idx) + 1
|
|
180
|
+
elif head.startswith(b"</"):
|
|
181
|
+
idx += 2
|
|
182
|
+
else:
|
|
183
|
+
return idx
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def sync_versions(ctx: RegistryModel) -> int:
|
|
187
|
+
"""Rewrite @schema on every root start tag to the manifest value.
|
|
188
|
+
|
|
189
|
+
Only @schema is synchronised: the project version is owned by the root
|
|
190
|
+
package.json and is deliberately never duplicated in the XML.
|
|
191
|
+
"""
|
|
192
|
+
count = 0
|
|
193
|
+
for path in expand_targets(ctx.root, "*.xml"):
|
|
194
|
+
try:
|
|
195
|
+
data = path.read_bytes()
|
|
196
|
+
except OSError:
|
|
197
|
+
continue
|
|
198
|
+
start = _root_start_tag(data)
|
|
199
|
+
if start is None:
|
|
200
|
+
continue
|
|
201
|
+
end = data.find(b">", start)
|
|
202
|
+
if end == -1:
|
|
203
|
+
continue
|
|
204
|
+
tag = data[start:end]
|
|
205
|
+
new = tag
|
|
206
|
+
if ctx.schema_id:
|
|
207
|
+
new = re.sub(rb'(\bschema=")[^"]*(")',
|
|
208
|
+
lambda m: m.group(1) + ctx.schema_id.encode("utf-8") + m.group(2), new)
|
|
209
|
+
if new != tag:
|
|
210
|
+
path.write_bytes(data[:start] + new + data[end:])
|
|
211
|
+
print(f" synced {path}")
|
|
212
|
+
count += 1
|
|
213
|
+
return count
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
# ---------------------------------------------------------------------------
|
|
217
|
+
# XSD conformance (delegated to the AGNOSTIC linter)
|
|
218
|
+
# ---------------------------------------------------------------------------
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def validate_xsd(ctx: RegistryModel, schema_path: Path, verbose: bool) -> Report:
|
|
222
|
+
import sys as _sys
|
|
223
|
+
from pathlib import Path as _Path
|
|
224
|
+
|
|
225
|
+
_sys.path.insert(0, str(_Path(__file__).resolve().parents[1]))
|
|
226
|
+
from linter import XSDLinter
|
|
227
|
+
|
|
228
|
+
report = Report()
|
|
229
|
+
linter = XSDLinter(schema_path=str(schema_path))
|
|
230
|
+
files = [ctx.manifest_path, *ctx.catalog_files.values()]
|
|
231
|
+
for path in files:
|
|
232
|
+
result = linter.validate_file(str(path))
|
|
233
|
+
for err in result.errors:
|
|
234
|
+
severity = err.severity or "error"
|
|
235
|
+
report.diagnostics.append(Diagnostic(
|
|
236
|
+
rule_id="xsd",
|
|
237
|
+
severity=severity,
|
|
238
|
+
file=err.file,
|
|
239
|
+
line=err.line,
|
|
240
|
+
message=err.message,
|
|
241
|
+
))
|
|
242
|
+
return report
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from lxml import etree
|
|
8
|
+
|
|
9
|
+
NS = "urn:flipova:foundation:registry"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def q(tag: str) -> str:
|
|
13
|
+
return f"{{{NS}}}{tag}"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def localname(tag: str) -> str:
|
|
17
|
+
"""Strips a namespace prefix from an XML tag, returning the bare name.
|
|
18
|
+
|
|
19
|
+
Comments and processing instructions carry a callable ``tag`` in lxml:
|
|
20
|
+
return '' for them so ``doc.iter()`` loops can skip them uniformly.
|
|
21
|
+
"""
|
|
22
|
+
if not isinstance(tag, str):
|
|
23
|
+
return ""
|
|
24
|
+
return tag.rsplit("}", 1)[-1] if "}" in tag else tag
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def natural_key(value: str) -> list:
|
|
28
|
+
"""Locale-independent natural key used for canonical ordering."""
|
|
29
|
+
return [
|
|
30
|
+
(0, int(part)) if part.isdigit() else (1, part.casefold())
|
|
31
|
+
for part in re.split(r"(\d+)", value)
|
|
32
|
+
if part != ""
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def cap(s: str) -> str:
|
|
37
|
+
"""CamelCase the slug ``a-b-c`` -> ``ABC`` (dashes -> upper, strip others)."""
|
|
38
|
+
return "".join(w.upper() for w in s.split("-") if w)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def slug(name: str) -> str:
|
|
42
|
+
"""Turn ``CamelCase`` into ``kebab-case`` (``TextInput`` -> ``text-input``)."""
|
|
43
|
+
return re.sub(r"(?<=[a-z])(?=[A-Z])|[^a-zA-Z0-9]", "-", name).strip("-").lower()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# ---------------------------------------------------------------------------
|
|
47
|
+
# Rule parsing (declarative, from the manifest)
|
|
48
|
+
# ---------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass
|
|
52
|
+
class Rule:
|
|
53
|
+
id: str
|
|
54
|
+
kind: str
|
|
55
|
+
severity: str
|
|
56
|
+
description: str
|
|
57
|
+
apply_to: str
|
|
58
|
+
params: dict[str, str] = field(default_factory=dict)
|
|
59
|
+
|
|
60
|
+
def get(self, name: str, default: str | None = None) -> str | None:
|
|
61
|
+
return self.params.get(name, default)
|
|
62
|
+
|
|
63
|
+
def get_list(self, name: str, default: list[str] | None = None) -> list[str]:
|
|
64
|
+
raw = self.params.get(name)
|
|
65
|
+
if raw is None:
|
|
66
|
+
return list(default or [])
|
|
67
|
+
return [part.strip() for part in raw.split(",") if part.strip()]
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def parse_rules(manifest: etree._Element) -> list[Rule]:
|
|
71
|
+
rules: list[Rule] = []
|
|
72
|
+
for rule_el in manifest.findall(q("meta") + "/" + q("determinism") + "/" + q("rule")):
|
|
73
|
+
params = {}
|
|
74
|
+
for param in rule_el.findall(q("params") + "/" + q("param")):
|
|
75
|
+
params[param.get("name")] = (param.text or "").strip()
|
|
76
|
+
apply_to = rule_el.findtext(q("applyTo"))
|
|
77
|
+
apply_to = apply_to.strip() if apply_to else "*.xml"
|
|
78
|
+
rules.append(Rule(
|
|
79
|
+
id=rule_el.get("id"),
|
|
80
|
+
kind=rule_el.get("kind"),
|
|
81
|
+
severity=rule_el.get("severity") or "error",
|
|
82
|
+
description=(rule_el.findtext(q("description")) or "").strip(),
|
|
83
|
+
apply_to=apply_to,
|
|
84
|
+
params=params,
|
|
85
|
+
))
|
|
86
|
+
return rules
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# ---------------------------------------------------------------------------
|
|
90
|
+
# Diagnostics
|
|
91
|
+
# ---------------------------------------------------------------------------
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@dataclass
|
|
95
|
+
class Diagnostic:
|
|
96
|
+
rule_id: str
|
|
97
|
+
severity: str
|
|
98
|
+
file: str
|
|
99
|
+
line: int | None
|
|
100
|
+
message: str
|
|
101
|
+
|
|
102
|
+
def __str__(self) -> str:
|
|
103
|
+
loc = self.file
|
|
104
|
+
if self.line is not None:
|
|
105
|
+
loc += f":{self.line}"
|
|
106
|
+
return f"[{self.severity.upper()}] {loc} [rule={self.rule_id}]: {self.message}"
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# ---------------------------------------------------------------------------
|
|
110
|
+
# Registry model (what the checker reasons about)
|
|
111
|
+
# ---------------------------------------------------------------------------
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
@dataclass
|
|
115
|
+
class RegistryModel:
|
|
116
|
+
root: Path
|
|
117
|
+
manifest_path: Path
|
|
118
|
+
registers: list[str]
|
|
119
|
+
reserves: list[str]
|
|
120
|
+
index: dict[str, list[str]]
|
|
121
|
+
catalog_files: dict[str, Path]
|
|
122
|
+
token_values: dict[str, dict[str, str]] # token id -> value id -> literal
|
|
123
|
+
theme_roles: dict[str, dict[str, str]] # theme id -> role id -> ref
|
|
124
|
+
rules: list[Rule]
|
|
125
|
+
version: str = "" # root package.json version (the single source of truth)
|
|
126
|
+
schema_id: str = "" # manifest root @schema (propagated to every root tag)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def resolve_reference(ctx: RegistryModel, ref: str) -> bool:
|
|
130
|
+
"""True when *ref* resolves against the registry (never implicit links)."""
|
|
131
|
+
parts = ref.split(".")
|
|
132
|
+
if ref.startswith("$ref."):
|
|
133
|
+
parts = ref[len("$ref."):].split(".")
|
|
134
|
+
if parts and parts[0] in ctx.registers:
|
|
135
|
+
parts = parts[1:]
|
|
136
|
+
if not parts:
|
|
137
|
+
return False
|
|
138
|
+
item_id = parts[0]
|
|
139
|
+
path = parts[1:]
|
|
140
|
+
if item_id in ctx.token_values:
|
|
141
|
+
return ".".join(path) in ctx.token_values[item_id] if path else True
|
|
142
|
+
if item_id in ctx.theme_roles:
|
|
143
|
+
return True if not path else ".".join(path) in ctx.theme_roles[item_id]
|
|
144
|
+
return False
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import fnmatch
|
|
4
|
+
import glob
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Callable
|
|
8
|
+
|
|
9
|
+
from lxml import etree
|
|
10
|
+
|
|
11
|
+
from .model import RegistryModel, Rule, localname, q
|
|
12
|
+
|
|
13
|
+
HANDLERS: dict[str, Callable] = {}
|
|
14
|
+
|
|
15
|
+
IGNORE_DIRS = frozenset({
|
|
16
|
+
".git", ".svn", ".hg", "node_modules", ".venv", "__pycache__",
|
|
17
|
+
".DS_Store", "dist", "build", "docs", "generated",
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def register(kind: str) -> Callable:
|
|
22
|
+
"""Decorator that registers a rule handler under *kind*.
|
|
23
|
+
|
|
24
|
+
The manifest declares rules with a ``kind`` attribute; checker dispatches
|
|
25
|
+
each declared rule to the handler registered for its kind.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def decorator(fn: Callable) -> Callable:
|
|
29
|
+
HANDLERS[kind] = fn
|
|
30
|
+
return fn
|
|
31
|
+
|
|
32
|
+
return decorator
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def expand_targets(root: Path, pattern: str) -> list[Path]:
|
|
36
|
+
"""Expand a rule.applyTo glob (relative to root) into concrete files."""
|
|
37
|
+
if not pattern:
|
|
38
|
+
return []
|
|
39
|
+
pat = pattern.replace("\\", "/")
|
|
40
|
+
if "/" not in pat and "**" not in pat:
|
|
41
|
+
return sorted(p.resolve() for p in iter_files(root, pat))
|
|
42
|
+
hits = [Path(p).resolve() for p in glob.glob(str(root / pat), recursive=True)]
|
|
43
|
+
if not hits and "/" in pat:
|
|
44
|
+
for p in iter_files(root, "*"):
|
|
45
|
+
rel = p.relative_to(root).as_posix()
|
|
46
|
+
if fnmatch.fnmatch(rel, pat):
|
|
47
|
+
hits.append(p.resolve())
|
|
48
|
+
return sorted(set(hits))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def iter_files(root: Path, pattern: str):
|
|
52
|
+
"""Yield files under *root* matching *pattern*, skipping nested vendor trees past the IGNORE_DIRS filter."""
|
|
53
|
+
pat = pattern.replace("\\", "/")
|
|
54
|
+
match_name_only = "/" not in pat and "*" in pat
|
|
55
|
+
for base, dirs, files in os.walk(str(root)):
|
|
56
|
+
dirs[:] = sorted(d for d in dirs if d not in IGNORE_DIRS)
|
|
57
|
+
for name in sorted(files):
|
|
58
|
+
if match_name_only:
|
|
59
|
+
hit = fnmatch.fnmatch(name, pat)
|
|
60
|
+
else:
|
|
61
|
+
rel = Path(base).relative_to(root) / name
|
|
62
|
+
hit = fnmatch.fnmatch(rel.as_posix(), pat)
|
|
63
|
+
if hit:
|
|
64
|
+
yield Path(base) / name
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _check_register_order(ctx: RegistryModel, rule: Rule, report) -> None:
|
|
68
|
+
"""Enforce that the canonical register order is consistent everywhere."""
|
|
69
|
+
canonical = ctx.registers
|
|
70
|
+
mroot = etree.parse(str(ctx.manifest_path)).getroot()
|
|
71
|
+
catalogs = [c.get("register") for c in mroot.findall(q("catalogs") + "/" + q("catalog"))]
|
|
72
|
+
index_regs = [r.get("name") for r in mroot.findall(q("index") + "/" + q("register"))]
|
|
73
|
+
for label, got in (("catalogs", catalogs), ("index", index_regs)):
|
|
74
|
+
if got != canonical:
|
|
75
|
+
report.add(rule, str(ctx.manifest_path), None,
|
|
76
|
+
f"{label} register order {got!r} != canonical {canonical!r} (canonical sort by (register, id) requires one order everywhere)")
|
|
77
|
+
for catalog in mroot.findall(q("catalogs") + "/" + q("catalog")):
|
|
78
|
+
declared = catalog.get("register")
|
|
79
|
+
file_el = catalog.find(q("file"))
|
|
80
|
+
if file_el is None or not file_el.text:
|
|
81
|
+
continue
|
|
82
|
+
path = (ctx.manifest_path.parent / file_el.text.strip()).resolve()
|
|
83
|
+
if not path.exists():
|
|
84
|
+
continue
|
|
85
|
+
try:
|
|
86
|
+
actual = etree.parse(str(path)).getroot().get("register")
|
|
87
|
+
except etree.XMLSyntaxError:
|
|
88
|
+
continue
|
|
89
|
+
if actual != declared:
|
|
90
|
+
report.add(rule, str(path), None,
|
|
91
|
+
f"file declares register={actual!r} but the catalog expects {declared!r}")
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _check_sibling_order(path: Path, rule: Rule, selectors: list[str], report) -> None:
|
|
95
|
+
"""Enforce natural sort order of id-bearing sibling lists."""
|
|
96
|
+
from .model import natural_key
|
|
97
|
+
|
|
98
|
+
doc = etree.parse(str(path))
|
|
99
|
+
selector_set = set(selectors)
|
|
100
|
+
for parent in doc.iter():
|
|
101
|
+
last: dict[str, list] = {}
|
|
102
|
+
for child in parent:
|
|
103
|
+
name = localname(child.tag)
|
|
104
|
+
if selector_set and name not in selector_set:
|
|
105
|
+
continue
|
|
106
|
+
ident = child.get("id") or child.get("name") or child.get("register")
|
|
107
|
+
if ident is None and name in ("item", "field", "key", "register"):
|
|
108
|
+
ident = (child.text or "").strip()
|
|
109
|
+
if not ident:
|
|
110
|
+
continue
|
|
111
|
+
key = natural_key(ident)
|
|
112
|
+
if name in last and key < last[name]:
|
|
113
|
+
report.add(rule, str(path), child.sourceline,
|
|
114
|
+
f"{name} {ident!r} out of canonical order (expected non-decreasing natural sort by id/name)")
|
|
115
|
+
last[name] = key
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
|
|
5
|
+
from .model import Diagnostic, Rule
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass
|
|
9
|
+
class Report:
|
|
10
|
+
diagnostics: list[Diagnostic] = field(default_factory=list)
|
|
11
|
+
|
|
12
|
+
def add(self, rule: Rule, file_: str, line: int | None, message: str) -> None:
|
|
13
|
+
self.diagnostics.append(Diagnostic(rule.id, rule.severity, file_, line, message))
|
|
14
|
+
|
|
15
|
+
@property
|
|
16
|
+
def errors(self) -> list[Diagnostic]:
|
|
17
|
+
return [d for d in self.diagnostics if d.severity == "error"]
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def warnings(self) -> list[Diagnostic]:
|
|
21
|
+
return [d for d in self.diagnostics if d.severity == "warning"]
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""Flipova Foundation documentation generator (implementation package).
|
|
2
|
+
|
|
3
|
+
Split out of the historical ``docgen.py`` monolith for modularity:
|
|
4
|
+
|
|
5
|
+
- ``xsddoc.py`` : generic XSD -> Markdown walker (Schema Reference)
|
|
6
|
+
- ``model.py`` : parse_manifest / parse_documentation + typed models
|
|
7
|
+
- ``reference.py`` : tokens / themes / schema reference renderers
|
|
8
|
+
- ``site.py`` : article rendering, xref resolution, site writing
|
|
9
|
+
- ``cli.py`` : argument parsing & assembly (``main``)
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from .cli import main
|
|
15
|
+
from .model import DocArticle, DocSection, parse_documentation, parse_manifest
|
|
16
|
+
from .reference import (
|
|
17
|
+
render_schema_reference,
|
|
18
|
+
render_themes_reference,
|
|
19
|
+
render_tokens_reference,
|
|
20
|
+
)
|
|
21
|
+
from .site import build_title_index, render_article_body, resolve_xrefs, write_site
|
|
22
|
+
from .xsddoc import collect_types, render_markdown
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
# model
|
|
26
|
+
"DocArticle",
|
|
27
|
+
"DocSection",
|
|
28
|
+
# site
|
|
29
|
+
"build_title_index",
|
|
30
|
+
# xsd walker
|
|
31
|
+
"collect_types",
|
|
32
|
+
# cli
|
|
33
|
+
"main",
|
|
34
|
+
"parse_documentation",
|
|
35
|
+
"parse_manifest",
|
|
36
|
+
"render_article_body",
|
|
37
|
+
# reference
|
|
38
|
+
"render_markdown",
|
|
39
|
+
"render_schema_reference",
|
|
40
|
+
"render_themes_reference",
|
|
41
|
+
"render_tokens_reference",
|
|
42
|
+
"resolve_xrefs",
|
|
43
|
+
"write_site",
|
|
44
|
+
]
|
|
45
|
+
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""docgen CLI - assembles the content kinds and writes the site.
|
|
2
|
+
|
|
3
|
+
python3 docgen.py --manifest ../../manifest.xml --documentation ../../documentation.xml
|
|
4
|
+
--root ../.. --out ../../docs/generated
|
|
5
|
+
(or via the wrappers: design/tools/unix/doc.sh / windows/doc.cmd)
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import argparse
|
|
10
|
+
import json
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
15
|
+
|
|
16
|
+
from .model import parse_documentation, parse_manifest
|
|
17
|
+
from .reference import (
|
|
18
|
+
render_schema_reference,
|
|
19
|
+
render_themes_reference,
|
|
20
|
+
render_tokens_reference,
|
|
21
|
+
)
|
|
22
|
+
from .site import write_site
|
|
23
|
+
|
|
24
|
+
# ---------------------------------------------------------------------------
|
|
25
|
+
# CLI
|
|
26
|
+
# ---------------------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
def main() -> int:
|
|
29
|
+
repo_root_default = Path(__file__).resolve().parents[4]
|
|
30
|
+
default_manifest = repo_root_default / "design" / "manifest.xml"
|
|
31
|
+
|
|
32
|
+
parser = argparse.ArgumentParser(
|
|
33
|
+
description="Generate the Flipova Foundation documentation site from the manifest and documentation.xml.")
|
|
34
|
+
parser.add_argument("--manifest", "-m", default=str(default_manifest))
|
|
35
|
+
parser.add_argument("--documentation", "-d", default=None,
|
|
36
|
+
help="Path to documentation.xml (default: <design dir>/documentation.xml)")
|
|
37
|
+
parser.add_argument("--root", "-r", default=None,
|
|
38
|
+
help="Repo root (defaults to the manifest's parent's parent, "
|
|
39
|
+
"i.e. the directory containing design/)")
|
|
40
|
+
parser.add_argument("--out", "-o", default=None,
|
|
41
|
+
help="Output directory for the generated site "
|
|
42
|
+
"(default: <repo root>/docs/generated)")
|
|
43
|
+
args = parser.parse_args()
|
|
44
|
+
|
|
45
|
+
manifest_path = Path(args.manifest).resolve()
|
|
46
|
+
design_dir = manifest_path.parent
|
|
47
|
+
root = Path(args.root).resolve() if args.root else design_dir.parent
|
|
48
|
+
out_dir = Path(args.out).resolve() if args.out else root / "docs" / "generated"
|
|
49
|
+
doc_path = Path(args.documentation).resolve() if args.documentation else design_dir / "documentation.xml"
|
|
50
|
+
if not doc_path.exists():
|
|
51
|
+
raise SystemExit(f"documentation file not found: {doc_path} -- run docgen from a checkout containing design/documentation.xml")
|
|
52
|
+
|
|
53
|
+
model = parse_manifest(manifest_path)
|
|
54
|
+
model["doc_sections"] = parse_documentation(doc_path)
|
|
55
|
+
|
|
56
|
+
schema_path = design_dir / "schema.xsd"
|
|
57
|
+
tokens_path = design_dir / "tokens.xml"
|
|
58
|
+
themes_path = design_dir / "themes.xml"
|
|
59
|
+
|
|
60
|
+
dynamic: dict[str, str] = {}
|
|
61
|
+
try:
|
|
62
|
+
dynamic["schema"] = render_schema_reference(schema_path)
|
|
63
|
+
except Exception as exc: # noqa: BLE001
|
|
64
|
+
print(f"warning: could not render schema reference: {exc}", file=sys.stderr)
|
|
65
|
+
dynamic["schema"] = "_Schema reference unavailable -- see `design/schema.xsd` directly._\n"
|
|
66
|
+
|
|
67
|
+
dynamic["tokens"] = render_tokens_reference(tokens_path)
|
|
68
|
+
dynamic["themes"] = render_themes_reference(themes_path)
|
|
69
|
+
|
|
70
|
+
# Version stamping: the ONE version is the root package.json (the version
|
|
71
|
+
# actually published). The registry deliberately stores no copy of it, so
|
|
72
|
+
# there is nothing that can drift after `changeset version` bumps it.
|
|
73
|
+
# Resolved BEFORE writing the site: the generated pages show the version.
|
|
74
|
+
version = ""
|
|
75
|
+
try:
|
|
76
|
+
version = json.loads((root / "package.json").read_text(encoding="utf-8")).get("version", "")
|
|
77
|
+
except (ValueError, OSError):
|
|
78
|
+
version = ""
|
|
79
|
+
model["version"] = version
|
|
80
|
+
|
|
81
|
+
written = write_site(model, out_dir, dynamic, root)
|
|
82
|
+
|
|
83
|
+
# Keep the Docusaurus site package.json (docs/package.json) aligned.
|
|
84
|
+
site_pkg_path = out_dir.parent / "package.json"
|
|
85
|
+
if version and site_pkg_path.exists():
|
|
86
|
+
try:
|
|
87
|
+
site_pkg = json.loads(site_pkg_path.read_text(encoding="utf-8"))
|
|
88
|
+
if site_pkg.get("version") != version:
|
|
89
|
+
site_pkg["version"] = version
|
|
90
|
+
with open(site_pkg_path, "w", encoding="utf-8", newline="\n") as fh:
|
|
91
|
+
fh.write(json.dumps(site_pkg, indent=2) + "\n")
|
|
92
|
+
print(f"synced {site_pkg_path} version -> {version}")
|
|
93
|
+
except (ValueError, OSError) as exc:
|
|
94
|
+
print(f"warning: could not sync {site_pkg_path}: {exc}", file=sys.stderr)
|
|
95
|
+
|
|
96
|
+
print(f"Documentation generated: {len(written)} file(s) under {out_dir}")
|
|
97
|
+
return 0
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
if __name__ == "__main__":
|
|
101
|
+
sys.exit(main())
|