mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 10:33:30 +01:00
feat: discord-api-types on docs
This commit is contained in:
@@ -1,34 +1,36 @@
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
// import { sql } from '@vercel/postgres';
|
||||
import { PACKAGES_WITH_ENTRY_POINTS } from './constants';
|
||||
import { ENV } from './env';
|
||||
|
||||
export async function fetchEntryPoints(packageName: string, version: string) {
|
||||
const hasEntryPoint = PACKAGES_WITH_ENTRY_POINTS.includes(packageName);
|
||||
|
||||
if (!hasEntryPoint) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (ENV.IS_LOCAL_DEV) {
|
||||
const fileContent = await readFile(
|
||||
join(process.cwd(), `../../packages/${packageName}/docs/${packageName}/split/${version}.entrypoints.api.json`),
|
||||
join(
|
||||
process.cwd(),
|
||||
`${hasEntryPoint ? `../../../discord-api-types` : `../../packages/${packageName}`}/docs/${packageName}/split/${version}.entrypoints.api.json`,
|
||||
),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
return JSON.parse(fileContent);
|
||||
}
|
||||
|
||||
// try {
|
||||
// const { rows } = await sql<{
|
||||
// entryPoint: string;
|
||||
// }>`select entryPoint from documentation where name = ${packageName} and version = ${version} order by
|
||||
// case
|
||||
// when version = 'main' then 0
|
||||
// else 1
|
||||
// end,
|
||||
// case
|
||||
// when version = 'main' then null
|
||||
// else string_to_array(version, '.')::int[]
|
||||
// end desc;
|
||||
// `;
|
||||
const isMain = version === 'main';
|
||||
const fileContent = await fetch(
|
||||
`${process.env.CF_R2_DOCS_BUCKET_URL}/${packageName}/${version}.entrypoints.api.json`,
|
||||
{ next: { revalidate: isMain ? 0 : 604_800 } },
|
||||
);
|
||||
|
||||
// return rows;
|
||||
// } catch {
|
||||
return [];
|
||||
// }
|
||||
if (!fileContent.ok) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return fileContent.json();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user