-
Notifications
You must be signed in to change notification settings - Fork 3
/
compile.py
81 lines (61 loc) · 2.11 KB
/
compile.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
import os
import datetime
now = datetime.datetime.now()
PLUGIN = "plugin.lua"
VERSION_PREFIX = "b"
HEADER = """
--[[
THIS FILE IS AUTOGENERATED WITH THE COMPILE.PY FILE.
THIS IS DONE IN ORDER TO ALLOW A MULTIFILE MODULE STRUCTURE
FOR THE PROJECT.
For users:
Don't worry too much about it. You only really need the
plugin.lua file and the settings.ini file. Delete everything
else, if you really don't care about anything.
For developers:
Please refrain from editing the plugin.lua file directly.
Rather, do edit the modules directly and then compile with
the provided script.
]]
-- MODULES:
""".strip() + "\n"
VAR_DICTIONARY = {
"%VERSION%": VERSION_PREFIX + f"{now.year}.{now.month}.{now.day}"
}
def searchTree(path: str) -> (list, list):
modules = []
lines = []
for filePath in os.listdir(path):
newPath = os.path.join(path, filePath)
if os.path.isdir(newPath):
returnValues = searchTree(newPath)
modules.extend(returnValues[0])
lines.extend(returnValues[1])
elif newPath.endswith(".lua"):
moduleName = os.path.basename(newPath)[:-len(".lua")]
if not moduleName.startswith("_"):
modules.append(moduleName)
with open(newPath) as file:
lines.extend([
"",
"-"*85,
f"-- {newPath}",
"-"*85,
""
])
lines.extend([line.strip("\n") for line in file.readlines()])
return modules, lines
def replaceVars(content: str) -> str:
for var in VAR_DICTIONARY:
content = content.replace(var, VAR_DICTIONARY[var])
return content
if __name__ == "__main__":
returnValues = searchTree("modules")
modulesString = "\n".join(
[f"{module} = {{}}" for module in returnValues[0]]
)
content = replaceVars("\n".join(returnValues[1]))
with open(PLUGIN, "w+") as pluginFile:
pluginFile.write(HEADER)
pluginFile.write(modulesString)
pluginFile.write(content)