mirror of
https://github.com/pesde-pkg/hello.git
synced 2024-12-12 19:30:37 +00:00
77 lines
1.7 KiB
Text
77 lines
1.7 KiB
Text
--!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",
|
|
}
|
|
|
|
fs.copy("LICENSE", `{outDir}/LICENSE`)
|
|
fs.copy("README.md", `{outDir}/README.md`)
|
|
|
|
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
|