Skip to content

Commit 3190745

Browse files
committed
Refactor almost all components.
1 parent 41ecff7 commit 3190745

38 files changed

Lines changed: 3578 additions & 1918 deletions

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,10 @@ pnpm-debug.log*
162162
*.njsproj
163163
*.sln
164164
*.sw?
165+
.marscode
166+
167+
# Subpackages
168+
3rd-party/
169+
170+
# Auto-generated files
171+
public/licenses-data

.rubisco/gen-licenses-data.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: 📄 Generate licenses-data.
2+
3+
steps:
4+
- name: 📁 Create licenses-data directory.
5+
mkdir: public/licenses-data
6+
7+
- name: 📄 Find licenses metadata files.
8+
glob: "3rd-party/license-list-data/json/details/*.json"
9+
save-to: licenses-meta-files
10+
11+
- name: 🛠️ Copy and trim JSON files.
12+
matrix:
13+
file: ${{ licenses-meta-files }}
14+
steps:
15+
- name: 🛠️ Build JSON file for ${{ file }}.
16+
run:
17+
[
18+
"${{ python }}",
19+
".rubisco/licenses-meta.py",
20+
"${{ file }}",
21+
"3rd-party/license-list-data/html/$&{{ file.stem }}.html",
22+
"public/licenses-data/$&{{ file.stem }}.json",
23+
]

.rubisco/licenses-meta.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env python3
2+
3+
# -*- mode: python -*-
4+
# vi: set ft=python :
5+
6+
# pylint: disable=C0103
7+
8+
# Copyright (C) 2024 The C++ Plus Project.
9+
# This file is part of the Rubisco Extension Repository.
10+
#
11+
# Rubisco Extension Repository is free software: you can redistribute it and/or
12+
# modify it under the terms of the GNU General Public License as published
13+
# by the Free Software Foundation, either version 3 of the License,
14+
# or (at your option) any later version.
15+
#
16+
# Rubisco Extension Repository is distributed in the hope that it will be
17+
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
# GNU General Public License for more details.
20+
#
21+
# You should have received a copy of the GNU General Public License
22+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
23+
24+
"""Utility script to trim the license metadata JSON file."""
25+
26+
import json
27+
import sys
28+
from pathlib import Path
29+
from typing import cast
30+
31+
32+
def get_typecheck[T](obj: object, expected_type: type[T]) -> T:
33+
"""Check the type of an object and return it if it matches.
34+
35+
Returns:
36+
T: The object cast to the expected type.
37+
38+
"""
39+
if not isinstance(obj, expected_type):
40+
sys.exit(f"Error: Expected {expected_type}, got {type(obj)}.")
41+
return obj
42+
43+
44+
if __name__ == "__main__":
45+
if len(sys.argv) != 4: # noqa: PLR2004
46+
sys.exit("Usage: licenses-meta.py metafile htmlfile destfile")
47+
src_file = Path(sys.argv[1])
48+
license_html = Path(sys.argv[2])
49+
dest_file = Path(sys.argv[3])
50+
with (
51+
src_file.open(encoding="utf-8") as in_file,
52+
dest_file.open("w", encoding="utf-8") as out_file,
53+
):
54+
data_ = json.load(in_file)
55+
if not isinstance(data_, dict):
56+
sys.exit(f"Error: {src_file} does not contain a JSON object.")
57+
data = cast("dict[str, object]", data_)
58+
out_data: dict[str, str | bool] = {}
59+
out_data["isFsfLibre"] = get_typecheck(
60+
data.get("isFsfLibre", False),
61+
bool,
62+
)
63+
out_data["name"] = get_typecheck(data["name"], str)
64+
out_data["isOsiApproved"] = get_typecheck(
65+
data.get("isOsiApproved", False),
66+
bool,
67+
)
68+
license_id = get_typecheck(data["licenseId"], str)
69+
out_data["licenseHtmlText"] = license_html.read_text(encoding="utf-8")
70+
json.dump(out_data, out_file, ensure_ascii=False, sort_keys=True)

hooks.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
},
66
"build": {
77
"exec": "npm run build"
8+
},
9+
"gen-licenses-data": {
10+
"run": ".rubisco/gen-licenses-data.yml"
811
}
912
}
1013
}

0 commit comments

Comments
 (0)