mirror of
https://github.com/lune-org/docs.git
synced 2024-12-12 13:00:37 +00:00
73 lines
2 KiB
Lua
73 lines
2 KiB
Lua
local fs = require("@lune/fs")
|
|
local process = require("@lune/process")
|
|
local serde = require("@lune/serde")
|
|
|
|
local moonwave = require("./moonwave")
|
|
local writeMarkdown = require("./writer")
|
|
|
|
-- Parse the newly extracted moonwave file
|
|
local typedefsFile = fs.readFile("temp/moonwave.json")
|
|
local items: { moonwave.Item } = serde.decode("json", typedefsFile)
|
|
|
|
-- Generate markdown for all of the libraries
|
|
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")
|
|
|
|
-- 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
|
|
if fs.isDir("pages/api-reference") then
|
|
fs.removeDir("pages/api-reference")
|
|
end
|
|
fs.writeDir("pages/api-reference")
|
|
for _, file in generatedFiles do
|
|
fs.writeFile(`pages/api-reference/{file.name}.md`, file.content)
|
|
end
|
|
|
|
-- Also generate a meta file to make the sidebar look nicer, note that
|
|
-- we generate it manually instead of serializing as json because that
|
|
-- would not preserve order and the sidebar is order-sensitive
|
|
local meta = "{\n"
|
|
for index, file in generatedFiles do
|
|
meta ..= ` "{file.name}": "{file.displayName}"`
|
|
if index == #generatedFiles then
|
|
meta ..= "\n}"
|
|
else
|
|
meta ..= ",\n"
|
|
end
|
|
end
|
|
fs.writeFile(`pages/api-reference/_meta.json`, meta)
|
|
|
|
-- Finally, call out to prettier to ensure that our
|
|
-- generated markdown files are formatted properly
|
|
process.spawn("prettier", {
|
|
"--write",
|
|
"pages/api-reference/",
|
|
})
|