-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuilder.lua
More file actions
120 lines (87 loc) · 2.6 KB
/
builder.lua
File metadata and controls
120 lines (87 loc) · 2.6 KB
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
118
119
120
string.split = function(str, pat)
local out, counter = { }, 0
string.gsub(str, pat, function(value)
counter = counter + 1
out[counter] = tonumber(value) or value
end)
return out
end
local insertTabInEveryLine = function(str, tabs)
tabs = string.rep("\t", tabs)
str = string.split(str, "([^\n]*)\n?")
for i = 1, #str do
str[i] = tabs .. str[i]
end
return table.concat(str, "\n")
end
local readFile = function(fileName)
local file = io.open(fileName, 'r')
if not file then return end
local content = file:read("*a")
file:close()
return content
end
local modeMetaInfo = { }
local getMode = function(path, src, srcName, notOptimize)
local file, module, package
package = readFile(path .. "package.lua")
local name = load("return " .. package)().name
modeMetaInfo[#modeMetaInfo + 1] = insertTabInEveryLine(string.format("[%q] = %s,", name, package), 1)
module = readFile(path .. "module.lua")
if not module then return end
if not notOptimize then
module = string.format("\t%s[%q] = (modeName == %q) and function()\n%s\n\tend", srcName, name, name, insertTabInEveryLine(module, 2))
else
module = string.format("\t%s[%q] = function()\n%s\n\tend", srcName, name, insertTabInEveryLine(module, 2))
end
if src then
src[#src + 1] = module
else
return module
end
end
local isWindows = string.sub(package.config, 1, 1) == "\\"
local getModes = function(folder, ...)
local file = io.popen((isWindows and "dir /b" or "ls") .. " \"src/" .. folder .. "\"")
local list = string.split(file:read("*a"), "[^\r\n]+")
file:close()
local path = "src/" .. folder .. "/"
local src = { }
for i = 1, #list do
if list[i] ~= "main" then
i = path .. list[i] .. "/"
getMode(i, src, ...)
end
end
return table.concat(src, "\n\n")
end
----------------------------------------------
local main = getMode("src/roomModes/main/", nil, "modules", true)
local modules = getModes("roomModes", "modules")
local tribeModule = getModes("tribeModes", "tribeModule")
modeMetaInfo = "{\n" .. table.concat(modeMetaInfo, "\n") .. "\n}"
local modes = string.format([=[local modeMetaInfo = %s
do -- Main
%s
end
local roomModes = function(modeName)
%s
return modules
end
local tribeModes = function(modeName)
%s
return tribeModule
end]=], modeMetaInfo, main, modules, tribeModule)
----------------------------------------------
local api = readFile("src/api.lua")
local wrapper = readFile("src/wrapper.lua")
local module = string.format([=[--[[ API ]]--
%s
--[[ Modes ]]--
%s
--[[ Wrapper ]]--
%s
]=], api, modes, wrapper)
local file = io.open("builds/" .. os.date("%d_%m_%y") .. ".lua", "w+")
file:write(module)
file:close()