hello/scripts/build.luau

80 lines
1.7 KiB
Text
Raw Permalink Normal View History

2024-10-12 17:56:33 +01:00
--!strict
local fs = require("@lune/fs")
local serde = require("@lune/serde")
type Target = {
environment: string,
lib: string,
bin: string?,
build_files: { string }?,
}
local TARGETS: { [string]: Target } = {
luau = {
environment = "luau",
lib = "lib.luau",
bin = "bin.luau",
},
lune = {
environment = "lune",
lib = "lib.luau",
bin = "bin.luau",
},
roblox = {
environment = "roblox",
lib = "lib.luau",
build_files = { "lib.luau" },
},
}
local baseManifest = fs.readFile("pesde-base.toml")
local binScript = fs.readFile("bin.luau")
local libTemplate = fs.readFile("lib.luau")
local manifest = serde.decode("toml", baseManifest)
if fs.isDir("build") then
fs.removeDir("build")
end
fs.writeDir("build")
for targetName, target in TARGETS do
local outDir = `build/{targetName}`
fs.writeDir(outDir)
local includes = {
"pesde.toml",
"README.md",
"LICENSE",
2024-10-29 20:06:05 +00:00
"docs",
2024-10-12 17:56:33 +01:00
}
fs.copy("LICENSE", `{outDir}/LICENSE`)
fs.copy("README.md", `{outDir}/README.md`)
2024-10-29 20:06:05 +00:00
fs.copy("docs", `{outDir}/docs`)
2024-10-12 17:56:33 +01:00
if target.lib then
local message = `Hello, pesde! ({manifest.name}@{manifest.version}, {targetName})`
local file = string.gsub(libTemplate, "<< PRINT MESSAGE >>", message)
fs.writeFile(`{outDir}/{target.lib}`, file)
table.insert(includes, target.lib)
end
if target.bin then
fs.writeFile(`{outDir}/{target.bin}`, binScript)
table.insert(includes, target.bin)
end
local targetSection = serde.encode("toml", { target = target }, true)
local includesSection = serde.encode("toml", { includes = includes }, true)
local manifestFile = baseManifest
manifestFile ..= "\n" .. targetSection
manifestFile = string.gsub(manifestFile, "includes = %[%]\n", includesSection)
fs.writeFile(`{outDir}/pesde.toml`, manifestFile)
end