2024-03-29 16:55:57 +00:00
|
|
|
local fs = require("@lune/fs")
|
|
|
|
local stdio = require("@lune/stdio")
|
|
|
|
local task = require("@lune/task")
|
|
|
|
|
|
|
|
local terracotta = require("terracotta")
|
|
|
|
|
2024-03-29 18:12:18 +00:00
|
|
|
local LUAU_TYPES_PATH = "out/rbxts/init.luau"
|
2024-03-30 05:53:04 +00:00
|
|
|
local TS_TYPES_PATH = "out/rbxts/index.d.ts"
|
2024-03-29 18:12:18 +00:00
|
|
|
|
2024-03-29 16:55:57 +00:00
|
|
|
local function map<k, v>(tbl: { [k]: v }, callback: (k: k, v: v) -> v)
|
|
|
|
for k, v in tbl do
|
|
|
|
local ok, val = pcall(function()
|
|
|
|
return callback(k, v)
|
|
|
|
end)
|
|
|
|
|
|
|
|
if not ok then
|
|
|
|
tbl[k] = nil
|
|
|
|
else
|
|
|
|
tbl[k] = val
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return tbl
|
|
|
|
end
|
|
|
|
|
|
|
|
print("\n")
|
|
|
|
|
|
|
|
local dirChildren = fs.readDir("out/rbxts")
|
|
|
|
local ENTYRPOINTS = map(dirChildren, function(k, path)
|
2024-03-30 05:53:04 +00:00
|
|
|
if path ~= "rbxts" and path:find("%.lua.?$") then
|
2024-03-29 16:55:57 +00:00
|
|
|
print(`{k}/{#dirChildren} include`, path)
|
|
|
|
return "out/rbxts/" .. path
|
|
|
|
end
|
|
|
|
|
|
|
|
print(`{k}/{#dirChildren} ignore`, path)
|
|
|
|
error("not a lua file")
|
|
|
|
end)
|
|
|
|
|
|
|
|
function main()
|
|
|
|
local bundleStart = os.clock()
|
|
|
|
|
|
|
|
local out = terracotta.Build({
|
|
|
|
entryPoints = ENTYRPOINTS,
|
|
|
|
bundle = true,
|
|
|
|
rules = {
|
|
|
|
"remove_spaces",
|
|
|
|
"remove_unused_while",
|
|
|
|
"remove_unused_if_branch",
|
|
|
|
"remove_empty_do",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
print(`\nbundled {#ENTYRPOINTS} files in {os.clock() - bundleStart}s`)
|
|
|
|
|
|
|
|
local fsStart = os.clock()
|
2024-03-30 06:05:39 +00:00
|
|
|
for pos, path in { TS_TYPES_PATH, table.unpack(ENTYRPOINTS) } do
|
2024-03-29 16:55:57 +00:00
|
|
|
local bundle = out[path]
|
|
|
|
|
2024-03-29 18:12:18 +00:00
|
|
|
if path == LUAU_TYPES_PATH then
|
|
|
|
bundle = fs.readFile(LUAU_TYPES_PATH)
|
2024-03-30 05:53:04 +00:00
|
|
|
elseif path == TS_TYPES_PATH then
|
2024-03-30 06:05:39 +00:00
|
|
|
bundle = fs.readFile(TS_TYPES_PATH)
|
2024-03-29 18:12:18 +00:00
|
|
|
end
|
|
|
|
|
2024-03-29 16:55:57 +00:00
|
|
|
path = "out/" .. path:split("/")[3]
|
2024-03-30 06:05:39 +00:00
|
|
|
stdio.write(`\x1B[2K\r{pos}/{#ENTYRPOINTS + 1} write {path}`)
|
2024-03-30 06:00:36 +00:00
|
|
|
task.wait(0.1)
|
2024-03-29 16:55:57 +00:00
|
|
|
|
|
|
|
fs.writeFile(path, bundle)
|
|
|
|
end
|
|
|
|
|
2024-03-30 06:05:39 +00:00
|
|
|
stdio.write(`\x1B[2K\rwrote {#ENTYRPOINTS + 1} files in {os.clock() - fsStart}s\n`)
|
2024-03-29 16:55:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return main()
|