Files
discord.js/apps/website/src/util/fetchEntryPoints.ts
Almeida 456a6f4548 fix: header link on packages with entrypoints (#11285)
* fix: header link on packages with entrypoints

* types: add types

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2025-11-20 21:22:36 +00:00

44 lines
1.0 KiB
TypeScript

import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { PACKAGES_WITH_ENTRY_POINTS } from './constants';
import { ENV } from './env';
export async function fetchEntryPoints(packageName: string, version: string): Promise<EntryPoint[] | null> {
const hasEntryPoint = PACKAGES_WITH_ENTRY_POINTS.includes(packageName);
if (!hasEntryPoint) {
return [];
}
if (ENV.IS_LOCAL_DEV) {
try {
const fileContent = await readFile(
join(
process.cwd(),
`${hasEntryPoint ? `../../../discord-api-types` : `../../packages/${packageName}`}/docs/${packageName}/split/${version}.entrypoints.api.json`,
),
'utf8',
);
return JSON.parse(fileContent);
} catch {
return null;
}
}
const fileContent = await fetch(
`${process.env.CF_R2_DOCS_BUCKET_URL}/${packageName}/${version}.entrypoints.api.json`,
{ cache: 'no-store' },
);
if (!fileContent.ok) {
return null;
}
return fileContent.json();
}
export interface EntryPoint {
readonly entryPoint: string;
}