mirror of
https://github.com/0x5eal/terracotta.git
synced 2024-12-12 12:50:35 +00:00
chore(scripts): prettier tui for make script
This commit is contained in:
parent
4218024182
commit
81f7bfc078
1 changed files with 78 additions and 18 deletions
|
@ -1,6 +1,7 @@
|
||||||
local spawn = require("@lune/process").spawn
|
local spawn = require("@lune/process").spawn
|
||||||
local stdio = require("@lune/stdio")
|
local stdio = require("@lune/stdio")
|
||||||
local fs = require("@lune/fs")
|
local fs = require("@lune/fs")
|
||||||
|
local task = require("@lune/task")
|
||||||
|
|
||||||
local codegen = require("../darklua/codegen")
|
local codegen = require("../darklua/codegen")
|
||||||
|
|
||||||
|
@ -8,6 +9,45 @@ 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")
|
return stdio.color(if type == "error" then "red" else "green") .. (scope or "[wax]") .. stdio.color("reset")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local boxifyOutput = function(msg: string)
|
||||||
|
local pad = (" "):rep(#msg / 2)
|
||||||
|
|
||||||
|
if msg:find("\n") then
|
||||||
|
local lines = msg:split("\n")
|
||||||
|
local paddingNum = 0
|
||||||
|
|
||||||
|
for k, line in lines do
|
||||||
|
if paddingNum and #line > paddingNum then
|
||||||
|
paddingNum = math.round(#line / 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
pad = (" "):rep(paddingNum)
|
||||||
|
|
||||||
|
local processedLines = {}
|
||||||
|
|
||||||
|
for k, line in lines do
|
||||||
|
local paddedMsg = pad .. line .. (" "):rep((paddingNum * 5.5) - paddingNum - utf8.len(line))
|
||||||
|
|
||||||
|
-- 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
|
||||||
|
|
||||||
|
print("┏" .. ("━"):rep(paddingNum * 5.5) .. "┓")
|
||||||
|
print(table.concat(processedLines, "\n"))
|
||||||
|
print("┗" .. ("━"):rep(paddingNum * 5.5) .. "┛")
|
||||||
|
else
|
||||||
|
print("┏" .. ("━"):rep(#msg * 4) .. "┓")
|
||||||
|
print("┃" .. pad .. msg .. pad .. " " .. "┃")
|
||||||
|
print("┗" .. ("━"):rep(#msg * 4) .. "┛")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
print(`{WAX_PREFIX_FORMAT("info", "[codegen]")} Generating darklua config file at darklua.config.json`)
|
print(`{WAX_PREFIX_FORMAT("info", "[codegen]")} Generating darklua config file at darklua.config.json`)
|
||||||
fs.writeFile(
|
fs.writeFile(
|
||||||
".darklua.json5",
|
".darklua.json5",
|
||||||
|
@ -20,31 +60,51 @@ fs.writeFile(
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
print()
|
|
||||||
print("------------------------------------------------------------------")
|
|
||||||
|
|
||||||
codegen({
|
codegen({
|
||||||
rules = {
|
rules = {
|
||||||
"config",
|
"config",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
local child = spawn(
|
local loader = task.spawn(function()
|
||||||
|
local chars = { "-", "\\", "|", "/" }
|
||||||
|
local isFirstRun = true
|
||||||
|
|
||||||
|
stdio.write(`{WAX_PREFIX_FORMAT("info", "[build]")} Building with terracotta with wax... `)
|
||||||
|
|
||||||
|
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()
|
||||||
|
local child = spawn(
|
||||||
"lune",
|
"lune",
|
||||||
{ "wax", "bundle", "input=default.project.json", "verbose=true", "minify=true", "output=terracotta.luau" },
|
{ "wax", "bundle", "input=default.project.json", "verbose=true", "minify=true", "output=terracotta.luau" }
|
||||||
{
|
)
|
||||||
stdio = "inherit",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
print("------------------------------------------------------------------")
|
task.cancel(loader)
|
||||||
|
print("\b \n")
|
||||||
|
|
||||||
if not child.ok then
|
boxifyOutput(child.stdout)
|
||||||
|
|
||||||
|
if not child.ok then
|
||||||
print()
|
print()
|
||||||
print(`{WAX_PREFIX_FORMAT("error")} Exited with code {child.code}.`)
|
print(`{WAX_PREFIX_FORMAT("error")} Exited with code {child.code}.`)
|
||||||
else
|
else
|
||||||
print()
|
print()
|
||||||
print(`{WAX_PREFIX_FORMAT("info")} Successfully built terracotta.luau!`)
|
print(`{WAX_PREFIX_FORMAT("info")} Successfully built terracotta.luau!`)
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
fs.removeFile(".darklua.json5")
|
fs.removeFile(".darklua.json5")
|
||||||
|
|
Loading…
Reference in a new issue