diff --git a/tools/api-plugins/component-lookup/index.js b/tools/api-plugins/component-lookup/index.js new file mode 100644 index 000000000..b1f3ae14f --- /dev/null +++ b/tools/api-plugins/component-lookup/index.js @@ -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)); + }); +} \ No newline at end of file diff --git a/tools/api-plugins/index.js b/tools/api-plugins/index.js index 2f0931e8c..f9bc571d3 100644 --- a/tools/api-plugins/index.js +++ b/tools/api-plugins/index.js @@ -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; } diff --git a/tools/build_api_docs.mjs b/tools/build_api_docs.mjs index ec813f0da..768c04c50 100644 --- a/tools/build_api_docs.mjs +++ b/tools/build_api_docs.mjs @@ -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,