docusaurus-plugin-typedoc 1.0.0-next.7 → 1.0.0-next.9

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) and [typedoc-plugin-frontmatter]() are required 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 typedoc-plugin-frontmatter@next --save-dev
18
22
  ```
19
23
 
20
24
  ## Usage
@@ -65,42 +69,63 @@ 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
+ "entryDocument": "index.md",
96
+ "includeFileNumberPrefixes": true
97
+ }
77
98
  ```
78
99
 
79
- Additional TypeDoc plugins will need to be explicitly set:
100
+ ### Plugin options
80
101
 
81
- ```js
82
- plugin: ['typedoc-plugin-xyz'];
83
- ```
102
+ Options specific to the plugin should also be declared in the same object.
84
103
 
85
- #### Other config options
104
+ #### `--sidebar`
86
105
 
87
- TypeDoc options can also be declared:
106
+ `sidebar.autoConfiguration`
88
107
 
89
- - Using a `typedoc.json` file.
90
- - Under the `typedocOptions` key in `tsconfig.json`.
108
+ Set to `false` to disable sidebar generation. Defaults to `true`.
91
109
 
92
- > Note: Options declared in this manner will take priority and overwrite options declared in `docusaurus.config.js`.
110
+ `sidebar.categoryLabel`
93
111
 
94
- ### Plugin options
112
+ The sidebar main parent category label. Defaults to `API`.
95
113
 
96
- Options specific to the plugin should also be declared in the same object.
114
+ `sidebar.indexLabel`
115
+
116
+ 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`.
117
+
118
+ `sidebar.position`
119
+
120
+ The position of the sidebar in the tree.
121
+
122
+ #### `--docsRoot`
123
+
124
+ The Docusaurus docs folder root. Use `./` if no root folder specified. Defaults to `./docs`.
97
125
 
98
- | Name | Default | Description |
99
- | :---------------------- | :------ | :------------------------------------------------------- |
100
- | `out` | `"api"` | Output dir relative to docs dir (use `.` for no subdir). |
101
- | `sidebar.categoryLabel` | `API` | The sidebar parent category label. |
102
- | `sidebar.fullNames` | `false` | Display full names with module path. |
103
- | `sidebar.position` | `auto` | The position of the sidebar in the tree. |
126
+ ```shell
127
+ --docsRoot <path/to/vitepress-docs/>
128
+ ```
104
129
 
105
130
  ### An example configuration
106
131
 
@@ -128,6 +153,21 @@ module.exports = {
128
153
  };
129
154
  ```
130
155
 
156
+ ## Frontmatter
157
+
158
+ Additional frontmatter options can be added to the config. Please see [typedoc-plugin-frontmatter](https://github.com/tgreyuk/typedoc-plugin-frontmatter#typedoc-plugin-frontmatter).
159
+
160
+ For example:
161
+
162
+ ```json
163
+ {
164
+ "frontmatterGlobals": {
165
+ "pagination_prev": null,
166
+ "pagination_next": null
167
+ }
168
+ }
169
+ ```
170
+
131
171
  ## Recipes
132
172
 
133
173
  ### Sidebar and Navbar
@@ -190,27 +230,6 @@ A navbar item can be configured in `themeConfig` options in `docusaurus.config.j
190
230
 
191
231
  Please see https://docusaurus.io/docs/api/themes/configuration#navbar-items for navbar documentation.
192
232
 
193
- ### Frontmatter
194
-
195
- By default the plugin will configure minimal required [Frontmatter](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-docs#markdown-front-matter) configuration.
196
- Additionally required global Frontmatter options can be passed in using the `frontmatterGlobals` options object
197
-
198
- `docusaurus.config.js`:
199
-
200
- ```js
201
- plugins: [
202
- [
203
- 'docusaurus-plugin-typedoc',
204
- {
205
- // .... other plugin option
206
- frontmatterGlobals: {
207
- pagination_prev: null,
208
- pagination_next: null
209
- }
210
- ]
211
- ]
212
- ```
213
-
214
233
  ### Multi instance
215
234
 
216
235
  It is possible to build multi TypeDoc instances by passing in multiple configs with unique ids:
@@ -272,27 +291,6 @@ module.exports = {
272
291
  };
273
292
  ```
274
293
 
275
- ### Monorepo setup
276
-
277
- `docusaurus.config.js`
278
-
279
- ```js
280
- module.exports = {
281
- plugins: [
282
- [
283
- 'docusaurus-plugin-typedoc',
284
- {
285
- entryPoints: ['../packages/package-a', '../packages/package-b'],
286
- entryPointStrategy: 'packages',
287
- sidebar: {
288
- fullNames: true,
289
- },
290
- },
291
- ],
292
- ],
293
- };
294
- ```
295
-
296
294
  ## License
297
295
 
298
296
  [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
+ }
package/dist/models.d.ts CHANGED
@@ -6,13 +6,19 @@ export interface PluginOptions extends TypedocPluginMarkdownOptions {
6
6
  }
7
7
  export interface SidebarOptions {
8
8
  categoryLabel: string;
9
- collapsed: boolean;
10
9
  position: number | null;
11
10
  autoConfiguration: boolean;
11
+ indexLabel: string;
12
12
  }
13
13
  export interface SidebarCategory {
14
14
  type: string;
15
15
  label: string;
16
16
  items: SidebarItem[];
17
17
  }
18
+ export interface CategoryYamlOptions {
19
+ path: string;
20
+ label: string;
21
+ position: number | null;
22
+ collapsed: boolean;
23
+ }
18
24
  export type SidebarItem = SidebarCategory | string;
package/dist/options.d.ts CHANGED
@@ -1,2 +1,4 @@
1
+ import { Application } from 'typedoc';
1
2
  import { PluginOptions } from './models';
2
- export declare const getPluginOptions: (opts: Partial<PluginOptions>) => PluginOptions;
3
+ export declare function getPluginOptions(opts: Partial<PluginOptions>): PluginOptions;
4
+ export declare function loadOptions(app: Application): void;
package/dist/options.js CHANGED
@@ -1,26 +1,25 @@
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',
9
+ watch: false,
10
+ plugin: [],
11
+ hideInPageTOC: true,
12
+ hideBreadcrumbs: true,
13
+ hidePageHeader: true,
14
+ includeFileNumberPrefixes: true,
8
15
  sidebar: {
9
16
  categoryLabel: 'API',
10
- collapsed: true,
11
17
  position: null,
12
18
  autoConfiguration: true,
19
+ indexLabel: 'Index',
13
20
  },
14
- hideInPageTOC: true,
15
- hideBreadcrumbs: true,
16
- hidePageTitle: false,
17
- entryDocument: 'index.md',
18
- watch: false,
19
- enableFrontmatter: true,
20
- numberPrefixOutput: true,
21
- theme: 'docusaurus',
22
21
  };
23
- const getPluginOptions = (opts) => {
22
+ function getPluginOptions(opts) {
24
23
  const options = {
25
24
  ...DEFAULT_PLUGIN_OPTIONS,
26
25
  ...opts,
@@ -30,5 +29,31 @@ const getPluginOptions = (opts) => {
30
29
  },
31
30
  };
32
31
  return options;
33
- };
32
+ }
34
33
  exports.getPluginOptions = getPluginOptions;
34
+ function loadOptions(app) {
35
+ app.options.addReader(new typedoc_1.PackageJsonReader());
36
+ app.options.addReader(new typedoc_1.TypeDocReader());
37
+ app.options.addReader(new typedoc_1.TSConfigReader());
38
+ app.options.addDeclaration({
39
+ name: 'sidebar',
40
+ type: typedoc_1.ParameterType.Mixed,
41
+ });
42
+ app.options.addReader(new (class {
43
+ constructor() {
44
+ this.name = 'docusaurus-options';
45
+ this.order = 900;
46
+ this.supportsPackages = false;
47
+ }
48
+ read(container) {
49
+ const plugins = container.getValue('plugin');
50
+ ['typedoc-plugin-markdown', 'typedoc-plugin-frontmatter'].forEach((defaultPlugin) => {
51
+ if (!plugins.includes(defaultPlugin)) {
52
+ plugins.push(defaultPlugin);
53
+ }
54
+ });
55
+ container.setValue('plugin', plugins);
56
+ }
57
+ })());
58
+ }
59
+ exports.loadOptions = loadOptions;
@@ -0,0 +1,2 @@
1
+ import { Application } from 'typedoc';
2
+ export declare function loadRenderer(app: Application): void;
@@ -0,0 +1,85 @@
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, _h;
19
+ const renderContext = app.renderer.theme.getRenderContext();
20
+ const hasReadme = !app.options.getValue('readme').endsWith('none');
21
+ const sidebar = app.options.getValue('sidebar');
22
+ const isModulesPage = (_a = event.page) === null || _a === void 0 ? void 0 : _a.url.endsWith(renderContext.modulesFile);
23
+ const isIndexPage = (_b = event.page) === null || _b === void 0 ? void 0 : _b.url.endsWith(renderContext.indexFile);
24
+ const isReadmePage = (_c = event.page) === null || _c === void 0 ? void 0 : _c.url.endsWith(renderContext.readmeFile);
25
+ const isPackageModule = event.page.model.kindOf(typedoc_1.ReflectionKind.Module) &&
26
+ !Boolean(((_d = event.page.model) === null || _d === void 0 ? void 0 : _d.parent).groups);
27
+ const model = (_e = event.page) === null || _e === void 0 ? void 0 : _e.model;
28
+ let pluginFrontmatter = {};
29
+ if (sidebar.autoConfiguration) {
30
+ if (!isModulesPage && !isReadmePage) {
31
+ const sidebarLabel = !model.kindOf(typedoc_1.ReflectionKind.Module) &&
32
+ !app.options.getValue('hideKindTag') &&
33
+ app.options.getValue('excludeGroups')
34
+ ? `(${Array.from(typedoc_1.ReflectionKind.singularString(model.kind))[0]}) ${model === null || model === void 0 ? void 0 : model.name}`
35
+ : model === null || model === void 0 ? void 0 : model.name;
36
+ pluginFrontmatter = {
37
+ ...pluginFrontmatter,
38
+ sidebar_label: sidebarLabel,
39
+ };
40
+ }
41
+ if (((_f = event.page) === null || _f === void 0 ? void 0 : _f.url) === renderContext.readmeFile ||
42
+ (!hasReadme && isModulesPage)) {
43
+ if (sidebar.categoryLabel) {
44
+ pluginFrontmatter = {
45
+ ...pluginFrontmatter,
46
+ sidebar_label: sidebar.categoryLabel,
47
+ };
48
+ }
49
+ if (sidebar.position !== null && !Number.isNaN(sidebar.position)) {
50
+ pluginFrontmatter = {
51
+ ...pluginFrontmatter,
52
+ sidebar_position: sidebar.position,
53
+ };
54
+ }
55
+ }
56
+ if (isModulesPage) {
57
+ pluginFrontmatter = {
58
+ ...pluginFrontmatter,
59
+ sidebar_label: sidebar.indexLabel,
60
+ };
61
+ }
62
+ if (isPackageModule && isReadmePage) {
63
+ pluginFrontmatter = {
64
+ ...pluginFrontmatter,
65
+ sidebar_label: event.page.model.name,
66
+ };
67
+ }
68
+ if (isPackageModule && isIndexPage && Boolean((_g = event.page.model) === null || _g === void 0 ? void 0 : _g.readme)) {
69
+ pluginFrontmatter = {
70
+ ...pluginFrontmatter,
71
+ sidebar_label: sidebar.indexLabel,
72
+ };
73
+ }
74
+ if (isPackageModule && isIndexPage && !Boolean((_h = event.page.model) === null || _h === void 0 ? void 0 : _h.readme)) {
75
+ pluginFrontmatter = {
76
+ ...pluginFrontmatter,
77
+ sidebar_label: event.page.model.name,
78
+ };
79
+ }
80
+ }
81
+ event.frontmatter = {
82
+ ...pluginFrontmatter,
83
+ ...event.frontmatter,
84
+ };
85
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-typedoc",
3
- "version": "1.0.0-next.7",
3
+ "version": "1.0.0-next.9",
4
4
  "description": "A Docusaurus v2 plugin to build API documentation with TypeDoc.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -16,7 +16,8 @@
16
16
  },
17
17
  "homepage": "https://github.com/tgreyuk/typedoc-plugin-markdown/tree/master/packages/docusaurus-plugin-typedoc",
18
18
  "peerDependencies": {
19
- "typedoc-plugin-markdown": ">=4.0.0-next.8"
19
+ "typedoc-plugin-frontmatter": "^0.0.2",
20
+ "typedoc-plugin-markdown": ">=4.0.0-next.11"
20
21
  },
21
22
  "scripts": {
22
23
  "lint": "eslint ./src --ext .ts",
package/dist/plugin.d.ts DELETED
@@ -1,6 +0,0 @@
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/plugin.js DELETED
@@ -1,80 +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
- const app = new typedoc_1.Application();
63
- app.renderer.defineTheme('docusaurus', theme_1.DocusaurusTheme);
64
- (0, typedoc_plugin_markdown_1.load)(app);
65
- (0, render_1.addTypedocReaders)(app);
66
- (0, render_1.addTypedocDeclarations)(app);
67
- await app.bootstrapWithPlugins(options);
68
- const project = app.convert();
69
- if (!project) {
70
- return;
71
- }
72
- if (options.watch) {
73
- app.convertAndWatch(async (project) => {
74
- await app.generateDocs(project, outputDir);
75
- });
76
- }
77
- else {
78
- await app.generateDocs(project, outputDir);
79
- }
80
- }
package/dist/render.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { Application } from 'typedoc';
2
- export declare function addTypedocReaders(app: Application): void;
3
- export declare function addTypedocDeclarations(app: Application): void;
package/dist/render.js DELETED
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addTypedocDeclarations = exports.addTypedocReaders = void 0;
4
- const typedoc_1 = require("typedoc");
5
- function addTypedocReaders(app) {
6
- app.options.addReader(new typedoc_1.TypeDocReader());
7
- app.options.addReader(new typedoc_1.TSConfigReader());
8
- }
9
- exports.addTypedocReaders = addTypedocReaders;
10
- function addTypedocDeclarations(app) {
11
- app.options.addDeclaration({
12
- name: 'id',
13
- });
14
- app.options.addDeclaration({
15
- name: 'docsRoot',
16
- });
17
- app.options.addDeclaration({
18
- name: 'globalsTitle',
19
- });
20
- app.options.addDeclaration({
21
- name: 'sidebar',
22
- type: typedoc_1.ParameterType.Mixed,
23
- });
24
- }
25
- exports.addTypedocDeclarations = addTypedocDeclarations;
package/dist/theme.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { DeclarationReflection, PageEvent, Renderer, RendererEvent } from 'typedoc';
2
- import { MarkdownTheme } from 'typedoc-plugin-markdown';
3
- import { SidebarOptions } from './models';
4
- export declare class DocusaurusTheme extends MarkdownTheme {
5
- sidebar: SidebarOptions;
6
- constructor(renderer: Renderer);
7
- onPageEnd(page: PageEvent<DeclarationReflection>): void;
8
- onRendererEnd(renderer: RendererEvent): void;
9
- loopAndWriteCategories(path: string, level?: number): void;
10
- writeCategoryYaml: (categoryPath: string, label: string, position: number | null, collapsed: boolean, generatedIndex: boolean) => void;
11
- }
package/dist/theme.js DELETED
@@ -1,95 +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
- class DocusaurusTheme extends typedoc_plugin_markdown_1.MarkdownTheme {
37
- constructor(renderer) {
38
- super(renderer);
39
- this.writeCategoryYaml = (categoryPath, label, position, collapsed, generatedIndex) => {
40
- const yaml = [`label: "${label}"`];
41
- if (position !== null) {
42
- yaml.push(`position: ${position}`);
43
- }
44
- if (!collapsed) {
45
- yaml.push(`collapsed: false`);
46
- }
47
- if (generatedIndex) {
48
- yaml.push(`link:
49
- type: "generated-index"
50
- title: "${label}"`);
51
- }
52
- if (fs.existsSync(categoryPath)) {
53
- fs.writeFileSync(categoryPath + '/_category_.yml', yaml.join('\n'));
54
- }
55
- };
56
- this.listenTo(this.application.renderer, {
57
- [typedoc_1.PageEvent.END]: this.onPageEnd,
58
- [typedoc_1.RendererEvent.END]: this.onRendererEnd,
59
- });
60
- }
61
- onPageEnd(page) {
62
- if (page.contents) {
63
- page.contents = page.contents.replace(/\\</g, '<');
64
- }
65
- }
66
- onRendererEnd(renderer) {
67
- if (this.sidebar.autoConfiguration) {
68
- this.writeCategoryYaml(renderer.outputDirectory, this.sidebar.categoryLabel, this.sidebar.position, this.sidebar.collapsed, false);
69
- this.loopAndWriteCategories(renderer.outputDirectory);
70
- }
71
- }
72
- loopAndWriteCategories(path, level = 0) {
73
- const directory = fs.readdirSync(path);
74
- directory.forEach((segment) => {
75
- const fullPath = `${path}/${segment}`;
76
- const isDirectory = fs.lstatSync(fullPath).isDirectory();
77
- if (isDirectory) {
78
- const mapping = Object.entries(this.mappings)
79
- .filter((entry) => {
80
- return entry[1].directory === segment.slice(3);
81
- })
82
- .map((entry) => entry[1])[0];
83
- const subdirectory = fs.readdirSync(fullPath);
84
- if (mapping && !subdirectory.includes(`${mapping === null || mapping === void 0 ? void 0 : mapping.directory}.md`)) {
85
- this.writeCategoryYaml(fullPath, typedoc_1.ReflectionKind.pluralString(mapping.kind), null, true, true);
86
- }
87
- this.loopAndWriteCategories(fullPath);
88
- }
89
- });
90
- }
91
- }
92
- __decorate([
93
- (0, typedoc_1.BindOption)('sidebar')
94
- ], DocusaurusTheme.prototype, "sidebar", void 0);
95
- exports.DocusaurusTheme = DocusaurusTheme;