From a1c0917908c3dece40924334b498beca39319df6 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Sat, 13 Sep 2025 10:13:47 +0200 Subject: [PATCH] Another try --- .github/workflows/main.yml | 7 ++-- src/elements/Tree.lua | 1 - tools/generate-docs.lua | 73 +++++++++++++++++++++++++++++--------- 3 files changed, 59 insertions(+), 22 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1801333..a1df1bf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,10 +39,7 @@ jobs: run: | mkdir -p release lua tools/bundler.lua - # Step 4: Install LuaFileSystem - - name: Install LuaFileSystem - run: luarocks install luafilesystem - # Step 5: Prepare and Generate Documentation + # Step 4: Prepare and Generate Documentation - name: Prepare docs directory run: | # Checkout gh-pages branch in a separate directory @@ -57,7 +54,7 @@ jobs: lua tools/generate-docs.lua cp -r build_docs/docs/references/* gh-pages/docs/references/ - # Step 6: Deploy Documentation + # Step 5: Deploy Documentation - name: Deploy Documentation if: github.event_name == 'push' && github.ref == 'refs/heads/main' uses: peaceiris/actions-gh-pages@v3 diff --git a/src/elements/Tree.lua b/src/elements/Tree.lua index b3711e7..070d0d7 100644 --- a/src/elements/Tree.lua +++ b/src/elements/Tree.lua @@ -2,7 +2,6 @@ local VisualElement = require("elements/VisualElement") local sub = string.sub ---@cofnigDescription The tree element provides a hierarchical view of nodes that can be expanded and collapsed, with support for selection and scrolling. - --- This is the tree class. It provides a hierarchical view of nodes that can be expanded and collapsed, --- with support for selection and scrolling. ---@class Tree : VisualElement diff --git a/tools/generate-docs.lua b/tools/generate-docs.lua index dbb68bc..62668f7 100644 --- a/tools/generate-docs.lua +++ b/tools/generate-docs.lua @@ -6,6 +6,7 @@ local OUT_DIR = arg[2] or 'docs' local BasaltDoc = require('tools/BasaltDoc') local fileSystem + if fs then fileSystem = { list = fs.list, @@ -20,23 +21,63 @@ if fs then close = function(file) file.close() end } else - local lfs = require("lfs") - fileSystem = { - list = function(dir) - local items = {} - for item in lfs.dir(dir) do - if item ~= "." and item ~= ".." then - table.insert(items, item) - end + local function executeCommand(cmd) + local handle = io.popen(cmd) + local result = handle:read("*a") + local success, _, code = handle:close() + return result, success, code + end + + local function pathExists(path) + local result, success = executeCommand("test -e '" .. path .. "' && echo 'exists' || echo 'not_exists'") + return success and result:match("exists") + end + + local function isDirectory(path) + local result, success = executeCommand("test -d '" .. path .. "' && echo 'dir' || echo 'not_dir'") + return success and result:match("dir") + end + + local function makeDirectory(path) + local _, success = executeCommand("mkdir -p '" .. path .. "'") + return success + end + + local function listDirectory(dir) + local result, success = executeCommand("ls -1 '" .. dir .. "' 2>/dev/null || true") + if not success then + return {} + end + + local items = {} + for item in result:gmatch("[^\r\n]+") do + if item ~= "" then + table.insert(items, item) end - return items - end, - combine = function(a, b) return a .. "/" .. b end, - isDir = function(path) return lfs.attributes(path).mode == "directory" end, - exists = function(path) return lfs.attributes(path) ~= nil end, - makeDir = lfs.mkdir, + end + return items + end + + local function combinePath(a, b) + if a:sub(-1) == "/" then + return a .. b + else + return a .. "/" .. b + end + end + + local function getDirectory(path) + return path:match("(.+)/[^/]*$") or "" + end + + fileSystem = { + list = listDirectory, + combine = combinePath, + isDir = isDirectory, + exists = pathExists, + makeDir = makeDirectory, open = io.open, - getDir = function(path) return path:match("(.+)/") end, + getDir = getDirectory, readAll = function(file) return file:read("*all") end, write = function(file, data) file:write(data) end, close = function(file) file:close() end @@ -79,7 +120,7 @@ for _, filePath in ipairs(luaFiles) do local outPath = fileSystem.combine(OUT_DIR, relativePath) local outDir = fileSystem.getDir(outPath) - if outDir and not fileSystem.exists(outDir) then + if outDir and outDir ~= "" and not fileSystem.exists(outDir) then fileSystem.makeDir(outDir) end