forked from polyfillpolyfill/polyfill-service
-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate-library-json.py
49 lines (35 loc) · 1.31 KB
/
generate-library-json.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
import sys
import json
from glob import glob
folder = sys.argv[1]
out_json = {}
out_json["polyfills"] = []
out_json["polyfillAliases"] = {}
out_json["version"] = "add version here"
for polyfill_folder in glob(folder + "/*"):
polyfill = polyfill_folder.replace(folder + "/", "")
if polyfill == "aliases.json":
continue
if polyfill.startswith("_"):
continue
if ".~" in polyfill:
index = polyfill.index(".~")
polyfill = polyfill[:index]
f = open(polyfill_folder + "/meta.json", "r")
meta = json.loads(f.read())
f.close()
if "aliases" in meta:
for alias in meta["aliases"]:
if alias.startswith("dom") or alias.startswith("es") or alias == "default":
if alias not in out_json["polyfillAliases"]:
out_json["polyfillAliases"][alias] = []
out_json["polyfillAliases"][alias].append(polyfill)
if polyfill not in out_json["polyfills"]:
out_json["polyfills"].append(polyfill)
out_json["polyfills"].sort()
for alias in out_json["polyfillAliases"]:
out_json["polyfillAliases"][alias].sort()
polyfillAliases = list(out_json["polyfillAliases"].keys())
polyfillAliases.sort()
out_json["polyfillAliases"] = {i: out_json["polyfillAliases"][i] for i in polyfillAliases}
print(json.dumps(out_json))