Fix docs generation when there are multiple classes in a library

This commit is contained in:
Filip Tibell 2024-06-17 13:39:41 +02:00
parent 097297a8c0
commit 1b768a5a7f
No known key found for this signature in database

View file

@ -10,16 +10,36 @@ local typedefsFile = fs.readFile("temp/moonwave.json")
local items: { moonwave.Item } = serde.decode("json", typedefsFile) local items: { moonwave.Item } = serde.decode("json", typedefsFile)
-- Generate markdown for all of the libraries -- Generate markdown for all of the libraries
local generatedFiles = {} local generatedFiles = {} :: { [number]: {
displayName: string,
name: string,
content: string,
} }
for _, item in items do for _, item in items do
local file = item.source.path local file = item.source.path
local name = string.match(file, "(.+)%.luau") local name = string.match(file, "(.+)%.luau")
assert(name ~= nil, "Failed to remove luau suffix from file name") assert(name ~= nil, "Failed to remove luau suffix from file name")
table.insert(generatedFiles, {
displayName = item.name, -- If we have an existing entry, such as when we have multiple
name = string.lower(name), -- classes within the same library (Regex, RegexCaptures, ...)
content = writeMarkdown(item), -- we want to append to the existing entry instead of creating
}) local existing = nil
for _, info in generatedFiles do
if info.name == string.lower(name) then
existing = info
break
end
end
if existing then
existing.content ..= writeMarkdown(item)
else
table.insert(generatedFiles, {
displayName = item.name,
name = string.lower(name),
content = writeMarkdown(item),
})
end
end end
-- Remove any old files, generate new ones -- Remove any old files, generate new ones