Improve lua build process + folder structure

This commit is contained in:
Kai Vogelgesang 2022-09-26 22:16:31 +02:00
parent cf0be21596
commit 52b4c9000f
Signed by: kai
GPG Key ID: 0A95D3B6E62C0879
12 changed files with 38 additions and 23 deletions

View File

@ -1,30 +1,31 @@
default:
@just --list
lua_files := `find . -type f -name "*.lua" ! -path './out/*' ! -name tlconfig.lua ! -name minify.lua -printf "%p "`
teal_files := `find . -type f -name "*.tl" ! -name '*.d.tl' -printf "%p "`
build:
mkdir -p out
for file in {{lua_files}}; do \
lua minify.lua $file; \
done
for file in {{teal_files}}; do \
tl gen $file; \
lua minify.lua ${file%.tl}.lua; \
rm ${file%.tl}.lua; \
done
build: && manifest
tl build
@mkdir -p out/vendor
find src/vendor -name "*.lua" -exec cp -t out/vendor {} +
alias b := build
manifest_file := "out/manifest.txt"
manifest:
rm -f {{ manifest_file }}
find out -name "*.lua" -exec realpath --relative-to=out {} >> {{ manifest_file }} \;
min-build: build
find out -name "*.lua" -exec lua minify.lua {} \;
clean:
rm -r out
alias c := clean
watch_recipe := env_var_or_default("WATCH_RECIPE", "build")
watch:
while sleep 0.1; do \
find . -type f ! -path './out/*' | entr -d just build; \
find . -type f ! -path './out/*' | entr -d just {{ watch_recipe }}; \
[ $? -eq 0 ] && exit 0; \
done

View File

@ -11,6 +11,6 @@ parser.minify(ast, true)
local output = parser.toLua(ast)
local f = io.open("out/"..filename, "w")
local f = io.open(filename, "w")
f:write(output)
f:close()

View File

@ -1,7 +1,7 @@
local json = require("json")
local Framebuffer = require("framebuffer")
local Ringbuffer = require("ringbuffer")
local Socket = require("socket")
local json = require("vendor/json")
local Framebuffer = require("lib/framebuffer")
local Ringbuffer = require("lib/ringbuffer")
local Socket = require("lib/socket")
local auth = require("auth")
local ENDPOINT <const> = auth.server:gsub("http", "ws", 1) .. "/ipmi/computer/" .. auth.id .. "/ws"
local HEADERS <const> = { ["Authorization"] = "Bearer " .. auth.token }

View File

@ -1,4 +1,7 @@
return {
source_dir = "src",
include_dir = {"src"},
build_dir = "out",
global_env_def = "cc",
gen_target = "5.1",
}

View File

@ -23,11 +23,22 @@ app.mount("/tiles/", map_tiles)
app.mount("/ipmi/", monitoring)
app.mount("/api/", api)
installer = j2env.get_template("install.lua").render(deploy_path=settings.deploy_path)
def render_lua_installer():
with open(f"{settings.lua_out_path}/manifest.txt", "r") as f:
file_list = [name.strip() for name in f.readlines()]
return j2env.get_template("install.lua").render(
deploy_path=settings.deploy_path, file_list=file_list
)
installer = render_lua_installer()
@app.get("/install")
async def get_installer():
if settings.dev_mode:
installer = render_lua_installer()
return PlainTextResponse(installer)

View File

@ -1,6 +1,6 @@
local args = { ... }
local token = args[1]
local existing = fs.exists("auth.lua")
if not token and not existing then
error("A token is required.")
@ -16,8 +16,8 @@ elseif token then
error("Token failed!")
end
end
local files = { "main.lua", "json.lua", "framebuffer.lua", "ringbuffer.lua", "socket.lua" }
local files = { {% for filename in file_list %} "{{ filename }}", {% endfor %} }
for _, file in ipairs(files) do
fs.delete(file)
shell.run(("wget %s/lua/%s"):format(path, file))
shell.run(("wget %s/lua/%s %s"):format(path, file, file))
end