Skip to content

Commit 7098bf7

Browse files
committed
docs: add api gen
1 parent 7b8b037 commit 7098bf7

File tree

7 files changed

+203
-2
lines changed

7 files changed

+203
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ package-lock.json
1010
temp
1111
roadmap.md
1212
*-debug.log
13+
docs/api

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"funding": "https://github.com/sponsors/posva",
2929
"scripts": {
3030
"docs": "vitepress dev docs --port 3000",
31-
"docs:build": "vitepress build docs",
31+
"docs:build": "pnpm run docs:api:build && vitepress build docs",
32+
"docs:api:build": "node ./scripts/run-typedoc.cjs",
3233
"build": "unbuild",
3334
"release": "node scripts/release.mjs",
3435
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1",
@@ -82,6 +83,8 @@
8283
"p-series": "^3.0.0",
8384
"prettier": "^2.0.5",
8485
"semver": "^7.3.8",
86+
"typedoc": "^0.23.17",
87+
"typedoc-plugin-markdown": "^3.13.6",
8588
"typescript": "~4.8.4",
8689
"unbuild": "^0.9.4",
8790
"vitepress": "1.0.0-alpha.21",

pnpm-lock.yaml

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

scripts/run-typedoc.cjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { createTypeDocApp } = require('./typedoc-markdown.cjs')
2+
const path = require('path')
3+
4+
createTypeDocApp({
5+
name: 'API Documentation',
6+
tsconfig: path.resolve(__dirname, './typedoc.tsconfig.json'),
7+
// entryPointStrategy: 'packages',
8+
githubPages: false,
9+
disableSources: true,
10+
entryPoints: [path.resolve(__dirname, '../src/index.ts')],
11+
}).build()

scripts/typedoc-markdown.cjs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
const _fs = require('fs')
2+
const path = require('path')
3+
const TypeDoc = require('typedoc')
4+
const { PageEvent } = TypeDoc
5+
const {
6+
prependYAML,
7+
} = require('typedoc-plugin-markdown/dist/utils/front-matter')
8+
9+
const fs = _fs.promises
10+
11+
const DEFAULT_OPTIONS = {
12+
// disableOutputCheck: true,
13+
cleanOutputDir: true,
14+
excludeInternal: true,
15+
readme: 'none',
16+
out: path.resolve(__dirname, '../docs/api'),
17+
entryDocument: 'index.md',
18+
hideBreadcrumbs: false,
19+
hideInPageTOC: true,
20+
}
21+
22+
/**
23+
*
24+
* @param {Partial<import('typedoc').TypeDocOptions>} config
25+
*/
26+
exports.createTypeDocApp = function createTypeDocApp(config = {}) {
27+
const options = {
28+
...DEFAULT_OPTIONS,
29+
...config,
30+
}
31+
32+
const app = new TypeDoc.Application()
33+
34+
// If you want TypeDoc to load tsconfig.json / typedoc.json files
35+
app.options.addReader(new TypeDoc.TSConfigReader())
36+
// app.options.addReader(new TypeDoc.TypeDocReader())
37+
38+
/** @type {'build' | 'serve'} */
39+
let targetMode = 'build'
40+
41+
app.renderer.on(
42+
PageEvent.END,
43+
/**
44+
*
45+
* @param {import('typedoc/dist/lib/output/events').PageEvent} page
46+
*/
47+
(page) => {
48+
if (page.url !== 'index.md' && page.contents) {
49+
page.contents = prependYAML(page.contents, {
50+
sidebar: 'auto',
51+
// TODO: figure out a way to point to the source files?
52+
editLinks: false,
53+
sidebarDepth: 3,
54+
})
55+
}
56+
}
57+
)
58+
59+
async function serve() {
60+
app.bootstrap(options)
61+
app.convertAndWatch(handleProject)
62+
}
63+
64+
async function build() {
65+
if (
66+
(await exists(options.out)) &&
67+
(await fs.stat(options.out)).isDirectory()
68+
) {
69+
await fs.rm(options.out, { recursive: true })
70+
}
71+
app.bootstrap(options)
72+
const project = app.convert()
73+
return handleProject(project)
74+
}
75+
76+
/**
77+
*
78+
* @param {import('typedoc').ProjectReflection} project
79+
*/
80+
async function handleProject(project) {
81+
if (project) {
82+
// Rendered docs
83+
try {
84+
await app.generateDocs(project, options.out)
85+
app.logger.info(`generated at ${options.out}.`)
86+
} catch (error) {
87+
app.logger.error(error)
88+
}
89+
} else {
90+
app.logger.error('No project')
91+
}
92+
}
93+
94+
return {
95+
build,
96+
serve,
97+
/**
98+
*
99+
* @param {'build' | 'serve'} command
100+
*/
101+
setTargetMode(command) {
102+
targetMode = command
103+
},
104+
}
105+
}
106+
107+
async function exists(path) {
108+
try {
109+
await fs.access(path)
110+
return true
111+
} catch {
112+
return false
113+
}
114+
}

scripts/typedoc.tsconfig.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"include": ["../src/**/*.ts"],
3+
"exclude": ["**/*.spec.ts"],
4+
"compilerOptions": {
5+
"baseUrl": ".",
6+
"rootDir": "..",
7+
"outDir": "dist",
8+
"sourceMap": false,
9+
"noEmit": true,
10+
"paths": {
11+
"vuefire": ["../src"]
12+
},
13+
14+
"target": "esnext",
15+
"module": "esnext",
16+
"moduleResolution": "node",
17+
"allowJs": false,
18+
"skipLibCheck": true,
19+
20+
"noUnusedLocals": false,
21+
"strictNullChecks": true,
22+
"noImplicitAny": true,
23+
"noImplicitThis": true,
24+
"noImplicitReturns": false,
25+
"strict": true,
26+
"isolatedModules": true,
27+
28+
"experimentalDecorators": true,
29+
"resolveJsonModule": true,
30+
"esModuleInterop": true,
31+
"removeComments": false,
32+
"jsx": "preserve",
33+
"lib": ["esnext", "dom"]
34+
}
35+
}

src/firestore/subscribe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface FirestoreOptions {
3131
snapshotOptions?: SnapshotOptions
3232

3333
/**
34-
* @inheritdoc {SnapshotListenOptions}
34+
* @inheritDoc {SnapshotListenOptions}
3535
*/
3636
snapshotListenOptions?: SnapshotListenOptions
3737

0 commit comments

Comments
 (0)