Skip to content

Commit

Permalink
add generated component lookup json
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridherbst committed Oct 8, 2024
1 parent 7782caf commit eb2c3f1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
36 changes: 36 additions & 0 deletions tools/api-plugins/component-lookup/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Application, JSX, ParameterType, ReflectionKind } from "typedoc";
import path from "path";
import fs from "fs";

/**
* @param {import("typedoc").Application} app
*/
export function load(app) {

const map = new Map();

app.renderer.on("beginRender", (ctx) => {
map.clear();
});

app.renderer.on("endPage", (page) => {
// get currently generated page
const model = page.model;
const url = page.url;

map.set(model, url);
});

app.renderer.on("endRender", (ctx) => {
const file = path.join(ctx.outputDirectory, "component-lookup.json");
const data = {};
for (const [model, url] of map) {
// check if there's a duplicate
if (data[model.name]) {
console.warn(`Duplicate component name for ${model.name} – component lookup may not work as expected`);
}
data[model.name] = url;
}
fs.writeFileSync(file, JSON.stringify(data, null, 2));
});
}
2 changes: 1 addition & 1 deletion tools/api-plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function tryGetThreejsDocsLink(dottedName) {
for (const test of urls) {
const [testName, url] = test.split(": ");
if (testName === name) {
console.log("Found", name, url);
// console.log("Found", name, url); // for debugging
threejsDocsLinkCache.set(dottedName, url);
return url;
}
Expand Down
1 change: 1 addition & 0 deletions tools/build_api_docs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ async function produceDocs(packageDir, outputDirectory) {
"./tools/api-plugins/index.js",
"./tools/api-plugins/keywords/index.js",
"./tools/api-plugins/plausible/index.js",
"./tools/api-plugins/component-lookup/index.js",
],
keywords: ["typescript", "library", "threejs", "webgl", "engine", "browser", "webxr", "api"],
footerDate: true,
Expand Down

0 comments on commit eb2c3f1

Please sign in to comment.