-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprebuilder.py
executable file
·117 lines (100 loc) · 3.83 KB
/
prebuilder.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python3
from FileSystemManager import FileSystemManager
from DesignSystem import DesignSystem
from RustGenerator import RustGenerator
from SchemaGenerator import SchemaGenerator
from ExamplesExporter import ExamplesExporter
from TemplateManager import TemplateManager
import sys
import glob
import os
import logging
import coloredlogs
SOURCE_ROOT = "/data/input"
TARGET_ROOT = "/data/output"
coloredlogs.install(level="INFO", stream=sys.stdout)
def copy_tests(source_path: str, target_path: str) -> None:
source_path = os.path.join(source_path, "tests")
target_path = os.path.join(target_path, "tests")
if not os.path.exists(source_path):
return
FileSystemManager.copy_directory(source_path, target_path)
def copy_static_data(source_path: str, target_path: str) -> None:
EXCLUDE_EXTENSIONS = [
".yaml",
".yml",
".json",
".twig",
".jinja",
".scss",
".css.map",
".js.map",
".py",
".php",
".theme",
".inc",
".md",
"Makefile",
]
EXCLUDE_FOLDERS = [
"tests/",
]
pattern = os.path.join(source_path, "**", "*")
paths = glob.glob(pattern, recursive=True)
paths = [path for path in paths if not os.path.isdir(path)]
for folder in EXCLUDE_FOLDERS:
folder = os.path.join(source_path, folder)
paths = [path for path in paths if not path.startswith(folder)]
for extension in EXCLUDE_EXTENSIONS:
paths = [path for path in paths if not path.endswith(extension)]
for path in paths:
dst = path.replace(source_path, target_path)
FileSystemManager.copy_file(path, dst)
def run_build(cdn: str) -> None:
pattern = os.path.join(SOURCE_ROOT, "**", "info.yml")
generic_schema = SchemaGenerator.get_generic_schema()
for path in glob.glob(pattern, recursive=True):
logging.info(path)
source_path = os.path.dirname(path)
target_path = source_path.replace(SOURCE_ROOT, TARGET_ROOT)
target_path = os.path.join(target_path, "build/")
design_system = DesignSystem(source_path, cdn)
FileSystemManager.prepare_target(target_path)
design_system.export(target_path)
definition = design_system.getData()
rust_generator = RustGenerator()
rust = rust_generator.generate(definition, source_path)
rust_generator.export(rust, target_path)
schema_generator = SchemaGenerator(generic_schema)
schema = schema_generator.generate(definition)
schema_generator.export(schema, target_path)
template_manager = TemplateManager(design_system)
template_manager.copy(source_path, target_path)
# Before ExamplesExporter to avoid conflicts.
copy_tests(source_path, target_path)
examples_exporter = ExamplesExporter()
examples_exporter.export(definition, target_path)
logging.info("Build folder created!")
def run_data() -> None:
pattern = os.path.join(SOURCE_ROOT, "**", "info.yml")
for path in glob.glob(pattern, recursive=True):
logging.info(path)
source_path = os.path.dirname(path)
target_path = source_path.replace(SOURCE_ROOT, TARGET_ROOT)
target_path = os.path.join(target_path, "data/")
FileSystemManager.prepare_target(target_path)
copy_static_data(source_path, target_path)
logging.info("Data folder created!")
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "run":
cdn = sys.argv[2] if len(sys.argv) > 2 else ""
run_build(cdn)
run_data()
elif len(sys.argv) > 1 and sys.argv[1] == "build":
cdn = sys.argv[2] if len(sys.argv) > 2 else ""
run_build(cdn)
elif len(sys.argv) > 1 and sys.argv[1] == "data":
run_data()
else:
logging.error("Unknown command: %s", sys.argv[1])
sys.exit()