-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathastra_build.lua
123 lines (104 loc) · 3.46 KB
/
astra_build.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
--[[
Astra's build system script written by Elham Aryanpur.
There are many commands to automate the common tasks around.
This script was tested with Lua 5.4 and LuaJIT.
The license is same as the Astra's license.
]]
local runtime = "luajit"
------------- UTILS
---@param table_to_check table
---@param value_to_check any
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
---@param directory string
---@param ignore table?
---@param command string
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
-- Check if the entry is a directory
local is_dir = os.execute("test -d " .. full_path) == 0
if runtime == "lua" then
---@diagnostic disable-next-line: cast-local-type
is_dir = os.execute("test -d " .. full_path)
end
if is_dir then
print("Executing command in directory: " .. full_path)
if not ignore then
---@diagnostic disable-next-line: param-type-mismatch
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
------------- COMMANDS
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()
-- Placeholder for generating documentation
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)