-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(typedoc): Add
generateReferenceDocs
function (#132)
* feat(typedoc): Add reference doc generation * Export packages type * Rename type to Package
- Loading branch information
1 parent
9b1843a
commit 8e41006
Showing
10 changed files
with
290 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,6 @@ | |
"test:build": { | ||
"cache": true | ||
}, | ||
"test:format": { | ||
"cache": true | ||
}, | ||
"test:sherif": { | ||
"cache": true | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,37 @@ | ||
import type { RunOptions } from './types' | ||
export type Commit = { | ||
hash: string | ||
body: string | ||
subject: string | ||
author_name: string | ||
author_email: string | ||
type: string | ||
scope: string | null | undefined | ||
} | ||
|
||
export type Package = { | ||
name: string | ||
packageDir: string | ||
} | ||
|
||
export type BranchConfig = { | ||
prerelease: boolean | ||
previousVersion?: boolean | ||
} | ||
|
||
export type Options = { | ||
/** Contains config for publishable branches. */ | ||
branchConfigs: Record<string, BranchConfig> | ||
/** List your npm packages here. The first package will be used as the versioner. */ | ||
packages: Array<Package> | ||
/** Path to root directory of your project. */ | ||
rootDir: string | ||
/** The branch to publish. Defaults to the current branch if none supplied. */ | ||
branch?: string | ||
/** A manual tag to force release. Must start with `v` */ | ||
tag?: string | ||
/** The GitHub token used to search for user metadata and make a GitHub release. */ | ||
ghToken?: string | ||
} | ||
|
||
/** https://tanstack.com/config/latest/docs/publish */ | ||
export function publish(options: RunOptions): Promise<void> | ||
export function publish(options: Options): Promise<void> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { UserConfig } from 'vite' | ||
|
||
export type Package = { | ||
name: string | ||
entryPoints: Array<string> | ||
tsconfig: string | ||
outputDir: string | ||
exclude?: Array<string> | ||
} | ||
|
||
export type Options = { | ||
/** Config for packages that need reference docs */ | ||
packages: Array<Package> | ||
} | ||
|
||
export function generateReferenceDocs(config: Options): Promise<void> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { resolve } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { mkdir, rm } from 'node:fs/promises' | ||
import * as TypeDoc from 'typedoc' | ||
|
||
const __dirname = fileURLToPath(new URL('.', import.meta.url)) | ||
|
||
/** | ||
* @type {Partial<import("typedoc").TypeDocOptions & import("typedoc-plugin-markdown").PluginOptions>} | ||
*/ | ||
const settings = { | ||
plugin: [ | ||
'typedoc-plugin-markdown', | ||
'typedoc-plugin-frontmatter', | ||
resolve(__dirname, './typedoc-custom-settings.js'), | ||
], | ||
hideGenerator: true, | ||
readme: 'none', | ||
flattenOutputFiles: true, | ||
entryFileName: 'index', | ||
hideBreadcrumbs: true, | ||
hidePageHeader: true, | ||
useCodeBlocks: true, | ||
excludePrivate: true, | ||
} | ||
|
||
/** | ||
* @param {import('./index.js').Options} options | ||
* @returns {Promise<void>} | ||
*/ | ||
export const generateReferenceDocs = async (options) => { | ||
for (const pkg of options.packages) { | ||
// Clean and recreate the output directories | ||
try { | ||
await rm(pkg.outputDir, { recursive: true }) | ||
} catch (error) { | ||
// @ts-expect-error | ||
if (error.code !== 'ENOENT') { | ||
throw error | ||
} | ||
} | ||
await mkdir(pkg.outputDir, { recursive: true }) | ||
|
||
const app = await TypeDoc.Application.bootstrapWithPlugins({ | ||
...settings, | ||
entryPoints: pkg.entryPoints, | ||
tsconfig: pkg.tsconfig, | ||
exclude: pkg.exclude, | ||
}) | ||
|
||
const project = await app.convert() | ||
|
||
if (project) { | ||
await app.generateDocs(project, pkg.outputDir) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { | ||
MarkdownPageEvent, | ||
MarkdownRendererEvent, | ||
} from 'typedoc-plugin-markdown' | ||
|
||
/** | ||
* @param {import("typedoc-plugin-markdown").MarkdownApplication} app | ||
*/ | ||
export function load(app) { | ||
// Add `id` and `title` to frontmatter | ||
app.renderer.on( | ||
MarkdownPageEvent.BEGIN, | ||
/** @param {import('typedoc-plugin-markdown').MarkdownPageEvent} page */ | ||
(page) => { | ||
page.frontmatter = { | ||
id: page.model.name, | ||
title: page.model.name, | ||
} | ||
}, | ||
) | ||
// Rename output files | ||
app.renderer.on( | ||
MarkdownRendererEvent.BEGIN, | ||
/** | ||
* @param {import("typedoc-plugin-markdown").MarkdownRendererEvent} renderer | ||
*/ (renderer) => { | ||
renderer.urls = renderer.urls?.map((urlMapping) => { | ||
const name = urlMapping.url.split('.') | ||
if (name[0] !== 'index') { | ||
name.splice(0, 1) | ||
} | ||
const newBasename = name.join('.') | ||
urlMapping.url = newBasename | ||
urlMapping.model.url = newBasename | ||
return urlMapping | ||
}) | ||
}, | ||
) | ||
} |
Oops, something went wrong.