Compare commits

..

1 Commits

Author SHA1 Message Date
iCrawl
41d55e4139 chore(create-discord-bot): release create-discord-bot@0.2.1 2023-08-17 21:35:44 +02:00
750 changed files with 32125 additions and 69736 deletions

View File

@@ -1,5 +1,4 @@
{
"$schema": "https://json.schemastore.org/commitlintrc.json",
"extends": ["@commitlint/config-angular"],
"rules": {
"type-enum": [

11
.eslintrc.json Normal file
View File

@@ -0,0 +1,11 @@
{
"root": true,
"extends": ["neon/common", "neon/node", "neon/typescript", "neon/prettier"],
"parserOptions": {
"project": ["./tsconfig.eslint.json", "./apps/*/tsconfig.eslint.json", "./packages/*/tsconfig.eslint.json"]
},
"rules": {
"@typescript-eslint/consistent-type-definitions": ["error", "interface"]
},
"ignorePatterns": ["**/dist/*"]
}

View File

@@ -11,21 +11,22 @@ is a great boon to your development process.
To get ready to work on the codebase, please do the following:
1. Fork & clone the repository, and make sure you're on the **main** branch
2. Run `pnpm install --frozen-lockfile` ([install](https://pnpm.io/installation))
3. Run `pnpm run build` to build local packages
2. Run `yarn --immutable` ([install](https://yarnpkg.com/getting-started/install))
3. Run `yarn build` to build local packages
4. Code your heart out!
5. Run `pnpm run test` to run ESLint and ensure any JSDoc changes are valid
5. Run `yarn test` to run ESLint and ensure any JSDoc changes are valid
6. [Submit a pull request](https://github.com/discordjs/discord.js/compare) (Make sure you follow the [conventional commit format](https://github.com/discordjs/discord.js/blob/main/.github/COMMIT_CONVENTION.md))
## Testing changes locally
If you want to test changes you've made locally, you can do so by using `pnpm link <package-you-want-to-link-to-your-current-package>`. This will create a symlink to your local copy of the discord.js libraries.
If you want to test changes you've made locally, you can do so by using `yarn link`. This will create a symlink to your local copy of the discord.js libraries.
1. Create a new directory `mkdir discordjs-test` and move into it `cd discordjs-test`
2. Initialize a new pnpm project `pnpm init`
3. Now link the local discord.js project you cloned earlier `pnpm link {PATH_TO_DISCORDJS_REPO}`
4. Install packages you'd like to test locally `pnpm add discord.js@latest`, `pnpm add @discordjs/rest@latest`, etc. **Note: Make sure you use `latest` tag or else pnpm will try to install the remote package from npm**
5. Import the package in your source code and test them out!
2. Initialize a new yarn 3 project `yarn init -2`
3. Disable pnp `yarn config set nodeLinker node-modules`
4. Now link the local discord.js project you cloned earlier `yarn link -A {PATH_TO_DISCORDJS_REPO}`
5. Install packages you'd like to test locally `yarn add discord.js@latest`, `yarn add @discordjs/rest@latest`, etc. **Note: Make sure you use `latest` tag or else yarn will try to install the remote package from npm**
6. Import the package in your source code and test them out!
### Working with TypeScript packages
@@ -33,18 +34,15 @@ When testing local changes, you may notice you need to manually recompile TypeSc
To avoid this you can use the `--watch` parameter in the package build script to automatically recompile the project when changes are detected.
For example, to automatically recompile the `@discordjs/rest` project when changes are detected, run `pnpm turbo run build --filter='@discordjs/rest' -- --watch` in the root folder of where you cloned the discord.js repo.
For example, to automatically recompile the `@discordjs/rest` project when changes are detected, run `yarn turbo run build --filter=@discordjs/rest -- --watch` in the root folder of where you cloned the discord.js repo.
## Adding new packages
If you'd like to create another package under the `@discordjs` organization run the following command:
```sh
pnpm run create-package <package-name> [package-description]
yarn create-package <package-name> [package-description]
```
This will create new package directory under `packages/` with the required configuration files. You may begin
to make changes within the `src/` directory. You may also need to:
- Update workflows that utilize packages
- Update the CODEOWNERS file
This will create new package directory under `packages/` with the required configuration files. You can
begin to make changes within the `src/` directory. It may also be required to update the CODEOWNERS file.

6
.github/labeler.yml vendored
View File

@@ -4,12 +4,6 @@ apps:guide:
apps:website:
- apps/website/*
- apps/website/**/*
packages:api-extractor:
- packages/api-extractor/*
- packages/api-extractor/**/*
packages:api-extractor-model:
- packages/api-extractor-model/*
- packages/api-extractor-model/**/*
packages:brokers:
- packages/brokers/*
- packages/brokers/**/*

12
.github/labels.yml vendored
View File

@@ -1,7 +1,7 @@
- name: api changes
color: '5663e9'
color: 5663e9
- name: api support
color: '5663e9'
color: 5663e9
- name: apps:guide
color: fbca04
- name: apps:website
@@ -23,7 +23,7 @@
- name: dependencies
color: 276bd1
- name: discord
color: '5663e9'
color: 5663e9
- name: discussion
color: b6b1f9
- name: documentation
@@ -41,7 +41,7 @@
- name: has PR
color: 4b1f8e
- name: help wanted
color: '008672'
color: 008672
- name: in progress
color: ffccd7
- name: in review
@@ -52,10 +52,6 @@
color: e4e669
- name: need repro
color: c66037
- name: packages:api-extractor
color: fbca04
- name: packages:api-extractor-model
color: fbca04
- name: packages:brokers
color: fbca04
- name: packages:builders

View File

@@ -1,35 +0,0 @@
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
name: Cleanup caches
on:
pull_request:
types:
- closed
workflow_dispatch:
jobs:
cleanup:
name: Cleanup caches
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Cleanup caches
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -1,28 +0,0 @@
name: Deploy website
on:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
deploy-website:
name: Deploy website
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
if: github.repository_owner == 'discordjs'
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Build & deploy website
uses: BetaHuhn/deploy-to-vercel-action@643bc80032ba62ca41d1a9aaba7b38b51c2b8646
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_SCOPE: 'discordjs'
GITHUB_DEPLOYMENT_ENV: 'Production discord-js'
PRODUCTION: true

View File

@@ -1,50 +0,0 @@
name: Deprecate version
on:
workflow_dispatch:
inputs:
package:
description: Package
required: true
type: choice
options:
- '@discordjs/brokers'
- '@discordjs/builders'
- '@discordjs/collection'
- '@discordjs/core'
- 'create-discord-bot'
- '@discordjs/formatters'
- 'discord.js'
- '@discordjs/next'
- '@discordjs/proxy'
- '@discordjs/rest'
- '@discordjs/util'
- '@discordjs/voice'
- '@discordjs/ws'
version:
description: Version(s)
required: true
type: string
message:
description: Deprecation message
required: false
type: string
jobs:
deprecate:
runs-on: ubuntu-latest
if: github.repository_owner == 'discordjs'
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Node.js v18
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
uses: ./packages/actions/src/pnpmCache
- name: Deprecate
run: pnpm exec npm-deprecate --name "${{inputs.version}}" --message "${{inputs.message || 'This version is deprecated. Please use a newer version.'}}" --package ${{inputs.package}}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

View File

@@ -5,9 +5,6 @@ on:
- 'main'
paths:
- 'packages/*/src/**'
- '!packages/create-discord-bot/**'
- '!packages/proxy-container/**'
- '!packages/ui/**'
tags:
- '**'
workflow_dispatch:
@@ -26,7 +23,7 @@ concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
build-docs:
build:
name: Build & upload documentation
runs-on: ubuntu-latest
env:
@@ -45,13 +42,13 @@ jobs:
node-version: 18
- name: Install dependencies
uses: ./packages/actions/src/pnpmCache
uses: ./packages/actions/src/yarnCache
- name: Build dependencies
run: pnpm run build
run: yarn build
- name: Build docs
run: pnpm run docs
run: yarn docs
- name: Checkout docs repository
uses: actions/checkout@v3
@@ -85,7 +82,6 @@ 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
@@ -99,12 +95,11 @@ jobs:
- name: Move docs to correct directory
if: ${{ github.ref_type == 'branch' }}
run: |
declare -a PACKAGES=("brokers" "builders" "collection" "core" "discord.js" "formatters" "next" "proxy" "rest" "util" "voice" "ws")
declare -a PACKAGES=("brokers" "builders" "collection" "core" "discord.js" "next" "formatters" "proxy" "rest" "util" "voice" "ws")
for PACKAGE in "${PACKAGES[@]}"; do
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"
@@ -119,56 +114,3 @@ jobs:
git add .
git commit -m "Docs build for ${GITHUB_REF_TYPE} ${GITHUB_REF_NAME}: ${GITHUB_SHA}" || true
git push
build-indices:
needs: build-docs
name: Build & upload search indices
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
if: github.repository_owner == 'discordjs'
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install node.js v18
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
uses: ./packages/actions/src/pnpmCache
- name: Build dependencies
run: pnpm run build
- name: Upload search indices to meilisearch
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
SEARCH_API_URL: ${{ secrets.SEARCH_API_URL }}
SEARCH_API_KEY: ${{ secrets.SEARCH_API_KEY }}
uses: ./packages/actions/src/uploadSearchIndices
deploy-website:
needs: build-docs
name: Deploy website
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
if: github.repository_owner == 'discordjs'
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Build & deploy website
uses: BetaHuhn/deploy-to-vercel-action@643bc80032ba62ca41d1a9aaba7b38b51c2b8646
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_SCOPE: 'discordjs'
GITHUB_DEPLOYMENT_ENV: 'Production discord-js'
PRODUCTION: true

View File

@@ -6,7 +6,7 @@ jobs:
issue-triage:
runs-on: ubuntu-latest
steps:
- uses: github/issue-labeler@v3.2
- uses: github/issue-labeler@v3.1
with:
repo-token: '${{ secrets.GITHUB_TOKEN }}'
configuration-path: .github/issue-labeler.yml

20
.github/workflows/lighthouse-main.yml vendored Normal file
View File

@@ -0,0 +1,20 @@
name: 'Lighthouse Audit (main)'
on:
workflow_dispatch:
jobs:
lighthouse_audit_main:
name: 'Lighthouse Audit (main)'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Audit production URLs with Lighthouse
id: lighthouse_audit
uses: treosh/lighthouse-ci-action@v9
with:
urls: |
https://discordjs.dev
https://guide.discordjs.dev
uploadArtifacts: true
temporaryPublicStorage: true

88
.github/workflows/lighthouse.yml vendored Normal file
View File

@@ -0,0 +1,88 @@
name: 'Lighthouse Audit'
on:
issue_comment:
types: [created, edited]
jobs:
lighthouse_audit:
name: 'Lighthouse Audit'
if: ${{ github.event.issue.pull_request }}
runs-on: ubuntu-latest
steps:
- name: Get Vercel preview URL
id: get_preview_url
uses: actions/github-script@v6
with:
script: |
const comment = context.payload.comment;
const regex = /https:\/\/[a-z0-9-]+\.vercel\.app/g;
const matches = comment.body.match(regex);
let previewUrl = "";
if (matches && matches.length) {
previewUrl = matches[0];
console.log('Preview url found:', previewUrl);
}
console.log("No preview url found.");
core.setOutput('vercel_preview_url', previewUrl);
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Add comment to PR
if: ${{ steps.get_preview_url.outputs.vercel_preview_url != '' }}
id: loading_comment_to_pr
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ github.event.issue.number }}
header: lighthouse
message: |
Running Lighthouse audit...
- name: Checkout repository
if: ${{ steps.get_preview_url.outputs.vercel_preview_url != '' }}
uses: actions/checkout@v3
- name: Audit preview URL with Lighthouse
if: ${{ steps.get_preview_url.outputs.vercel_preview_url != '' }}
id: lighthouse_audit
uses: treosh/lighthouse-ci-action@v9
with:
urls: |
${{ steps.get_preview_url.outputs.vercel_preview_url }}
uploadArtifacts: true
temporaryPublicStorage: true
- name: Format lighthouse score
if: ${{ steps.get_preview_url.outputs.vercel_preview_url != '' }}
id: format_lighthouse_score
uses: actions/github-script@v6
with:
script: |
const result = ${{ steps.lighthouse_audit.outputs.manifest }}[0].summary
const links = ${{ steps.lighthouse_audit.outputs.links }}
const formatResult = (res) => Math.round((res * 100))
Object.keys(result).forEach(key => result[key] = formatResult(result[key]))
const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴'
const comment = [
`⚡️ [Lighthouse report](${Object.values(links)[0]}) for the changes in this PR:`,
'| Category | Score |',
'| --- | --- |',
`| ${score(result.performance)} Performance | ${result.performance} |`,
`| ${score(result.accessibility)} Accessibility | ${result.accessibility} |`,
`| ${score(result['best-practices'])} Best practices | ${result['best-practices']} |`,
`| ${score(result.seo)} SEO | ${result.seo} |`,
`| ${score(result.pwa)} PWA | ${result.pwa} |`,
' ',
`*Lighthouse ran on [${Object.keys(links)[0]}](${Object.keys(links)[0]})*`
].join('\n')
core.setOutput("comment", comment);
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Add comment to PR
if: ${{ steps.get_preview_url.outputs.vercel_preview_url != '' }}
id: comment_to_pr
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ github.event.issue.number }}
header: lighthouse
message: |
${{ steps.format_lighthouse_score.outputs.comment }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -3,13 +3,13 @@ on:
schedule:
- cron: '0 16 * * *'
workflow_dispatch:
permissions:
issues: write
concurrency:
group: lock
jobs:
action:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- uses: dessant/lock-threads@v4
with:

View File

@@ -0,0 +1,26 @@
name: npm auto deprecate
on:
schedule:
- cron: '0 1 * * *'
workflow_dispatch:
jobs:
npm-auto-deprecate:
name: npm auto deprecate
runs-on: ubuntu-latest
if: github.repository_owner == 'discordjs'
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install node.js v18
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
uses: ./packages/actions/src/yarnCache
- name: Deprecate versions
run: 'yarn npm-deprecate --name "*dev*" --package @discordjs/brokers @discordjs/builders @discordjs/collection @discordjs/core @discordjs/formatters discord.js @discordjs/next @discordjs/proxy @discordjs/rest @discordjs/util @discordjs/voice @discordjs/ws'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

View File

@@ -18,7 +18,10 @@ jobs:
node-version: 18
- name: Install dependencies
uses: ./packages/actions/src/pnpmCache
uses: ./packages/actions/src/yarnCache
- name: Build dependencies
run: yarn build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
@@ -27,4 +30,4 @@ jobs:
run: echo ${{ secrets.DOCKER_ACCESS_TOKEN }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Build & push docker image
run: docker build -f packages/proxy-container/Dockerfile -t discordjs/proxy:latest --push .
run: yarn docker build --buildkit @discordjs/proxy-container -t discordjs/proxy:latest --push

View File

@@ -51,32 +51,15 @@ jobs:
node-version: 18
registry-url: https://registry.npmjs.org/
- name: Check the current development version
id: release-check
run: |
if [[ $(npm view ${{ matrix.package }}@dev version | grep -e "$(git rev-parse --short HEAD)") ]]; \
then echo "RELEASE=0" >> "$GITHUB_OUTPUT"; \
else echo "RELEASE=1" >> "$GITHUB_OUTPUT"; \
fi
- name: Install dependencies
if: steps.release-check.outputs.release == '1'
uses: ./packages/actions/src/pnpmCache
uses: ./packages/actions/src/yarnCache
- name: Build dependencies
if: steps.release-check.outputs.release == '1'
run: pnpm run build
run: yarn build
- name: Publish package
if: steps.release-check.outputs.release == '1'
run: |
pnpm --filter=${{ matrix.package }} run release --preid "dev.$(date +%s)-$(git rev-parse --short HEAD)"
pnpm --filter=${{ matrix.package }} publish --no-git-checks --tag dev || true
yarn workspace ${{ matrix.package }} release --preid "dev.$(date +%s)-$(git rev-parse --short HEAD)"
yarn workspace ${{ matrix.package }} npm publish --tag dev || true
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
- name: Deprecate prior development releases
if: steps.release-check.outputs.release == '1'
run: pnpm exec npm-deprecate --name "*dev*" --message "This version is deprecated. Please use a newer version." --package ${{ matrix.package }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

View File

@@ -15,7 +15,10 @@ jobs:
node-version: 18
- name: Install dependencies
uses: ./packages/actions/src/pnpmCache
uses: ./packages/actions/src/yarnCache
- name: Build dependencies
run: yarn build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
@@ -24,4 +27,4 @@ jobs:
run: echo ${{ secrets.DOCKER_ACCESS_TOKEN }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Build & push docker image
run: docker build -f packages/proxy-container/Dockerfile -t discordjs/proxy:$(cut -d '.' -f1 <<< $(jq --raw-output '.version' packages/proxy-container/package.json)) --push .
run: yarn docker build --buildkit @discordjs/proxy-container -t discordjs/proxy:$(cut -d '.' -f1 <<< $(jq --raw-output '.version' packages/proxy-container/package.json)) --push

View File

@@ -21,10 +21,10 @@ jobs:
registry-url: https://registry.npmjs.org/
- name: Install dependencies
uses: ./packages/actions/src/pnpmCache
uses: ./packages/actions/src/yarnCache
- name: Build dependencies
run: pnpm run build
run: yarn build
- name: Extract package and semver from tag
id: extract-tag
@@ -34,6 +34,6 @@ jobs:
- name: Publish package
run: |
pnpm --filter=${{ steps.extract-tag.outputs.subpackage == 'true' && '@discordjs/' || '' }}${{ steps.extract-tag.outputs.package }} publish --no-git-checks
yarn workspace ${{ steps.extract-tag.outputs.subpackage == 'true' && '@discordjs/' || '' }}${{ steps.extract-tag.outputs.package }} npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

View File

@@ -25,39 +25,39 @@ jobs:
node-version: 18
- name: Install dependencies
uses: ./packages/actions/src/pnpmCache
uses: ./packages/actions/src/yarnCache
- name: Build dependencies (PR)
if: ${{ github.event_name != 'push' }}
run: pnpm exec turbo run build --filter="...[origin/${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || 'main' }}]" --concurrency=4
run: yarn build --filter="...[origin/${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || 'main' }}]"
- name: Build dependencies (Push)
if: ${{ github.event_name == 'push' }}
run: pnpm exec turbo run build --filter="...[HEAD^1]" --concurrency=4
run: yarn build --filter="...[HEAD^1]"
- name: ESLint (PR)
if: ${{ github.event_name != 'push' }}
run: pnpm exec turbo run lint --filter="...[origin/${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || 'main' }}]" --concurrency=4 -- --format=compact
run: yarn lint --filter="...[origin/${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || 'main' }}]" -- --format=compact
- name: ESLint (Push)
if: ${{ github.event_name == 'push' }}
run: pnpm exec turbo run lint --filter="...[HEAD^1]" --concurrency=4 -- --format=compact
run: yarn lint --filter="...[HEAD^1]" -- --format=compact
- name: Tests (PR)
if: ${{ github.event_name != 'push' }}
run: pnpm exec turbo run test --filter="...[origin/${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || 'main' }}]" --concurrency=4
run: yarn test --filter="...[origin/${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || 'main' }}]"
- name: Tests (Push)
if: ${{ github.event_name == 'push' }}
run: pnpm exec turbo run test --filter="...[HEAD^1]" --concurrency=4
run: yarn test --filter="...[HEAD^1]"
- name: Docs (PR)
if: ${{ github.event_name != 'push' }}
run: pnpm exec turbo run docs --filter="...[origin/${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || 'main' }}]" --concurrency=4
run: yarn docs --filter="...[origin/${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || 'main' }}]"
- name: Docs (Push)
if: ${{ github.event_name == 'push' }}
run: pnpm exec turbo run docs --filter="...[HEAD^1]" --concurrency=4
run: yarn docs --filter="...[HEAD^1]"
- name: Upload Coverage
if: github.repository_owner == 'discordjs'

11
.gitignore vendored
View File

@@ -20,7 +20,7 @@ dist-docs
# Miscellaneous
.tmp
.vscode/*
.vscode
!.vscode/extensions.json
!.vscode/settings.json
.idea
@@ -29,15 +29,6 @@ dist-docs
tsconfig.tsbuildinfo
coverage
out
package.tgz
tsup.config.bundled*
vitest.config.ts.timestamp*
# Deno
deno.lock
# Bun
bun.lockb
# yarn
.pnp.*

View File

@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
pnpm exec commitlint --edit $1
yarn commitlint --edit $1

View File

@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
pnpm run build:affected && pnpm exec lint-staged
yarn build:affected && yarn lint-staged

View File

@@ -1,6 +1,5 @@
{
"$schema": "https://json.schemastore.org/lintstagedrc.schema.json",
"*": "prettier --ignore-unknown --write",
"{src/**,__tests__/**}.{mjs,js,cjs,ts,tsx}": "eslint --fix",
"{src/**,__tests__/**}.{mjs,js,cjs,ts,tsx}": "eslint --ext .mjs,.js,.cjs,.ts,.tsx --fix",
"src/**.ts": "vitest related --run --config ../../vitest.config.ts"
}

6
.npmrc
View File

@@ -1,6 +0,0 @@
auto-install-peers=false
resolution-mode=highest
public-hoist-pattern[]=*eslint*
public-hoist-pattern[]=*prettier*
public-hoist-pattern[]=*@rushstack/node-core-library*
public-hoist-pattern[]=*jju*

View File

@@ -1,5 +1,2 @@
CODEOWNERS
CHANGELOG.md
tsup.config.bundled*
vitest.config.ts.timestamp*
pnpm-lock.yaml

View File

@@ -1,5 +1,4 @@
{
"$schema": "https://json.schemastore.org/prettierrc.json",
"printWidth": 120,
"useTabs": true,
"singleQuote": true,

28
.vscode/settings.json vendored
View File

@@ -1,34 +1,18 @@
{
"eslint.workingDirectories": [{ "pattern": "./apps/*" }, { "pattern": "./packages/*" }],
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
"eslint.experimental.useFlatConfig": true,
"eslint.workingDirectories": [
{ "directory": "${workspaceFolder}" },
{ "pattern": "./apps/*/" },
{ "pattern": "./packages/*/" }
],
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": false,
"source.fixAll.eslint": true,
"source.fixAll": true
"source.fixAll": true,
"source.organizeImports": false
},
"editor.trimAutoWhitespace": false,
"files.associations": {
"api-extractor.json": "jsonc",
"api-extractor-docs.json": "jsonc",
"tsconfig.json": "jsonc",
"tsconfig.eslint.json": "jsonc",
"tsconfig.docs.json": "jsonc"
"*.mdx": "markdown"
},
"files.insertFinalNewline": true,
"files.eol": "\n",
"npm.packageManager": "pnpm",
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true,
"deno.enable": false,
"deno.enablePaths": ["./packages/create-discord-bot/template/Deno"],
"deno.lint": false,
"deno.unstable": false,
"deno.config": "./packages/create-discord-bot/template/Deno/deno.jsonc"
"npm.packageManager": "yarn",
"typescript.tsdk": "node_modules/typescript/lib"
}

View File

@@ -1,5 +1,5 @@
diff --git a/lib/TSDocConfigFile.js b/lib/TSDocConfigFile.js
index caf3515d60fd386c5909db5a0aa8b4180b10d602..f8a7ff05d972e8dca4c5a485feb6ef37388274ac 100644
index caf3515d60fd386c5909db5a0aa8b4180b10d602..5f7cfed7611e3fe660b5265ff99c5da0beb7caec 100644
--- a/lib/TSDocConfigFile.js
+++ b/lib/TSDocConfigFile.js
@@ -31,8 +31,7 @@ const ajv_1 = __importDefault(require("ajv"));

View File

@@ -0,0 +1,18 @@
diff --git a/package.json b/package.json
index fc35658a40f9ba3e3513c459ba9f4f6e1b3f59f5..bc35eda66f270c95ba52e721cb6976fd61622c58 100644
--- a/package.json
+++ b/package.json
@@ -26,11 +26,13 @@
},
"exports": {
".": {
+ "types": "./dist/index.d.ts",
"node": "./dist/index.js",
"default": "./browser/index.js"
},
"./package.json": "./package.json",
"./util": {
+ "types": "./dist/util.d.ts",
"node": "./dist/util.js",
"default": "./browser/dist/util.js"
}

View File

@@ -0,0 +1,260 @@
/* eslint-disable */
module.exports = {
name: '@yarnpkg/plugin-docker-build',
factory: function (require) {
var plugin;
(() => {
'use strict';
var t = {
d: (e, o) => {
for (var r in o) t.o(o, r) && !t.o(e, r) && Object.defineProperty(e, r, { enumerable: !0, get: o[r] });
},
o: (t, e) => Object.prototype.hasOwnProperty.call(t, e),
r: (t) => {
'undefined' != typeof Symbol &&
Symbol.toStringTag &&
Object.defineProperty(t, Symbol.toStringTag, { value: 'Module' }),
Object.defineProperty(t, '__esModule', { value: !0 });
},
},
e = {};
t.r(e), t.d(e, { default: () => u });
const o = require('@yarnpkg/cli'),
r = require('clipanion'),
i = require('@yarnpkg/core'),
a = require('@yarnpkg/plugin-patch'),
n = require('@yarnpkg/fslib');
const s = require('@yarnpkg/plugin-pack');
async function c({ workspace: t, destination: e, report: o }) {
await s.packUtils.prepareForPack(t, { report: o }, async () => {
const r = await s.packUtils.genPackList(t),
a = i.Report.progressViaCounter(r.length),
c = o.reportProgress(a);
try {
for (const i of r) {
const r = n.ppath.join(t.cwd, i),
s = n.ppath.join(e, t.relativeCwd, i);
o.reportInfo(null, i), await n.xfs.copyPromise(s, r, { overwrite: !0 }), a.tick();
}
} finally {
c.stop();
}
});
}
function p(t, e) {
const o = (0, n.toFilename)(e);
return n.ppath.isAbsolute(o) ? n.ppath.relative(t, o) : o;
}
const l = /^builtin<([^>]+)>$/;
var d = function (t, e, o, r) {
var i,
a = arguments.length,
n = a < 3 ? e : null === r ? (r = Object.getOwnPropertyDescriptor(e, o)) : r;
if ('object' == typeof Reflect && 'function' == typeof Reflect.decorate) n = Reflect.decorate(t, e, o, r);
else
for (var s = t.length - 1; s >= 0; s--)
(i = t[s]) && (n = (a < 3 ? i(n) : a > 3 ? i(e, o, n) : i(e, o)) || n);
return a > 3 && n && Object.defineProperty(e, o, n), n;
};
class f extends o.BaseCommand {
constructor() {
super(...arguments), (this.args = []);
}
async execute() {
const t = await i.Configuration.find(this.context.cwd, this.context.plugins),
{ project: e } = await i.Project.find(t, this.context.cwd),
o = e.getWorkspaceByIdent(i.structUtils.parseIdent(this.workspaceName)),
r = (function ({
project: t,
workspaces: e,
production: o = !1,
scopes: r = o ? ['dependencies'] : i.Manifest.hardDependencies,
}) {
const a = new Set([...e]);
for (const e of a)
for (const o of r) {
const r = e.manifest.getForScope(o).values();
for (const e of r) {
const o = t.tryWorkspaceByDescriptor(e);
o && a.add(o);
}
}
for (const e of t.workspaces)
a.has(e)
? o && e.manifest.devDependencies.clear()
: (e.manifest.dependencies.clear(),
e.manifest.devDependencies.clear(),
e.manifest.peerDependencies.clear());
return a;
})({ project: e, workspaces: [o], production: this.production }),
s = await (async function (t, e = 'Dockerfile') {
const o = (0, n.toFilename)(e);
if (n.ppath.isAbsolute(o)) return o;
const r = [n.ppath.join(t.cwd, o), n.ppath.join(t.project.cwd, o)];
for (const t of r) if (await n.xfs.existsPromise(t)) return t;
throw new Error('Dockerfile is required');
})(o, this.dockerFilePath),
d = await i.Cache.find(t);
return (
await i.StreamReport.start(
{ configuration: t, stdout: this.context.stdout, includeLogs: !this.context.quiet },
async (t) => {
await t.startTimerPromise('Resolution Step', async () => {
await e.resolveEverything({ report: t, cache: d });
}),
await t.startTimerPromise('Fetch Step', async () => {
await e.fetchEverything({ report: t, cache: d });
}),
await n.xfs.mktempPromise(async (o) => {
const f = n.ppath.join(o, (0, n.toFilename)('manifests')),
u = n.ppath.join(o, (0, n.toFilename)('packs'));
await t.startTimerPromise('Copy files', async () => {
await (async function ({ destination: t, project: e, report: o }) {
const r = e.configuration.get('rcFilename');
o.reportInfo(null, r),
await n.xfs.copyPromise(n.ppath.join(t, r), n.ppath.join(e.cwd, r), { overwrite: !0 });
})({ destination: f, project: e, report: t }),
await (async function ({ destination: t, project: e, report: o }) {
const r = n.ppath.join((0, n.toFilename)('.yarn'), (0, n.toFilename)('plugins'));
o.reportInfo(null, r),
await n.xfs.copyPromise(n.ppath.join(t, r), n.ppath.join(e.cwd, r), { overwrite: !0 });
})({ destination: f, project: e, report: t }),
await (async function ({ destination: t, project: e, report: o }) {
const r = e.configuration.get('yarnPath'),
i = n.ppath.relative(e.cwd, r),
a = n.ppath.join(t, i);
o.reportInfo(null, i), await n.xfs.copyPromise(a, r, { overwrite: !0 });
})({ destination: f, project: e, report: t }),
await (async function ({ destination: t, workspaces: e, report: o }) {
for (const r of e) {
const e = n.ppath.join(r.relativeCwd, i.Manifest.fileName),
a = n.ppath.join(t, e),
s = {};
r.manifest.exportTo(s),
o.reportInfo(null, e),
await n.xfs.mkdirpPromise(n.ppath.dirname(a)),
await n.xfs.writeJsonPromise(a, s);
}
})({ destination: f, workspaces: e.workspaces, report: t }),
await (async function ({ destination: t, report: e, project: o, parseDescriptor: r }) {
const a = new Set();
for (const s of o.storedDescriptors.values()) {
const c = r(
i.structUtils.isVirtualDescriptor(s) ? i.structUtils.devirtualizeDescriptor(s) : s,
);
if (!c) continue;
const { parentLocator: p, paths: d } = c;
for (const r of d) {
if (l.test(r)) continue;
if (n.ppath.isAbsolute(r)) continue;
const i = o.getWorkspaceByLocator(p),
s = n.ppath.join(i.relativeCwd, r);
if (a.has(s)) continue;
a.add(s);
const c = n.ppath.join(i.cwd, r),
d = n.ppath.join(t, s);
e.reportInfo(null, s),
await n.xfs.mkdirpPromise(n.ppath.dirname(d)),
await n.xfs.copyFilePromise(c, d);
}
}
})({
destination: f,
report: t,
project: e,
parseDescriptor: (t) => {
if (t.range.startsWith('exec:')) {
const e = (function (t) {
const { params: e, selector: o } = i.structUtils.parseRange(t),
r = n.npath.toPortablePath(o);
return {
parentLocator:
e && 'string' == typeof e.locator ? i.structUtils.parseLocator(e.locator) : null,
path: r,
};
})(t.range);
if (!e || !e.parentLocator) return;
return { parentLocator: e.parentLocator, paths: [e.path] };
}
if (t.range.startsWith('patch:')) {
const { parentLocator: e, patchPaths: o } = a.patchUtils.parseDescriptor(t);
if (!e) return;
return { parentLocator: e, paths: o };
}
},
}),
await (async function ({ destination: t, project: e, cache: o, report: r }) {
for (const i of o.markedFiles) {
const o = n.ppath.relative(e.cwd, i);
(await n.xfs.existsPromise(i)) &&
(r.reportInfo(null, o), await n.xfs.copyPromise(n.ppath.join(t, o), i));
}
})({ destination: f, project: e, cache: d, report: t }),
await (async function ({ destination: t, project: e, report: o }) {
const r = (0, n.toFilename)(e.configuration.get('lockfileFilename')),
i = n.ppath.join(t, r);
o.reportInfo(null, r),
await n.xfs.mkdirpPromise(n.ppath.dirname(i)),
await n.xfs.writeFilePromise(i, e.generateLockfile());
})({ destination: f, project: e, report: t }),
this.copyFiles &&
this.copyFiles.length &&
(await (async function ({ destination: t, files: e, dockerFilePath: o, report: r }) {
const i = n.ppath.dirname(o);
for (const o of e) {
const e = p(i, o),
a = n.ppath.join(i, e),
s = n.ppath.join(t, e);
r.reportInfo(null, e), await n.xfs.copyPromise(s, a);
}
})({ destination: f, files: this.copyFiles, dockerFilePath: s, report: t }));
});
for (const e of r) {
const o = e.manifest.name ? i.structUtils.stringifyIdent(e.manifest.name) : '';
await t.startTimerPromise('Pack workspace ' + o, async () => {
await c({ workspace: e, report: t, destination: u });
});
}
const h = this.buildKit ? ['buildx', 'build'] : ['build'];
await i.execUtils.pipevp('docker', [...h, ...this.args, '-f', s, '.'], {
cwd: o,
strict: !0,
stdin: this.context.stdin,
stdout: this.context.stdout,
stderr: this.context.stderr,
});
});
},
)
).exitCode();
}
}
(f.usage = r.Command.Usage({
category: 'Docker-related commands',
description: 'Build a Docker image for a workspace',
details:
'\n This command will build a efficient Docker image which only contains necessary dependencies for the specified workspace.\n\n You have to create a Dockerfile in your workspace or your project. You can also specify the path to Dockerfile using the "-f, --file" option.\n\n Additional arguments can be passed to "docker build" directly, please check the Docker docs for more info: https://docs.docker.com/engine/reference/commandline/build/\n\n You can copy additional files or folders to a Docker image using the "--copy" option. This is useful for secret keys or configuration files. The files will be copied to "manifests" folder. The path can be either a path relative to the Dockerfile or an absolute path.\n ',
examples: [
['Build a Docker image for a workspace', 'yarn docker build @foo/bar'],
['Pass additional arguments to docker build command', 'yarn docker build @foo/bar -t image-tag'],
[
'Copy additional files to a Docker image',
'yarn docker build --copy secret.key --copy config.json @foo/bar',
],
['Install production dependencies only', 'yarn docker build --production @foo/bar'],
['Build a Docker image using BuildKit', 'yarn docker build --buildkit @foo/bar'],
],
})),
d([r.Command.String()], f.prototype, 'workspaceName', void 0),
d([r.Command.Proxy()], f.prototype, 'args', void 0),
d([r.Command.String('-f,--file')], f.prototype, 'dockerFilePath', void 0),
d([r.Command.Array('--copy')], f.prototype, 'copyFiles', void 0),
d([r.Command.Boolean('--production')], f.prototype, 'production', void 0),
d([r.Command.Boolean('--buildkit')], f.prototype, 'buildKit', void 0),
d([r.Command.Path('docker', 'build')], f.prototype, 'execute', null);
const u = { commands: [f] };
plugin = e;
})();
return plugin;
},
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

874
.yarn/releases/yarn-3.6.1.cjs vendored Executable file

File diff suppressed because one or more lines are too long

23
.yarnrc.yml Normal file
View File

@@ -0,0 +1,23 @@
logFilters:
- code: YN0002
level: discard
- code: YN0013
level: discard
- code: YN0032
level: discard
- code: YN0060
level: discard
nodeLinker: node-modules
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: '@yarnpkg/plugin-interactive-tools'
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: '@yarnpkg/plugin-workspace-tools'
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
spec: '@yarnpkg/plugin-version'
- path: .yarn/plugins/@yarnpkg/plugin-docker-build.cjs
spec: 'https://github.com/Dcard/yarn-plugins/releases/latest/download/plugin-docker-build.js'
yarnPath: .yarn/releases/yarn-3.6.1.cjs

View File

@@ -96,40 +96,34 @@
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noPropertyAccessFromIndexSignature": false,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strict": true,
"useUnknownInCatchVariables": true,
"noUncheckedIndexedAccess": true,
// Modules
"allowArbitraryExtensions": false,
"allowImportingTsExtensions": false,
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"resolvePackageJsonExports": false,
"resolvePackageJsonImports": false,
// Emit
"declaration": true,
"declarationMap": true,
"importHelpers": false,
"importHelpers": true,
"inlineSources": true,
"newLine": "lf",
"noEmitHelpers": true,
"outDir": "dist",
"removeComments": false,
"sourceMap": true,
// Interop Constraints
"esModuleInterop": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
// Language and Environment
"experimentalDecorators": true,
"lib": ["ESNext"],
"target": "ES2022",
"target": "ES2021",
"useDefineForClassFields": true
}
/**
@@ -222,7 +216,7 @@
/**
* (REQUIRED) Whether to generate the .d.ts rollup file.
*/
"enabled": false,
"enabled": true,
/**
* Specifies the output path for a .d.ts rollup file to be generated without any trimming.

View File

@@ -1 +0,0 @@
METADATA_BASE_URL=http://localhost:3000

1
apps/guide/.eslintignore Normal file
View File

@@ -0,0 +1 @@
next-env.d.ts

12
apps/guide/.eslintrc.json Normal file
View File

@@ -0,0 +1,12 @@
{
"extends": ["../../.eslintrc.json", "neon/react", "neon/next", "neon/edge", "@unocss", "neon/prettier"],
"settings": {
"react": {
"version": "detect"
}
},
"rules": {
"react/react-in-jsx-scope": 0,
"react/jsx-filename-extension": [1, { "extensions": [".tsx"] }]
}
}

View File

@@ -13,13 +13,12 @@ module.exports = withBundleAnalyzer(
withContentlayer({
reactStrictMode: true,
experimental: {
typedRoutes: true,
appDir: true,
},
images: {
dangerouslyAllowSVG: true,
contentDispositionType: 'attachment',
contentSecurityPolicy: "default-src 'self'; frame-src 'none'; sandbox;",
},
poweredByHeader: false,
}),
);

View File

@@ -1,26 +1,26 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@discordjs/guide",
"version": "0.1.0",
"description": "Imagine a guide... that explores the many possibilities for your discord.js bot",
"private": true,
"scripts": {
"test": "vitest run",
"build:check": "tsc --noEmit",
"build:local": "pnpm run build:prod",
"build:prod": "next build",
"build:analyze": "cross-env ANALYZE=true pnpm run build:prod",
"test:lighthouse": "lighthouse http://localhost:3000 --output-path=./lighthouse-results",
"build:local": "yarn build:prod",
"build:prod": "yarn build:css && yarn build:next",
"build:next": "next build",
"build:css": "yarn generate:css",
"build:analyze": "cross-env ANALYZE=true yarn build:prod",
"preview": "next start",
"dev": "next dev",
"generate:contentlayer": "contentlayer build",
"lint": "pnpm run build:check && prettier --check . && cross-env TIMING=1 eslint --format=pretty src",
"format": "pnpm run build:check && prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src",
"fmt": "pnpm run format"
"dev": "concurrently 'yarn dev:css' 'yarn dev:next'",
"dev:next": "next dev",
"dev:css": "yarn generate:css --watch",
"generate:css": "unocss 'src/**/*.tsx' 'contentlayer.config.ts' '../../packages/ui/src/lib/components/**/*.tsx' --out-file ./src/styles/unocss.css --config ../../unocss.config.ts",
"lint": "prettier --check . && cross-env TIMING=1 eslint src --ext .mjs,.js,.cjs,.ts,.tsx --format=pretty",
"format": "prettier --write . && cross-env TIMING=1 eslint src --ext .mjs,.js,.cjs,.ts,.tsx --fix --format=pretty",
"fmt": "yarn format"
},
"type": "commonjs",
"directories": {
"lib": "src"
},
"contributors": [
"Crawl <icrawltogo@gmail.com>"
],
@@ -47,14 +47,14 @@
"@code-hike/mdx": "^0.9.0",
"@discordjs/ui": "workspace:^",
"@react-icons/all-files": "^4.1.0",
"@vercel/analytics": "^1.1.1",
"@vercel/edge-config": "^0.4.1",
"@vercel/og": "^0.5.20",
"ariakit": "2.0.0-next.44",
"@vercel/analytics": "^1.0.2",
"@vercel/edge-config": "^0.2.1",
"@vercel/og": "^0.5.11",
"ariakit": "^2.0.0-next.44",
"cmdk": "^0.2.0",
"contentlayer": "^0.3.4",
"next": "14.0.3-canary.2",
"next-contentlayer": "^0.3.4",
"contentlayer": "0.3.1",
"next": "^13.4.17",
"next-contentlayer": "0.3.1",
"next-themes": "^0.2.1",
"react": "^18.2.0",
"react-custom-scrollbars-2": "^4.5.0",
@@ -62,38 +62,39 @@
"rehype-autolink-headings": "^6.1.1",
"rehype-slug": "^5.1.0",
"remark-gfm": "^3.0.1",
"sharp": "^0.32.6"
"sharp": "^0.32.5"
},
"devDependencies": {
"@next/bundle-analyzer": "14.0.3-canary.2",
"@testing-library/react": "^14.1.0",
"@testing-library/user-event": "^14.5.1",
"@types/html-escaper": "^3.0.2",
"@types/node": "18.18.8",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@unocss/eslint-plugin": "^0.57.3",
"@unocss/postcss": "^0.57.3",
"@unocss/reset": "^0.57.3",
"@vitejs/plugin-react": "^4.1.1",
"@vitest/coverage-v8": "^0.34.6",
"@next/bundle-analyzer": "^13.4.17",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/html-escaper": "^3.0.0",
"@types/node": "18.17.5",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"@unocss/cli": "^0.55.1",
"@unocss/eslint-config": "^0.55.1",
"@unocss/reset": "^0.55.1",
"@vitejs/plugin-react": "^4.0.4",
"@vitest/coverage-v8": "^0.34.2",
"concurrently": "^8.2.0",
"cross-env": "^7.0.3",
"eslint": "^8.53.0",
"eslint-config-neon": "^0.1.57",
"eslint": "^8.47.0",
"eslint-config-neon": "^0.1.47",
"eslint-formatter-pretty": "^5.0.0",
"happy-dom": "^12.10.3",
"happy-dom": "^10.10.2",
"hast-util-to-string": "^2.0.0",
"hastscript": "^8.0.0",
"hastscript": "^7.2.0",
"html-escaper": "^3.0.3",
"postcss": "^8.4.31",
"prettier": "^3.0.3",
"turbo": "^1.10.17-canary.0",
"typescript": "^5.2.2",
"unocss": "^0.57.3",
"vercel": "^32.5.3",
"vitest": "^0.34.6"
"lighthouse": "^10.4.0",
"prettier": "^2.8.8",
"turbo": "^1.10.12",
"typescript": "^5.1.6",
"unocss": "^0.55.1",
"vercel": "^31.4.0",
"vitest": "^0.34.2"
},
"engines": {
"node": ">=18"
"node": ">=18.13.0"
}
}

View File

@@ -1,5 +0,0 @@
module.exports = {
plugins: {
'@unocss/postcss': {},
},
};

View File

@@ -1,10 +1,7 @@
'use client';
import { inter } from '~/util/fonts';
import { Providers } from './providers';
import '~/styles/cmdk.css';
import '~/styles/main.css';
import { inter } from '~/util/fonts';
export default function GlobalError({ error }: { readonly error: Error }) {
console.error(error);

View File

@@ -1,5 +1,5 @@
import { notFound } from 'next/navigation';
import { allContents } from 'contentlayer/generated';
import { notFound } from 'next/navigation';
import { Mdx } from '~/components/Mdx';
export async function generateStaticParams() {

View File

@@ -1,8 +1,8 @@
import type { PropsWithChildren } from 'react';
import { Providers } from './providers';
import Footer from '~/components/Footer';
import Header from '~/components/Header';
import { Nav } from '~/components/Nav';
import { Providers } from './providers';
export default function Layout({ children }: PropsWithChildren) {
return (

View File

@@ -1,29 +1,25 @@
import { Analytics } from '@vercel/analytics/react';
import type { Metadata, Viewport } from 'next';
import type { Metadata } from 'next';
import type { PropsWithChildren } from 'react';
import { Providers } from './providers';
import { DESCRIPTION } from '~/util/constants';
import { inter, jetBrainsMono } from '~/util/fonts';
import { Providers } from './providers';
import '@unocss/reset/tailwind-compat.css';
import '~/styles/unocss.css';
import '~/styles/cmdk.css';
import '@code-hike/mdx/styles.css';
import '~/styles/ch.css';
import '~/styles/main.css';
export const viewport: Viewport = {
themeColor: [
{ media: '(prefers-color-scheme: light)', color: '#f1f3f5' },
{ media: '(prefers-color-scheme: dark)', color: '#181818' },
],
colorScheme: 'light dark',
};
export const metadata: Metadata = {
metadataBase: new URL(
process.env.METADATA_BASE_URL ? process.env.METADATA_BASE_URL : `http://localhost:${process.env.PORT ?? 3_000}`,
),
title: 'discord.js',
description: DESCRIPTION,
viewport: {
minimumScale: 1,
initialScale: 1,
width: 'device-width',
},
icons: {
other: [
{
@@ -48,6 +44,12 @@ export const metadata: Metadata = {
manifest: '/site.webmanifest',
themeColor: [
{ media: '(prefers-color-scheme: light)', color: '#f1f3f5' },
{ media: '(prefers-color-scheme: dark)', color: '#181818' },
],
colorScheme: 'light dark',
appleWebApp: {
title: 'discord.js',
},

View File

@@ -3,7 +3,6 @@
import { VscGithubInverted } from '@react-icons/all-files/vsc/VscGithubInverted';
import { VscMenu } from '@react-icons/all-files/vsc/VscMenu';
import { Button } from 'ariakit/button';
import type { Route } from 'next';
import dynamic from 'next/dynamic';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
@@ -24,7 +23,7 @@ export default function Header() {
.map((path, idx, original) => (
<Link
className="rounded outline-none hover:underline focus:ring focus:ring-width-2 focus:ring-blurple"
href={`/${original.slice(0, idx + 1).join('/')}` as Route}
href={`/${original.slice(0, idx + 1).join('/')}`}
key={`${path}-${idx}`}
>
{path}

View File

@@ -2,13 +2,13 @@
import { Alert, Section, DiscordMessages, DiscordMessage, DiscordMessageEmbed } from '@discordjs/ui';
import { useMDXComponent } from 'next-contentlayer/hooks';
import { DocsLink } from '~/components/DocsLink';
import { ResultingCode } from '~/components/ResultingCode';
import { DiscordAPITypesLink } from './DiscordAPITypesLink';
import { H1 } from './H1';
import { H2 } from './H2';
import { H3 } from './H3';
import { H4 } from './H4';
import { DocsLink } from '~/components/DocsLink';
import { ResultingCode } from '~/components/ResultingCode';
export function Mdx({ code }: { readonly code: string }) {
const Component = useMDXComponent(code);

View File

@@ -1,8 +1,8 @@
'use client';
import { Scrollbars } from 'react-custom-scrollbars-2';
import { useNav } from '~/contexts/nav';
import { Sidebar } from './Sidebar';
import { useNav } from '~/contexts/nav';
export function Nav() {
const { opened } = useNav();

View File

@@ -1,11 +1,10 @@
'use client';
import type { Route } from 'next';
import { allContents } from 'contentlayer/generated';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { allContents } from 'contentlayer/generated';
import { useNav } from '~/contexts/nav';
import { Section } from './Section';
import { useNav } from '~/contexts/nav';
const items = allContents.map((content) => ({
title: content.title,
@@ -46,7 +45,7 @@ export function Sidebar() {
? 'bg-blurple text-white'
: 'dark:hover:bg-dark-200 dark:active:bg-dark-100 hover:bg-light-700 active:bg-light-800'
}`}
href={member.href as Route}
href={member.href}
key={`${member.title}-${index}`}
onClick={() => setOpened(false)}
title={member.title}

View File

@@ -9,7 +9,7 @@ If you're reading this, it probably means you want to learn how to make a bot wi
This guide will teach you things such as:
- How to get a bot [up and running](/preparations/) from scratch;
- How to properly [create](/creating-your-bot/), [organize](/creating-your-bot/handling-command-interactions.md), and expand on your commands;
- How to properly [create](/creating-your-bot/), [organize](/creating-your-bot/command-handling.md), and expand on your commands;
- In-depth explanations and examples regarding popular topics (e.g. [reactions](/popular-topics/reactions.md), [embeds](/popular-topics/embeds.md), [canvas](/popular-topics/canvas.md));
- Working with databases (e.g. [sequelize](/sequelize/) and [keyv](/keyv/));
- Getting started with [sharding](/sharding/);

View File

@@ -48,7 +48,7 @@ All content has been updated to use discord.js v14 syntax. The v13 version of th
- Commando: Replaced with [Sapphire](https://sapphirejs.dev/docs/Guide/getting-started/getting-started-with-sapphire)
- [Voice](/voice/): Rewritten to use the [_`@discordjs/voice`_](https://github.com/discordjs/discord.js/tree/main/packages/voice) package
- [Command handling](/creating-your-bot/handling-command-interactions.md/): Updated to use slash commands
- [Command handling](/creating-your-bot/command-handling.md/): Updated to use slash commands
- Obsolete sections removed
- _`client.on('message')`_ snippets updated to _`client.on(Events.InteractionCreate)`_
- [Message content became a privileged intent on August 31, 2022](https://support-dev.discord.com/hc/articles/4404772028055)

View File

@@ -67,10 +67,6 @@ yarn init
pnpm init; pnpm pkg set type="module"
```
```sh bun
bun init
```
</CH.Code>
This is the next command you'll be running. This command creates a _`package.json`_ file for you, which will keep track of the dependencies your project uses, as well as other info.
@@ -97,10 +93,6 @@ yarn add discord.js
pnpm add discord.js
```
```sh bun
bun add discord.js
```
</CH.Code>
And that's it! With all the necessities installed, you're almost ready to start coding your bot.

View File

@@ -7,7 +7,7 @@ category: Creating your bot
Once you [add your bot to a server](../installations-and-preparations/adding-your-bot-to-servers), the next step is to start coding and get it online! Let's start by creating a config file to prepare the necessary values your client will need.
As explained in the ["What is a token, anyway?"](../installations-and-preparations/setting-up-a-bot-application#what-is-a-token-anyway) section, your token is essentially your bot's password, and you should protect it as best as possible. This can be done through a _`config.json`_ file or by using environment variables.
As explained in the ["What is a token, anyway?"](../installations-and-preparations/setting-up-a-bot-application.md#what-is-a-token-anyway) section, your token is essentially your bot's password, and you should protect it as best as possible. This can be done through a _`config.json`_ file or by using environment variables.
Open your application in the [Discord Developer Portal](https://discord.com/developers/applications) and go to the "Bot" page to copy your token.
@@ -77,10 +77,6 @@ yarn add dotenv
pnpm add dotenv
```
```sh bun
# Bun automatically reads .env files
```
</CH.Code>
<CH.Code lineNumbers={false} rows={7}>

View File

@@ -22,8 +22,8 @@ Slash commands provide a huge number of benefits over manual message parsing, in
For fully functional slash commands, there are three important pieces of code that need to be written. They are:
1. The individual command files, containing their definitions and functionality.
2. The [command handler](handling-command-interactions.html), which dynamically reads the files and executes the commands.
3. The [command deployment script](registering-slash-commands.html), to register your slash commands with Discord so they appear in the interface.
2. The [command handler](command-handling.html), which dynamically reads the files and executes the commands.
3. The [command deployment script](command-deployment.html), to register your slash commands with Discord so they appear in the interface.
These steps can be done in any order, but **all are required** before the commands are fully functional.

View File

@@ -12,7 +12,7 @@ Unless your bot project is small, it's not a very good idea to have a single fil
1. The [individual command files](slash-commands), containing their definitions and functionality.
2. The command handler, which dynamically reads the files and executes the commands.
3. The [command deployment script](registering-slash-commands), to register your slash commands with Discord so they appear in the interface.
3. The [command deployment script](command-deployment), to register your slash commands with Discord so they appear in the interface.
These steps can be done in any order, but **all are required** before the commands are fully functional.

View File

@@ -9,7 +9,7 @@ category: Creating your bot
For fully functional slash commands, you need three important pieces of code:
1. The [individual command files](slash-commands), containing their definitions and functionality.
2. The [command handler](handling-command-interactions), which dynamically reads the files and executes the commands.
2. The [command handler](command-handling), which dynamically reads the files and executes the commands.
3. The command deployment script, to register your slash commands with Discord so they appear in the interface.
These steps can be done in any order, but **all are required** before the commands are fully functional.
@@ -152,4 +152,4 @@ You've successfully sent a response to a slash command! However, this is only th
#### Resulting code
<ResultingCode path="creating-your-bot/registering-slash-commands" />
<ResultingCode path="creating-your-bot/command-deployment" />

View File

@@ -27,10 +27,6 @@ yarn remove @discordjs/builders @discordjs/formatters @discordjs/rest discord-ap
pnpm remove @discordjs/builders @discordjs/formatters @discordjs/rest discord-api-types
```
```sh bun
bun remove @discordjs/builders @discordjs/formatters @discordjs/rest discord-api-types
```
</CH.Code>
## Breaking Changes

View File

@@ -1,6 +1,3 @@
@import '@unocss/reset/tailwind-compat.css';
@unocss all;
body {
font-family: var(--font-inter);
min-height: 100vh;

View File

@@ -15,9 +15,9 @@ export const PACKAGES = [
'collection',
'core',
'formatters',
'next',
'proxy',
'rest',
'next',
'util',
'voice',
'ws',
@@ -26,7 +26,7 @@ export const PACKAGES = [
/**
* The stable version of discord.js.
*/
export const VERSION = '14.13.0' as const;
export const VERSION = '14.11.0' as const;
/**
* The API version (for discord-api-types). This is prefixed with a "v".

View File

@@ -0,0 +1,4 @@
export const fetcher = async (url: string) => {
const res = await fetch(url);
return res.json();
};

View File

@@ -1,26 +1,21 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"allowJs": true
},
"include": [
"*.ts",
"*.tsx",
"*.js",
".jsx",
"*.cjs",
"*.mjs",
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.js",
"src/**/*.jsx",
"src/**/*.cjs",
"src/**/*.mjs",
"bin",
"scripts",
"__tests__",
"__mocks__"
"**/*.ts",
"**/*.tsx",
"**/*.js",
"**/*.cjs",
"**/*.mjs",
"**/*.jsx",
"**/*.test.ts",
"**/*.test.js",
"**/*.test.mjs",
"**/*.spec.ts",
"**/*.spec.js",
"**/*.spec.mjs"
],
"exclude": ["node_modules"]
"exclude": []
}

View File

@@ -1,16 +1,15 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"lib": ["ESNext", "DOM", "DOM.Iterable"],
"isolatedModules": true,
"jsx": "preserve",
"baseUrl": ".",
"outDir": "dist",
"noEmit": true,
"esModuleInterop": true,
"allowJs": true,
"allowJs": false,
"incremental": true,
"skipLibCheck": true,
"sourceMap": true,
"plugins": [
{
"name": "next"
@@ -19,17 +18,10 @@
"paths": {
"~/*": ["./src/*"],
"contentlayer/generated": ["./.contentlayer/generated"]
}
},
"strictNullChecks": true,
"moduleResolution": "node"
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.js",
"src/**/*.jsx",
"src/**/*.cjs",
"src/**/*.mjs",
"next-env.d.ts",
".next/types/**/*.ts"
],
"include": ["src/**/*.ts", "src/**/*.tsx", "next-env.d.ts", ".next/types/**/*.ts", ".contentlayer/generated"],
"exclude": ["node_modules"]
}

View File

@@ -1,2 +1 @@
NEXT_PUBLIC_LOCAL_DEV=true
METADATA_BASE_URL=http://localhost:3000

View File

@@ -0,0 +1 @@
next-env.d.ts

View File

@@ -0,0 +1,12 @@
{
"extends": ["../../.eslintrc.json", "neon/react", "neon/next", "neon/edge", "@unocss", "neon/prettier"],
"settings": {
"react": {
"version": "detect"
}
},
"rules": {
"react/react-in-jsx-scope": 0,
"react/jsx-filename-extension": [1, { "extensions": [".tsx"] }]
}
}

View File

@@ -27,4 +27,3 @@ src/styles/unocss.css
.vscode
lighthouse-results
.vercel

View File

@@ -1 +0,0 @@
export * from '../../.lintstagedrc.json' assert { type: 'json' };

View File

@@ -1 +0,0 @@
export * from '../../.prettierrc.json' assert { type: 'json' };

View File

@@ -7,18 +7,14 @@ const withBundleAnalyzer = bundleAnalyzer({
export default withBundleAnalyzer({
reactStrictMode: true,
experimental: {
typedRoutes: true,
serverComponentsExternalPackages: ['@rushstack/node-core-library', '@discordjs/api-extractor-model', 'jju'],
appDir: true,
serverComponentsExternalPackages: ['@microsoft/api-extractor-model', 'jju'],
},
images: {
dangerouslyAllowSVG: true,
contentDispositionType: 'attachment',
contentSecurityPolicy: "default-src 'self'; frame-src 'none'; sandbox;",
},
poweredByHeader: false,
env: {
MAX_FETCH_SIZE: '5',
},
async redirects() {
return [
{

View File

@@ -1,28 +1,28 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@discordjs/website",
"version": "0.1.0",
"description": "Imagine a bot... the most popular way to build discord bots",
"private": true,
"scripts": {
"test": "vitest run",
"build:copy_readme": "cpy '../../packages/(discord.js|brokers|builders|collection|core|formatters|next|proxy|rest|util|voice|ws)/README.md' 'src/assets/readme' --rename='home-{{basename}}'",
"build:check": "tsc --noEmit",
"build:local": "cross-env NEXT_PUBLIC_LOCAL_DEV=true pnpm run build:prod",
"build:prod": "pnpm run build:copy_readme && pnpm run build:next",
"test:lighthouse": "lighthouse http://localhost:3000 --output-path=./lighthouse-results",
"build:copy_readme": "cpy '../../packages/*/README.md' 'src/assets/readme' --rename='home-{{basename}}'",
"build:local": "cross-env NEXT_PUBLIC_LOCAL_DEV=true yarn build:prod",
"build:prod": "yarn build:copy_readme && yarn build:css && yarn build:next",
"build:next": "next build",
"build:search_indices": "pnpm node scripts/generateAllIndices.js",
"build:analyze": "turbo run docs --filter='@discordjs/*' --concurrency=4 && cross-env ANALYZE=true NEXT_PUBLIC_LOCAL_DEV=true pnpm run build:prod",
"build:css": "yarn generate:css",
"build:search_indices": "yarn node scripts/generateAllIndices.js",
"build:analyze": "turbo run docs && cross-env ANALYZE=true NEXT_PUBLIC_LOCAL_DEV=true yarn build:prod",
"preview": "next start",
"dev": "next dev",
"lint": "pnpm run build:check && prettier --check . && cross-env TIMING=1 eslint --format=pretty src",
"format": "pnpm run build:check && prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src",
"fmt": "pnpm run format"
"dev": "concurrently 'yarn dev:css' 'yarn dev:next'",
"dev:next": "next dev",
"dev:css": "yarn generate:css --watch",
"generate:css": "unocss 'src/**/*.tsx' '../../packages/ui/src/lib/components/**/*.tsx' --out-file ./src/styles/unocss.css --config ../../unocss.config.ts",
"lint": "prettier --check . && cross-env TIMING=1 eslint src --ext .mjs,.js,.cjs,.ts,.tsx --format=pretty",
"format": "prettier --write . && cross-env TIMING=1 eslint src --ext .mjs,.js,.cjs,.ts,.tsx --fix --format=pretty",
"fmt": "yarn format"
},
"type": "module",
"directories": {
"lib": "src"
},
"contributors": [
"Crawl <icrawltogo@gmail.com>"
],
@@ -46,59 +46,61 @@
},
"homepage": "https://discord.js.org",
"dependencies": {
"@discordjs/api-extractor-model": "workspace:^",
"@discordjs/api-extractor-utils": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@discordjs/ui": "workspace:^",
"@microsoft/tsdoc": "^0.14.2",
"@microsoft/tsdoc-config": "0.16.2",
"@planetscale/database": "^1.11.0",
"@microsoft/api-extractor-model": "7.27.6",
"@microsoft/tsdoc": "0.14.2",
"@planetscale/database": "1.7.0",
"@react-icons/all-files": "^4.1.0",
"@vercel/analytics": "^1.1.1",
"@vercel/edge-config": "^0.4.1",
"@vercel/og": "^0.5.20",
"ariakit": "2.0.0-next.44",
"@vercel/analytics": "^1.0.2",
"@vercel/edge-config": "^0.2.1",
"@vercel/og": "^0.5.11",
"ariakit": "^2.0.0-next.44",
"bright": "^0.8.4",
"class-variance-authority": "^0.7.0",
"cmdk": "^0.2.0",
"meilisearch": "^0.35.0",
"next": "14.0.3-canary.2",
"meilisearch": "^0.34.1",
"next": "^13.4.17",
"next-mdx-remote": "^4.4.1",
"next-themes": "^0.2.1",
"react": "^18.2.0",
"react-custom-scrollbars-2": "^4.5.0",
"react-dom": "^18.2.0",
"react-use": "^17.4.0",
"rehype-raw": "^6.1.1",
"rehype-slug": "^5.1.0",
"remark-gfm": "^3.0.1",
"sharp": "^0.32.6"
"sharp": "^0.32.5",
"swr": "^2.2.1"
},
"devDependencies": {
"@next/bundle-analyzer": "14.0.3-canary.2",
"@testing-library/react": "^14.1.0",
"@testing-library/user-event": "^14.5.1",
"@types/node": "18.18.8",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@unocss/eslint-plugin": "^0.57.3",
"@unocss/postcss": "^0.57.3",
"@unocss/reset": "^0.57.3",
"@vitejs/plugin-react": "^4.1.1",
"@vitest/coverage-v8": "^0.34.6",
"@next/bundle-analyzer": "^13.4.17",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/node": "18.17.5",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"@unocss/cli": "^0.55.1",
"@unocss/eslint-config": "^0.55.1",
"@unocss/reset": "^0.55.1",
"@vitejs/plugin-react": "^4.0.4",
"@vitest/coverage-v8": "^0.34.2",
"concurrently": "^8.2.0",
"cpy-cli": "^5.0.0",
"cross-env": "^7.0.3",
"eslint": "^8.53.0",
"eslint-config-neon": "^0.1.57",
"eslint": "^8.47.0",
"eslint-config-neon": "^0.1.47",
"eslint-formatter-pretty": "^5.0.0",
"happy-dom": "^12.10.3",
"postcss": "^8.4.31",
"prettier": "^3.0.3",
"turbo": "^1.10.17-canary.0",
"typescript": "^5.2.2",
"vercel": "^32.5.3",
"vitest": "^0.34.6"
"happy-dom": "^10.10.2",
"lighthouse": "^10.4.0",
"prettier": "^2.8.8",
"turbo": "^1.10.12",
"typescript": "^5.1.6",
"vercel": "^31.4.0",
"vitest": "^0.34.2"
},
"engines": {
"node": ">=18"
"node": ">=18.13.0"
}
}

View File

@@ -1,5 +0,0 @@
module.exports = {
plugins: {
'@unocss/postcss': {},
},
};

View File

@@ -1,15 +1,5 @@
import { readFile } from 'node:fs/promises';
import { generateAllIndices } from '@discordjs/scripts';
console.log('Generating all indices...');
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'));
},
});
await generateAllIndices();
console.log('Generated all indices.');

View File

@@ -1,12 +1,78 @@
'use client';
import { Analytics } from '@vercel/analytics/react';
import { inter } from '~/util/fonts';
import type { Metadata } from 'next';
import { Providers } from './providers';
import { DESCRIPTION } from '~/util/constants';
import { inter } from '~/util/fonts';
import '@unocss/reset/tailwind-compat.css';
import '~/styles/unocss.css';
import '~/styles/cmdk.css';
import '~/styles/main.css';
export const metadata: Metadata = {
title: 'discord.js',
description: DESCRIPTION,
viewport: {
minimumScale: 1,
initialScale: 1,
width: 'device-width',
},
icons: {
other: [
{
url: '/favicon-32x32.png',
sizes: '32x32',
type: 'image/png',
},
{
url: '/favicon-16x16.png',
sizes: '16x16',
type: 'image/png',
},
],
apple: [
'/apple-touch-icon.png',
{
url: '/safari-pinned-tab.svg',
rel: 'mask-icon',
},
],
},
manifest: '/site.webmanifest',
themeColor: [
{ media: '(prefers-color-scheme: light)', color: '#f1f3f5' },
{ media: '(prefers-color-scheme: dark)', color: '#1c1c1e' },
],
colorScheme: 'light dark',
appleWebApp: {
title: 'discord.js',
},
applicationName: 'discord.js',
openGraph: {
siteName: 'discord.js',
type: 'website',
title: 'discord.js',
description: DESCRIPTION,
images: 'https://discordjs.dev/api/open-graph.png',
},
twitter: {
card: 'summary_large_image',
creator: '@iCrawlToGo',
},
other: {
'msapplication-TileColor': '#1c1c1e',
},
};
export default function GlobalError({ error }: { readonly error: Error }) {
console.error(error);

View File

@@ -1,6 +1,6 @@
/* eslint-disable react/no-unknown-property */
import type { ApiItemKind } from '@discordjs/api-extractor-model';
import type { ApiItemKind } from '@microsoft/api-extractor-model';
import { ImageResponse } from '@vercel/og';
import type { NextRequest } from 'next/server';

View File

@@ -1,71 +1,43 @@
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({
url: process.env.DATABASE_URL!,
async fetch(url, init) {
delete init?.cache;
return fetch(url, { ...init, next: { revalidate: 3_600 } });
async fetch(input, init) {
// @ts-expect-error: Deleting cache or setting as undefined, same thing
return fetch(input, { ...init, cache: undefined, next: { revalidate: 3_600 } });
},
url: process.env.DATABASE_URL!,
});
export const fetchVersions = cache(async (packageName: string): Promise<string[]> => {
if (process.env.NEXT_PUBLIC_LOCAL_DEV || process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview') {
return ['main'];
}
export async function fetchVersions(packageName: string): Promise<string[]> {
const response = await fetch(`https://docs.discordjs.dev/api/info?package=${packageName}`, {
next: { revalidate: 3_600 },
});
try {
const { rows } = await sql.execute('select version from documentation where name = ? order by version desc', [
packageName,
]);
return response.json();
}
// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
return rows.map((row) => row.version).slice(0, N_RECENT_VERSIONS);
} catch {
return [];
}
});
export const fetchModelJSON = cache(async (packageName: string, version: string) => {
export async function fetchModelJSON(packageName: string, version: string): Promise<unknown> {
if (process.env.NEXT_PUBLIC_LOCAL_DEV) {
try {
const res = await readFile(
join(process.cwd(), '..', '..', 'packages', packageName, 'docs', 'docs.api.json'),
'utf8',
);
const res = await readFile(
join(process.cwd(), '..', '..', 'packages', packageName, 'docs', 'docs.api.json'),
'utf8',
);
try {
return JSON.parse(res);
} catch {
return null;
console.log(res);
return {};
}
}
if (process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview') {
try {
const { rows } = await sql.execute('select data from documentation where name = ? and version = ?', [
packageName,
'main',
]);
const { rows } = await sql.execute('select data from documentation where name = ? and version = ?', [
packageName,
version,
]);
// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
return rows[0]?.data ?? null;
} catch {
return null;
}
}
try {
const { rows } = await sql.execute('select data from documentation where name = ? and version = ?', [
packageName,
version,
]);
// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
return rows[0]?.data ?? null;
} catch {
return null;
}
});
// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
return rows[0].data;
}

View File

@@ -1,6 +1,5 @@
'use client';
import type { Route } from 'next';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
@@ -14,7 +13,7 @@ export default function NotFound() {
<h2 className="text-[2rem] md:text-[3rem]">Not found.</h2>
<Link
className="h-11 flex flex-row transform-gpu cursor-pointer select-none appearance-none place-items-center border-0 rounded bg-blurple px-6 text-base font-semibold leading-none text-white no-underline outline-none active:translate-y-px focus:ring focus:ring-width-2 focus:ring-white"
href={href as Route}
href={href}
>
Take me back
</Link>

View File

@@ -1,3 +1,4 @@
import { addPackageToModel, tryResolveSummaryText } from '@discordjs/scripts';
import type {
ApiClass,
ApiDeclaredItem,
@@ -12,9 +13,8 @@ import type {
ApiTypeAlias,
ApiVariable,
ApiFunction,
} from '@discordjs/api-extractor-model';
import { ApiItemKind, ApiModel } from '@discordjs/api-extractor-model';
import { tryResolveSummaryText } from '@discordjs/scripts';
} from '@microsoft/api-extractor-model';
import { ApiItemKind, ApiModel } from '@microsoft/api-extractor-model';
import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { fetchModelJSON } from '~/app/docAPI';
@@ -24,30 +24,16 @@ import { TypeAlias } from '~/components/model/TypeAlias';
import { Variable } from '~/components/model/Variable';
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 const revalidate = 3_600;
export interface ItemRouteParams {
item: string;
package: string;
version: string;
}
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;
}
@@ -101,11 +87,7 @@ export async function generateMetadata({ params }: { params: ItemRouteParams })
const searchParams = resolveMemberSearchParams(params.package, member);
url.search = searchParams.toString();
const ogImage = url.toString();
let description;
if (member) {
description = tryResolveSummaryText(member as ApiDeclaredItem);
}
const description = tryResolveSummaryText(member as ApiDeclaredItem);
return {
title: name,
@@ -120,23 +102,16 @@ export async function generateMetadata({ params }: { params: ItemRouteParams })
export async function generateStaticParams({ params: { package: packageName, version } }: { params: ItemRouteParams }) {
const modelJSON = await fetchModelJSON(packageName, version);
if (!modelJSON) {
return [{ package: packageName, version, item: '' }];
}
const model = addPackageToModel(new ApiModel(), modelJSON);
const pkg = model.tryGetPackageByName(packageName);
const entry = pkg?.entryPoints[0];
if (!entry) {
return [{ package: packageName, version, item: '' }];
notFound();
}
return entry.members.map((member: ApiItem) => ({
package: packageName,
version,
item: `${member.displayName}${OVERLOAD_SEPARATOR}${member.kind}`,
}));
}
@@ -161,7 +136,7 @@ function Member({ member }: { readonly member?: ApiItem }) {
}
export default async function Page({ params }: { params: ItemRouteParams }) {
const member = await fetchMember(params.package, params.version ?? 'main', params.item);
const member = await fetchMember(params);
if (!member) {
notFound();

View File

@@ -1,57 +1,51 @@
import type { ApiFunction, ApiItem } from '@discordjs/api-extractor-model';
import { ApiModel } from '@discordjs/api-extractor-model';
import { addPackageToModel } from '@discordjs/scripts';
import type { ApiFunction, ApiItem } from '@microsoft/api-extractor-model';
import { ApiModel } from '@microsoft/api-extractor-model';
import dynamic from 'next/dynamic';
import { notFound } from 'next/navigation';
import { cache, type PropsWithChildren } from 'react';
import type { PropsWithChildren } from 'react';
import { Providers } from './providers';
import { fetchModelJSON, fetchVersions } from '~/app/docAPI';
import { Banner } from '~/components/Banner';
import { CmdKDialog } from '~/components/CmdK';
import { Nav } from '~/components/Nav';
import type { SidebarSectionItemData } from '~/components/Sidebar';
import { resolveItemURI } from '~/components/documentation/util';
import { addPackageToModel } from '~/util/addPackageToModel';
import { PACKAGES } from '~/util/constants';
import { Providers } from './providers';
export const revalidate = 3_600;
import { N_RECENT_VERSIONS, PACKAGES } from '~/util/constants';
const Header = dynamic(async () => import('~/components/Header'));
const Footer = dynamic(async () => import('~/components/Footer'));
interface VersionRouteParams {
export interface VersionRouteParams {
package: string;
version: string;
}
export const generateStaticParams = async () => {
export async function generateStaticParams() {
const params: VersionRouteParams[] = [];
await Promise.all(
PACKAGES.slice(1).map(async (packageName) => {
const versions = await fetchVersions(packageName);
PACKAGES.map(async (packageName) => {
const versions = (await fetchVersions(packageName)).slice(-N_RECENT_VERSIONS);
params.push(...versions.map((version) => ({ package: packageName, version })));
}),
);
return params;
};
}
const serializeIntoSidebarItemData = cache((item: ApiItem) => {
function serializeIntoSidebarItemData(item: ApiItem): SidebarSectionItemData {
return {
kind: item.kind,
name: item.displayName,
href: resolveItemURI(item),
overloadIndex: 'overloadIndex' in item ? (item.overloadIndex as number) : undefined,
} as 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);
@@ -74,15 +68,14 @@ export default async function PackageLayout({ children, params }: PropsWithChild
return (member as ApiFunction).overloadIndex === 1;
});
const versions = await fetchVersions(params.package);
return (
<Providers>
<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">
<div className="lg:sticky lg:top-23 lg:h-[calc(100vh_-_105px)]">
<Nav members={members.map((member) => serializeIntoSidebarItemData(member))} versions={versions} />
<div className="lg:sticky lg:top-23 lg:h-[calc(100vh_-_145px)]">
<Nav members={members.map((member) => serializeIntoSidebarItemData(member))} />
</div>
<div className="mx-auto max-w-5xl min-w-xs w-full pb-10">

View File

@@ -1,38 +1,34 @@
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { compileMDX } from 'next-mdx-remote/rsc';
import { cache } from 'react';
import type { SerializeOptions } from 'next-mdx-remote/dist/types';
import { MDXRemote } from 'next-mdx-remote/rsc';
import rehypeRaw from 'rehype-raw';
import rehypeSlug from 'rehype-slug';
import remarkGfm from 'remark-gfm';
import type { VersionRouteParams } from './layout';
import { SyntaxHighlighter } from '~/components/SyntaxHighlighter';
interface VersionRouteParams {
package: string;
version: string;
}
const loadREADME = cache(async (packageName: string) => {
async function loadREADME(packageName: string) {
return readFile(join(process.cwd(), 'src', 'assets', 'readme', packageName, 'home-README.md'), 'utf8');
});
export async function generateStaticParams({ params }: { params: VersionRouteParams }) {
return [{ package: params.package, version: params.version }];
}
const mdxOptions = {
mdxOptions: {
remarkPlugins: [remarkGfm],
remarkRehypeOptions: { allowDangerousHtml: true },
rehypePlugins: [rehypeRaw, rehypeSlug],
format: 'md',
},
} satisfies SerializeOptions;
export default async function Page({ params }: { params: VersionRouteParams }) {
const readmeSource = await loadREADME(params.package);
const { content } = await compileMDX({
source: readmeSource,
// @ts-expect-error SyntaxHighlighter is assignable
components: { pre: SyntaxHighlighter },
options: {
mdxOptions: {
remarkPlugins: [remarkGfm],
rehypePlugins: [rehypeSlug],
format: 'mdx',
},
},
});
const { package: packageName } = params;
const readmeSource = await loadREADME(packageName);
return <div className="relative top-4 max-w-none prose">{content}</div>;
return (
<div className="max-w-none prose">
{/* @ts-expect-error SyntaxHighlighter is assignable */}
<MDXRemote components={{ pre: SyntaxHighlighter }} options={mdxOptions} source={readmeSource} />
</div>
);
}

View File

@@ -3,18 +3,28 @@ import { VscArrowRight } from '@react-icons/all-files/vsc/VscArrowRight';
import { VscVersions } from '@react-icons/all-files/vsc/VscVersions';
import Link from 'next/link';
import { notFound } from 'next/navigation';
import { fetchVersions } from '~/app/docAPI';
import { buttonVariants } from '~/styles/Button';
import { PACKAGES } from '~/util/constants';
export const revalidate = 3_600;
export const runtime = 'edge';
export default async function Page({ params }: { params: { package: string } }) {
if (!PACKAGES.includes(params.package)) {
async function getData(pkg: string) {
if (!PACKAGES.includes(pkg)) {
notFound();
}
const data = await fetchVersions(params.package);
const res = await fetch(`https://docs.discordjs.dev/api/info?package=${pkg}`, { next: { revalidate: 3_600 } });
const data: string[] = await res.json();
if (!data.length) {
throw new Error('Failed to fetch data');
}
return data.reverse();
}
export default async function Page({ params }: { params: { package: string } }) {
const data = await getData(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">

View File

@@ -6,11 +6,22 @@ import Link from 'next/link';
import { buttonVariants } from '~/styles/Button';
import { PACKAGES } from '~/util/constants';
export const runtime = 'edge';
export default function Page() {
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">
<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">
<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>
{PACKAGES.map((pkg, idx) => (
<Link
className={buttonVariants({ variant: 'secondary' })}
@@ -22,6 +33,14 @@ export default function Page() {
<VscPackage size={25} />
<h2 className="font-semibold">{pkg}</h2>
</div>
{/* <Link href={`/docs/packages/${pkg}`}>
<div
className="bg-blurple focus:ring-width-2 flex h-6 transform-gpu cursor-pointer select-none appearance-none flex-row place-content-center place-items-center rounded border-0 px-2 text-xs font-semibold leading-none text-white outline-none focus:ring focus:ring-white active:translate-y-px"
role="link"
>
Select version
</div>
</Link> */}
<VscArrowRight size={20} />
</div>
</Link>

View File

@@ -1,27 +1,23 @@
import { Analytics } from '@vercel/analytics/react';
import type { Metadata, Viewport } from 'next';
import type { Metadata } from 'next';
import type { PropsWithChildren } from 'react';
import { Providers } from './providers';
import { DESCRIPTION } from '~/util/constants';
import { inter, jetBrainsMono } from '~/util/fonts';
import { Providers } from './providers';
import '@unocss/reset/tailwind-compat.css';
import '~/styles/unocss.css';
import '~/styles/cmdk.css';
import '~/styles/main.css';
export const viewport: Viewport = {
themeColor: [
{ media: '(prefers-color-scheme: light)', color: '#f1f3f5' },
{ media: '(prefers-color-scheme: dark)', color: '#1c1c1e' },
],
colorScheme: 'light dark',
};
export const metadata: Metadata = {
metadataBase: new URL(
process.env.METADATA_BASE_URL ? process.env.METADATA_BASE_URL : `http://localhost:${process.env.PORT ?? 3_000}`,
),
title: 'discord.js',
description: DESCRIPTION,
viewport: {
minimumScale: 1,
initialScale: 1,
width: 'device-width',
},
icons: {
other: [
{
@@ -46,6 +42,12 @@ export const metadata: Metadata = {
manifest: '/site.webmanifest',
themeColor: [
{ media: '(prefers-color-scheme: light)', color: '#f1f3f5' },
{ media: '(prefers-color-scheme: dark)', color: '#1c1c1e' },
],
colorScheme: 'light dark',
appleWebApp: {
title: 'discord.js',
},

View File

@@ -1,4 +1,3 @@
import type { Route } from 'next';
import Link from 'next/link';
export default function NotFound() {
@@ -8,7 +7,7 @@ export default function NotFound() {
<h2 className="text-[2rem] md:text-[3rem]">Not found.</h2>
<Link
className="h-11 flex flex-row transform-gpu cursor-pointer select-none appearance-none place-items-center border-0 rounded bg-blurple px-6 text-base font-semibold leading-none text-white no-underline outline-none active:translate-y-px focus:ring focus:ring-width-2 focus:ring-white"
href={'/docs' as Route}
href="/docs"
>
Take me back
</Link>

View File

@@ -1,9 +1,9 @@
import { FiExternalLink } from '@react-icons/all-files/fi/FiExternalLink';
import type { Route } from 'next';
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 { InstallButton } from '~/components/InstallButton';
import { buttonVariants } from '~/styles/Button';
import { DESCRIPTION } from '~/util/constants';
@@ -11,6 +11,7 @@ import { DESCRIPTION } from '~/util/constants';
export default function Page() {
return (
<div className="min-h-screen">
<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">
@@ -20,8 +21,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">
<Link className={buttonVariants()} href={'/docs' as Route}>
<a className={buttonVariants()} href="https://old.discordjs.dev/#/docs" rel="noopener noreferrer">
Docs
</a>
<Link className={buttonVariants()} href="/docs">
Module docs
</Link>
<a
className={buttonVariants({ variant: 'secondary' })}

View File

@@ -1,5 +1,5 @@
import type { ApiDocumentedItem } from '@discordjs/api-extractor-model';
import { ApiAbstractMixin, ApiProtectedMixin, ApiReadonlyMixin, ApiStaticMixin } from '@discordjs/api-extractor-model';
import type { ApiDocumentedItem } from '@microsoft/api-extractor-model';
import { ApiAbstractMixin, ApiProtectedMixin, ApiReadonlyMixin, ApiStaticMixin } from '@microsoft/api-extractor-model';
import type { PropsWithChildren } from 'react';
export enum BadgeColor {

View File

@@ -0,0 +1,15 @@
import type { HTMLAttributes } from 'react';
export function Banner({ className, ...props }: HTMLAttributes<HTMLDivElement>) {
return (
<div className={`bg-blurple px-4 py-2 text-center text-sm text-white ${className}`} {...props}>
You are reading the documentation for the <strong>next</strong> version of discord.js. Documentation for v13/v14+
has been moved to{' '}
<strong>
<a href="https://old.discordjs.dev/#/docs" rel="external noopener noreferrer" target="_blank">
old.discordjs.dev
</a>
</strong>
</div>
);
}

View File

@@ -1,10 +1,9 @@
'use client';
import type { ApiItemKind } from '@discordjs/api-extractor-model';
import type { ApiItemKind } from '@microsoft/api-extractor-model';
import { VscArrowRight } from '@react-icons/all-files/vsc/VscArrowRight';
import { VscSymbolClass } from '@react-icons/all-files/vsc/VscSymbolClass';
import { VscSymbolEnum } from '@react-icons/all-files/vsc/VscSymbolEnum';
import { VscSymbolEvent } from '@react-icons/all-files/vsc/VscSymbolEvent';
import { VscSymbolInterface } from '@react-icons/all-files/vsc/VscSymbolInterface';
import { VscSymbolMethod } from '@react-icons/all-files/vsc/VscSymbolMethod';
import { VscSymbolProperty } from '@react-icons/all-files/vsc/VscSymbolProperty';
@@ -31,8 +30,6 @@ function resolveIcon(item: keyof typeof ApiItemKind) {
return <VscSymbolVariable className="shrink-0" size={25} />;
case 'Variable':
return <VscSymbolVariable className="shrink-0" size={25} />;
case 'Event':
return <VscSymbolEvent className="shrink-0" size={25} />;
default:
return <VscSymbolMethod className="shrink-0" size={25} />;
}
@@ -101,9 +98,7 @@ export function CmdKDialog() {
useEffect(() => {
const searchDoc = async (searchString: string, version: string) => {
const res = await client
.index(`${packageName?.replaceAll('.', '-')}-${version}`)
.search(searchString, { limit: 5 });
const res = await client.index(`${packageName}-${version}`).search(searchString, { limit: 5 });
setSearchResults(res.hits);
};

View File

@@ -1,6 +1,5 @@
import type { ReactNode } from 'react';
import { Anchor } from './Anchor';
import { SourceLink } from './documentation/SourceLink';
export interface CodeListingProps {
/**
@@ -15,26 +14,15 @@ export interface CodeListingProps {
* The href of this heading.
*/
readonly href?: string | undefined;
/**
* The line in the source code where this part is declared
*/
readonly sourceLine?: number | undefined;
/**
* The URL of the source code of this code part
*/
readonly sourceURL?: string | undefined;
}
export function CodeHeading({ href, className, children, sourceURL, sourceLine }: CodeListingProps) {
export function CodeHeading({ href, className, children }: CodeListingProps) {
return (
<div className="flex flex-row place-items-center justify-between gap-1">
<div
className={`flex flex-row flex-wrap place-items-center gap-1 break-all font-mono text-lg font-bold ${className}`}
>
{href ? <Anchor href={href} /> : null}
{children}
</div>
{sourceURL ? <SourceLink className="text-2xl" sourceLine={sourceLine} sourceURL={sourceURL} /> : null}
<div
className={`flex flex-row flex-wrap place-items-center gap-1 break-all font-mono text-lg font-bold ${className}`}
>
{href ? <Anchor href={href} /> : null}
{children}
</div>
);
}

View File

@@ -1,9 +0,0 @@
import type { PropsWithChildren } from 'react';
export function DocumentationLink({ children, href }: PropsWithChildren<{ readonly href: string }>) {
return (
<a className="text-blurple" href={href} rel="external noreferrer noopener" target="_blank">
{children}
</a>
);
}

View File

@@ -1,10 +1,8 @@
import type { ApiModel, Excerpt } from '@discordjs/api-extractor-model';
import { ExcerptTokenKind } from '@discordjs/api-extractor-model';
import { BuiltinDocumentationLinks } from '~/util/builtinDocumentationLinks';
import { DISCORD_API_TYPES_DOCS_URL } from '~/util/constants';
import { DocumentationLink } from './DocumentationLink';
import type { ApiModel, Excerpt } from '@microsoft/api-extractor-model';
import { ExcerptTokenKind } from '@microsoft/api-extractor-model';
import { ItemLink } from './ItemLink';
import { resolveItemURI } from './documentation/util';
import { DISCORD_API_TYPES_DOCS_URL } from '~/util/constants';
export interface ExcerptTextProps {
/**
@@ -25,37 +23,23 @@ export function ExcerptText({ model, excerpt }: ExcerptTextProps) {
<span>
{excerpt.spannedTokens.map((token, idx) => {
if (token.kind === ExcerptTokenKind.Reference) {
if (token.text in BuiltinDocumentationLinks) {
const href = BuiltinDocumentationLinks[token.text as keyof typeof BuiltinDocumentationLinks];
return (
<DocumentationLink key={`${token.text}-${idx}`} href={href}>
{token.text}
</DocumentationLink>
);
}
const source = token.canonicalReference?.source;
const symbol = token.canonicalReference?.symbol;
if (source && 'packageName' in source && source.packageName === 'discord-api-types' && symbol) {
const { meaning, componentPath: path } = symbol;
let href = DISCORD_API_TYPES_DOCS_URL;
// 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' || meaning === 'var') href += `#${token.text}`;
else href += `/${meaning}/${token.text}`;
if (source && 'packageName' in source && source.packageName === 'discord-api-types') {
const meaning = token.canonicalReference.symbol?.meaning;
const href =
meaning === 'type'
? `${DISCORD_API_TYPES_DOCS_URL}#${token.text}`
: `${DISCORD_API_TYPES_DOCS_URL}/${meaning}/${token.text}`;
return (
<DocumentationLink key={`${token.text}-${idx}`} href={href}>
<a className="text-blurple" href={href} key={idx} rel="external noreferrer noopener" target="_blank">
{token.text}
</DocumentationLink>
</a>
);
}
const item = token.canonicalReference
? model.resolveDeclarationReference(token.canonicalReference!, model).resolvedApiItem
: null;
const item = model.resolveDeclarationReference(token.canonicalReference!, model).resolvedApiItem;
if (!item) {
return token.text;
@@ -73,7 +57,7 @@ export function ExcerptText({ model, excerpt }: ExcerptTextProps) {
);
}
return token.text.replace(/import\("discord-api-types(?:\/v\d+)?"\)\./, '');
return token.text;
})}
</span>
);

View File

@@ -5,7 +5,6 @@ import { VscGithubInverted } from '@react-icons/all-files/vsc/VscGithubInverted'
import { VscMenu } from '@react-icons/all-files/vsc/VscMenu';
import { VscSearch } from '@react-icons/all-files/vsc/VscSearch';
import { Button } from 'ariakit/button';
import type { Route } from 'next';
import dynamic from 'next/dynamic';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
@@ -28,7 +27,7 @@ export default function Header() {
.map((path, idx, original) => (
<Link
className="rounded outline-none hover:underline focus:ring focus:ring-width-2 focus:ring-blurple"
href={`/${original.slice(0, idx + 1).join('/')}` as Route}
href={`/${original.slice(0, idx + 1).join('/')}`}
key={`${path}-${idx}`}
>
{path}

View File

@@ -1,4 +1,4 @@
import type { ApiDeclaredItem } from '@discordjs/api-extractor-model';
import type { ApiDeclaredItem } from '@microsoft/api-extractor-model';
import { ItemLink } from './ItemLink';
import { resolveItemURI } from './documentation/util';

View File

@@ -3,11 +3,15 @@
import type { LinkProps } from 'next/link';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import type { PropsWithChildren } from 'react';
import type { AnchorHTMLAttributes, PropsWithChildren, RefAttributes } from 'react';
import { useCurrentPathMeta } from '~/hooks/useCurrentPathMeta';
export interface ItemLinkProps<Route extends string> extends Omit<LinkProps<Route>, 'href'> {
export interface ItemLinkProps
extends Omit<LinkProps, 'href'>,
RefAttributes<HTMLAnchorElement>,
Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof LinkProps> {
readonly className?: string;
/**
* The URI of the api item to link to. (e.g. `/RestManager`)
*/
@@ -17,9 +21,6 @@ export interface ItemLinkProps<Route extends string> extends Omit<LinkProps<Rout
* The name of the package the item belongs to.
*/
readonly packageName?: string | undefined;
// TODO: This needs to be properly typed above but monkey-patching it for now.
readonly title?: string | undefined;
}
/**
@@ -29,7 +30,7 @@ export interface ItemLinkProps<Route extends string> extends Omit<LinkProps<Rout
* This component only needs the relative path to the item, and will automatically
* generate the full path to the item client-side.
*/
export function ItemLink<Route extends string>(props: PropsWithChildren<ItemLinkProps<Route>>) {
export function ItemLink(props: PropsWithChildren<ItemLinkProps>) {
const pathname = usePathname();
const { packageName, version } = useCurrentPathMeta();
@@ -39,5 +40,5 @@ export function ItemLink<Route extends string>(props: PropsWithChildren<ItemLink
const { itemURI, packageName: pkgName, ...linkProps } = props;
return <Link {...linkProps} href={`/docs/packages/${pkgName ?? packageName}/${version}/${itemURI}`} />;
return <Link href={`/docs/packages/${pkgName ?? packageName}/${version}/${itemURI}`} {...linkProps} />;
}

View File

@@ -2,20 +2,14 @@
import dynamic from 'next/dynamic';
import { Scrollbars } from 'react-custom-scrollbars-2';
import { useNav } from '~/contexts/nav';
import { Sidebar } from './Sidebar';
import type { SidebarSectionItemData } from './Sidebar';
import { useNav } from '~/contexts/nav';
const PackageSelect = dynamic(async () => import('./PackageSelect'));
const VersionSelect = dynamic(async () => import('./VersionSelect'));
export function Nav({
members,
versions,
}: {
readonly members: SidebarSectionItemData[];
readonly versions: string[];
}) {
export function Nav({ members }: { readonly members: SidebarSectionItemData[] }) {
const { opened } = useNav();
return (
@@ -36,7 +30,7 @@ export function Nav({
>
<div className="flex flex-col gap-4 p-3">
<PackageSelect />
<VersionSelect versions={versions} />
<VersionSelect />
</div>
<Sidebar members={members} />
</Scrollbars>

View File

@@ -15,8 +15,18 @@ export default function PackageSelect() {
const packageMenu = useMenuState({ gutter: 8, sameWidth: true, fitViewport: true });
const packageMenuItems = useMemo(
() =>
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"
@@ -28,6 +38,7 @@ export default function PackageSelect() {
</MenuItem>
</Link>
)),
],
[packageMenu],
);

Some files were not shown because too many files have changed in this diff Show More