2023-09-26 14:44:58 +01:00
|
|
|
local spawn = require("@lune/process").spawn
|
|
|
|
local stdio = require("@lune/stdio")
|
|
|
|
local fs = require("@lune/fs")
|
2023-09-26 19:40:17 +01:00
|
|
|
local task = require("@lune/task")
|
2023-09-26 14:44:58 +01:00
|
|
|
|
|
|
|
local codegen = require("../darklua/codegen")
|
|
|
|
|
|
|
|
local WAX_PREFIX_FORMAT = function(type: "error" | "info", scope: string?)
|
|
|
|
return stdio.color(if type == "error" then "red" else "green") .. (scope or "[wax]") .. stdio.color("reset")
|
|
|
|
end
|
|
|
|
|
2023-09-26 19:55:15 +01:00
|
|
|
local LARGE_SCALE_FACTOR = 5.5
|
|
|
|
local REGULAR_SCALE_FACTOR = 4
|
|
|
|
|
2023-09-26 19:49:18 +01:00
|
|
|
local BoxifyOutput = function(msg: string)
|
2023-09-26 19:40:17 +01:00
|
|
|
local pad = (" "):rep(#msg / 2)
|
|
|
|
|
|
|
|
if msg:find("\n") then
|
|
|
|
local lines = msg:split("\n")
|
|
|
|
local paddingNum = 0
|
|
|
|
|
2023-09-26 19:50:19 +01:00
|
|
|
for _, line in lines do
|
2023-09-26 19:40:17 +01:00
|
|
|
if paddingNum and #line > paddingNum then
|
|
|
|
paddingNum = math.round(#line / 2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
pad = (" "):rep(paddingNum)
|
|
|
|
|
|
|
|
local processedLines = {}
|
|
|
|
|
|
|
|
for k, line in lines do
|
2023-09-26 19:55:15 +01:00
|
|
|
local paddedMsg = pad .. line .. (" "):rep((paddingNum * LARGE_SCALE_FACTOR) - paddingNum - utf8.len(line))
|
2023-09-26 19:40:17 +01:00
|
|
|
|
|
|
|
-- This is a hack for outputs made by wax, if the first line contains
|
|
|
|
-- "creating directory"
|
|
|
|
if line:find("Creating directory") and k == 1 then
|
|
|
|
paddedMsg ..= " "
|
|
|
|
end
|
|
|
|
|
|
|
|
table.insert(processedLines, "┃" .. paddedMsg .. "┃")
|
|
|
|
end
|
|
|
|
|
2023-09-26 19:55:15 +01:00
|
|
|
print("┏" .. ("━"):rep(paddingNum * LARGE_SCALE_FACTOR) .. "┓")
|
2023-09-26 19:40:17 +01:00
|
|
|
print(table.concat(processedLines, "\n"))
|
2023-09-26 19:55:15 +01:00
|
|
|
print("┗" .. ("━"):rep(paddingNum * LARGE_SCALE_FACTOR) .. "┛")
|
2023-09-26 19:40:17 +01:00
|
|
|
else
|
2023-09-26 19:55:15 +01:00
|
|
|
print("┏" .. ("━"):rep(#msg * REGULAR_SCALE_FACTOR) .. "┓")
|
2023-09-26 19:40:17 +01:00
|
|
|
print("┃" .. pad .. msg .. pad .. " " .. "┃")
|
2023-09-26 19:55:15 +01:00
|
|
|
print("┗" .. ("━"):rep(#msg * REGULAR_SCALE_FACTOR) .. "┛")
|
2023-09-26 19:40:17 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-19 12:02:15 +01:00
|
|
|
if not fs.isDir("dist/") then
|
|
|
|
fs.writeDir("dist/")
|
|
|
|
end
|
|
|
|
|
2023-09-26 14:44:58 +01:00
|
|
|
print(`{WAX_PREFIX_FORMAT("info", "[codegen]")} Generating darklua config file at darklua.config.json`)
|
2023-10-19 12:05:42 +01:00
|
|
|
|
|
|
|
if not fs.isFile("dist/.darklua.json5") then
|
|
|
|
fs.writeFile(
|
|
|
|
"dist/.darklua.json5",
|
|
|
|
codegen({
|
|
|
|
generator = "dense",
|
|
|
|
rules = {
|
|
|
|
"remove_spaces",
|
|
|
|
"remove_comments",
|
|
|
|
"rename_variables",
|
|
|
|
"rename_variables",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
end
|
2023-09-26 14:44:58 +01:00
|
|
|
|
2023-09-26 19:40:17 +01:00
|
|
|
local loader = task.spawn(function()
|
|
|
|
local chars = { "-", "\\", "|", "/" }
|
|
|
|
local isFirstRun = true
|
2023-09-26 14:44:58 +01:00
|
|
|
|
2023-09-26 19:40:17 +01:00
|
|
|
stdio.write(`{WAX_PREFIX_FORMAT("info", "[build]")} Building with terracotta with wax... `)
|
2023-09-26 14:44:58 +01:00
|
|
|
|
2023-09-26 19:40:17 +01:00
|
|
|
while true do
|
|
|
|
for _, char in chars do
|
|
|
|
task.wait(0.1)
|
|
|
|
|
|
|
|
if not isFirstRun then
|
|
|
|
stdio.write("\b")
|
|
|
|
end
|
|
|
|
|
|
|
|
stdio.write(char)
|
|
|
|
|
|
|
|
isFirstRun = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
task.spawn(function()
|
2023-10-19 12:02:15 +01:00
|
|
|
local child = spawn("lune", {
|
|
|
|
"wax",
|
|
|
|
"bundle",
|
|
|
|
"input=default.project.json",
|
|
|
|
"verbose=true",
|
|
|
|
"minify=true",
|
|
|
|
"ci-mode=true",
|
2023-10-19 12:05:42 +01:00
|
|
|
"darklua-config-path=dist/.darklua.json5",
|
2023-10-19 12:02:15 +01:00
|
|
|
"output=dist/terracotta.luau",
|
|
|
|
})
|
2023-09-26 19:40:17 +01:00
|
|
|
|
|
|
|
task.cancel(loader)
|
|
|
|
print("\b \n")
|
|
|
|
|
2023-09-26 19:49:18 +01:00
|
|
|
BoxifyOutput(child.stdout)
|
2023-09-26 19:40:17 +01:00
|
|
|
|
|
|
|
if not child.ok then
|
|
|
|
print()
|
|
|
|
print(`{WAX_PREFIX_FORMAT("error")} Exited with code {child.code}.`)
|
|
|
|
else
|
|
|
|
print()
|
|
|
|
print(`{WAX_PREFIX_FORMAT("info")} Successfully built terracotta.luau!`)
|
|
|
|
end
|
2023-09-26 20:00:06 +01:00
|
|
|
end)
|