Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptibell committed Jul 22, 2023
0 parents commit 4a9aa95
Show file tree
Hide file tree
Showing 40 changed files with 12,196 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = tab
indent_size = 4
tab_width = 4

[*.{yml,yaml,rs}]
indent_style = space

[*.{yml,yaml}]
indent_size = 2
15 changes: 15 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"env": { "browser": true, "es2020": true },
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": { "ecmaVersion": "latest", "sourceType": "module" },
"plugins": ["react-refresh"],
"rules": {
"semi": ["error", "never"],
"react-refresh/only-export-components": "warn"
}
}
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/.DS_Store
/node_modules
/temp
/out
/.next
/.env

/**/.DS_Store
/**/node_modules
/**/temp
/**/out
/**/.next
/**/.env
23 changes: 23 additions & 0 deletions .justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Installs development tooling for documentation
install-dev-tools:
aftman install
npm install
cargo binstall moonwave

# Extract documentation from the main repository using moonwave
extract-documentation COMMIT="":
lune download "{{COMMIT}}"
lune extract
lune generate

# Re-generates documentation from the main repository using moonwave
generate-documentation:
lune generate

# Builds and generates a static site directory
build:
npm run build

# Starts a local development server for the docs site
dev:
npm run dev
56 changes: 56 additions & 0 deletions .lune/download.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
local MAIN_REPOSITORY_URL = "https://github.com/filiptibell/lune"

local fs = require("@lune/fs")
local net = require("@lune/net")
local process = require("@lune/process")

-- Find the url we should download from, either from a
-- given commit or by looking up the latest release tag
local name
local commit = process.args[1]
if commit ~= nil and #commit > 0 then
name = commit
else
print("Looking for the latest tag")
local tagsResult = process.spawn("git", {
"ls-remote",
"--tags",
"--sort=-v:refname",
MAIN_REPOSITORY_URL,
})
assert(tagsResult.ok, tagsResult.stderr)

local lines = string.split(tagsResult.stdout, "\n")
assert(#lines > 0, "No tags were found for the repository")

local latestTag = string.match(lines[1], "%s*refs/tags/(%S+)%s*$")
assert(latestTag ~= nil, "Failed to find latest tag for repository")
name = latestTag
end

-- Remove any previously downloaded repository folder
if fs.isDir("temp/repository") then
fs.removeDir("temp/repository")
end

-- Download the repository using the given tag or commit, unzip it, remove zip
print(`Downloading '{name}'`)
local downloaded = net.request(`{MAIN_REPOSITORY_URL}/archive/{name}.zip`)
assert(downloaded.ok, downloaded.statusMessage)

fs.writeFile("temp/download.zip", downloaded.body)

local unzipResult = process.spawn("unzip", {
"temp/download.zip",
"-d",
"temp/download",
})
assert(unzipResult.ok, unzipResult.stderr)

fs.removeFile("temp/download.zip")

-- Move the repository folder we just downloaded, which we do not know
-- the name of, but we know there is only one, into a known location
local repoFolderName = fs.readDir("temp/download")[1]
fs.move("temp/download/" .. repoFolderName, "temp/repository")
fs.removeDir("temp/download")
27 changes: 27 additions & 0 deletions .lune/extract.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
local fs = require("@lune/fs")
local process = require("@lune/process")
local serde = require("@lune/serde")

-- Make sure we have a repository folder downloaded
assert(fs.isDir("temp/repository"), "Missing downloaded repository folder")

-- Look for where type definitions are stored
local sourceDir
if fs.isDir("temp/repository/docs/typedefs") then
sourceDir = "temp/repository/docs/typedefs"
elseif fs.isDir("temp/repository/typedefs") then
sourceDir = "temp/repository/typedefs"
elseif fs.isDir("temp/repository/types") then
sourceDir = "temp/repository/types"
else
error("Failed to find typedefs folder in repository")
end

-- Run moonwave to parse typedef files and extract documentation, write to file
local moonwaveResult = process.spawn("moonwave-extractor", { "extract", sourceDir })
assert(moonwaveResult.ok and #moonwaveResult.stderr <= 0, moonwaveResult.stderr)
fs.writeFile("temp/moonwave.json", moonwaveResult.stdout)

-- Let the user know how many typedefs we have extracted
local arr = serde.decode("json", moonwaveResult.stdout)
print("Extracted", #arr, "type definitions")
53 changes: 53 additions & 0 deletions .lune/generate.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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 = {}
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),
})
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/",
})
50 changes: 50 additions & 0 deletions .lune/moonwave.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
export type Source = {
path: string,
line: number,
}

export type FunctionParam = {
name: string,
desc: string,
lua_type: string,
}

export type FunctionReturn = {
desc: string,
lua_type: string,
}

export type Function = {
name: string,
desc: string,
params: { FunctionParam },
returns: { FunctionReturn },
function_type: string,
tags: { string },
source: Source,
}

export type Property = {
name: string,
desc: string,
lua_type: string,
tags: { string },
source: Source,
}

export type Type = {
name: string,
desc: string,
source: Source,
}

export type Item = {
name: string,
desc: string,
functions: { Function },
properties: { Property },
types: { Type },
source: Source,
}

return {}
104 changes: 104 additions & 0 deletions .lune/writer.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
local moonwave = require("./moonwave")

local buffer = {}
local function write(text: string)
table.insert(buffer, text)
end

local function writeDesc(desc: string)
desc = string.gsub(desc, "###", "####")
write(`{desc}\n\n`)
end

local function writeTypeAndDesc(typ: string, desc: string, inline: boolean)
if #typ > 0 and #desc <= 0 then
-- HACK: Got empty desc but we have a type, this is a doc comment not a type
if inline then
write(" ")
end
write(typ)
if not inline then
write("\n\n")
end
elseif #desc > 0 then
if #typ > 0 then
if inline then
write(" ")
end
write("`" .. typ .. "`")
if not inline then
write("\n\n")
end
end
if inline then
write(" ")
end
write(desc)
if not inline then
write("\n\n")
end
end
end

local function writeParams(params: { moonwave.FunctionParam })
if #params > 0 then
write(`#### Parameters\n\n`)
for _, param in params do
write(`- \`{param.name}\``)
writeTypeAndDesc(param.lua_type, param.desc, true)
write("\n\n")
end
end
end

local function writeReturns(returns: { moonwave.FunctionReturn })
if #returns > 0 then
write(`#### Returns\n\n`)
for _, ret in returns do
write(`- `)
writeTypeAndDesc(ret.lua_type, ret.desc, true)
write("\n\n")
end
end
end

local function writeMarkdown(item: moonwave.Item)
write(`# {item.name}\n\n`)
writeDesc(item.desc)

if #item.properties > 0 then
write(`## Properties\n\n`)
for _, prop in item.properties do
write(`### {prop.name}\n\n`)
writeTypeAndDesc(prop.lua_type, prop.desc, false)
write("\n\n")
write(`---\n\n`)
end
end

if #item.functions > 0 then
write(`## Functions\n\n`)
for _, fn in item.functions do
write(`### {fn.name}\n\n`)
writeDesc(fn.desc)
writeParams(fn.params)
writeReturns(fn.returns)
write(`---\n\n`)
end
end

if #item.types > 0 then
write(`## Types\n\n`)
for _, typ in item.types do
write(`### {typ.name}\n\n`)
writeDesc(typ.desc)
write(`---\n\n`)
end
end

local result = table.concat(buffer, "")
table.clear(buffer)
return result
end

return writeMarkdown
17 changes: 17 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": true,
"jsxSingleQuote": false,
"printWidth": 100,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": false,
"singleQuote": false,
"tabWidth": 4,
"trailingComma": "all",
"useTabs": true
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"luau-lsp.types.roblox": false,
"luau-lsp.sourcemap.enabled": false,
"luau-lsp.ignoreGlobs": ["temp/**"],
"luau-lsp.require.mode": "relativeToFile",
"luau-lsp.require.directoryAliases": {
"@lune/": "~/.lune/.typedefs/0.7.4/"
}
}
5 changes: 5 additions & 0 deletions aftman.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[tools]
just = "readysetplay/[email protected]"
luau-lsp = "JohnnyMorganz/[email protected]"
lune = "filiptibell/[email protected]"
stylua = "JohnnyMorganz/[email protected]"
Loading

0 comments on commit 4a9aa95

Please sign in to comment.