Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix doc generation for v12
  • Loading branch information
tsnobip committed Jun 16, 2025
commit 403b2e359d38548a7213a5e17f814afe756a3b3e
388 changes: 194 additions & 194 deletions data/api/v12.0.0/belt.json

Large diffs are not rendered by default.

10,498 changes: 0 additions & 10,498 deletions data/api/v12.0.0/core.json

This file was deleted.

5,646 changes: 1,611 additions & 4,035 deletions data/api/v12.0.0/js.json

Large diffs are not rendered by default.

9,656 changes: 5,761 additions & 3,895 deletions data/api/v12.0.0/stdlib.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/api/v12.0.0/toc_tree.json

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions scripts/gendocs.res
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ if Fs.existsSync(dirVersion) {
Fs.mkdirSync(dirVersion)
}

// "Js.res" does not work for some reason
let entryPointFiles = ["Belt.res", "Dom.res", "Stdlib.res"]
let entryPointFiles = ["Belt.res", "Dom.res", "Js.res", "Stdlib.res"]

let hiddenModules = ["Js.Internal", "Js.MapperRt"]

Expand All @@ -72,23 +71,32 @@ type section = {

let env = Process.env

let docsDecoded = entryPointFiles->Array.map(libFile => {
let entryPointFile = Path.join2(compilerLibPath, libFile)
let docsDecoded = entryPointFiles->Array.map(libFile =>
try {
let entryPointFile = Path.join2(compilerLibPath, libFile)

Dict.set(env, "FROM_COMPILER", "false")
Dict.set(env, "FROM_COMPILER", "false")

let output =
ChildProcess.execSync(
let output = ChildProcess.execSync(
`./node_modules/.bin/rescript-tools doc ${entryPointFile}`,
~options={
maxBuffer: 30_000_000.,
},
)->Buffer.toString

output
->JSON.parseExn
->Docgen.decodeFromJson
})

let isStdlib = (id: string) => String.startsWith(id, "Stdlib")
let replaceIdWithStdlib = (id: string) => isStdlib(id) ? String.replace(id, "Stdlib", "Core") : id
output
->JSON.parseExn
->Docgen.decodeFromJson
} catch {
| Exn.Error(error) =>
Console.error(
`Error while generating docs from ${libFile}: ${error
->Error.message
->Option.getOr("[no message]")}`,
)
Error.raise(error)
}
)

let removeStdlibOrPrimitive = s => s->String.replaceAllRegExp(/Stdlib_|Primitive_js_extern\./g, "")

Expand All @@ -111,7 +119,6 @@ let docs = docsDecoded->Array.map(doc => {
if Array.includes(hiddenModules, id) {
getModules(rest, moduleNames)
} else {
let id = replaceIdWithStdlib(id)
getModules(
list{...rest, ...List.fromArray(items)},
list{{id, items, name, docstrings}, ...moduleNames},
Expand All @@ -121,7 +128,7 @@ let docs = docsDecoded->Array.map(doc => {
| list{} => moduleNames
}

let id = replaceIdWithStdlib(doc.name)
let id = doc.name

let top = {id, name: id, docstrings: doc.docstrings, items: topLevelItems}
let submodules = getModules(doc.items->List.fromArray, list{})->List.toArray
Expand All @@ -135,7 +142,6 @@ let allModules = {
let encodeItem = (docItem: Docgen.item) => {
switch docItem {
| Value({id, name, docstrings, signature, ?deprecated}) => {
let id = replaceIdWithStdlib(id)
let dict = Dict.fromArray(
[
("id", id->String),
Expand Down Expand Up @@ -164,7 +170,6 @@ let allModules = {
}

| Type({id, name, docstrings, signature, ?deprecated}) =>
let id = replaceIdWithStdlib(id)
let dict = Dict.fromArray(
[
("id", id->String),
Expand Down Expand Up @@ -194,10 +199,8 @@ let allModules = {
->Array.filterMap(item => encodeItem(item))
->Array

let id = replaceIdWithStdlib(mod.id)

let rest = Dict.fromArray([
("id", id->String),
("id", mod.id->String),
("name", mod.name->String),
("docstrings", mod.docstrings->Array.map(s => s->String)->Array),
("items", items),
Expand All @@ -220,8 +223,6 @@ let () = {
allModules->Array.forEach(((topLevelName, mod)) => {
let json = JSON.Object(mod)

let topLevelName = replaceIdWithStdlib(topLevelName)

Fs.writeFileSync(
Path.join([dirVersion, `${topLevelName->String.toLowerCase}.json`]),
json->JSON.stringify(~space=2),
Expand Down Expand Up @@ -264,7 +265,6 @@ let () = {
}

let tocTree = docsDecoded->Array.map(({name, items}) => {
let name = replaceIdWithStdlib(name)
let path = name->String.toLowerCase
(
path,
Expand Down
3 changes: 2 additions & 1 deletion src/bindings/Node.res
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module Buffer = {
}

module ChildProcess = {
type options = {maxBuffer?: float}
@module("child_process")
external execSync: string => Buffer.t = "execSync"
external execSync: (string, ~options: options=?) => Buffer.t = "execSync"
}