From 164b7fa454071c5bbc35ac14fdccaf7e294af3ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Fri, 19 Dec 2025 17:50:59 -0600 Subject: [PATCH] feat: api renderer --- packages/website-ue/src/pages/api/index.astro | 54 +++++++++++++++++++ .../website-ue/src/pages/api/tanks/[id].pb.ts | 3 ++ .../pages/api/tanks/characteristics.json.ts | 3 ++ packages/website-ue/src/pages/index.astro | 10 +++- .../website-ue/src/pages/tanks/index.astro | 22 ++++---- 5 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 packages/website-ue/src/pages/api/index.astro diff --git a/packages/website-ue/src/pages/api/index.astro b/packages/website-ue/src/pages/api/index.astro new file mode 100644 index 000000000..b8e5f2585 --- /dev/null +++ b/packages/website-ue/src/pages/api/index.astro @@ -0,0 +1,54 @@ +--- +import { + createProgram, + displayPartsToString, + forEachChild, + isFunctionDeclaration, +} from "typescript"; + +const root = `/src/pages/api`; +const globbed = import.meta.glob("/src/pages/api/**/*.ts", { + eager: true, + query: "?raw", +}); +const paths: { + path: string; + documentation: string; +}[] = []; + +for (const fullPath in globbed) { + const relativePath = `.${fullPath}`; + const path = fullPath.slice(root.length + 1, -3); + const program = createProgram([relativePath], {}); + const source = program.getSourceFile(relativePath); + if (!source) throw new Error(`Could not find source for ${fullPath}`); + + const checker = program.getTypeChecker(); + + const getter = forEachChild(source, (node) => { + if (!isFunctionDeclaration(node) || node.name?.text !== "GET") return; + return checker.getSymbolAtLocation(node.name); + }); + + const documentationComment = getter?.getDocumentationComment(checker); + if (!documentationComment) continue; + + const documentation = displayPartsToString(documentationComment); + if (documentation.length === 0) continue; + + paths.push({ path, documentation }); +} + +paths.sort((a, b) => a.path.localeCompare(b.path)); +--- + +
{documentation}
+ > + )) +} diff --git a/packages/website-ue/src/pages/api/tanks/[id].pb.ts b/packages/website-ue/src/pages/api/tanks/[id].pb.ts index 1cc6ce655..9897df41e 100644 --- a/packages/website-ue/src/pages/api/tanks/[id].pb.ts +++ b/packages/website-ue/src/pages/api/tanks/[id].pb.ts @@ -8,6 +8,9 @@ export const getStaticPaths = (async () => { return tanks.map(({ id }) => ({ params: { id } })); }) satisfies GetStaticPaths; +/** + * Even Noah can't save these animals. + */ export async function GET({ params }: APIContext