Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mainlib docs on new website #9930

Merged
merged 38 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8e75934
fix(ExceptText): don't display import("d..-types/v10"). in return type
Qjuh Oct 29, 2023
4200eaf
Squashed 'packages/api-extractor-model/' content from commit 39ecb196c
Qjuh Oct 31, 2023
a1af1b6
Merge commit '4200eaf76e4130eb8e31cec543e45593c3ace11d' as 'packages/…
Qjuh Oct 31, 2023
eff803b
Squashed 'packages/api-extractor/' content from commit 341ad6c51
Qjuh Oct 31, 2023
a4fdd99
Merge commit 'eff803b2f8d23488ae0058fe79ceaa035f55ee7a' as 'packages/…
Qjuh Oct 31, 2023
7ae844a
feat(api-extractor): add api-extractor and -model
Qjuh Nov 4, 2023
bdf6b88
Merge branch 'main' into feat/package-api-extractor
Qjuh Nov 4, 2023
d32c1dd
fix: package.json docs script
Qjuh Nov 4, 2023
9caa478
fix(SourcLink): use <> instead of function syntax
Qjuh Nov 4, 2023
ebcb5e9
fix: make packages private
Qjuh Nov 4, 2023
149aa58
fix: rest params showing in docs, added labels
Qjuh Nov 4, 2023
fc9240a
fix: missed two files
Qjuh Nov 4, 2023
ec7ff66
Merge branch 'main' into feat/package-api-extractor
Qjuh Nov 5, 2023
8adc94c
Merge branch 'main' into feat/package-api-extractor
Qjuh Nov 6, 2023
78b21c5
Merge branch 'main' into feat/package-api-extractor
Qjuh Nov 7, 2023
26b84db
feat: merge docs.json from docgen and docs.api.json
Qjuh Nov 7, 2023
f397ae5
fix: cpy-cli & pnpm-lock
Qjuh Nov 7, 2023
668479e
Merge branch 'main' into feat/package-api-extractor
Qjuh Nov 7, 2023
8f90fde
Merge branch 'main' into feat/package-api-extractor
Qjuh Nov 7, 2023
e1f8a59
fix: increase icon size
Qjuh Nov 7, 2023
265208c
Merge branch 'main' into feat/package-api-extractor
Qjuh Nov 7, 2023
a1d7ecc
fix: icon size again
Qjuh Nov 7, 2023
b0d1396
Merge branch 'feat/package-api-extractor' into feat/api-extractor-merge
Qjuh Nov 7, 2023
8acdebe
feat: run both docs on mainlib
Qjuh Nov 7, 2023
81e1cba
Merge branch 'main' into feat/api-extractor-merge
Qjuh Nov 8, 2023
f569fba
Merge branch 'main' into feat/api-extractor-merge
iCrawl Nov 8, 2023
8246b84
Merge branch 'main' into feat/api-extractor-merge
iCrawl Nov 8, 2023
651327b
chore: website fixes
iCrawl Nov 8, 2023
21935fc
fix: more website fixes
iCrawl Nov 8, 2023
96b38a6
fix: tests and dev database script
iCrawl Nov 8, 2023
daab301
chore: comment out old docs
iCrawl Nov 8, 2023
8018911
fix: increase max fetch cache
iCrawl Nov 8, 2023
861f0a0
fix: env should always be a string
iCrawl Nov 8, 2023
45afe13
fix: try to reapply patches
iCrawl Nov 8, 2023
3c58e40
fix: remove prepare for docgen
iCrawl Nov 8, 2023
4be621d
fix: temporary cosmetic fixes
iCrawl Nov 8, 2023
cd8b524
fix: horizontal scroll
iCrawl Nov 8, 2023
8d6fedc
feat: generate index for new docs
iCrawl Nov 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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