Test
This commit is contained in:
35
.github/workflows/minify.yml
vendored
35
.github/workflows/minify.yml
vendored
@@ -35,32 +35,49 @@ jobs:
|
|||||||
local lfs = require("lfs")
|
local lfs = require("lfs")
|
||||||
|
|
||||||
local files = {}
|
local files = {}
|
||||||
for file in lfs.dir("src") do
|
|
||||||
if file:match("%.lua$") then
|
local function scanDir(dir, baseDir)
|
||||||
table.insert(files, file)
|
baseDir = baseDir or ""
|
||||||
|
for file in lfs.dir(dir) do
|
||||||
|
if file ~= "." and file ~= ".." then
|
||||||
|
local fullPath = dir .. "/" .. file
|
||||||
|
local attr = lfs.attributes(fullPath)
|
||||||
|
if attr.mode == "directory" then
|
||||||
|
scanDir(fullPath, baseDir .. file .. "/")
|
||||||
|
elseif file:match("%.lua$") then
|
||||||
|
table.insert(files, {
|
||||||
|
path = baseDir .. file,
|
||||||
|
fullPath = fullPath
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scanDir("src")
|
||||||
|
|
||||||
local output = {
|
local output = {
|
||||||
'local minified = true\n',
|
'local minified = true\n',
|
||||||
'local project = {}\n'
|
'local project = {}\n',
|
||||||
|
'local baseRequire = require\n',
|
||||||
|
'require = function(path) return project[path] or baseRequire(path) end\n'
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file in ipairs(files) do
|
for _, file in ipairs(files) do
|
||||||
local f = io.open("src/" .. file, "r")
|
local f = io.open(file.fullPath, "r")
|
||||||
local content = f:read("*all")
|
local content = f:read("*all")
|
||||||
f:close()
|
f:close()
|
||||||
|
|
||||||
local success, minified = minify(content)
|
local success, minified = minify(content)
|
||||||
if not success then
|
if not success then
|
||||||
print("Failed to minify " .. file)
|
print("Failed to minify " .. file.path)
|
||||||
print(minified)
|
print(minified)
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(output, string.format(
|
table.insert(output, string.format(
|
||||||
'project["%s"] = function(...) %s end\n',
|
'project["%s"] = function(...) %s end\n',
|
||||||
file, minified
|
file.path, minified
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -77,8 +94,8 @@ jobs:
|
|||||||
echo "Running minification..."
|
echo "Running minification..."
|
||||||
if lua minify_script.lua; then
|
if lua minify_script.lua; then
|
||||||
echo "Minification successful"
|
echo "Minification successful"
|
||||||
echo "Minified content:"
|
echo "Files processed:"
|
||||||
cat release/project.min.lua
|
find src -name "*.lua" | sed 's|^src/||'
|
||||||
else
|
else
|
||||||
echo "Minification failed"
|
echo "Minification failed"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -112,5 +112,6 @@ function basalt.run(isActive)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
basalt.autoUpdate = basalt.run
|
||||||
|
|
||||||
return basalt
|
return basalt
|
||||||
Reference in New Issue
Block a user