1+ -- generate-docs.lua
2+
3+ -- Argumente
14local arg = arg or {... }
5+ local SRC_DIR = arg [1 ] or " src"
6+ local OUT_DIR = arg [2 ] or " build_docs/docs/references"
7+
8+ package.path = package.path .. " ;./tools/?.lua"
29
3- local SRC_DIR = arg [1 ] or ' src'
4- local OUT_DIR = arg [2 ] or ' build_docs/docs/references'
10+ local BasaltDoc = require (" tools/BasaltDoc" )
511
6- local BasaltDoc = require (' tools/BasaltDoc' )
12+ ---- ----------------------------------------------------
13+ -- Filesystem Abstraction
14+ ---- ----------------------------------------------------
715
816local fileSystem
917
@@ -23,32 +31,30 @@ if fs then
2331else
2432 local function executeCommand (cmd )
2533 local handle = io.popen (cmd )
34+ if not handle then return " " , false , 1 end
2635 local result = handle :read (" *a" )
27- local success , _ , code = handle :close ()
28- return result , success , code
36+ local ok , _ , code = handle :close ()
37+ return result , ok , code
2938 end
3039
3140 local function pathExists (path )
32- local result , success = executeCommand (" test -e '" .. path .. " ' && echo 'exists' || echo 'not_exists' " )
33- return success and result : match ( " exists " )
41+ local _ , _ , code = executeCommand (" [ -e '" .. path .. " ' ] " )
42+ return code == 0
3443 end
3544
3645 local function isDirectory (path )
37- local result , success = executeCommand (" test -d '" .. path .. " ' && echo 'dir' || echo 'not_dir' " )
38- return success and result : match ( " dir " )
46+ local _ , _ , code = executeCommand (" [ -d '" .. path .. " ' ] " )
47+ return code == 0
3948 end
4049
4150 local function makeDirectory (path )
42- local _ , success = executeCommand (" mkdir -p '" .. path .. " '" )
43- return success
51+ local _ , ok = executeCommand (" mkdir -p '" .. path .. " '" )
52+ return ok
4453 end
4554
4655 local function listDirectory (dir )
47- local result , success = executeCommand (" ls -1 '" .. dir .. " ' 2>/dev/null || true" )
48- if not success then
49- return {}
50- end
51-
56+ local result , ok = executeCommand (" ls -1 '" .. dir .. " ' 2>/dev/null" )
57+ if not ok then return {} end
5258 local items = {}
5359 for item in result :gmatch (" [^\r\n ]+" ) do
5460 if item ~= " " then
8490 }
8591end
8692
93+ ---- ----------------------------------------------------
94+ -- Main
95+ ---- ----------------------------------------------------
96+
97+ print (" Starting documentation generation..." )
98+ print (" Source directory: " .. SRC_DIR )
99+ print (" Output directory: " .. OUT_DIR )
100+
87101if not fileSystem .exists (OUT_DIR ) then
88102 print (" Output directory does not exist, creating it..." )
89103 fileSystem .makeDir (OUT_DIR )
@@ -92,17 +106,29 @@ else
92106end
93107
94108local function getLuaFiles (dir )
109+ print (" Scanning directory: " .. dir )
110+ if not fileSystem .exists (dir ) then
111+ print (" Directory does not exist: " .. dir )
112+ return {}
113+ end
114+
95115 local files = {}
96116 local list = fileSystem .list (dir )
117+ print (" Found " .. # list .. " items in " .. dir )
118+
97119 for _ , item in ipairs (list ) do
98120 local path = fileSystem .combine (dir , item )
99121 if fileSystem .isDir (path ) then
122+ print (" -> Directory, scanning recursively: " .. path )
100123 local subFiles = getLuaFiles (path )
101124 for _ , subFile in ipairs (subFiles ) do
102125 table.insert (files , subFile )
103126 end
104127 elseif item :match (" %.lua$" ) then
128+ print (" -> Lua file found: " .. path )
105129 table.insert (files , path )
130+ else
131+ print (" -> Skipping: " .. item )
106132 end
107133 end
108134 return files
@@ -141,4 +167,4 @@ for _, filePath in ipairs(luaFiles) do
141167 end
142168end
143169
144- print (" Documentation generation complete." )
170+ print (" Documentation generation complete." )
0 commit comments