Skip to content

Commit 6ee9a24

Browse files
committed
build: vercel serverless function for docs delivery
1 parent 84050d7 commit 6ee9a24

14 files changed

+4605
-0
lines changed

.eslintrc.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"root": true,
3+
"extends": "marine/prettier/node",
4+
"parserOptions": {
5+
"project": "./tsconfig.eslint.json"
6+
}
7+
}

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.gitignore

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Packages
2+
node_modules/
3+
4+
# Log files
5+
logs/
6+
*.log
7+
npm-debug.log*
8+
9+
# Runtime data
10+
pids
11+
*.pid
12+
*.seed
13+
14+
# Env
15+
.env
16+
17+
# Miscellaneous
18+
.tmp/
19+
.vscode/*
20+
!.vscode/extensions.json
21+
!.vscode/settings.json
22+
.idea/
23+
.DS_Store
24+
tsconfig.tsbuildinfo
25+
26+
# yarn
27+
.pnp.*
28+
.yarn/*
29+
!.yarn/patches
30+
!.yarn/plugins
31+
!.yarn/releases
32+
!.yarn/sdks
33+
!.yarn/versions
34+
.vercel

.prettierignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Autogenerated
2+
.yarn/
3+
builders/
4+
collection/
5+
discord.js/
6+
proxy/
7+
rest/
8+
voice/

.prettierrc.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"printWidth": 120,
3+
"useTabs": true,
4+
"singleQuote": true,
5+
"quoteProps": "as-needed",
6+
"trailingComma": "all",
7+
"endOfLine": "lf"
8+
}

.vercelignore

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.vercel
2+
.yarn/*
3+
!.yarn/patches
4+
!.yarn/plugins
5+
!.yarn/releases
6+
!.yarn/sdks
7+
!.yarn/versions
8+
node_modules
9+
.eslintrc.json
10+
.gitattributes
11+
.gitignore
12+
.prettierignore
13+
.prettierrc.json
14+
.vercelignore
15+
README.md
16+
tsconfig.eslint.json

.yarn/releases/yarn-3.2.2.cjs

+783
Large diffs are not rendered by default.

.yarnrc.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
nodeLinker: node-modules
2+
3+
yarnPath: .yarn/releases/yarn-3.2.2.cjs

api/index.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { readFile } from 'node:fs/promises';
2+
import { join } from 'node:path';
3+
import { cwd } from 'node:process';
4+
import type { VercelRequest, VercelResponse } from '@vercel/node';
5+
6+
export default async function handler(request: VercelRequest, response: VercelResponse) {
7+
const url = request.query.url as string;
8+
try {
9+
const filePath = join(cwd(), url);
10+
const file = await readFile(filePath, 'utf8');
11+
response.setHeader('Content-Type', 'application/json').send(file);
12+
} catch {
13+
response.status(404).end();
14+
}
15+
}

package.json

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "@discordjs/docs",
3+
"version": "0.1.0",
4+
"description": "The generated doc files for our documentation website",
5+
"private": true,
6+
"scripts": {
7+
"lint": "prettier --check . && eslint api --ext ts && tsc --noEmit",
8+
"format": "prettier --write . && eslint api --ext ts --fix",
9+
"fmt": "yarn format"
10+
},
11+
"directories": {
12+
"lib": "api"
13+
},
14+
"contributors": [
15+
"Crawl <icrawltogo@gmail.com>"
16+
],
17+
"license": "Apache-2.0",
18+
"keywords": [
19+
"api",
20+
"bot",
21+
"client",
22+
"node",
23+
"discordjs"
24+
],
25+
"repository": {
26+
"type": "git",
27+
"url": "https://github.com/discordjs/docs.git"
28+
},
29+
"bugs": {
30+
"url": "https://github.com/discordjs/docs/issues"
31+
},
32+
"homepage": "https://discord.js.org",
33+
"devDependencies": {
34+
"@typescript-eslint/eslint-plugin": "^5.30.7",
35+
"@typescript-eslint/parser": "^5.30.7",
36+
"@vercel/node": "^2.4.5",
37+
"eslint": "^8.20.0",
38+
"eslint-config-marine": "^9.4.1",
39+
"eslint-config-prettier": "^8.5.0",
40+
"eslint-import-resolver-typescript": "^3.3.0",
41+
"eslint-plugin-import": "^2.26.0",
42+
"prettier": "^2.7.1",
43+
"typescript": "^4.7.4",
44+
"vercel": "^27.2.0"
45+
},
46+
"engines": {
47+
"node": ">=16.9.0"
48+
},
49+
"packageManager": "yarn@3.2.2"
50+
}

tsconfig.eslint.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"allowJs": true
5+
},
6+
"include": [
7+
"**/*.ts",
8+
"**/*.tsx",
9+
"**/*.js",
10+
"**/*.mjs",
11+
"**/*.jsx",
12+
"**/*.test.ts",
13+
"**/*.test.js",
14+
"**/*.test.mjs",
15+
"**/*.spec.ts",
16+
"**/*.spec.js",
17+
"**/*.spec.mjs"
18+
],
19+
"exclude": []
20+
}

tsconfig.json

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
// Mapped from https://www.typescriptlang.org/tsconfig
3+
"compilerOptions": {
4+
// Type Checking
5+
"allowUnreachableCode": false,
6+
"allowUnusedLabels": false,
7+
"noFallthroughCasesInSwitch": true,
8+
"noImplicitOverride": true,
9+
"noImplicitReturns": true,
10+
"noUnusedLocals": true,
11+
"noUnusedParameters": true,
12+
"strict": true,
13+
"noUncheckedIndexedAccess": true,
14+
15+
// Modules
16+
"module": "CommonJS",
17+
"moduleResolution": "node",
18+
"resolveJsonModule": true,
19+
20+
// Emit
21+
"declaration": true,
22+
"declarationMap": true,
23+
"importHelpers": true,
24+
"importsNotUsedAsValues": "error",
25+
"inlineSources": true,
26+
"newLine": "lf",
27+
"noEmitHelpers": true,
28+
"outDir": "dist",
29+
"preserveConstEnums": true,
30+
"removeComments": false,
31+
"sourceMap": true,
32+
"esModuleInterop": true,
33+
"forceConsistentCasingInFileNames": true,
34+
35+
// Language and Environment
36+
"emitDecoratorMetadata": true,
37+
"experimentalDecorators": true,
38+
"lib": ["ESNext"],
39+
"target": "ES2021",
40+
"useDefineForClassFields": true
41+
},
42+
"include": ["api/**/*.ts"]
43+
}

vercel.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"functions": {
3+
"api/index.ts": {
4+
"includeFiles": "{builders,collection,discord.js,proxy,rest,voice}/**"
5+
}
6+
},
7+
"trailingSlash": false,
8+
"rewrites": [{ "source": "/docs/:url(.*)", "destination": "/api" }]
9+
}

0 commit comments

Comments
 (0)