From 1b768a5a7f1d1fa649aed5ba8f7cd684d6f502e7 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 17 Jun 2024 13:39:41 +0200 Subject: [PATCH] Fix docs generation when there are multiple classes in a library --- .lune/generate.luau | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/.lune/generate.luau b/.lune/generate.luau index 97eef5a..e0ed79f 100644 --- a/.lune/generate.luau +++ b/.lune/generate.luau @@ -10,16 +10,36 @@ local typedefsFile = fs.readFile("temp/moonwave.json") local items: { moonwave.Item } = serde.decode("json", typedefsFile) -- Generate markdown for all of the libraries -local generatedFiles = {} +local generatedFiles = {} :: { [number]: { + displayName: string, + name: string, + content: string, +} } for _, item in items do local file = item.source.path local name = string.match(file, "(.+)%.luau") assert(name ~= nil, "Failed to remove luau suffix from file name") - table.insert(generatedFiles, { - displayName = item.name, - name = string.lower(name), - content = writeMarkdown(item), - }) + + -- If we have an existing entry, such as when we have multiple + -- classes within the same library (Regex, RegexCaptures, ...) + -- 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 -- Remove any old files, generate new ones