forked from polyfillpolyfill/polyfill-service
-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate-meta-db.py
73 lines (60 loc) · 1.86 KB
/
generate-meta-db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from glob import glob
print("//! Metadata files")
print("//!")
print("//! DO NOT EDIT MANUALLY")
print("//! generated by: python3 generate-meta-db.py > library/src/meta.rs")
def generate_version(version):
folder = "./polyfill-libraries/" + version
files = glob(folder + "/*/meta.json")
safe_version = version.replace(".", "_")
def key(name):
return f"F_{safe_version}_" + name \
.replace("/", "_") \
.replace(".", "_") \
.replace("-", "_") \
.replace("~", "_") \
.replace("@", "_") \
.upper()
for file in files:
f = open(file, "r")
contents = f.read()
f.close()
name = key(file.replace(folder, ""))
contents = contents.replace("#", "\\\\#")
print("const %s: &str = r#\"%s\"#;" % (name, contents))
print("")
print("pub(crate) fn lookup_" + safe_version + "(n: &str) -> Option<&'static str> {")
print(" match n {")
for file in files:
name = file.replace(folder, "")
print(" \"%s\" => Some(%s)," % (name, key(name)))
print(" _ => None,")
print(" }")
print("}")
generate_version("3.101.0")
generate_version("3.103.0")
generate_version("3.104.0")
generate_version("3.108.0")
generate_version("3.109.0")
generate_version("3.110.1")
generate_version("3.111.0")
generate_version("3.27.4")
generate_version("3.34.0")
generate_version("3.39.0")
generate_version("3.40.0")
generate_version("3.41.0")
generate_version("3.42.0")
generate_version("3.46.0")
generate_version("3.48.0")
generate_version("3.50.2")
generate_version("3.51.0")
generate_version("3.52.0")
generate_version("3.52.1")
generate_version("3.52.2")
generate_version("3.52.3")
generate_version("3.53.1")
generate_version("3.89.4")
generate_version("3.96.0")
generate_version("3.98.0")
generate_version("4.8.0")
generate_version("3.25.1")