Skip to content

Commit

Permalink
docs: split docs.api.json into multiple json files
Browse files Browse the repository at this point in the history
  • Loading branch information
iCrawl committed Feb 6, 2024
1 parent ae57d7f commit 597340f
Show file tree
Hide file tree
Showing 28 changed files with 1,144 additions and 62 deletions.
36 changes: 36 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "tab",
"indentWidth": 2,
"lineWidth": 120,
"lineEnding": "lf",
"ignore": [
".turbo",
".vercel",
".contentlayer",
".next",
"coverage",
"dist",
"dist-docs",
"docs",
"CHANGELOG.md",
"tsup.config.bundled*"
]
},
"javascript": {
"formatter": {
"enabled": true,
"quoteStyle": "single",
"quoteProperties": "asNeeded",
"trailingComma": "all",
"semicolons": "always"
}
},
"files": {
"ignoreUnknown": true,
"maxSize": 1000000
}
}
4 changes: 4 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import node from 'eslint-config-neon/flat/node.js';
import prettier from 'eslint-config-neon/flat/prettier.js';
import react from 'eslint-config-neon/flat/react.js';
import typescript from 'eslint-config-neon/flat/typescript.js';
// import oxlint from 'eslint-plugin-oxlint';
import merge from 'lodash.merge';

const commonFiles = '{js,mjs,cjs,ts,mts,cts,jsx,tsx}';
Expand Down Expand Up @@ -63,6 +64,8 @@ const edgeRuleset = merge(...edge, { files: [`apps/**/*${commonFiles}`] });

const prettierRuleset = merge(...prettier, { files: [`**/*${commonFiles}`] });

// const oxlintRuleset = merge({ rules: oxlint.rules }, { files: [`**/*${commonFiles}`] });

/** @type {import('eslint').Linter.FlatConfig[]} */
export default [
{
Expand Down Expand Up @@ -133,4 +136,5 @@ export default [
rules: { 'tsdoc/syntax': 0 },
},
prettierRuleset,
// oxlintRuleset,
];
2 changes: 1 addition & 1 deletion packages/actions/src/uploadDocumentation/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'Upload documentation'
description: 'Uploads the docs.api.json file to a planetscale database'
description: 'Uploads the docs.api.json file to a neon postgresql database'
inputs:
package:
description: 'The package string'
Expand Down
10 changes: 10 additions & 0 deletions packages/actions/src/uploadSplitDocumentation/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: 'Upload split documentation'
description: 'Splits and uploads the docs.api.json file into more fine-grained [item].api.json files'
inputs:
package:
description: 'The package string'
version:
description: 'The semver string'
runs:
using: node20
main: ../../dist/uploadSplitDocumentation/index.js
34 changes: 34 additions & 0 deletions packages/actions/src/uploadSplitDocumentation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { readFile } from 'node:fs/promises';
import { basename } from 'node:path';
import process from 'node:process';
import { getInput, setFailed } from '@actions/core';
import { create } from '@actions/glob';
import { put } from '@vercel/blob';
import { createPool } from '@vercel/postgres';

if (!process.env.DATABASE_URL) {
setFailed('DATABASE_URL is not set');
}

const pkg = getInput('package') || '*';
const version = getInput('version') || 'main';

const pool = createPool({
connectionString: process.env.DATABASE_URL,
});

const globber = await create(`packages/${pkg}/docs/split/main.*.*.api.json`);
for await (const file of globber.globGenerator()) {
const data = await readFile(file, 'utf8');
try {
console.log(`Uploading ${file} with ${version}...`);
const name = basename(file).replace('main.', '');
const { url } = await put(`${version}.${name}`, data, {
access: 'public',
addRandomSuffix: false,
});
await pool.sql`insert into documentation (name, version, url) values (${name}, ${version}, ${url}) on conflict (name, version) do update set url = EXCLUDED.url`;
} catch (error) {
console.log(error);
}
}
1 change: 1 addition & 0 deletions packages/actions/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createTsupConfig } from '../../tsup.config.js';

export default createTsupConfig({
entry: [
'src/buildSplitDocumentation/index.ts',
'src/index.ts',
'src/formatTag/index.ts',
'src/uploadDocumentation/index.ts',
Expand Down
3 changes: 2 additions & 1 deletion packages/brokers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"fmt": "pnpm run format",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation",
"prepack": "pnpm run lint && pnpm run test && pnpm run build",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/brokers/*'",
"release": "cliff-jumper"
Expand Down Expand Up @@ -72,6 +72,7 @@
},
"devDependencies": {
"@discordjs/api-extractor": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^2.2.3",
"@types/node": "18.18.8",
"@vitest/coverage-v8": "^1.2.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/builders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"fmt": "pnpm run format",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation",
"prepack": "pnpm run lint && pnpm run test && pnpm run build",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/builders/*'",
"release": "cliff-jumper"
Expand Down Expand Up @@ -74,6 +74,7 @@
},
"devDependencies": {
"@discordjs/api-extractor": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^2.2.3",
"@types/node": "16.18.60",
"@vitest/coverage-v8": "^1.2.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"fmt": "pnpm run format",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation",
"prepack": "pnpm run lint && pnpm run test && pnpm run build",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/collection/*'",
"release": "cliff-jumper"
Expand Down Expand Up @@ -61,6 +61,7 @@
"homepage": "https://discord.js.org",
"devDependencies": {
"@discordjs/api-extractor": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^2.2.3",
"@types/node": "18.18.8",
"@vitest/coverage-v8": "^1.2.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation",
"prepack": "pnpm run build && pnpm run lint",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/core/*'",
"release": "cliff-jumper"
Expand Down Expand Up @@ -73,6 +73,7 @@
},
"devDependencies": {
"@discordjs/api-extractor": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^2.2.3",
"@types/node": "18.18.8",
"@vitest/coverage-v8": "^1.2.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/discord.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"fmt": "pnpm run format",
"docs": "docgen -i \"./src/*.js\" \"./src/**/*.js\" -c ./docs/index.json -r ../../ -o ./docs/docs.json && pnpm run docs:new",
"docs:test": "docgen -i \"./src/*.js\" \"./src/**/*.js\" -c ./docs/index.json -r ../../",
"docs:new": "api-extractor run --local --minify",
"docs:new": "api-extractor run --local --minify && generate-split-documentation",
"prepack": "pnpm run lint && pnpm run test && node ./scripts/esmDts.mjs",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/discord.js/*'",
"release": "cliff-jumper"
Expand Down Expand Up @@ -82,6 +82,7 @@
"devDependencies": {
"@discordjs/api-extractor": "workspace:^",
"@discordjs/docgen": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "2.2.3",
"@types/node": "16.18.60",
"@typescript-eslint/eslint-plugin": "^6.21.0",
Expand Down
1 change: 1 addition & 0 deletions packages/docgen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"lib": "src"
},
"files": [
"bin/index.js",
"dist"
],
"contributors": [
Expand Down
3 changes: 2 additions & 1 deletion packages/formatters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation",
"prepack": "pnpm run build && pnpm run lint",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/formatters/*'",
"release": "cliff-jumper"
Expand Down Expand Up @@ -58,6 +58,7 @@
},
"devDependencies": {
"@discordjs/api-extractor": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^2.2.3",
"@types/node": "16.18.60",
"@vitest/coverage-v8": "^1.2.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation",
"prepack": "pnpm run build && pnpm run lint",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/next/*'",
"release": "cliff-jumper"
Expand Down Expand Up @@ -75,6 +75,7 @@
},
"devDependencies": {
"@discordjs/api-extractor": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^2.2.3",
"@types/node": "18.18.8",
"@vitest/coverage-v8": "^1.2.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"fmt": "pnpm run format",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation",
"prepack": "pnpm run lint && pnpm run test && pnpm run build",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/proxy/*'",
"release": "cliff-jumper"
Expand Down Expand Up @@ -71,6 +71,7 @@
},
"devDependencies": {
"@discordjs/api-extractor": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^2.2.3",
"@types/node": "18.18.8",
"@types/supertest": "^6.0.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"fmt": "pnpm run format",
"docs": "pnpm run build:docs && api-extractor run --local --minify",
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation",
"prepack": "pnpm run lint && pnpm run test && pnpm run build",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/rest/*'",
"release": "cliff-jumper"
Expand Down Expand Up @@ -94,6 +94,7 @@
},
"devDependencies": {
"@discordjs/api-extractor": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^2.2.3",
"@types/node": "18.17.9",
"@vitest/coverage-v8": "^1.2.2",
Expand Down
2 changes: 2 additions & 0 deletions packages/scripts/bin/generateSplitDocumentation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../dist/bin/generateSplitDocumentation.js');
31 changes: 31 additions & 0 deletions packages/scripts/bin/generateSplitDocumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env node
/* eslint-disable n/shebang */
import { readFile } from 'node:fs/promises';
import process from 'node:process';
import { createCommand } from 'commander';
import packageFile from '../package.json';
import { generateSplitDocumentation } from '../src/index.js';

export interface CLIOptions {
custom: string;
input: string[];
newOutput: string;
output: string;
root: string;
typescript: boolean;
}

const command = createCommand().version(packageFile.version);

const program = command.parse(process.argv);
program.opts<CLIOptions>();

console.log('Generating split documentation...');
void generateSplitDocumentation({
fetchPackageVersions: async (_) => {
return ['main'];
},
fetchPackageVersionDocs: async (_, __) => {
return JSON.parse(await readFile(`${process.cwd()}/docs/docs.api.json`, 'utf8'));
},
}).then(() => console.log('Generated split documentation.'));
20 changes: 13 additions & 7 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,31 @@
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src turbo/generators/config.ts",
"fmt": "pnpm run format"
},
"bin": {
"generate-split-documentation": "./bin/generateSplitDocumentation.js"
},
"exports": {
".": {
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
"types": "./dist/src/index.d.ts",
"default": "./dist/src/index.js"
},
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
"types": "./dist/src/index.d.mts",
"default": "./dist/src/index.mjs"
}
}
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"main": "./dist/src/index.js",
"module": "./dist/src/index.mjs",
"types": "./dist/src/index.d.ts",
"directories": {
"bin": "bin",
"lib": "src",
"example": "turbo"
},
"files": [
"bin/generateSplitDocumentation.js",
"dist"
],
"contributors": [
Expand Down Expand Up @@ -60,6 +65,7 @@
"@microsoft/tsdoc-config": "0.16.2",
"@vercel/blob": "^0.20.0",
"@vercel/postgres": "^0.7.2",
"commander": "^11.1.0",
"tslib": "^2.6.2",
"undici": "6.6.1",
"yaml": "2.3.4"
Expand Down
Loading

0 comments on commit 597340f

Please sign in to comment.