forked from windmill-labs/windmilldocs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_public_templates.py
64 lines (46 loc) · 1.37 KB
/
generate_public_templates.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
import os
import json
SCRIPT_P = "/starter/scripts/u/bot/"
root_path = os.listdir()[0]
def build_template(script, obj, name):
return f"""---
title: {obj["summary"]}
---
[See on Github](https://github.com/windmill-labs/windmill/blob/main/starter/scripts/u/bot/{name}.py)
## Description
{obj["description"]}
## Code
```python
{script}
```
## Schema
```json
{json.dumps(obj["schema"], indent=4)}
```
"""
scs = {}
scripts = os.listdir("{}{}".format(root_path, SCRIPT_P))
for s in scripts:
if s.endswith(".py"):
sc = open("{}{}{}".format(root_path, SCRIPT_P, s), "r").read()
name = s.split(".")[0]
c = open("{}{}{}.json".format(root_path, SCRIPT_P, name), "r").read()
p = json.loads(c)
scs[name] = p
wf = open("../docs/Blueprints/scripts/{}.md".format(name), "w")
wf.write(build_template(sc, p, name))
wf.close()
wf = open("../src/components/scripts.json", "w")
wf.write(json.dumps(scs, indent=4, sort_keys=True))
wf.close()
RT_P = "/starter/resource_types/"
resource_types = os.listdir("{}{}".format(root_path, RT_P))
rts = {}
for s in resource_types:
if s.endswith(".json"):
c = open("{}{}{}".format(root_path, RT_P, s), "r").read()
p = json.loads(c)
rts[p["name"]] = p
wf = open("../src/components/resource_types.json", "w")
wf.write(json.dumps(rts, indent=4, sort_keys=True))
wf.close()