jecs-nightly/src/init.luau
2025-03-02 18:54:40 +01:00

80 lines
2.4 KiB
Text

--!strict
local fs = require("@lune/fs")
local process = require("@lune/process")
local frkcli = require("./util/frkcli")
local release = require("./release")
local sync = require("./sync")
local test = require("./test")
local cli = frkcli.new_subcommands("nightly_cli", "A CLI to sync & release jecs nightly")
local command_sync = cli:add_subcommand("sync", "Synchronize files from the jecs repository")
command_sync:add_positional(
"to",
{ help = "Directory to synchronize the files in, defaults to current working directory", default = process.cwd }
)
local command_release = cli:add_subcommand("release", "Publish a release from the given directory")
command_release:add_positional(
"from",
{ help = "Directory to release from, defaults to current working directory", default = process.cwd }
)
command_release:add_flag("dry", { help = "Dry run the publishes" })
command_release:add_option(
"pesde-scope",
{ help = "The pesde scope to publish under (eg. marked/jecs_nightly)", default = "nil" }
)
command_release:add_option(
"wally-scope",
{ help = "The wally scope to publish under (eg. mark-marks/jecs-nightly)", default = "nil" }
)
local command_test = cli:add_subcommand("test", "Run unit tests on the stored jecs source")
command_test:add_positional("in", {
help = "Directory with the jecs source to run tests in, defaults to current working directory",
default = process.cwd,
})
local parsed, err = cli:parse(process.args)
if err ~= nil then
error(err)
end
assert(parsed ~= nil)
local values = parsed.result.values
local flags = parsed.result.flags
if parsed.command == "sync" then
sync(values.to)
elseif parsed.command == "release" then
local scopes = {}
if values["pesde-scope"] ~= "nil" then
scopes.pesde = values["pesde-scope"]
end
if values["wally-scope"] ~= "nil" then
scopes.wally = values["wally-scope"]
end
local metadata = fs.metadata(values.from)
if not metadata.exists or metadata.kind ~= "dir" then
error(`The path {values.from} doesn't exist or isn't a valid directory.`)
end
local fpath = process.cwd
if values.from ~= process.cwd then
fpath ..= values.from
end
if flags.dry then
release(fpath, scopes, true)
else
release(fpath, scopes, false)
end
elseif parsed.command == "test" then
local fpath = process.cwd
if values["in"] ~= process.cwd then
fpath ..= values["in"]
end
test(fpath)
end