Skip to content

Commit

Permalink
docs: add typedoc
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Dec 13, 2023
1 parent ed2531a commit 3498bef
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .config/typedoc.workspace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// @ts-check

const path = require('node:path');
const fs = require('node:fs');

/**
* Generates `entryPoints` for TypeDoc for a workspace.
*
* This inspects exports for the `typedoc` conditional, and uses that, if
* present.
*
* This does not recurse exports.
*
* @param {string} cwd
* @returns {Partial<import('typedoc').TypeDocOptions>}
*/
module.exports = function (cwd) {
/**
* @type {import('type-fest').PackageJson}
*/
const pkgJson = JSON.parse(
fs.readFileSync(path.join(cwd, 'package.json'), 'utf-8'),
);
const {exports} = pkgJson;
if (!exports) {
throw new TypeError('package.json does not have exports');
}
if (typeof exports !== 'object') {
throw new TypeError('package.json exports is not an object');
}

return {
entryPoints: Object.values(exports)
.filter(
(entryPoint) =>
entryPoint &&
typeof entryPoint === 'object' &&
'typedoc' in entryPoint &&
typeof entryPoint.typedoc === 'string',
)
.map((entryPoint) =>
path.join(
cwd,
/**
* @type {{typedoc: string}}
*/ (entryPoint).typedoc,
),
),
excludeInternal: true,
excludePrivate: true,
};
};
110 changes: 110 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"sinon": "16.1.3",
"snap-shot-it": "7.9.10",
"ts-node": "10.9.2",
"typedoc": "0.25.3",
"typedoc-plugin-zod": "1.1.0",
"typescript": "5.2.2",
"unexpected": "13.2.1",
"unexpected-sinon": "11.1.0"
Expand Down
5 changes: 5 additions & 0 deletions packages/midnight-smoker/.config/typedoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const path = require('node:path');

module.exports = require('../../../.config/typedoc.workspace')(
path.resolve(__dirname, '..'),
);
5 changes: 5 additions & 0 deletions packages/test-util/.config/typedoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const path = require('node:path');

module.exports = require('../../../.config/typedoc.workspace')(
path.resolve(__dirname, '..'),
);
15 changes: 15 additions & 0 deletions typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://typedoc.org/schema.json",
"entryPoints": [
"./packages/midnight-smoker",
"./packages/plugin-default",
"./packages/test-util"
],
"out": "docs/api",
"entryPointStrategy": "packages",
"plugin": ["typedoc-plugin-zod"],
"excludeInternal": true,
"excludePrivate": true,
"cleanOutputDir": true,
"logLevel": "Info"
}

0 comments on commit 3498bef

Please sign in to comment.