Skip to content

Commit

Permalink
feat: mainlib docs on new website (#9930)
Browse files Browse the repository at this point in the history
* fix(ExceptText): don't display import("d..-types/v10"). in return type

* Squashed 'packages/api-extractor-model/' content from commit 39ecb196c

git-subtree-dir: packages/api-extractor-model
git-subtree-split: 39ecb196ca210bdf84ba6c9cadb1bb93571849d7

* Squashed 'packages/api-extractor/' content from commit 341ad6c51

git-subtree-dir: packages/api-extractor
git-subtree-split: 341ad6c51b01656d4f73b74ad4bdb3095f9262c4

* feat(api-extractor): add api-extractor and -model

* fix: package.json docs script

* fix(SourcLink): use <> instead of function syntax

* fix: make packages private

* fix: rest params showing in docs, added labels

* fix: missed two files

* feat: merge docs.json from docgen and docs.api.json

* fix: cpy-cli & pnpm-lock

* fix: increase icon size

* fix: icon size again

* feat: run both docs on mainlib

* chore: website fixes

* fix: more website fixes

* fix: tests and dev database script

* chore: comment out old docs

* fix: increase max fetch cache

* fix: env should always be a string

* fix: try to reapply patches

* fix: remove prepare for docgen

* fix: temporary cosmetic fixes

* fix: horizontal scroll

* feat: generate index for new docs

---------

Co-authored-by: Noel <buechler.noel@outlook.com>
  • Loading branch information
Qjuh and iCrawl authored Nov 8, 2023
1 parent f713e47 commit da455bc
Show file tree
Hide file tree
Showing 63 changed files with 1,878 additions and 254 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
mkdir -p "out/${PACKAGE}"
if [[ "${PACKAGE}" == "discord.js" ]]; then
mv "packages/${PACKAGE}/docs/docs.json" "out/${PACKAGE}/${SEMVER}.json"
mv "packages/${PACKAGE}/docs/docs.api.json" "out/${PACKAGE}/${SEMVER}.api.json"
else
mv "packages/${PACKAGE}/docs/docs.api.json" "out/${PACKAGE}/${SEMVER}.api.json"
fi
Expand All @@ -106,6 +107,7 @@ jobs:
if [[ "${PACKAGE}" == "discord.js" ]]; then
mkdir -p "out/${PACKAGE}"
mv "packages/${PACKAGE}/docs/docs.json" "out/${PACKAGE}/${GITHUB_REF_NAME}.json"
mv "packages/${PACKAGE}/docs/docs.api.json" "out/${PACKAGE}/${GITHUB_REF_NAME}.api.json"
else
mkdir -p "out/${PACKAGE}"
mv "packages/${PACKAGE}/docs/docs.api.json" "out/${PACKAGE}/${GITHUB_REF_NAME}.api.json"
Expand Down
4 changes: 2 additions & 2 deletions apps/guide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"ariakit": "2.0.0-next.44",
"cmdk": "^0.2.0",
"contentlayer": "^0.3.4",
"next": "^14.0.2-canary.14",
"next": "14.0.2-canary.20",
"next-contentlayer": "^0.3.4",
"next-themes": "^0.2.1",
"react": "^18.2.0",
Expand All @@ -66,7 +66,7 @@
"sharp": "^0.32.6"
},
"devDependencies": {
"@next/bundle-analyzer": "^14.0.1",
"@next/bundle-analyzer": "14.0.2-canary.20",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.5.1",
"@types/html-escaper": "^3.0.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/guide/src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const PACKAGES = [
/**
* The stable version of discord.js.
*/
export const VERSION = '14.11.0' as const;
export const VERSION = '14.13.0' as const;

/**
* The API version (for discord-api-types). This is prefixed with a "v".
Expand Down
3 changes: 3 additions & 0 deletions apps/website/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export default withBundleAnalyzer({
contentSecurityPolicy: "default-src 'self'; frame-src 'none'; sandbox;",
},
poweredByHeader: false,
env: {
MAX_FETCH_SIZE: '5',
},
async redirects() {
return [
{
Expand Down
4 changes: 2 additions & 2 deletions apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"class-variance-authority": "^0.7.0",
"cmdk": "^0.2.0",
"meilisearch": "^0.35.0",
"next": "^14.0.2-canary.14",
"next": "14.0.2-canary.20",
"next-mdx-remote": "^4.4.1",
"next-themes": "^0.2.1",
"react": "^18.2.0",
Expand All @@ -75,7 +75,7 @@
"sharp": "^0.32.6"
},
"devDependencies": {
"@next/bundle-analyzer": "^14.0.1",
"@next/bundle-analyzer": "14.0.2-canary.20",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.5.1",
"@types/node": "18.18.8",
Expand Down
12 changes: 11 additions & 1 deletion apps/website/scripts/generateAllIndices.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { readFile } from 'node:fs/promises';
import { generateAllIndices } from '@discordjs/scripts';

console.log('Generating all indices...');
await generateAllIndices();
await generateAllIndices({
fetchPackageVersions: async (pkg) => {
console.log(`Fetching versions for ${pkg}...`);
return ['main'];
},
fetchPackageVersionDocs: async (pkg, version) => {
console.log(`Fetching data for ${pkg} ${version}...`);
return JSON.parse(await readFile(`${process.cwd()}/../../packages/${pkg}/docs/docs.api.json`, 'utf8'));
},
});
console.log('Generated all indices.');
2 changes: 1 addition & 1 deletion apps/website/src/app/docAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function fetchVersions(packageName: string): Promise<string[]> {
return rows.map((row) => row.version);
}

export async function fetchModelJSON(packageName: string, version: string): Promise<unknown> {
export async function fetchModelJSON(packageName: string, version: string): Promise<unknown | null> {
if (process.env.NEXT_PUBLIC_LOCAL_DEV) {
const res = await readFile(
join(process.cwd(), '..', '..', 'packages', packageName, 'docs', 'docs.api.json'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ import { findMember } from '~/util/model';

async function fetchHeadMember({ package: packageName, version, item }: ItemRouteParams) {
const modelJSON = await fetchModelJSON(packageName, version);

if (!modelJSON) {
return undefined;
}

const model = addPackageToModel(new ApiModel(), modelJSON);
const pkg = model.tryGetPackageByName(packageName);
const entry = pkg?.entryPoints[0];

if (!entry) {
return undefined;
}
Expand Down Expand Up @@ -88,7 +94,11 @@ export async function generateMetadata({ params }: { params: ItemRouteParams })
const searchParams = resolveMemberSearchParams(params.package, member);
url.search = searchParams.toString();
const ogImage = url.toString();
const description = tryResolveSummaryText(member as ApiDeclaredItem);
let description;

if (member) {
description = tryResolveSummaryText(member as ApiDeclaredItem);
}

return {
title: name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import dynamic from 'next/dynamic';
import { notFound } from 'next/navigation';
import type { PropsWithChildren } from 'react';
import { fetchModelJSON, fetchVersions } from '~/app/docAPI';
import { Banner } from '~/components/Banner';
// import { Banner } from '~/components/Banner';
import { CmdKDialog } from '~/components/CmdK';
import { Nav } from '~/components/Nav';
import type { SidebarSectionItemData } from '~/components/Sidebar';
Expand Down Expand Up @@ -46,6 +46,11 @@ function serializeIntoSidebarItemData(item: ApiItem): SidebarSectionItemData {

export default async function PackageLayout({ children, params }: PropsWithChildren<{ params: VersionRouteParams }>) {
const modelJSON = await fetchModelJSON(params.package, params.version);

if (!modelJSON) {
notFound();
}

const model = addPackageToModel(new ApiModel(), modelJSON);

const pkg = model.tryGetPackageByName(params.package);
Expand All @@ -72,7 +77,7 @@ export default async function PackageLayout({ children, params }: PropsWithChild

return (
<Providers>
<Banner className="mb-6" />
{/* <Banner className="mb-6" /> */}
<main className="mx-auto max-w-7xl px-4 lg:max-w-full">
<Header />
<div className="relative top-2.5 mx-auto max-w-7xl gap-6 lg:max-w-full lg:flex">
Expand Down
16 changes: 3 additions & 13 deletions apps/website/src/app/docs/packages/[package]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,12 @@ import { fetchVersions } from '~/app/docAPI';
import { buttonVariants } from '~/styles/Button';
import { PACKAGES } from '~/util/constants';

async function getData(pkg: string) {
if (!PACKAGES.includes(pkg)) {
export default async function Page({ params }: { params: { package: string } }) {
if (!PACKAGES.includes(params.package)) {
notFound();
}

const data = await fetchVersions(pkg);

if (!data.length) {
throw new Error('Failed to fetch data');
}

return data;
}

export default async function Page({ params }: { params: { package: string } }) {
const data = await getData(params.package);
const data = await fetchVersions(params.package);

return (
<div className="mx-auto min-h-screen min-w-xs flex flex-col gap-8 px-4 py-6 sm:w-md lg:px-6 lg:py-6">
Expand Down
4 changes: 2 additions & 2 deletions apps/website/src/app/docs/packages/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export default function Page() {
<div className="mx-auto min-h-screen min-w-xs flex flex-col gap-8 px-4 py-6 sm:w-md lg:px-6 lg:py-6">
<h1 className="text-2xl font-semibold">Select a package:</h1>
<div className="flex flex-col gap-4">
<a className={buttonVariants({ variant: 'secondary' })} href="https://old.discordjs.dev/#/docs/discord.js">
{/* <a className={buttonVariants({ variant: 'secondary' })} href="https://old.discordjs.dev/#/docs/discord.js">
<div className="flex grow flex-row place-content-between place-items-center gap-4">
<div className="flex flex-row place-content-between place-items-center gap-4">
<VscPackage size={25} />
<h2 className="font-semibold">discord.js</h2>
</div>
<VscArrowRight size={20} />
</div>
</a>
</a> */}
{PACKAGES.map((pkg, idx) => (
<Link
className={buttonVariants({ variant: 'secondary' })}
Expand Down
10 changes: 5 additions & 5 deletions apps/website/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import Image from 'next/image';
import Link from 'next/link';
import vercelLogo from '~/assets/powered-by-vercel.svg';
import workersLogo from '~/assets/powered-by-workers.png';
import { Banner } from '~/components/Banner';
// import { Banner } from '~/components/Banner';
import { InstallButton } from '~/components/InstallButton';
import { buttonVariants } from '~/styles/Button';
import { DESCRIPTION } from '~/util/constants';

export default function Page() {
return (
<div className="min-h-screen">
<Banner />
{/* <Banner /> */}
<div className="mx-auto max-w-6xl flex flex-col place-items-center gap-24 px-8 pb-16 pt-12 lg:min-h-[calc(100vh_-_40px)] lg:place-content-center lg:py-10">
<div className="flex flex-col place-items-center gap-10 lg:flex-row lg:gap-6">
<div className="flex flex-col place-items-center gap-10 text-center">
Expand All @@ -22,11 +22,11 @@ export default function Page() {
</h1>
<p className="my-6 leading-normal text-neutral-700 dark:text-neutral-300">{DESCRIPTION}</p>
<div className="flex flex-wrap place-content-center gap-4 md:flex-row">
<a className={buttonVariants()} href="https://old.discordjs.dev/#/docs" rel="noopener noreferrer">
{/* <a className={buttonVariants()} href="https://old.discordjs.dev/#/docs" rel="noopener noreferrer">
Docs
</a>
</a> */}
<Link className={buttonVariants()} href={'/docs' as Route}>
Module docs
Docs
</Link>
<a
className={buttonVariants({ variant: 'secondary' })}
Expand Down
14 changes: 8 additions & 6 deletions apps/website/src/components/ExcerptText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export function ExcerptText({ model, excerpt }: ExcerptTextProps) {
return (
<span>
{excerpt.spannedTokens.map((token, idx) => {
// TODO: Real fix in api-extractor needed
const text = token.text.replaceAll('\n', '').replaceAll(/\s{2}$/g, '');
if (token.kind === ExcerptTokenKind.Reference) {
const source = token.canonicalReference?.source;
const symbol = token.canonicalReference?.symbol;
Expand All @@ -32,20 +34,20 @@ export function ExcerptText({ model, excerpt }: ExcerptTextProps) {
// dapi-types doesn't have routes for class members
// so we can assume this member is for an enum
if (meaning === 'member' && path && 'parent' in path) href += `/enum/${path.parent}#${path.component}`;
else if (meaning === 'type') href += `#${token.text}`;
else href += `/${meaning}/${token.text}`;
else if (meaning === 'type') href += `#${text}`;
else href += `/${meaning}/${text}`;

return (
<a className="text-blurple" href={href} key={idx} rel="external noreferrer noopener" target="_blank">
{token.text}
{text}
</a>
);
}

const item = model.resolveDeclarationReference(token.canonicalReference!, model).resolvedApiItem;

if (!item) {
return token.text;
return text;
}

return (
Expand All @@ -55,12 +57,12 @@ export function ExcerptText({ model, excerpt }: ExcerptTextProps) {
key={`${item.displayName}-${item.containerKey}-${idx}`}
packageName={item.getAssociatedPackage()?.displayName.replace('@discordjs/', '')}
>
{token.text}
{text}
</ItemLink>
);
}

return token.text.replace(/import\("discord-api-types(?:\/v\d+)?"\)\./, '');
return text.replace(/import\("discord-api-types(?:\/v\d+)?"\)\./, '');
})}
</span>
);
Expand Down
25 changes: 12 additions & 13 deletions apps/website/src/components/PackageSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ export default function PackageSelect() {
const packageMenu = useMenuState({ gutter: 8, sameWidth: true, fitViewport: true });

const packageMenuItems = useMemo(
() => [
<a href="https://old.discordjs.dev/#/docs/discord.js" key="discord.js">
<MenuItem
className="my-0.5 rounded bg-white p-3 text-sm outline-none active:bg-light-800 dark:bg-dark-600 hover:bg-light-700 focus:ring focus:ring-width-2 focus:ring-blurple dark:active:bg-dark-400 dark:hover:bg-dark-500"
id="discord-js"
onClick={() => packageMenu.setOpen(false)}
state={packageMenu}
>
discord.js
</MenuItem>
</a>,
...PACKAGES.map((pkg, idx) => (
() =>
// <a href="https://old.discordjs.dev/#/docs/discord.js" key="discord.js">
// <MenuItem
// className="my-0.5 rounded bg-white p-3 text-sm outline-none active:bg-light-800 dark:bg-dark-600 hover:bg-light-700 focus:ring focus:ring-width-2 focus:ring-blurple dark:active:bg-dark-400 dark:hover:bg-dark-500"
// id="discord-js"
// onClick={() => packageMenu.setOpen(false)}
// state={packageMenu}
// >
// discord.js
// </MenuItem>
// </a>,
PACKAGES.map((pkg, idx) => (
<Link href={`/docs/packages/${pkg}/main`} key={`${pkg}-${idx}`}>
<MenuItem
className="my-0.5 rounded bg-white p-3 text-sm outline-none active:bg-light-800 dark:bg-dark-600 hover:bg-light-700 focus:ring focus:ring-width-2 focus:ring-blurple dark:active:bg-dark-400 dark:hover:bg-dark-500"
Expand All @@ -38,7 +38,6 @@ export default function PackageSelect() {
</MenuItem>
</Link>
)),
],
[packageMenu],
);

Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/components/Property.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function Property({
</CodeHeading>
</div>
{hasSummary || inheritedFrom ? (
<div className="mb-4 flex flex-col gap-4">
<div className="mb-4 w-full flex flex-col gap-4">
{item.tsdocComment ? <TSDoc item={item} tsdoc={item.tsdocComment} /> : null}
{inheritedFrom ? <InheritanceText parent={inheritedFrom} /> : null}
{children}
Expand Down
Loading

1 comment on commit da455bc

@vercel
Copy link

@vercel vercel bot commented on da455bc Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.