Skip to content

Commit da455bc

Browse files
QjuhiCrawl
andauthored
feat: mainlib docs on new website (#9930)
* 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 <[email protected]>
1 parent f713e47 commit da455bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1878
-254
lines changed

.github/workflows/documentation.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ jobs:
8888
mkdir -p "out/${PACKAGE}"
8989
if [[ "${PACKAGE}" == "discord.js" ]]; then
9090
mv "packages/${PACKAGE}/docs/docs.json" "out/${PACKAGE}/${SEMVER}.json"
91+
mv "packages/${PACKAGE}/docs/docs.api.json" "out/${PACKAGE}/${SEMVER}.api.json"
9192
else
9293
mv "packages/${PACKAGE}/docs/docs.api.json" "out/${PACKAGE}/${SEMVER}.api.json"
9394
fi
@@ -106,6 +107,7 @@ jobs:
106107
if [[ "${PACKAGE}" == "discord.js" ]]; then
107108
mkdir -p "out/${PACKAGE}"
108109
mv "packages/${PACKAGE}/docs/docs.json" "out/${PACKAGE}/${GITHUB_REF_NAME}.json"
110+
mv "packages/${PACKAGE}/docs/docs.api.json" "out/${PACKAGE}/${GITHUB_REF_NAME}.api.json"
109111
else
110112
mkdir -p "out/${PACKAGE}"
111113
mv "packages/${PACKAGE}/docs/docs.api.json" "out/${PACKAGE}/${GITHUB_REF_NAME}.api.json"

apps/guide/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"ariakit": "2.0.0-next.44",
5555
"cmdk": "^0.2.0",
5656
"contentlayer": "^0.3.4",
57-
"next": "^14.0.2-canary.14",
57+
"next": "14.0.2-canary.20",
5858
"next-contentlayer": "^0.3.4",
5959
"next-themes": "^0.2.1",
6060
"react": "^18.2.0",
@@ -66,7 +66,7 @@
6666
"sharp": "^0.32.6"
6767
},
6868
"devDependencies": {
69-
"@next/bundle-analyzer": "^14.0.1",
69+
"@next/bundle-analyzer": "14.0.2-canary.20",
7070
"@testing-library/react": "^14.0.0",
7171
"@testing-library/user-event": "^14.5.1",
7272
"@types/html-escaper": "^3.0.1",

apps/guide/src/util/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const PACKAGES = [
2626
/**
2727
* The stable version of discord.js.
2828
*/
29-
export const VERSION = '14.11.0' as const;
29+
export const VERSION = '14.13.0' as const;
3030

3131
/**
3232
* The API version (for discord-api-types). This is prefixed with a "v".

apps/website/next.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export default withBundleAnalyzer({
1616
contentSecurityPolicy: "default-src 'self'; frame-src 'none'; sandbox;",
1717
},
1818
poweredByHeader: false,
19+
env: {
20+
MAX_FETCH_SIZE: '5',
21+
},
1922
async redirects() {
2023
return [
2124
{

apps/website/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"class-variance-authority": "^0.7.0",
6464
"cmdk": "^0.2.0",
6565
"meilisearch": "^0.35.0",
66-
"next": "^14.0.2-canary.14",
66+
"next": "14.0.2-canary.20",
6767
"next-mdx-remote": "^4.4.1",
6868
"next-themes": "^0.2.1",
6969
"react": "^18.2.0",
@@ -75,7 +75,7 @@
7575
"sharp": "^0.32.6"
7676
},
7777
"devDependencies": {
78-
"@next/bundle-analyzer": "^14.0.1",
78+
"@next/bundle-analyzer": "14.0.2-canary.20",
7979
"@testing-library/react": "^14.0.0",
8080
"@testing-library/user-event": "^14.5.1",
8181
"@types/node": "18.18.8",
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
import { readFile } from 'node:fs/promises';
12
import { generateAllIndices } from '@discordjs/scripts';
23

34
console.log('Generating all indices...');
4-
await generateAllIndices();
5+
await generateAllIndices({
6+
fetchPackageVersions: async (pkg) => {
7+
console.log(`Fetching versions for ${pkg}...`);
8+
return ['main'];
9+
},
10+
fetchPackageVersionDocs: async (pkg, version) => {
11+
console.log(`Fetching data for ${pkg} ${version}...`);
12+
return JSON.parse(await readFile(`${process.cwd()}/../../packages/${pkg}/docs/docs.api.json`, 'utf8'));
13+
},
14+
});
515
console.log('Generated all indices.');

apps/website/src/app/docAPI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function fetchVersions(packageName: string): Promise<string[]> {
2323
return rows.map((row) => row.version);
2424
}
2525

26-
export async function fetchModelJSON(packageName: string, version: string): Promise<unknown> {
26+
export async function fetchModelJSON(packageName: string, version: string): Promise<unknown | null> {
2727
if (process.env.NEXT_PUBLIC_LOCAL_DEV) {
2828
const res = await readFile(
2929
join(process.cwd(), '..', '..', 'packages', packageName, 'docs', 'docs.api.json'),

apps/website/src/app/docs/packages/[package]/[version]/[item]/page.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,15 @@ import { findMember } from '~/util/model';
3232

3333
async function fetchHeadMember({ package: packageName, version, item }: ItemRouteParams) {
3434
const modelJSON = await fetchModelJSON(packageName, version);
35+
36+
if (!modelJSON) {
37+
return undefined;
38+
}
39+
3540
const model = addPackageToModel(new ApiModel(), modelJSON);
3641
const pkg = model.tryGetPackageByName(packageName);
3742
const entry = pkg?.entryPoints[0];
43+
3844
if (!entry) {
3945
return undefined;
4046
}
@@ -88,7 +94,11 @@ export async function generateMetadata({ params }: { params: ItemRouteParams })
8894
const searchParams = resolveMemberSearchParams(params.package, member);
8995
url.search = searchParams.toString();
9096
const ogImage = url.toString();
91-
const description = tryResolveSummaryText(member as ApiDeclaredItem);
97+
let description;
98+
99+
if (member) {
100+
description = tryResolveSummaryText(member as ApiDeclaredItem);
101+
}
92102

93103
return {
94104
title: name,

apps/website/src/app/docs/packages/[package]/[version]/layout.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import dynamic from 'next/dynamic';
44
import { notFound } from 'next/navigation';
55
import type { PropsWithChildren } from 'react';
66
import { fetchModelJSON, fetchVersions } from '~/app/docAPI';
7-
import { Banner } from '~/components/Banner';
7+
// import { Banner } from '~/components/Banner';
88
import { CmdKDialog } from '~/components/CmdK';
99
import { Nav } from '~/components/Nav';
1010
import type { SidebarSectionItemData } from '~/components/Sidebar';
@@ -46,6 +46,11 @@ function serializeIntoSidebarItemData(item: ApiItem): SidebarSectionItemData {
4646

4747
export default async function PackageLayout({ children, params }: PropsWithChildren<{ params: VersionRouteParams }>) {
4848
const modelJSON = await fetchModelJSON(params.package, params.version);
49+
50+
if (!modelJSON) {
51+
notFound();
52+
}
53+
4954
const model = addPackageToModel(new ApiModel(), modelJSON);
5055

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

7378
return (
7479
<Providers>
75-
<Banner className="mb-6" />
80+
{/* <Banner className="mb-6" /> */}
7681
<main className="mx-auto max-w-7xl px-4 lg:max-w-full">
7782
<Header />
7883
<div className="relative top-2.5 mx-auto max-w-7xl gap-6 lg:max-w-full lg:flex">

apps/website/src/app/docs/packages/[package]/page.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,12 @@ import { fetchVersions } from '~/app/docAPI';
77
import { buttonVariants } from '~/styles/Button';
88
import { PACKAGES } from '~/util/constants';
99

10-
async function getData(pkg: string) {
11-
if (!PACKAGES.includes(pkg)) {
10+
export default async function Page({ params }: { params: { package: string } }) {
11+
if (!PACKAGES.includes(params.package)) {
1212
notFound();
1313
}
1414

15-
const data = await fetchVersions(pkg);
16-
17-
if (!data.length) {
18-
throw new Error('Failed to fetch data');
19-
}
20-
21-
return data;
22-
}
23-
24-
export default async function Page({ params }: { params: { package: string } }) {
25-
const data = await getData(params.package);
15+
const data = await fetchVersions(params.package);
2616

2717
return (
2818
<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">

0 commit comments

Comments
 (0)