Skip to content

Commit 36a306f

Browse files
committed
docs: add typedoc site
1 parent 3e023b6 commit 36a306f

21 files changed

Lines changed: 1012 additions & 3 deletions

.config/typedoc-plugin-bargs.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* This mini-plugin copies media files from `site/media/` to the output
3+
* directory's `media/` folder at end of rendering.
4+
*
5+
* @packageDocumentation
6+
*/
7+
import fs from 'node:fs';
8+
import path from 'node:path';
9+
import { fileURLToPath } from 'node:url';
10+
import { PageEvent, RendererEvent } from 'typedoc';
11+
12+
/**
13+
* @import {Application} from "typedoc"
14+
*/
15+
16+
const SOURCE_DIR = fileURLToPath(new URL('../site/media/', import.meta.url));
17+
18+
/**
19+
* @function
20+
* @param {Application} app
21+
*/
22+
export const load = (app) => {
23+
const outputDir = app.options.getValue('out');
24+
const mediaDir = path.join(outputDir, 'media');
25+
26+
// Listen for declaration creation to inspect JSDoc block tags
27+
28+
app.logger.info(
29+
`Will copy all files in ${path.relative(process.cwd(), SOURCE_DIR)} to ${path.relative(process.cwd(), mediaDir)}`,
30+
);
31+
32+
app.renderer.on(RendererEvent.END, () => {
33+
for (const file of fs.readdirSync(SOURCE_DIR)) {
34+
const sourceFile = path.join(SOURCE_DIR, file);
35+
const destFile = path.join(mediaDir, file);
36+
fs.cpSync(sourceFile, destFile);
37+
app.logger.info(
38+
`Copied ${path.relative(process.cwd(), sourceFile)} to ${path.relative(process.cwd(), destFile)}`,
39+
);
40+
}
41+
});
42+
43+
app.renderer.on(PageEvent.END, (page) => {
44+
if (!page.contents) {
45+
return;
46+
}
47+
const navigationLinks = app.options.getValue('navigationLinks');
48+
if (!navigationLinks) {
49+
return;
50+
}
51+
52+
if ('GitHub' in navigationLinks) {
53+
// Replace the GitHub link in the footer with one that includes the icon
54+
page.contents = page.contents.replace(
55+
`<a href="${navigationLinks.GitHub}">GitHub</a>`,
56+
`<a href="${navigationLinks.GitHub}" title="bargs on GitHub"><span class="icon-github" aria-label="GitHub"></span></a>`,
57+
);
58+
}
59+
if ('npm' in navigationLinks) {
60+
// Replace the npm link in the footer with one that includes the icon
61+
page.contents = page.contents.replace(
62+
`<a href="${navigationLinks.npm}">npm</a>`,
63+
`<a href="${navigationLinks.npm}" title="@boneskull/bargs on npm"><span class="icon-npm" aria-label="npm"></span></a>`,
64+
);
65+
}
66+
});
67+
};

.config/typedoc.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { readFileSync } from 'node:fs';
2+
3+
/**
4+
* @import {TypeDocOptions} from "typedoc"
5+
*/
6+
7+
const customFooterHtml = readFileSync(
8+
new URL('../site/media/footer.html', import.meta.url),
9+
'utf8',
10+
);
11+
12+
/** @type {Partial<TypeDocOptions>} */
13+
export default {
14+
basePath: process.env.GITHUB_ACTIONS ? '/bargs/' : '/',
15+
customCss: '../site/media/bargs-theme.css',
16+
customFooterHtml,
17+
darkHighlightTheme: 'vitesse-dark',
18+
entryPoints: ['../src/index.ts'],
19+
excludeExternals: true,
20+
excludeInternal: true,
21+
excludePrivate: true,
22+
externalSymbolLinkMappings: {
23+
'@types/node': {
24+
'util.parseArgs': 'https://nodejs.org/api/util.html#utilparseargsconfig',
25+
},
26+
typescript: {
27+
PromiseLike:
28+
'https://github.com/microsoft/TypeScript/blob/3320dfdfcf17cdcdbfccb8040ea73cf110d94ba3/src/lib/es5.d.ts', // current of Sep 9 2025
29+
},
30+
},
31+
favicon: '../site/media/favicon.svg',
32+
// @ts-expect-error from extras plugin
33+
footerLastModified: true,
34+
lightHighlightTheme: 'vitesse-light',
35+
markdownLinkExternal: true,
36+
name: 'BARGS',
37+
navigationLinks: {
38+
GitHub: 'https://github.com/boneskull/bargs',
39+
npm: 'https://www.npmjs.com/package/@boneskull/bargs',
40+
},
41+
out: '../docs',
42+
plugin: [
43+
'./typedoc-plugin-bargs.js',
44+
'typedoc-plugin-mdn-links',
45+
'typedoc-plugin-extras',
46+
],
47+
preserveWatchOutput: true,
48+
searchInComments: true,
49+
searchInDocuments: true,
50+
tsconfig: '../tsconfig.json',
51+
};

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,4 @@ dist/
144144

145145
.worktrees/
146146

147+
docs/

cspell.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
"linkifying",
5757
"wallabyjs",
5858
"ptmux",
59-
"nargs"
59+
"nargs",
60+
"vitesse"
6061
],
6162
"words": [
6263
"bupkis",

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export default defineConfig(
113113
},
114114
},
115115
{
116-
files: ['*.js', 'scripts/**/*.js'],
116+
files: ['*.js', 'scripts/**/*.js', '.config/*.js'],
117117
languageOptions: {
118118
globals: globals.node,
119119
},

package-lock.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
"prettier-plugin-sort-json": "4.1.1",
8686
"tsx": "4.21.0",
8787
"typedoc": "0.28.15",
88+
"typedoc-plugin-extras": "4.0.1",
89+
"typedoc-plugin-mdn-links": "5.0.10",
8890
"typescript": "5.9.3",
8991
"typescript-eslint": "8.50.0",
9092
"zshy": "0.6.0"

site/media/apple-touch-icon.png

43.8 KB
Loading

0 commit comments

Comments
 (0)