docusaurus-plugin-typedoc 1.0.0-next.1 → 1.0.0-next.11

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,42 +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
- | `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. |
127
+ ```shell
128
+ --docsRoot <path/to/vitepress-docs/>
129
+ ```
104
130
 
105
131
  ### An example configuration
106
132
 
@@ -128,6 +154,21 @@ module.exports = {
128
154
  };
129
155
  ```
130
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
+
131
172
  ## Recipes
132
173
 
133
174
  ### Sidebar and Navbar
@@ -190,27 +231,6 @@ A navbar item can be configured in `themeConfig` options in `docusaurus.config.j
190
231
 
191
232
  Please see https://docusaurus.io/docs/api/themes/configuration#navbar-items for navbar documentation.
192
233
 
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
234
  ### Multi instance
215
235
 
216
236
  It is possible to build multi TypeDoc instances by passing in multiple configs with unique ids:
@@ -272,27 +292,6 @@ module.exports = {
272
292
  };
273
293
  ```
274
294
 
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
295
  ## License
297
296
 
298
297
  [MIT](https://github.com/tgreyuk/typedoc-plugin-markdown/blob/master/packages/docusaurus-plugin-typedoc/LICENSE)
package/dist/index.d.ts CHANGED
@@ -1 +1,5 @@
1
- export { default } from './plugin';
1
+ export default function pluginDocusaurus(context: any, opts: Record<string, any>): {
2
+ name: string;
3
+ loadContent(): Promise<void>;
4
+ extendCli(cli: any): void;
5
+ };
package/dist/index.js CHANGED
@@ -1,8 +1,91 @@
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 typedoc_plugin_frontmatter_1 = require("typedoc-plugin-frontmatter");
29
+ const typedoc_plugin_markdown_1 = require("typedoc-plugin-markdown");
30
+ const options_1 = require("./options");
31
+ const renderer_1 = require("./renderer");
32
+ // store list of plugin ids when running multiple instances
33
+ const apps = [];
34
+ function pluginDocusaurus(context, opts) {
35
+ return {
36
+ name: 'docusaurus-plugin-typedoc',
37
+ async loadContent() {
38
+ if (opts.id && !apps.includes(opts.id)) {
39
+ apps.push(opts.id);
40
+ generateTypedoc(context, opts);
41
+ }
42
+ },
43
+ extendCli(cli) {
44
+ cli
45
+ .command('generate-typedoc')
46
+ .description('(docusaurus-plugin-typedoc) Generate TypeDoc docs independently of the Docusaurus build process.')
47
+ .action(async () => {
48
+ var _a;
49
+ (_a = context.siteConfig) === null || _a === void 0 ? void 0 : _a.plugins.forEach((pluginConfig) => {
50
+ // Check PluginConfig is typed to [string, PluginOptions]
51
+ if (pluginConfig && typeof pluginConfig[1] === 'object') {
52
+ generateTypedoc(context, pluginConfig[1]);
53
+ }
54
+ });
55
+ });
56
+ },
57
+ };
58
+ }
59
+ exports.default = pluginDocusaurus;
60
+ /**
61
+ * Initiates a new typedoc Application bootstraped with plugin options
62
+ */
63
+ async function generateTypedoc(context, opts) {
64
+ const { siteDir } = context;
65
+ const options = (0, options_1.getPluginOptions)(opts);
66
+ const { id, docsRoot, ...optionsPassedToTypeDoc } = options;
67
+ const outputDir = path.resolve(siteDir, options.docsRoot, options.out);
68
+ const app = new typedoc_1.Application();
69
+ (0, options_1.loadOptions)(app);
70
+ (0, renderer_1.loadRenderer)(app);
71
+ (0, typedoc_plugin_markdown_1.load)(app);
72
+ (0, typedoc_plugin_frontmatter_1.load)(app);
73
+ await app.bootstrapWithPlugins(optionsPassedToTypeDoc);
74
+ const project = app.convert();
75
+ // if project is undefined typedoc has a problem - error logging will be supplied by typedoc.
76
+ if (!project) {
77
+ if (app.options.getValue('skipErrorChecking')) {
78
+ return;
79
+ }
80
+ console.error('[docusaurus-plugin-typedoc] TypeDoc exited with an error. Use the "skipErrorChecking" option to disable TypeDoc error checking.');
81
+ process.exit();
82
+ }
83
+ if (app.options.getValue('watch')) {
84
+ app.convertAndWatch(async (project) => {
85
+ await app.generateDocs(project, outputDir);
86
+ });
87
+ }
88
+ else {
89
+ await app.generateDocs(project, outputDir);
90
+ }
91
+ }
@@ -0,0 +1,11 @@
1
+ export interface PluginOptions {
2
+ id: string;
3
+ docsRoot: string;
4
+ sidebar: SidebarOptions;
5
+ }
6
+ export interface SidebarOptions {
7
+ autoConfiguration: boolean;
8
+ readmeLabel: string;
9
+ indexLabel: string;
10
+ categoryLabel: string;
11
+ }
package/dist/options.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- import { PluginOptions } from './types';
2
- export declare const getPluginOptions: (opts: Partial<PluginOptions>) => PluginOptions;
1
+ import { Application } from 'typedoc';
2
+ export declare function getPluginOptions(opts: Record<string, any>): Record<string, any>;
3
+ export declare function loadOptions(app: Application): void;
package/dist/options.js CHANGED
@@ -1,30 +1,22 @@
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
+ hideInPageTOC: true,
10
+ hideBreadcrumbs: true,
11
+ hidePageHeader: true,
12
+ githubPages: false,
13
+ includeFileNumberPrefixes: true,
14
+ entryFileName: 'index.md',
9
15
  sidebar: {
10
- fullNames: false,
11
- categoryLabel: 'API',
12
- collapsed: true,
13
- indexLabel: 'Overview',
14
- position: null,
15
16
  autoConfiguration: true,
16
17
  },
17
- hideInPageTOC: true,
18
- hideBreadcrumbs: true,
19
- hidePageTitle: false,
20
- entryDocument: 'index.md',
21
- plugin: ['none'],
22
- watch: false,
23
- theme: 'docusaurus',
24
- enableFrontmatter: true,
25
- enableEmojis: true,
26
18
  };
27
- const getPluginOptions = (opts) => {
19
+ function getPluginOptions(opts) {
28
20
  const options = {
29
21
  ...DEFAULT_PLUGIN_OPTIONS,
30
22
  ...opts,
@@ -34,5 +26,29 @@ const getPluginOptions = (opts) => {
34
26
  },
35
27
  };
36
28
  return options;
37
- };
29
+ }
38
30
  exports.getPluginOptions = getPluginOptions;
31
+ function loadOptions(app) {
32
+ app.options.addReader(new typedoc_1.PackageJsonReader());
33
+ app.options.addReader(new typedoc_1.TypeDocReader());
34
+ app.options.addReader(new typedoc_1.TSConfigReader());
35
+ app.options.addDeclaration({
36
+ name: 'sidebar',
37
+ type: typedoc_1.ParameterType.Mixed,
38
+ });
39
+ app.options.addReader(new (class {
40
+ constructor() {
41
+ this.name = 'docusaurus-options';
42
+ this.order = 900;
43
+ this.supportsPackages = false;
44
+ }
45
+ read(container) {
46
+ const plugins = container.getValue('plugin');
47
+ container.setValue('plugin', plugins === null || plugins === void 0 ? void 0 : plugins.filter((plugin) => ![
48
+ 'typedoc-plugin-markdown',
49
+ 'typedoc-plugin-frontmatter',
50
+ ].includes(plugin)));
51
+ }
52
+ })());
53
+ }
54
+ 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 hasReadme = !app.options.getValue('readme').endsWith('none');
20
+ const entryPage = app.options.getValue('entryFileName');
21
+ const indexPage = app.options.getValue('indexFileName');
22
+ const sidebar = app.options.getValue('sidebar');
23
+ const model = (_a = event.page) === null || _a === void 0 ? void 0 : _a.model;
24
+ const sidebarLabel = model === null || model === void 0 ? void 0 : model.name;
25
+ let pluginFrontmatter = {};
26
+ if (sidebar.autoConfiguration) {
27
+ if (((_b = event.page) === null || _b === void 0 ? void 0 : _b.url) === app.options.getValue('entryFileName')) {
28
+ if (sidebar.categoryLabel) {
29
+ pluginFrontmatter = {
30
+ ...pluginFrontmatter,
31
+ sidebar_label: sidebar.categoryLabel,
32
+ };
33
+ }
34
+ }
35
+ if (hasReadme) {
36
+ if (((_c = event.page) === null || _c === void 0 ? void 0 : _c.url) === entryPage) {
37
+ pluginFrontmatter = {
38
+ ...pluginFrontmatter,
39
+ ...(sidebar.readmeLabel && { sidebar_label: sidebar.readmeLabel }),
40
+ sidebar_position: 0,
41
+ };
42
+ }
43
+ if (((_d = event.page) === null || _d === void 0 ? void 0 : _d.url) === `01-${indexPage}`) {
44
+ pluginFrontmatter = {
45
+ ...pluginFrontmatter,
46
+ ...(sidebar.indexLabel && { sidebar_label: sidebar.indexLabel }),
47
+ };
48
+ }
49
+ }
50
+ else {
51
+ if (((_e = event.page) === null || _e === void 0 ? void 0 : _e.url) === entryPage) {
52
+ pluginFrontmatter = {
53
+ ...pluginFrontmatter,
54
+ ...(sidebar.indexLabel && { sidebar_label: sidebar.indexLabel }),
55
+ sidebar_position: 0,
56
+ };
57
+ }
58
+ }
59
+ // Add sidebar labels to all pages
60
+ if (!(((_f = event.page) === null || _f === void 0 ? void 0 : _f.url) === entryPage) &&
61
+ !(((_g = event.page) === null || _g === void 0 ? void 0 : _g.url) === `01-${indexPage}`)) {
62
+ pluginFrontmatter = {
63
+ ...pluginFrontmatter,
64
+ sidebar_label: sidebarLabel,
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.1",
3
+ "version": "1.0.0-next.11",
4
4
  "description": "A Docusaurus v2 plugin to build API documentation with TypeDoc.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -16,15 +16,14 @@
16
16
  },
17
17
  "homepage": "https://github.com/tgreyuk/typedoc-plugin-markdown/tree/master/packages/docusaurus-plugin-typedoc",
18
18
  "peerDependencies": {
19
- "typedoc": ">=0.23.0",
20
- "typedoc-plugin-markdown": ">=4.0.0-next.1"
19
+ "typedoc-plugin-markdown": ">=4.0.0-next.13",
20
+ "typedoc-plugin-frontmatter": ">=0.0.2"
21
21
  },
22
22
  "scripts": {
23
23
  "lint": "eslint ./src --ext .ts",
24
- "prepublishOnly": "npm run lint && npm run build && npm run test",
24
+ "prepublishOnly": "npm run lint && npm run build",
25
25
  "build": "rm -rf ./dist && tsc",
26
- "build-and-test": "npm run build && npm run test",
27
- "test": "jest --colors"
26
+ "build-and-test": "npm run build && npm run test"
28
27
  },
29
28
  "author": "Thomas Grey",
30
29
  "license": "MIT",
@@ -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,77 +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: 'sidebar',
71
- type: typedoc_1.ParameterType.Mixed,
72
- });
73
- };
74
- function removeDir(path) {
75
- fs.rmSync(path, { recursive: true, force: true });
76
- }
77
- exports.removeDir = removeDir;
@@ -1,11 +0,0 @@
1
- import { DeclarationReflection, PageEvent, Reflection } from 'typedoc';
2
- import { MarkdownThemeRenderContext } from 'typedoc-plugin-markdown';
3
- export declare class DocusaurusThemeRenderContext extends MarkdownThemeRenderContext {
4
- baseFrontmatterVars: (page: PageEvent<Reflection>) => {
5
- sidebar_position?: number | undefined;
6
- sidebar_label?: string | undefined;
7
- title: string;
8
- };
9
- getSidebarLabel(page: PageEvent<DeclarationReflection>): string | null | undefined;
10
- getSidebarPosition(page: PageEvent<DeclarationReflection>): "0.5" | "0" | null;
11
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DocusaurusThemeRenderContext = void 0;
4
- const typedoc_plugin_markdown_1 = require("typedoc-plugin-markdown");
5
- class DocusaurusThemeRenderContext extends typedoc_plugin_markdown_1.MarkdownThemeRenderContext {
6
- constructor() {
7
- super(...arguments);
8
- this.baseFrontmatterVars = (page) => {
9
- const sidebarPosition = parseFloat(this.getSidebarPosition(page));
10
- const sidebarLabel = this.getSidebarLabel(page);
11
- return {
12
- ...this.getBaseFrontmatterVars(page),
13
- ...(this.options.getValue('sidebar').autoConfiguration
14
- ? {
15
- ...(sidebarLabel && { sidebar_label: sidebarLabel }),
16
- ...(sidebarPosition && {
17
- sidebar_position: sidebarPosition,
18
- }),
19
- }
20
- : {}),
21
- };
22
- };
23
- }
24
- getSidebarLabel(page) {
25
- if (page.url === this.options.getValue('entryDocument')) {
26
- return this.options.getValue('sidebar').indexLabel;
27
- }
28
- return null;
29
- }
30
- getSidebarPosition(page) {
31
- if (page.url === this.options.getValue('entryDocument')) {
32
- return page.url === page.project.url ? '0.5' : '0';
33
- }
34
- if (page.url === this.globalsFile) {
35
- return '0.5';
36
- }
37
- if (page.model.getFullName().split('.').length === 1) {
38
- return '0';
39
- }
40
- return null;
41
- }
42
- }
43
- exports.DocusaurusThemeRenderContext = DocusaurusThemeRenderContext;
package/dist/theme.d.ts DELETED
@@ -1,13 +0,0 @@
1
- import { DeclarationReflection, PageEvent, Renderer, RendererEvent } from 'typedoc';
2
- import { MarkdownTheme } from 'typedoc-plugin-markdown';
3
- import { SidebarOptions } from './types';
4
- export declare class DocusaurusTheme extends MarkdownTheme {
5
- sidebar: SidebarOptions;
6
- private _contextCache?;
7
- constructor(renderer: Renderer);
8
- getRenderContext(): any;
9
- onPageEnd(page: PageEvent<DeclarationReflection>): void;
10
- onRendererEnd(renderer: RendererEvent): void;
11
- loopAndWriteCategories(path: string): void;
12
- writeCategoryYaml: (categoryPath: string, label: string, position: number | null, collapsed: boolean) => void;
13
- }
package/dist/theme.js DELETED
@@ -1,97 +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 navigation_1 = require("./navigation");
37
- const theme_context_1 = require("./theme-context");
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
- getRenderContext() {
59
- this._contextCache || (this._contextCache = new theme_context_1.DocusaurusThemeRenderContext(this, this.application.options));
60
- return this._contextCache;
61
- }
62
- onPageEnd(page) {
63
- if (page.contents) {
64
- page.contents = page.contents.replace(/\\</g, '<');
65
- }
66
- }
67
- onRendererEnd(renderer) {
68
- if (this.sidebar.autoConfiguration) {
69
- this.writeCategoryYaml(renderer.outputDirectory, this.sidebar.categoryLabel, this.sidebar.position, this.sidebar.collapsed);
70
- this.loopAndWriteCategories(renderer.outputDirectory);
71
- }
72
- }
73
- loopAndWriteCategories(path) {
74
- const directory = fs.readdirSync(path);
75
- directory.forEach((segment) => {
76
- const fullPath = `${path}/${segment}`;
77
- const isDirectory = fs.lstatSync(fullPath).isDirectory();
78
- if (isDirectory) {
79
- const mapping = Object.entries(this.mappings)
80
- .filter((entry) => {
81
- return entry[1].directory === segment;
82
- })
83
- .map((entry) => entry[1])[0];
84
- const subdirectory = fs.readdirSync(fullPath);
85
- const containsDir = subdirectory.some((item) => fs.lstatSync(`${fullPath}/${item}`).isDirectory());
86
- if (mapping && !containsDir) {
87
- this.writeCategoryYaml(fullPath, (0, navigation_1.getKindPlural)(mapping.kind), navigation_1.CATEGORY_POSITION[mapping.kind], true);
88
- }
89
- this.loopAndWriteCategories(fullPath);
90
- }
91
- });
92
- }
93
- }
94
- __decorate([
95
- (0, typedoc_1.BindOption)('sidebar')
96
- ], DocusaurusTheme.prototype, "sidebar", void 0);
97
- exports.DocusaurusTheme = DocusaurusTheme;
package/dist/types.d.ts DELETED
@@ -1,37 +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
- theme?: string;
20
- enableFrontmatter: boolean;
21
- enableEmojis: boolean;
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
- position: number | null;
30
- autoConfiguration: boolean;
31
- }
32
- export interface SidebarCategory {
33
- type: string;
34
- label: string;
35
- items: SidebarItem[];
36
- }
37
- export type SidebarItem = SidebarCategory | string;
File without changes