Skip to content

Commit bc80966

Browse files
committed
Merge branch 'annietang/lute_config_and_module_resolvers' of https://github.com/luau-lang/lute into annietang/lute_config_and_module_resolvers
2 parents b331981 + 91198b4 commit bc80966

File tree

15 files changed

+712
-377
lines changed

15 files changed

+712
-377
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,36 @@ jobs:
9494
- name: Run StyLua
9595
run: stylua --check .
9696

97+
build-docs-site:
98+
runs-on: ubuntu-latest
99+
100+
steps:
101+
- name: Checkout repository
102+
uses: actions/checkout@v4
103+
104+
- name: Setup Node.js
105+
uses: actions/setup-node@v4
106+
107+
- name: Install tools
108+
uses: Roblox/setup-foreman@v3
109+
with:
110+
token: ${{ secrets.GITHUB_TOKEN }}
111+
allow-external-github-orgs: true
112+
113+
- name: Install dependencies
114+
run: npm install
115+
working-directory: docs
116+
117+
- name: Build docs site
118+
run: npm run build
119+
working-directory: docs
120+
121+
- name: Upload docs artifact
122+
id: deployment
123+
uses: actions/upload-pages-artifact@v3
124+
with:
125+
path: docs/.vitepress/dist/
126+
97127
aggregator:
98128
name: Gated Commits
99129
runs-on: ubuntu-latest

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
66
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
77

88
# set the module path
9-
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeBuild")
9+
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeBuild")
1010

1111
include(get_version)
1212

docs/.vitepress/config.mts

Lines changed: 81 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default defineConfig({
99
// https://vitepress.dev/reference/default-theme-config
1010
nav: [
1111
{ text: 'Guide', link: '/guide/installation' },
12-
{ text: 'Reference', link: '/reference/fs' }
12+
{ text: 'Reference', link: '/reference/definitions/crypto' }
1313
],
1414

1515
sidebar: [
@@ -22,16 +22,86 @@ export default defineConfig({
2222
{
2323
text: "Reference",
2424
items: [
25-
{ text: 'crypto', link: '/reference/crypto' },
26-
{ text: 'fs', link: '/reference/fs' },
27-
{ text: 'io', link: '/reference/io' },
28-
{ text: 'luau', link: '/reference/luau' },
29-
{ text: 'net', link: '/reference/net' },
30-
{ text: 'process', link: '/reference/process' },
31-
{ text: 'system', link: '/reference/system' },
32-
{ text: 'task', link: '/reference/task' },
33-
{ text: 'time', link: '/reference/time' },
34-
{ text: 'vm', link: '/reference/vm' },
25+
// Definitions
26+
{ text: 'crypto', link: '/reference/definitions/crypto' },
27+
{ text: 'fs', link: '/reference/definitions/fs' },
28+
{ text: 'io', link: '/reference/definitions/io' },
29+
{ text: 'luau', link: '/reference/definitions/luau' },
30+
{ text: 'net', link: '/reference/definitions/net' },
31+
{ text: 'process', link: '/reference/definitions/process' },
32+
{ text: 'system', link: '/reference/definitions/system' },
33+
{ text: 'task', link: '/reference/definitions/task' },
34+
{ text: 'time', link: '/reference/definitions/time' },
35+
{ text: 'vm', link: '/reference/definitions/vm' },
36+
37+
// Standard Library subfolder
38+
{
39+
text: "Standard Library",
40+
items: [
41+
{ text: 'assert', link: '/reference/std/assert' },
42+
{ text: 'fs', link: '/reference/std/fs' },
43+
{ text: 'io', link: '/reference/std/io' },
44+
{ text: 'json', link: '/reference/std/json' },
45+
{ text: 'luau', link: '/reference/std/luau' },
46+
{ text: 'process', link: '/reference/std/process' },
47+
{ text: 'stringext', link: '/reference/std/stringext' },
48+
{ text: 'tableext', link: '/reference/std/tableext' },
49+
{ text: 'task', link: '/reference/std/task' },
50+
{ text: 'test', link: '/reference/std/test' },
51+
{ text: 'vectorext', link: '/reference/std/vectorext' },
52+
53+
// Path lib subfolder
54+
{
55+
text: "Path",
56+
items: [
57+
{ text: 'path', link: '/reference/std/path/path' },
58+
{ text: 'types', link: '/reference/std/path/types' },
59+
// Posix lib subfolder
60+
{
61+
text: "Posix",
62+
items: [
63+
{ text: 'posix', link: '/reference/std/path/posix/posix' },
64+
{ text: 'types', link: '/reference/std/path/posix/types' },
65+
]
66+
},
67+
// Win32 lib subfolder
68+
{
69+
text: "Win32",
70+
items: [
71+
{ text: 'win32', link: '/reference/std/path/win32/win32' },
72+
{ text: 'types', link: '/reference/std/path/win32/types' },
73+
]
74+
},
75+
]
76+
},
77+
// Syntax lib subfolder
78+
{
79+
text: "Syntax",
80+
items: [
81+
{ text: 'parser', link: '/reference/std/syntax/parser' },
82+
{ text: 'printer', link: '/reference/std/syntax/printer' },
83+
{ text: 'query', link: '/reference/std/syntax/query' },
84+
{ text: 'visitor', link: '/reference/std/syntax/visitor' },
85+
]
86+
},
87+
// System lib subfolder
88+
{
89+
text: "System",
90+
items: [
91+
{ text: 'system', link: '/reference/std/system/system' },
92+
{ text: 'platform', link: '/reference/std/system/platform' },
93+
]
94+
},
95+
// Time lib subfolder
96+
{
97+
text: "Time",
98+
items: [
99+
{ text: 'time', link: '/reference/std/time/time' },
100+
{ text: 'duration', link: '/reference/std/time/duration' },
101+
]
102+
}
103+
]
104+
}
35105
]
36106
}
37107
],

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ hero:
1212
link: /guide/installation
1313
- theme: alt
1414
text: Reference
15-
link: /reference/fs
15+
link: /reference/definitions/crypto
1616

1717
# TODO: add buzz words
1818
# features:

docs/scripts/reference.luau

Lines changed: 141 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
local fs = require("@lute/fs")
2-
local process = require("@lute/process")
3-
4-
local function projectRelative(...)
5-
local cwd = process.cwd()
6-
local pathSep = if string.find(string.lower(require("@lute/system").os), "windows") then "\\" else "/"
7-
return table.concat({ cwd, "..", ... }, pathSep)
8-
end
1+
local fs = require("@std/fs")
2+
local process = require("@std/process")
3+
local path = require("@std/path")
94

105
local function extractPropertySignature(module: string, line: string): (string?, string?)
116
-- Match property declarations like: process.env = {} :: { [string]: string }
@@ -26,13 +21,18 @@ local function extractPropertySignature(module: string, line: string): (string?,
2621
return nil, nil
2722
end
2823

29-
local function parseDefinitionFile(module: string, filePath: string): { { name: string, signature: string } }
24+
-- docs for definitions/*.luau --
25+
26+
local function parseDefinitionFile(
27+
module: path.pathlike,
28+
filePath: path.pathlike
29+
): { { name: string, signature: string } }
3030
local content = fs.readfiletostring(filePath)
3131
local lines = string.split(content, "\n")
3232
local definitions = {}
3333

3434
for _, line in lines do
35-
local name, signature = extractPropertySignature(module, line)
35+
local name, signature = extractPropertySignature(tostring(module), line)
3636

3737
if name and signature then
3838
table.insert(definitions, {
@@ -45,12 +45,109 @@ local function parseDefinitionFile(module: string, filePath: string): { { name:
4545
return definitions
4646
end
4747

48-
local function generateMarkdown(moduleName: string, definitions: { { name: string, signature: string } }): string
48+
local function generateDefinitionsMarkdown(
49+
moduleName: string,
50+
definitions: { { name: string, signature: string } }
51+
): string
52+
local lines = {
53+
`# {moduleName}`,
54+
"",
55+
"```luau",
56+
`local {moduleName} = require("@lute/{moduleName}")`,
57+
"```",
58+
"",
59+
}
60+
61+
table.sort(definitions, function(a, b)
62+
return a.name < b.name
63+
end)
64+
65+
for _, def in definitions do
66+
table.insert(lines, `## {moduleName}.{def.name}`)
67+
table.insert(lines, "```luau")
68+
table.insert(lines, def.signature)
69+
table.insert(lines, "```")
70+
table.insert(lines, "")
71+
end
72+
73+
return table.concat(lines, "\n")
74+
end
75+
76+
local function processDefinitionsDir(definitionsPath: path.pathlike, referencePath: path.pathlike)
77+
fs.createdirectory(referencePath, { makeparents = true })
78+
79+
local definitionFiles = fs.listdir(definitionsPath)
80+
81+
for _, file in definitionFiles do
82+
if file.type == "file" and string.find(file.name, "%.luau$") then
83+
local moduleName = string.gsub(file.name, "%.luau$", "")
84+
local definitionFilePath = path.join(definitionsPath, file.name)
85+
local referenceFilePath = path.join(referencePath, moduleName .. ".md")
86+
87+
print(`Processing {moduleName}...`)
88+
89+
local definitions = parseDefinitionFile(moduleName, definitionFilePath)
90+
local markdown = generateDefinitionsMarkdown(moduleName, definitions)
91+
92+
fs.writestringtofile(referenceFilePath, markdown)
93+
94+
print(`Generated {tostring(referenceFilePath)}`)
95+
end
96+
end
97+
end
98+
99+
-- docs for lute/std/libs/*.luau --
100+
101+
local STDLIB_MODULE_ALIASES = {
102+
assert = "assertions",
103+
fs = "fslib",
104+
io = "iolib",
105+
process = "processlib",
106+
task = "tasklib",
107+
path = "pathlib",
108+
system = "systemlib",
109+
}
110+
111+
local function parseStdlibFile(module: path.pathlike, filePath: path.pathlike): { { name: string, signature: string } }
112+
local content = fs.readfiletostring(filePath)
113+
local lines = string.split(content, "\n")
114+
local stdlibDefinitions = {}
115+
116+
for _, line in lines do
117+
local mod = STDLIB_MODULE_ALIASES[tostring(module)] or tostring(module)
118+
119+
local name, signature = extractPropertySignature(mod, line)
120+
121+
if name and signature then
122+
table.insert(stdlibDefinitions, {
123+
name = name,
124+
signature = signature,
125+
})
126+
end
127+
end
128+
129+
return stdlibDefinitions
130+
end
131+
132+
local function generateStdLibMarkdown(
133+
moduleName: string,
134+
definitions: { { name: string, signature: string } },
135+
stdlibFilePath: path.pathlike
136+
): string
137+
local referencePath = path.join(process.cwd(), "..", "lute", "std", "libs")
138+
139+
local refPathStr = tostring(referencePath)
140+
local stdlibFilePathStr = tostring(stdlibFilePath)
141+
142+
local relativePath = string.sub(stdlibFilePathStr, #refPathStr + 2) -- gets the path relative to std/libs for the require path
143+
relativePath = string.gsub(relativePath, "%.luau$", "")
144+
local requirePath = string.gsub(relativePath, "/init$", "")
145+
49146
local lines = {
50-
"# " .. moduleName,
147+
`# {moduleName}`,
51148
"",
52149
"```luau",
53-
"local " .. moduleName .. ' = require("@lute/' .. moduleName .. '")',
150+
`local {moduleName} = require("@std/{requirePath}")`,
54151
"```",
55152
"",
56153
}
@@ -60,7 +157,7 @@ local function generateMarkdown(moduleName: string, definitions: { { name: strin
60157
end)
61158

62159
for _, def in definitions do
63-
table.insert(lines, "## " .. def.name)
160+
table.insert(lines, `## {moduleName}.{def.name}`)
64161
table.insert(lines, "```luau")
65162
table.insert(lines, def.signature)
66163
table.insert(lines, "```")
@@ -70,28 +167,44 @@ local function generateMarkdown(moduleName: string, definitions: { { name: strin
70167
return table.concat(lines, "\n")
71168
end
72169

73-
local definitionsPath = projectRelative("definitions")
74-
local referencePath = projectRelative("docs", "reference")
170+
local function processStdlibDir(sourceDir: path.pathlike, referenceDir: path.pathlike)
171+
fs.createdirectory(referenceDir, { makeparents = true })
172+
173+
local entries = fs.listdir(sourceDir)
75174

76-
pcall(fs.mkdir, referencePath)
175+
for _, entry in entries do
176+
local sourcePath = path.join(sourceDir, entry.name)
177+
local referencePath = path.join(referenceDir, entry.name)
77178

78-
local definitionFiles = fs.listdir(definitionsPath)
179+
if entry.type == "dir" then
180+
fs.createdirectory(referencePath, { makeparents = true })
181+
processStdlibDir(sourcePath, referencePath)
182+
elseif entry.type == "file" and string.find(entry.name, "%.luau$") then
183+
local moduleName = string.gsub(entry.name, "%.luau$", "")
184+
if moduleName == "init" then
185+
moduleName = string.match(tostring(sourceDir), "([^/\\]+)$") or moduleName
186+
end
79187

80-
for _, file in definitionFiles do
81-
if file.type == "file" and string.find(file.name, "%.luau$") then
82-
local moduleName = string.gsub(file.name, "%.luau$", "")
83-
local definitionFilePath = definitionsPath .. "/" .. file.name
84-
local referenceFilePath = referencePath .. "/" .. moduleName .. ".md"
188+
local referenceFilePath = path.join(referenceDir, moduleName .. ".md")
85189

86-
print("Processing " .. moduleName .. "...")
190+
print(`Processing {moduleName}...`)
87191

88-
local definitions = parseDefinitionFile(moduleName, definitionFilePath)
89-
local markdown = generateMarkdown(moduleName, definitions)
192+
local stdlibDefinitions = parseStdlibFile(moduleName, sourcePath)
193+
local markdown = generateStdLibMarkdown(moduleName, stdlibDefinitions, sourcePath)
90194

91-
fs.writestringtofile(referenceFilePath, markdown)
195+
fs.writestringtofile(referenceFilePath, markdown)
92196

93-
print("Generated " .. referenceFilePath)
197+
print(`Generated {tostring(referenceFilePath)}`)
198+
end
94199
end
95200
end
96201

202+
local definitionsPath = path.join(process.cwd(), "..", "definitions")
203+
local referencePath = path.join(process.cwd(), "reference", "definitions")
204+
processDefinitionsDir(definitionsPath, referencePath)
205+
206+
local stdlibPath = path.join(process.cwd(), "..", "lute", "std", "libs")
207+
local stdlibReferencePath = path.join(process.cwd(), "reference", "std")
208+
processStdlibDir(stdlibPath, stdlibReferencePath)
209+
97210
print("Reference documentation generation complete!")

0 commit comments

Comments
 (0)