mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 10:33:30 +01:00
ci: deploy on vercel again
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { connect } from '@planetscale/database';
|
||||
import { cache } from 'react';
|
||||
import { N_RECENT_VERSIONS } from '~/util/constants';
|
||||
|
||||
const sql = connect({
|
||||
@@ -11,7 +12,7 @@ const sql = connect({
|
||||
},
|
||||
});
|
||||
|
||||
export async function fetchVersions(packageName: string): Promise<string[]> {
|
||||
export const fetchVersions = cache(async (packageName: string) => {
|
||||
if (process.env.NEXT_PUBLIC_LOCAL_DEV || process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview') {
|
||||
return ['main'];
|
||||
}
|
||||
@@ -22,9 +23,9 @@ export async function fetchVersions(packageName: string): Promise<string[]> {
|
||||
|
||||
// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
|
||||
return rows.map((row) => row.version).slice(0, N_RECENT_VERSIONS);
|
||||
}
|
||||
});
|
||||
|
||||
export async function fetchModelJSON(packageName: string, version: string): Promise<unknown | null> {
|
||||
export const fetchModelJSON = cache(async (packageName: string, version: string) => {
|
||||
if (process.env.NEXT_PUBLIC_LOCAL_DEV) {
|
||||
let res;
|
||||
|
||||
@@ -55,4 +56,4 @@ export async function fetchModelJSON(packageName: string, version: string): Prom
|
||||
|
||||
// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
|
||||
return rows[0]?.data ?? null;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -26,10 +26,15 @@ import { Enum } from '~/components/model/enum/Enum';
|
||||
import { Function } from '~/components/model/function/Function';
|
||||
import { addPackageToModel } from '~/util/addPackageToModel';
|
||||
import { OVERLOAD_SEPARATOR } from '~/util/constants';
|
||||
import type { ItemRouteParams } from '~/util/fetchMember';
|
||||
import { fetchMember } from '~/util/fetchMember';
|
||||
import { findMember } from '~/util/model';
|
||||
|
||||
export interface ItemRouteParams {
|
||||
item: string;
|
||||
package: string;
|
||||
version: string;
|
||||
}
|
||||
|
||||
async function fetchHeadMember({ package: packageName, version, item }: ItemRouteParams) {
|
||||
const modelJSON = await fetchModelJSON(packageName, version);
|
||||
|
||||
@@ -152,7 +157,7 @@ function Member({ member }: { readonly member?: ApiItem }) {
|
||||
}
|
||||
|
||||
export default async function Page({ params }: { params: ItemRouteParams }) {
|
||||
const member = await fetchMember(params);
|
||||
const member = await fetchMember(params.package, params.version ?? 'main', params.item);
|
||||
|
||||
if (!member) {
|
||||
notFound();
|
||||
|
||||
@@ -25,7 +25,7 @@ export async function generateStaticParams() {
|
||||
const params: VersionRouteParams[] = [];
|
||||
|
||||
await Promise.all(
|
||||
PACKAGES.map(async (packageName) => {
|
||||
PACKAGES.slice(1).map(async (packageName) => {
|
||||
const versions = await fetchVersions(packageName);
|
||||
|
||||
params.push(...versions.map((version) => ({ package: packageName, version })));
|
||||
|
||||
@@ -2,14 +2,15 @@ import { readFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import type { SerializeOptions } from 'next-mdx-remote/dist/types';
|
||||
import { MDXRemote } from 'next-mdx-remote/rsc';
|
||||
import { cache } from 'react';
|
||||
import rehypeSlug from 'rehype-slug';
|
||||
import remarkGfm from 'remark-gfm';
|
||||
import { SyntaxHighlighter } from '~/components/SyntaxHighlighter';
|
||||
import type { VersionRouteParams } from './layout';
|
||||
|
||||
async function loadREADME(packageName: string) {
|
||||
const loadREADME = cache(async (packageName: string) => {
|
||||
return readFile(join(process.cwd(), 'src', 'assets', 'readme', packageName, 'home-README.md'), 'utf8');
|
||||
}
|
||||
});
|
||||
|
||||
const mdxOptions = {
|
||||
mdxOptions: {
|
||||
|
||||
@@ -2,8 +2,9 @@ import type { ApiModel, ApiPackage } from '@discordjs/api-extractor-model';
|
||||
import { ApiItem } from '@discordjs/api-extractor-model';
|
||||
import { TSDocConfiguration } from '@microsoft/tsdoc';
|
||||
import { TSDocConfigFile } from '@microsoft/tsdoc-config';
|
||||
import { cache } from 'react';
|
||||
|
||||
export function addPackageToModel(model: ApiModel, data: any) {
|
||||
export const addPackageToModel = cache((model: ApiModel, data: any) => {
|
||||
let apiPackage: ApiPackage;
|
||||
if (data.metadata) {
|
||||
const tsdocConfiguration = new TSDocConfiguration();
|
||||
@@ -23,4 +24,4 @@ export function addPackageToModel(model: ApiModel, data: any) {
|
||||
|
||||
model.addMember(apiPackage);
|
||||
return model;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import { ApiModel, ApiFunction } from '@discordjs/api-extractor-model';
|
||||
import { cache } from 'react';
|
||||
import { fetchModelJSON } from '~/app/docAPI';
|
||||
import { addPackageToModel } from './addPackageToModel';
|
||||
import { OVERLOAD_SEPARATOR, PACKAGES } from './constants';
|
||||
import { findMember, findMemberByKey } from './model';
|
||||
|
||||
export interface ItemRouteParams {
|
||||
item: string;
|
||||
package: string;
|
||||
version: string;
|
||||
}
|
||||
|
||||
export async function fetchMember({ package: packageName, version: branchName = 'main', item }: ItemRouteParams) {
|
||||
export const fetchMember = cache(async (packageName: string, branchName: string, item: string) => {
|
||||
if (!PACKAGES.includes(packageName)) {
|
||||
return null;
|
||||
}
|
||||
@@ -46,4 +41,4 @@ export async function fetchMember({ package: packageName, version: branchName =
|
||||
}
|
||||
|
||||
return memberName && containerKey ? findMemberByKey(model, packageName, containerKey) ?? null : null;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -6,20 +6,21 @@ import type {
|
||||
Excerpt,
|
||||
} from '@discordjs/api-extractor-model';
|
||||
import type { DocSection } from '@microsoft/tsdoc';
|
||||
import { cache } from 'react';
|
||||
|
||||
export function findMemberByKey(model: ApiModel, packageName: string, containerKey: string) {
|
||||
export const findMemberByKey = cache((model: ApiModel, packageName: string, containerKey: string) => {
|
||||
const pkg = model.tryGetPackageByName(packageName === 'discord.js' ? packageName : `@discordjs/${packageName}`)!;
|
||||
return (pkg.members[0] as ApiEntryPoint).tryGetMemberByKey(containerKey);
|
||||
}
|
||||
});
|
||||
|
||||
export function findMember(model: ApiModel, packageName: string, memberName: string | undefined) {
|
||||
export const findMember = cache((model: ApiModel, packageName: string, memberName: string | undefined) => {
|
||||
if (!memberName) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const pkg = model.tryGetPackageByName(packageName === 'discord.js' ? packageName : `@discordjs/${packageName}`)!;
|
||||
return pkg.entryPoints[0]?.findMembersByName(memberName)[0];
|
||||
}
|
||||
});
|
||||
|
||||
interface ResolvedParameter {
|
||||
description?: DocSection | undefined;
|
||||
|
||||
Reference in New Issue
Block a user