-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgenerateFragmentDocs.py
78 lines (49 loc) · 2.38 KB
/
generateFragmentDocs.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
74
75
76
77
78
import glob, json, os
def write_field(file, langDict, field):
file.write("\n")
file.write(langDict[field["label"]])
file.write(" | " + field["type"])
file.write(" | ")
if "defaultValue" in field:
file.write(str(field["defaultValue"]))
file.write(" | ")
if "description" in field:
file.write(str(field["description"]))
collectionsReadmeFile = open("collections.md", "w")
for module in glob.glob("./modules/*-fragment-collection-contributor"):
langDict = {}
langFile = open(module + "/src/main/resources/content/Language.properties")
langFileLines = langFile.readlines()
for line in langFileLines:
keyValuePair = line.split("=")
langDict[keyValuePair[0]] = keyValuePair[1].rstrip()
for collection in glob.glob(module + "/src/main/resources/**/dependencies/collection.json", recursive=True):
openCollection = open(collection)
collectionData = json.load(openCollection)
collectionsReadmeFile.write("<h2>" + langDict[collectionData["name"]] + "</h2>\n\n")
if "description" in collectionData:
collectionsReadmeFile.write(collectionData["description"] + "\n\n")
for fragment in glob.glob(module + "/src/main/resources/**/dependencies/*", recursive=True):
if (fragment.endswith('collection.json')):
continue
fragmentJSON = open(fragment + "/fragment.json")
fragmentJSONData = json.load(fragmentJSON)
fragmentName = langDict[fragmentJSONData["name"]]
collectionsReadmeFile.write("<h3>" + fragmentName + "</h3>\n\n")
if "description" in fragmentJSONData:
collectionsReadmeFile.write(fragmentJSONData["description"] + "\n\n")
if "thumbnail" in fragmentJSONData:
thumbnailPath = module + "/src/main/resources/META-INF/resources/thumbnails/" + fragmentJSONData["thumbnail"]
collectionsReadmeFile.write("![Image of " + fragmentName + "](" + thumbnailPath + ")\n\n")
if os.stat(fragment + "/index.json").st_size != 0:
indexJSON = open(fragment + "/index.json")
indexJSONData = json.load(indexJSON)
if "fieldSets" in indexJSONData:
collectionsReadmeFile.write("Configuration | Type | Default Value | Description\n")
collectionsReadmeFile.write("------------- | ---- | ------------- | -------------")
for fieldSet in indexJSONData["fieldSets"]:
if "fields" in fieldSet:
for field in fieldSet["fields"]:
write_field(collectionsReadmeFile, langDict, field)
collectionsReadmeFile.write("\n\n")
collectionsReadmeFile.close()