local runtime = "luajit"
local function contains(table_to_check, value_to_check)
for _, value in ipairs(table_to_check) do
if value == value_to_check then
return true
end
end
return false
end
local function execute_command_in_subdirectories(directory, ignore, command)
local handle = io.popen("ls " .. directory, "r")
if not handle then
print("Failed to open directory: " .. directory)
return
end
for file in handle:lines() do
if file ~= "" then
local full_path = directory .. "/" .. file
local is_dir = os.execute("test -d " .. full_path) == 0
if runtime == "lua" then
is_dir = os.execute("test -d " .. full_path)
end
if is_dir then
print("Executing command in directory: " .. full_path)
if not ignore then
if not contains(ignore, file) then
os.execute("cd " .. full_path .. " && " .. command)
end
else
os.execute("cd " .. full_path .. " && " .. command)
end
end
end
end
handle:close()
end
local function print_usage()
io.write("Usage: astra_build.lua [command] [options]\n")
io.write("\nCommands:\n")
io.write(" help Display this help message.\n")
io.write(" version Show the version information.\n")
io.write(" pack Bundle the lua libraries.\n")
io.write(" changelog <TAG> Update CHANGELOG.md.\n")
io.write(" docs Generate documentation.\n")
end
local function show_version()
io.write("Astra Build CLI Version 1.0\n")
end
local function execute_pack()
os.execute("cd src/lua && " .. runtime .. " pack.lua astra.lua")
end
local function execute_update_changelog(tag)
if tag == "unreleased" or tag == nil then
os.execute("git cliff --unreleased --prepend CHANGELOG.md")
else
os.execute("git cliff --unreleased --tag=\"" .. tag .. "\" --prepend CHANGELOG.md")
end
end
local function execute_build_docs()
io.write("Generating documentation...\n")
execute_command_in_subdirectories("src/docs", { "theme" }, "mdbook build")
end
local function main(args)
if #args <= 0 then
print_usage()
return
end
local command = args[1]
if args[-1] == "lua" then
runtime = "lua"
end
if command == "help" then
print_usage()
elseif command == "version" then
show_version()
elseif command == "pack" then
execute_pack()
elseif command == "changelog" then
execute_update_changelog(args[2])
elseif command == "docs" then
execute_build_docs()
else
io.write("Unknown command: ", command, "\n")
print_usage()
end
end
main(arg)