docusaurus-plugin-typedoc 1.0.0-next.0 → 1.0.0-next.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,20 +1,24 @@
1
1
  # docusaurus-plugin-typedoc
2
2
 
3
- A [Docusaurus v2](https://v2.docusaurus.io/) plugin to build documentation with [TypeDoc](https://github.com/TypeStrong/typedoc).
3
+ A [Docusaurus](https://v2.docusaurus.io/) plugin to build TypeScript API documentation with [TypeDoc](https://github.com/TypeStrong/typedoc).
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/docusaurus-plugin-typedoc.svg)](https://www.npmjs.com/package/docusaurus-plugin-typedoc)
6
6
  ![CI](https://github.com/tgreyuk/typedoc-plugin-markdown/actions/workflows/ci.yml/badge.svg?branch=master)
7
7
 
8
- ## What it does?
8
+ ## What does it do?
9
9
 
10
- Generates static TypeDoc pages in Markdown with frontmatter as part of the Docusaurus build.
10
+ - Presets relevant options of [typedoc-plugin-markdown](https://github.com/tgreyuk/typedoc-plugin-markdown/tree/master/packages/typedoc-plugin-markdown#readme).
11
+ - Runs TypeDoc from the Docusaurus CLI.
12
+ - Adds some basic frontmatter to pages and exposes the ability to configure frontmatter further.
11
13
 
12
14
  ## Installation
13
15
 
14
16
  > Install [Docusaurus](https://v2.docusaurus.io/docs/installation) in the root of your project and install the plugin dependencies in the same location as the Docusaurus website directory.
15
17
 
18
+ > [typedoc](https://github.com/TypeStrong/typedoc), [typedoc-plugin-markdown](https://github.com/tgreyuk/typedoc-plugin-markdown) are peer dependencies.
19
+
16
20
  ```shell
17
- npm install typedoc typedoc-plugin-markdown docusaurus-plugin-typedoc --save-dev
21
+ npm install docusaurus-plugin-typedoc typedoc typedoc-plugin-markdown@next --save-dev
18
22
  ```
19
23
 
20
24
  ## Usage
@@ -65,44 +69,64 @@ Once built the docs will be available at `/docs/api` (or equivalent out director
65
69
 
66
70
  ## Options
67
71
 
72
+ Options can be declared:
73
+
74
+ - Passing arguments via the command line.
75
+ - Using a `typedoc.json` file.
76
+ - Under the `typedocOptions` key in `tsconfig.json`.
77
+
78
+ Please see https://typedoc.org/options/configuration for general TypeDoc option configuration.
79
+
68
80
  ### TypeDoc options
69
81
 
70
- To configure TypeDoc, pass any relevant [TypeDoc options](https://typedoc.org/guides/options/) to the config.
82
+ The following TypeDoc / Markdown plugin options can be passed to config:
71
83
 
72
- At a minimum the `entryPoints` and `tsconfig` options will need to be set.
84
+ - [typedoc](https://typedoc.org/options) options (HTML specific output options that will be ignored).
85
+ - [typedoc-plugin-markdown ](https://github.com/tgreyuk/typedoc-plugin-markdown/tree/next/packages/typedoc-plugin-markdown#options) options (Some options are already preset to target Docusaurus).
73
86
 
74
- ```js
75
- entryPoints: ['../src/index.ts'],
76
- tsconfig: '../tsconfig.json'
87
+ The following typedoc-plugin-markdown options are preset with the plugin.
88
+
89
+ ```json
90
+ {
91
+ "out": "api",
92
+ "hideInPageTOC": true,
93
+ "hideBreadcrumbs": true,
94
+ "hidePageHeader": true,
95
+ "entryFileName": "index.md",
96
+ "globalsPageStrategy": "skip",
97
+ "includeFileNumberPrefixes": true
98
+ }
77
99
  ```
78
100
 
79
- Additional TypeDoc plugins will need to be explicitly set:
101
+ ### Plugin options
80
102
 
81
- ```js
82
- plugin: ['typedoc-plugin-xyz'];
83
- ```
103
+ Options specific to the plugin should also be declared in the same object.
84
104
 
85
- #### Other config options
105
+ #### `--sidebar`
86
106
 
87
- TypeDoc options can also be declared:
107
+ `sidebar.autoConfiguration`
88
108
 
89
- - Using a `typedoc.json` file.
90
- - Under the `typedocOptions` key in `tsconfig.json`.
109
+ Set to `false` to disable sidebar generation. Defaults to `true`.
91
110
 
92
- > Note: Options declared in this manner will take priority and overwrite options declared in `docusaurus.config.js`.
111
+ `sidebar.categoryLabel`
93
112
 
94
- ### Plugin options
113
+ The sidebar main parent category label. Defaults to `API`.
95
114
 
96
- Options specific to the plugin should also be declared in the same object.
115
+ `sidebar.indexLabel`
116
+
117
+ The label of the main index page. Please note if `readme=none` this option has no effect because the index page becomes the root page. Defaults to `Index`.
118
+
119
+ `sidebar.position`
120
+
121
+ The position of the sidebar in the tree.
122
+
123
+ #### `--docsRoot`
124
+
125
+ The Docusaurus docs folder root. Use `./` if no root folder specified. Defaults to `./docs`.
97
126
 
98
- | Name | Default | Description |
99
- | :---------------------- | :------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
100
- | `out` | `"api"` | Output dir relative to docs dir (use `.` for no subdir). |
101
- | `includeExtension` | `true` | Determines whether to preserve the `.md` extension in relative links. `true` is recommended as per [Docusaurus documentation](https://docusaurus.io/docs/docs-markdown-features#referencing-other-documents) |
102
- | `frontmatter` | `null` | Additional frontmatter options object. See [Frontmatter](#frontmatter). |
103
- | `sidebar.categoryLabel` | `API` | The sidebar parent category label. |
104
- | `sidebar.fullNames` | `false` | Display full names with module path. |
105
- | `sidebar.position` | `auto` | The position of the sidebar in the tree. |
127
+ ```shell
128
+ --docsRoot <path/to/vitepress-docs/>
129
+ ```
106
130
 
107
131
  ### An example configuration
108
132
 
@@ -130,6 +154,21 @@ module.exports = {
130
154
  };
131
155
  ```
132
156
 
157
+ ## Frontmatter
158
+
159
+ Additional frontmatter options can be added to the config. Please see [typedoc-plugin-frontmatter](https://github.com/tgreyuk/typedoc-plugin-frontmatter#typedoc-plugin-frontmatter).
160
+
161
+ For example:
162
+
163
+ ```json
164
+ {
165
+ "frontmatterGlobals": {
166
+ "pagination_prev": null,
167
+ "pagination_next": null
168
+ }
169
+ }
170
+ ```
171
+
133
172
  ## Recipes
134
173
 
135
174
  ### Sidebar and Navbar
@@ -192,27 +231,6 @@ A navbar item can be configured in `themeConfig` options in `docusaurus.config.j
192
231
 
193
232
  Please see https://docusaurus.io/docs/api/themes/configuration#navbar-items for navbar documentation.
194
233
 
195
- ### Frontmatter
196
-
197
- By default the plugin will configure minimal required [Frontmatter](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-docs#markdown-front-matter) configuration.
198
- Additionally required global Frontmatter options can be passed in using the `frontmatter` options object
199
-
200
- `docusaurus.config.js`:
201
-
202
- ```js
203
- plugins: [
204
- [
205
- 'docusaurus-plugin-typedoc',
206
- {
207
- // .... other plugin option
208
- frontmatter: {
209
- pagination_prev: null,
210
- pagination_next: null
211
- }
212
- ]
213
- ]
214
- ```
215
-
216
234
  ### Multi instance
217
235
 
218
236
  It is possible to build multi TypeDoc instances by passing in multiple configs with unique ids:
@@ -274,27 +292,6 @@ module.exports = {
274
292
  };
275
293
  ```
276
294
 
277
- ### Monorepo setup
278
-
279
- `docusaurus.config.js`
280
-
281
- ```js
282
- module.exports = {
283
- plugins: [
284
- [
285
- 'docusaurus-plugin-typedoc',
286
- {
287
- entryPoints: ['../packages/package-a', '../packages/package-b'],
288
- entryPointStrategy: 'packages',
289
- sidebar: {
290
- fullNames: true,
291
- },
292
- },
293
- ],
294
- ],
295
- };
296
- ```
297
-
298
295
  ## License
299
296
 
300
297
  [MIT](https://github.com/tgreyuk/typedoc-plugin-markdown/blob/master/packages/docusaurus-plugin-typedoc/LICENSE)
package/dist/index.d.ts CHANGED
@@ -1 +1,6 @@
1
- export { default } from './plugin';
1
+ import { PluginOptions } from './models';
2
+ export default function pluginDocusaurus(context: any, opts: Partial<PluginOptions>): {
3
+ name: string;
4
+ loadContent(): Promise<void>;
5
+ extendCli(cli: any): void;
6
+ };
package/dist/index.js CHANGED
@@ -1,8 +1,81 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
4
24
  };
5
25
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = void 0;
7
- var plugin_1 = require("./plugin");
8
- Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(plugin_1).default; } });
26
+ const path = __importStar(require("path"));
27
+ const typedoc_1 = require("typedoc");
28
+ const options_1 = require("./options");
29
+ const renderer_1 = require("./renderer");
30
+ const apps = [];
31
+ function pluginDocusaurus(context, opts) {
32
+ return {
33
+ name: 'docusaurus-plugin-typedoc',
34
+ async loadContent() {
35
+ if (opts.id && !apps.includes(opts.id)) {
36
+ apps.push(opts.id);
37
+ generateTypedoc(context, opts);
38
+ }
39
+ },
40
+ extendCli(cli) {
41
+ cli
42
+ .command('generate-typedoc')
43
+ .description('(docusaurus-plugin-typedoc) Generate TypeDoc docs independently of the Docusaurus build process.')
44
+ .action(async () => {
45
+ var _a;
46
+ (_a = context.siteConfig) === null || _a === void 0 ? void 0 : _a.plugins.forEach((pluginConfig) => {
47
+ if (pluginConfig && typeof pluginConfig[1] === 'object') {
48
+ generateTypedoc(context, pluginConfig[1]);
49
+ }
50
+ });
51
+ });
52
+ },
53
+ };
54
+ }
55
+ exports.default = pluginDocusaurus;
56
+ async function generateTypedoc(context, opts) {
57
+ const { siteDir } = context;
58
+ const options = (0, options_1.getPluginOptions)(opts);
59
+ const { id, docsRoot, ...optionsPassedToTypeDoc } = options;
60
+ const outputDir = path.resolve(siteDir, options.docsRoot, options.out);
61
+ const app = new typedoc_1.Application();
62
+ (0, options_1.loadOptions)(app);
63
+ (0, renderer_1.loadRenderer)(app);
64
+ await app.bootstrapWithPlugins(optionsPassedToTypeDoc);
65
+ const project = app.convert();
66
+ if (!project) {
67
+ if (app.options.getValue('skipErrorChecking')) {
68
+ return;
69
+ }
70
+ console.error('[docusaurus-plugin-typedoc] TypeDoc exited with an error. Use the "skipErrorChecking" option to disable TypeDoc error checking.');
71
+ process.exit();
72
+ }
73
+ if (options.watch) {
74
+ app.convertAndWatch(async (project) => {
75
+ await app.generateDocs(project, outputDir);
76
+ });
77
+ }
78
+ else {
79
+ await app.generateDocs(project, outputDir);
80
+ }
81
+ }
@@ -0,0 +1,23 @@
1
+ import { TypedocPluginMarkdownOptions } from 'typedoc-plugin-markdown';
2
+ export interface PluginOptions extends TypedocPluginMarkdownOptions {
3
+ id: string;
4
+ docsRoot: string;
5
+ sidebar: SidebarOptions;
6
+ }
7
+ export interface SidebarOptions {
8
+ categoryLabel: string;
9
+ position: number | null;
10
+ autoConfiguration: boolean;
11
+ }
12
+ export interface SidebarCategory {
13
+ type: string;
14
+ label: string;
15
+ items: SidebarItem[];
16
+ }
17
+ export interface CategoryYamlOptions {
18
+ path: string;
19
+ label: string;
20
+ position: number | null;
21
+ collapsed: boolean;
22
+ }
23
+ export type SidebarItem = SidebarCategory | string;
package/dist/options.d.ts CHANGED
@@ -1,2 +1,4 @@
1
- import { PluginOptions } from './types';
2
- export declare const getPluginOptions: (opts: Partial<PluginOptions>) => PluginOptions;
1
+ import { Application } from 'typedoc';
2
+ import { PluginOptions } from './models';
3
+ export declare function getPluginOptions(opts: Partial<PluginOptions>): PluginOptions;
4
+ export declare function loadOptions(app: Application): void;
package/dist/options.js CHANGED
@@ -1,32 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPluginOptions = void 0;
3
+ exports.loadOptions = exports.getPluginOptions = void 0;
4
+ const typedoc_1 = require("typedoc");
4
5
  const DEFAULT_PLUGIN_OPTIONS = {
5
6
  id: 'default',
6
7
  docsRoot: 'docs',
7
8
  out: 'api',
8
- cleanOutputDir: true,
9
+ watch: false,
10
+ plugin: [],
11
+ hideInPageTOC: true,
12
+ hideBreadcrumbs: true,
13
+ hidePageHeader: true,
14
+ includeFileNumberPrefixes: true,
15
+ skipIndexPage: true,
16
+ entryFileName: 'index.md',
9
17
  sidebar: {
10
- fullNames: false,
11
18
  categoryLabel: 'API',
12
- collapsed: true,
13
- indexLabel: undefined,
14
- readmeLabel: 'Readme',
15
19
  position: null,
16
20
  autoConfiguration: true,
17
21
  },
18
- hideInPageTOC: true,
19
- hideBreadcrumbs: true,
20
- hidePageTitle: false,
21
- entryDocument: 'index.md',
22
- plugin: ['none'],
23
- watch: false,
24
- includeExtension: true,
25
- indexSlug: undefined,
26
- theme: 'docusaurus',
27
- frontmatter: undefined,
28
22
  };
29
- const getPluginOptions = (opts) => {
23
+ function getPluginOptions(opts) {
30
24
  const options = {
31
25
  ...DEFAULT_PLUGIN_OPTIONS,
32
26
  ...opts,
@@ -36,5 +30,31 @@ const getPluginOptions = (opts) => {
36
30
  },
37
31
  };
38
32
  return options;
39
- };
33
+ }
40
34
  exports.getPluginOptions = getPluginOptions;
35
+ function loadOptions(app) {
36
+ app.options.addReader(new typedoc_1.PackageJsonReader());
37
+ app.options.addReader(new typedoc_1.TypeDocReader());
38
+ app.options.addReader(new typedoc_1.TSConfigReader());
39
+ app.options.addDeclaration({
40
+ name: 'sidebar',
41
+ type: typedoc_1.ParameterType.Mixed,
42
+ });
43
+ app.options.addReader(new (class {
44
+ constructor() {
45
+ this.name = 'docusaurus-options';
46
+ this.order = 900;
47
+ this.supportsPackages = false;
48
+ }
49
+ read(container) {
50
+ const plugins = container.getValue('plugin');
51
+ ['typedoc-plugin-markdown', 'typedoc-plugin-frontmatter'].forEach((defaultPlugin) => {
52
+ if (!plugins.includes(defaultPlugin)) {
53
+ plugins.push(defaultPlugin);
54
+ }
55
+ });
56
+ container.setValue('plugin', plugins);
57
+ }
58
+ })());
59
+ }
60
+ exports.loadOptions = loadOptions;
@@ -0,0 +1,2 @@
1
+ import { Application } from 'typedoc';
2
+ export declare function loadRenderer(app: Application): void;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadRenderer = void 0;
4
+ const typedoc_1 = require("typedoc");
5
+ const typedoc_plugin_frontmatter_1 = require("typedoc-plugin-frontmatter");
6
+ function loadRenderer(app) {
7
+ app.renderer.on(typedoc_1.PageEvent.END, (page) => {
8
+ if (page.contents) {
9
+ page.contents = page.contents.replace(/\\</g, '<');
10
+ }
11
+ });
12
+ app.renderer.on(typedoc_plugin_frontmatter_1.FrontmatterEvent.PREPARE_FRONTMATTER, (event) => {
13
+ loadFrontmatter(app, event);
14
+ });
15
+ }
16
+ exports.loadRenderer = loadRenderer;
17
+ function loadFrontmatter(app, event) {
18
+ var _a, _b, _c, _d, _e, _f, _g;
19
+ const renderContext = app.renderer.theme.getRenderContext();
20
+ const sidebar = app.options.getValue('sidebar');
21
+ const isIndexPage = (_a = event.page) === null || _a === void 0 ? void 0 : _a.url.endsWith(renderContext.indexFileName);
22
+ const isReadmePage = (_b = event.page) === null || _b === void 0 ? void 0 : _b.url.endsWith(app.options.getValue('entryFileName'));
23
+ const isPackageModule = event.page.model.kindOf(typedoc_1.ReflectionKind.Module) &&
24
+ !Boolean(((_c = event.page.model) === null || _c === void 0 ? void 0 : _c.parent).groups);
25
+ const model = (_d = event.page) === null || _d === void 0 ? void 0 : _d.model;
26
+ let pluginFrontmatter = {};
27
+ if (sidebar.autoConfiguration) {
28
+ if (!isIndexPage && !isReadmePage) {
29
+ const sidebarLabel = model === null || model === void 0 ? void 0 : model.name;
30
+ pluginFrontmatter = {
31
+ ...pluginFrontmatter,
32
+ sidebar_label: sidebarLabel,
33
+ };
34
+ }
35
+ if (((_e = event.page) === null || _e === void 0 ? void 0 : _e.url) === app.options.getValue('entryFileName')) {
36
+ if (sidebar.categoryLabel) {
37
+ pluginFrontmatter = {
38
+ ...pluginFrontmatter,
39
+ sidebar_label: sidebar.categoryLabel,
40
+ };
41
+ }
42
+ if (sidebar.position !== null && !Number.isNaN(sidebar.position)) {
43
+ pluginFrontmatter = {
44
+ ...pluginFrontmatter,
45
+ sidebar_position: sidebar.position,
46
+ };
47
+ }
48
+ }
49
+ if ((_f = event.page) === null || _f === void 0 ? void 0 : _f.url.endsWith(app.options.getValue('entryFileName'))) {
50
+ pluginFrontmatter = {
51
+ ...pluginFrontmatter,
52
+ hide_table_of_contents: true,
53
+ };
54
+ }
55
+ if (isPackageModule && isReadmePage) {
56
+ pluginFrontmatter = {
57
+ ...pluginFrontmatter,
58
+ sidebar_label: event.page.model.name,
59
+ };
60
+ }
61
+ if (isPackageModule && isIndexPage && Boolean((_g = event.page.model) === null || _g === void 0 ? void 0 : _g.readme)) {
62
+ pluginFrontmatter = {
63
+ ...pluginFrontmatter,
64
+ sidebar_label: 'Index',
65
+ };
66
+ }
67
+ }
68
+ event.frontmatter = {
69
+ ...pluginFrontmatter,
70
+ ...event.frontmatter,
71
+ };
72
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-typedoc",
3
- "version": "1.0.0-next.0",
3
+ "version": "1.0.0-next.10",
4
4
  "description": "A Docusaurus v2 plugin to build API documentation with TypeDoc.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -15,9 +15,11 @@
15
15
  "directory": "packages/docusaurus-plugin-typedoc"
16
16
  },
17
17
  "homepage": "https://github.com/tgreyuk/typedoc-plugin-markdown/tree/master/packages/docusaurus-plugin-typedoc",
18
+ "dependencies": {
19
+ "typedoc-plugin-frontmatter": "^0.0.2"
20
+ },
18
21
  "peerDependencies": {
19
- "typedoc": ">=0.23.0",
20
- "typedoc-plugin-markdown": ">=4.0.0-next.0"
22
+ "typedoc-plugin-markdown": ">=4.0.0-next.12"
21
23
  },
22
24
  "scripts": {
23
25
  "lint": "eslint ./src --ext .ts",
@@ -1,4 +0,0 @@
1
- export interface FrontMatterVars {
2
- [key: string]: string | number | boolean;
3
- }
4
- export declare const prependYAML: (contents: string, vars: FrontMatterVars) => string;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prependYAML = void 0;
4
- const prependYAML = (contents, vars) => {
5
- return contents
6
- .replace(/^/, toYAML(vars) + '\n\n')
7
- .replace(/[\r\n]{3,}/g, '\n\n');
8
- };
9
- exports.prependYAML = prependYAML;
10
- const toYAML = (vars) => {
11
- const yaml = `---
12
- ${Object.entries(vars)
13
- .map(([key, value]) => `${key}: ${typeof value === 'string' ? `"${escapeString(value)}"` : value}`)
14
- .join('\n')}
15
- ---`;
16
- return yaml;
17
- };
18
- const escapeString = (str) => str.replace(/"/g, '\\"');
@@ -1,13 +0,0 @@
1
- import { ReflectionKind } from 'typedoc';
2
- export declare const CATEGORY_POSITION: {
3
- 2: number;
4
- 4: number;
5
- 8: number;
6
- 128: number;
7
- 256: number;
8
- 4194304: number;
9
- 32: number;
10
- 64: number;
11
- 2097152: number;
12
- };
13
- export declare function getKindPlural(kind: ReflectionKind): string;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getKindPlural = exports.CATEGORY_POSITION = void 0;
4
- const typedoc_1 = require("typedoc");
5
- const PLURALS = {
6
- [typedoc_1.ReflectionKind.Class]: 'Classes',
7
- [typedoc_1.ReflectionKind.Property]: 'Properties',
8
- [typedoc_1.ReflectionKind.Enum]: 'Enumerations',
9
- [typedoc_1.ReflectionKind.EnumMember]: 'Enumeration members',
10
- [typedoc_1.ReflectionKind.TypeAlias]: 'Type aliases',
11
- };
12
- exports.CATEGORY_POSITION = {
13
- [typedoc_1.ReflectionKind.Module]: 1,
14
- [typedoc_1.ReflectionKind.Namespace]: 1,
15
- [typedoc_1.ReflectionKind.Enum]: 2,
16
- [typedoc_1.ReflectionKind.Class]: 3,
17
- [typedoc_1.ReflectionKind.Interface]: 4,
18
- [typedoc_1.ReflectionKind.TypeAlias]: 5,
19
- [typedoc_1.ReflectionKind.Variable]: 6,
20
- [typedoc_1.ReflectionKind.Function]: 7,
21
- [typedoc_1.ReflectionKind.ObjectLiteral]: 8,
22
- };
23
- function getKindPlural(kind) {
24
- if (kind in PLURALS) {
25
- return PLURALS[kind];
26
- }
27
- else {
28
- return getKindString(kind) + 's';
29
- }
30
- }
31
- exports.getKindPlural = getKindPlural;
32
- function getKindString(kind) {
33
- let str = typedoc_1.ReflectionKind[kind];
34
- str = str.replace(/(.)([A-Z])/g, (_m, a, b) => a + ' ' + b.toLowerCase());
35
- return str;
36
- }
package/dist/plugin.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { PluginOptions } from './types';
2
- export default function pluginDocusaurus(context: any, opts: Partial<PluginOptions>): {
3
- name: string;
4
- loadContent(): Promise<void>;
5
- extendCli(cli: any): void;
6
- };
package/dist/plugin.js DELETED
@@ -1,81 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const path = __importStar(require("path"));
27
- const typedoc_1 = require("typedoc");
28
- const typedoc_plugin_markdown_1 = require("typedoc-plugin-markdown");
29
- const options_1 = require("./options");
30
- const render_1 = require("./render");
31
- const theme_1 = require("./theme");
32
- const apps = [];
33
- function pluginDocusaurus(context, opts) {
34
- return {
35
- name: 'docusaurus-plugin-typedoc',
36
- async loadContent() {
37
- if (opts.id && !apps.includes(opts.id)) {
38
- apps.push(opts.id);
39
- generateTypedoc(context, opts);
40
- }
41
- },
42
- extendCli(cli) {
43
- cli
44
- .command('generate-typedoc')
45
- .description('(docusaurus-plugin-typedoc) Generate TypeDoc docs independently of the Docusaurus build process.')
46
- .action(async () => {
47
- var _a;
48
- (_a = context.siteConfig) === null || _a === void 0 ? void 0 : _a.plugins.forEach((pluginConfig) => {
49
- if (pluginConfig && typeof pluginConfig[1] === 'object') {
50
- generateTypedoc(context, pluginConfig[1]);
51
- }
52
- });
53
- });
54
- },
55
- };
56
- }
57
- exports.default = pluginDocusaurus;
58
- async function generateTypedoc(context, opts) {
59
- const { siteDir } = context;
60
- const options = (0, options_1.getPluginOptions)(opts);
61
- const outputDir = path.resolve(siteDir, options.docsRoot, options.out);
62
- if (opts.cleanOutputDir) {
63
- (0, render_1.removeDir)(outputDir);
64
- }
65
- const app = new typedoc_1.Application();
66
- app.renderer.defineTheme('docusaurus', theme_1.DocusaurusTheme);
67
- (0, typedoc_plugin_markdown_1.load)(app);
68
- (0, render_1.bootstrap)(app, options);
69
- const project = app.convert();
70
- if (!project) {
71
- return;
72
- }
73
- if (options.watch) {
74
- app.convertAndWatch(async (project) => {
75
- await app.generateDocs(project, outputDir);
76
- });
77
- }
78
- else {
79
- await app.generateDocs(project, outputDir);
80
- }
81
- }
package/dist/render.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { Application, ProjectReflection } from 'typedoc';
2
- import { PluginOptions } from './types';
3
- export declare const bootstrap: (app: Application, options: PluginOptions) => void;
4
- export declare function render(project: ProjectReflection, outputDirectory: string): Promise<void>;
5
- export declare function removeDir(path: string): void;
package/dist/render.js DELETED
@@ -1,90 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.removeDir = exports.render = exports.bootstrap = void 0;
27
- const fs = __importStar(require("fs"));
28
- const typedoc_1 = require("typedoc");
29
- const bootstrap = (app, options) => {
30
- addTypedocReaders(app);
31
- addTypedocDeclarations(app);
32
- app.renderer.render = render;
33
- app.bootstrap(options);
34
- };
35
- exports.bootstrap = bootstrap;
36
- async function render(project, outputDirectory) {
37
- var _a;
38
- if (!this.prepareTheme()) {
39
- return;
40
- }
41
- const output = new typedoc_1.RendererEvent(typedoc_1.RendererEvent.BEGIN, outputDirectory, project);
42
- output.urls = this.theme.getUrls(project);
43
- this.trigger(output);
44
- if (!output.isDefaultPrevented) {
45
- (_a = output === null || output === void 0 ? void 0 : output.urls) === null || _a === void 0 ? void 0 : _a.forEach((mapping) => {
46
- this.renderDocument(output.createPageEvent(mapping));
47
- });
48
- this.trigger(typedoc_1.RendererEvent.END, output);
49
- }
50
- }
51
- exports.render = render;
52
- const addTypedocReaders = (app) => {
53
- app.options.addReader(new typedoc_1.TypeDocReader());
54
- app.options.addReader(new typedoc_1.TSConfigReader());
55
- };
56
- const addTypedocDeclarations = (app) => {
57
- app.options.addDeclaration({
58
- name: 'id',
59
- });
60
- app.options.addDeclaration({
61
- name: 'docsRoot',
62
- });
63
- app.options.addDeclaration({
64
- name: 'siteDir',
65
- });
66
- app.options.addDeclaration({
67
- name: 'globalsTitle',
68
- });
69
- app.options.addDeclaration({
70
- name: 'readmeTitle',
71
- });
72
- app.options.addDeclaration({
73
- name: 'indexSlug',
74
- });
75
- app.options.addDeclaration({
76
- name: 'includeExtension',
77
- });
78
- app.options.addDeclaration({
79
- name: 'sidebar',
80
- type: typedoc_1.ParameterType.Mixed,
81
- });
82
- app.options.addDeclaration({
83
- name: 'frontmatter',
84
- type: typedoc_1.ParameterType.Mixed,
85
- });
86
- };
87
- function removeDir(path) {
88
- fs.rmSync(path, { recursive: true, force: true });
89
- }
90
- exports.removeDir = removeDir;
package/dist/theme.d.ts DELETED
@@ -1,19 +0,0 @@
1
- import { DeclarationReflection, PageEvent, Renderer, RendererEvent } from 'typedoc';
2
- import { MarkdownTheme } from 'typedoc-plugin-markdown';
3
- import { FrontMatter, SidebarOptions } from './types';
4
- export declare class DocusaurusTheme extends MarkdownTheme {
5
- sidebar: SidebarOptions;
6
- readmeTitle: string;
7
- indexSlug: string;
8
- includeExtension: string;
9
- frontmatter: FrontMatter;
10
- constructor(renderer: Renderer);
11
- onPageEnd(page: PageEvent<DeclarationReflection>): void;
12
- onRendererEnd(renderer: RendererEvent): void;
13
- loopAndWriteCategories(path: string): void;
14
- writeCategoryYaml: (categoryPath: string, label: string, position: number | null, collapsed: boolean) => void;
15
- getYamlItems(page: PageEvent<DeclarationReflection>): FrontMatter;
16
- getSidebarLabel(page: PageEvent<DeclarationReflection>): string | undefined;
17
- getSidebarPosition(page: PageEvent<DeclarationReflection>): "0.5" | "0" | null;
18
- get globalsFile(): string;
19
- }
package/dist/theme.js DELETED
@@ -1,157 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
- return c > 3 && r && Object.defineProperty(target, key, r), r;
23
- };
24
- var __importStar = (this && this.__importStar) || function (mod) {
25
- if (mod && mod.__esModule) return mod;
26
- var result = {};
27
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
- __setModuleDefault(result, mod);
29
- return result;
30
- };
31
- Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.DocusaurusTheme = void 0;
33
- const fs = __importStar(require("fs"));
34
- const typedoc_1 = require("typedoc");
35
- const typedoc_plugin_markdown_1 = require("typedoc-plugin-markdown");
36
- const front_matter_1 = require("./front-matter");
37
- const navigation_1 = require("./navigation");
38
- class DocusaurusTheme extends typedoc_plugin_markdown_1.MarkdownTheme {
39
- constructor(renderer) {
40
- super(renderer);
41
- this.writeCategoryYaml = (categoryPath, label, position, collapsed) => {
42
- const yaml = [`label: "${label}"`];
43
- if (position !== null) {
44
- yaml.push(`position: ${position}`);
45
- }
46
- if (!collapsed) {
47
- yaml.push(`collapsed: false`);
48
- }
49
- if (fs.existsSync(categoryPath)) {
50
- fs.writeFileSync(categoryPath + '/_category_.yml', yaml.join('\n'));
51
- }
52
- };
53
- this.listenTo(this.application.renderer, {
54
- [typedoc_1.PageEvent.END]: this.onPageEnd,
55
- [typedoc_1.RendererEvent.END]: this.onRendererEnd,
56
- });
57
- }
58
- onPageEnd(page) {
59
- if (page.contents) {
60
- page.contents = (0, front_matter_1.prependYAML)(page.contents.replace(/\\</g, '<'), this.getYamlItems(page));
61
- }
62
- }
63
- onRendererEnd(renderer) {
64
- if (this.sidebar.autoConfiguration) {
65
- this.writeCategoryYaml(renderer.outputDirectory, this.sidebar.categoryLabel, this.sidebar.position, this.sidebar.collapsed);
66
- this.loopAndWriteCategories(renderer.outputDirectory);
67
- }
68
- }
69
- loopAndWriteCategories(path) {
70
- const directory = fs.readdirSync(path);
71
- directory.forEach((segment) => {
72
- const fullPath = `${path}/${segment}`;
73
- const isDirectory = fs.lstatSync(fullPath).isDirectory();
74
- if (isDirectory) {
75
- const mapping = Object.entries(this.mappings)
76
- .filter((entry) => {
77
- return entry[1].directory === segment;
78
- })
79
- .map((entry) => entry[1])[0];
80
- if (mapping) {
81
- this.writeCategoryYaml(fullPath, (0, navigation_1.getKindPlural)(mapping.kind), navigation_1.CATEGORY_POSITION[mapping.kind], true);
82
- }
83
- this.loopAndWriteCategories(fullPath);
84
- }
85
- });
86
- }
87
- getYamlItems(page) {
88
- const sidebarLabel = this.getSidebarLabel(page);
89
- const sidebarPosition = this.getSidebarPosition(page);
90
- let items = {};
91
- if (page.url === this.entryDocument && this.indexSlug) {
92
- items = { ...items, slug: this.indexSlug };
93
- }
94
- if (this.sidebar.autoConfiguration) {
95
- if (sidebarLabel) {
96
- items = { ...items, sidebar_label: sidebarLabel };
97
- }
98
- if (sidebarPosition) {
99
- items = { ...items, sidebar_position: parseFloat(sidebarPosition) };
100
- }
101
- }
102
- if (page.url === page.project.url && this.entryPoints.length > 1) {
103
- items = { ...items, hide_table_of_contents: true };
104
- }
105
- items = { ...items, custom_edit_url: null };
106
- if (this.frontmatter) {
107
- items = { ...items, ...this.frontmatter };
108
- }
109
- return {
110
- ...items,
111
- };
112
- }
113
- getSidebarLabel(page) {
114
- const indexLabel = this.sidebar.indexLabel ||
115
- (this.entryPoints.length > 1 ? 'Table of Contents' : 'Exports');
116
- if (page.url === this.entryDocument) {
117
- return page.url === page.project.url
118
- ? indexLabel
119
- : this.sidebar.readmeLabel;
120
- }
121
- if (page.url === this.globalsFile) {
122
- return indexLabel;
123
- }
124
- return this.sidebar.fullNames ? page.model.getFullName() : page.model.name;
125
- }
126
- getSidebarPosition(page) {
127
- if (page.url === this.entryDocument) {
128
- return page.url === page.project.url ? '0.5' : '0';
129
- }
130
- if (page.url === this.globalsFile) {
131
- return '0.5';
132
- }
133
- if (page.model.getFullName().split('.').length === 1) {
134
- return '0';
135
- }
136
- return null;
137
- }
138
- get globalsFile() {
139
- return 'modules.md';
140
- }
141
- }
142
- __decorate([
143
- (0, typedoc_1.BindOption)('sidebar')
144
- ], DocusaurusTheme.prototype, "sidebar", void 0);
145
- __decorate([
146
- (0, typedoc_1.BindOption)('readmeTitle')
147
- ], DocusaurusTheme.prototype, "readmeTitle", void 0);
148
- __decorate([
149
- (0, typedoc_1.BindOption)('indexSlug')
150
- ], DocusaurusTheme.prototype, "indexSlug", void 0);
151
- __decorate([
152
- (0, typedoc_1.BindOption)('includeExtension')
153
- ], DocusaurusTheme.prototype, "includeExtension", void 0);
154
- __decorate([
155
- (0, typedoc_1.BindOption)('frontmatter')
156
- ], DocusaurusTheme.prototype, "frontmatter", void 0);
157
- exports.DocusaurusTheme = DocusaurusTheme;
package/dist/types.d.ts DELETED
@@ -1,38 +0,0 @@
1
- export interface PluginOptions {
2
- id: string;
3
- docsRoot: string;
4
- out: string;
5
- sidebar: SidebarOptions;
6
- readmeTitle?: string;
7
- globalsTitle?: string;
8
- plugin: string[];
9
- readme?: string;
10
- disableOutputCheck?: boolean;
11
- cleanOutputDir?: boolean;
12
- entryPoints?: string[];
13
- watch: boolean;
14
- hideInPageTOC: boolean;
15
- hideBreadcrumbs: boolean;
16
- hidePageTitle: boolean;
17
- entryDocument: string;
18
- includeExtension?: boolean;
19
- indexSlug?: string;
20
- theme?: string;
21
- frontmatter: FrontMatter;
22
- }
23
- export type FrontMatter = Record<string, string | boolean | number | null> | undefined;
24
- export interface SidebarOptions {
25
- fullNames?: boolean;
26
- categoryLabel: string;
27
- collapsed: boolean;
28
- indexLabel?: string;
29
- readmeLabel?: string;
30
- position: number | null;
31
- autoConfiguration: boolean;
32
- }
33
- export interface SidebarCategory {
34
- type: string;
35
- label: string;
36
- items: SidebarItem[];
37
- }
38
- export type SidebarItem = SidebarCategory | string;
File without changes