docusaurus-plugin-typedoc 1.0.0-next.15 → 1.0.0-next.17

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,21 +1,29 @@
1
1
  # docusaurus-plugin-typedoc
2
2
 
3
+ ![npm](https://img.shields.io/npm/v/docusaurus-plugin-typedoc%2Fnext?&logo=npm) [![Build Status](https://github.com/tgreyuk/typedoc-plugin-markdown/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/tgreyuk/typedoc-plugin-markdown/actions/workflows/ci.yml)
4
+
3
5
  A [Docusaurus](https://v2.docusaurus.io/) plugin to build TypeScript API documentation with [TypeDoc](https://github.com/TypeStrong/typedoc).
4
6
 
5
- [![npm](https://img.shields.io/npm/v/docusaurus-plugin-typedoc.svg)](https://www.npmjs.com/package/docusaurus-plugin-typedoc)
6
- ![CI](https://github.com/tgreyuk/typedoc-plugin-markdown/actions/workflows/ci.yml/badge.svg?branch=master)
7
+ ## Contents
8
+
9
+ - [What does it do?](#what-does-it-do)
10
+ - [Installation](#installation)
11
+ - [Usage](#usage)
12
+ - [Options](#options)
13
+ - [Sidebar](#sidebar)
14
+ - [Other configuration](#other-configuration)
15
+ - [License](#license)
7
16
 
8
17
  ## What does it do?
9
18
 
10
19
  - Presets relevant options of [typedoc-plugin-markdown](https://github.com/tgreyuk/typedoc-plugin-markdown/tree/master/packages/typedoc-plugin-markdown#readme).
11
20
  - Runs TypeDoc from the Docusaurus CLI.
12
- - Adds some basic frontmatter to pages and exposes the ability to configure frontmatter further.
13
21
 
14
22
  ## Installation
15
23
 
16
24
  > 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.
17
25
 
18
- > [typedoc](https://github.com/TypeStrong/typedoc), [typedoc-plugin-markdown](https://github.com/tgreyuk/typedoc-plugin-markdown) are peer dependencies.
26
+ > [typedoc](https://github.com/TypeStrong/typedoc) and [typedoc-plugin-markdown](https://github.com/tgreyuk/typedoc-plugin-markdown) are peer dependencies.
19
27
 
20
28
  ```shell
21
29
  npm install docusaurus-plugin-typedoc typedoc typedoc-plugin-markdown@next --save-dev
@@ -23,8 +31,6 @@ npm install docusaurus-plugin-typedoc typedoc typedoc-plugin-markdown@next --sav
23
31
 
24
32
  ## Usage
25
33
 
26
- ### Config
27
-
28
34
  Add the plugin to `docusaurus.config.js` and specify the required options (see [options](#options)).
29
35
 
30
36
  ```js
@@ -50,34 +56,32 @@ TypeDoc will be bootstraped with the Docusaurus `start` and `build` [cli command
50
56
  "build": "docusaurus build",
51
57
  ```
52
58
 
53
- Once built the docs will be available at `/docs/api` (or equivalent out directory).
59
+ Once built the docs will be available at `http://localhost:3000/docs/api` (or equivalent out directory).
54
60
 
55
- ### Directory structure
61
+ Typical directory structure:
56
62
 
57
- ```
58
- ├── docusauruss-website
59
- ├── build/ (static site dir)
60
- ├── docs/
61
- ├── api/ (compiled typedoc markdown)
62
- ├── docusaurus.config.js
63
- ├── package.json
64
- ├── sidebars.js
65
- ├──package.json
66
- ├──src (typescript source files)
67
- ├──tsconfig.json
68
- ```
63
+ ├── docusaurus-website
64
+ ├── build/ (static site dir)
65
+ ├── docs/
66
+ ├── api/ (compiled typedoc markdown)
67
+ ├── docusaurus.config.js
68
+ ├── package.json
69
+ ├── sidebars.js
70
+ ├──package.json
71
+ ├──src (typescript source files)
72
+ ├──tsconfig.json
69
73
 
70
74
  ## Options
71
75
 
76
+ ### TypeDoc options
77
+
72
78
  Options can be declared:
73
79
 
74
80
  - Passing arguments via the command line.
75
81
  - Using a `typedoc.json` file.
76
82
  - Under the `typedocOptions` key in `tsconfig.json`.
77
83
 
78
- Please see https://typedoc.org/options/configuration for general TypeDoc option configuration.
79
-
80
- ### TypeDoc options
84
+ Please see <https://typedoc.org/options/configuration> for general TypeDoc option configuration.
81
85
 
82
86
  The following TypeDoc / Markdown plugin options can be passed to config:
83
87
 
@@ -88,12 +92,11 @@ The following typedoc-plugin-markdown options are preset with the plugin.
88
92
 
89
93
  ```json
90
94
  {
91
- "out": "api",
95
+ "out": "./docs/api",
92
96
  "hideInPageTOC": true,
93
97
  "hideBreadcrumbs": true,
94
98
  "hidePageHeader": true,
95
- "entryFileName": "index.md",
96
- "includeFileNumberPrefixes": true
99
+ "entryFileName": "index.md"
97
100
  }
98
101
  ```
99
102
 
@@ -105,118 +108,67 @@ Options specific to the plugin should also be declared in the same object.
105
108
 
106
109
  `sidebar.autoConfiguration`
107
110
 
108
- Set to `false` to disable sidebar metadata added to frontmatter. Defaults to `true`.
109
-
110
- `sidebar.categoryLabel`
111
+ Set to `false` to disable sidebar generation. Defaults to `true`.
111
112
 
112
- The sidebar main parent category label. Defaults to entry page title.
113
+ `sidebar.filteredIds`
113
114
 
114
- `sidebar.readmeLabel`
115
+ Ids of pages to be filtered from the sidebar. This would typically be used to filter README or index pages from the sidebar.
115
116
 
116
- The label of the readme page. Defaults to the h1 title of the readme page. Ignored if `readme=none`.
117
+ `sidebar.pretty`
117
118
 
118
- `sidebar.indexLabel`
119
+ Pretty format the sidebar JSON.
119
120
 
120
- The label of the index page. Defaults to the index page title.
121
+ ## Sidebar
121
122
 
122
- `sidebar.position`
123
+ > Previous versions of this plugin recommended an `autogenerated` sidebar configuration. However we have decided it is more deterministic and configurable to use a manual sidebar configuration with a generated sidebar file.
123
124
 
124
- The position of the sidebar in the tree.
125
+ A docusaurus sidebar file `typedoc-sidebar.cjs` is published to the relevant output directory along with the generated markdown documentation.
125
126
 
126
- #### `--docsRoot`
127
+ This file should be referenced in `sidebars.js` using a sidebar slice and can be configured in following ways:
127
128
 
128
- The Docusaurus docs folder root. Use `./` if no root folder specified. Defaults to `./docs`.
129
-
130
- ```shell
131
- --docsRoot <path/to/docs-dir/>
132
- ```
133
-
134
- ### An example configuration
129
+ 1. Display sidebar on the root:
135
130
 
136
131
  ```js
137
132
  module.exports = {
138
- plugins: [
139
- [
140
- 'docusaurus-plugin-typedoc',
141
- {
142
- // TypeDoc options
143
- entryPoints: ['../src/index.ts'],
144
- tsconfig: '../tsconfig.json',
145
- plugin: ['typedoc-plugin-xyz'],
146
-
147
- // Plugin options
148
- out: 'api-xyz',
149
- },
150
- ],
151
- ],
133
+ typedocSidebar: require('./docs/api/typedoc-sidebar.cjs'),
152
134
  };
153
135
  ```
154
136
 
155
- ## Typing the config file
156
-
157
- The config can be typed using JSDoc type annotations. See https://docusaurus.io/docs/typescript-support#typing-config.
137
+ 2. Display the sidebar inside a category:
158
138
 
159
139
  ```js
160
- /** @type {import('docusaurus-plugin-typedoc').PluginOptions} */
161
- ```
162
-
163
- ## Frontmatter
164
-
165
- Additional frontmatter options can be added to the config. Please see [typedoc-plugin-frontmatter](https://github.com/tgreyuk/typedoc-plugin-frontmatter#typedoc-plugin-frontmatter).
166
-
167
- For example:
168
-
169
- ```json
170
- {
171
- "frontmatterGlobals": {
172
- "pagination_prev": null,
173
- "pagination_next": null
174
- }
175
- }
140
+ module.exports = {
141
+ typedocSidebar: {
142
+ 'Typedoc Docs': require('./docs/api/typedoc-sidebar.cjs'),
143
+ },
144
+ };
176
145
  ```
177
146
 
178
- ## Recipes
179
-
180
- ### Sidebar and Navbar
181
-
182
- #### Sidebar
147
+ 3. Display the sidebar inside a linked category
183
148
 
184
- `sidebars.js` can be configured in following ways:
185
-
186
- 1. Generate the entire sidebar from file structure of your docs folder (default behaviour):
149
+ > Note the linked category page can be removed from sidebar using [`sidebar.filteredIds`]().
187
150
 
188
151
  ```js
189
152
  module.exports = {
190
- sidebar: [
153
+ typedocSidebar: [
191
154
  {
192
- type: 'autogenerated',
193
- dirName: '.', // '.' means the docs folder
155
+ type: 'category',
156
+ label: 'Typedoc Docs',
157
+ link: {
158
+ type: 'doc',
159
+ id: 'api/index',
160
+ },
161
+ items: require('./docs/api/typedoc-sidebar.cjs'),
194
162
  },
195
163
  ],
196
164
  };
197
165
  ```
198
166
 
199
- 2. Alternatively, if you wish to manually control other parts of your sidebar you can use a slice for the TypeDoc sidebar.
167
+ Please see <https://docusaurus.io/docs/sidebar> for sidebar documentation.
200
168
 
201
- > note: `sidebar.categoryLabel` and `sidebar.position` options are ignored with this implementation)
169
+ ## Other configuration
202
170
 
203
- ```js
204
- module.exports = {
205
- sidebar: {
206
- 'Category 1': ['doc1', 'doc2', 'doc3'],
207
- API: [
208
- {
209
- type: 'autogenerated',
210
- dirName: 'api', // 'api' is the 'out' directory
211
- },
212
- ],
213
- },
214
- };
215
- ```
216
-
217
- Please see https://docusaurus.io/docs/sidebar for sidebar documentation.
218
-
219
- #### Navbar
171
+ ### Navbar
220
172
 
221
173
  A navbar item can be configured in `themeConfig` options in `docusaurus.config.js`:
222
174
 
@@ -235,7 +187,7 @@ A navbar item can be configured in `themeConfig` options in `docusaurus.config.j
235
187
  },
236
188
  ```
237
189
 
238
- Please see https://docusaurus.io/docs/api/themes/configuration#navbar-items for navbar documentation.
190
+ Please see <https://docusaurus.io/docs/api/themes/configuration#navbar-items> for navbar documentation.
239
191
 
240
192
  ### Multi instance
241
193
 
@@ -268,9 +220,20 @@ module.exports = {
268
220
  };
269
221
  ```
270
222
 
223
+ `sidebars.js`
224
+
225
+ ```js
226
+ module.exports = {
227
+ typedocSidebar: {
228
+ 'API 1': require('./docs/api-1/typedoc-sidebar.cjs'),
229
+ 'API 2': require('./docs/api-2/typedoc-sidebar.cjs'),
230
+ },
231
+ };
232
+ ```
233
+
271
234
  ### Watch mode
272
235
 
273
- Watching files is supported by passing in the `watch: true` option see [https://typedoc.org/guides/options/#watch](https://typedoc.org/guides/options/#watch).
236
+ Watching files is supported by passing in the `watch: true` option see <https://typedoc.org/guides/options/#watch>.
274
237
 
275
238
  Targetting the option in development mode only can be achieved using Node.js Environment Variables:
276
239
 
@@ -298,6 +261,10 @@ module.exports = {
298
261
  };
299
262
  ```
300
263
 
264
+ ### Frontmatter
265
+
266
+ To add frontmatter to page please use [typedoc-plugin-frontmatter](https://github.com/tgreyuk/typedoc-plugin-frontmatter#typedoc-plugin-frontmatter) and add options exposed by the plugin to the config.
267
+
301
268
  ## License
302
269
 
303
270
  [MIT](https://github.com/tgreyuk/typedoc-plugin-markdown/blob/master/packages/docusaurus-plugin-typedoc/LICENSE)
package/dist/models.d.ts CHANGED
@@ -1,12 +1,10 @@
1
1
  import { PluginOptions as TypedocPluginMarkdownOptions } from 'typedoc-plugin-markdown';
2
2
  export interface PluginOptions extends TypedocPluginMarkdownOptions {
3
3
  id: string;
4
- docsRoot: string;
5
4
  sidebar: Partial<SidebarOptions>;
6
5
  }
7
6
  export interface SidebarOptions {
8
7
  autoConfiguration: boolean;
9
- readmeLabel: string;
10
- indexLabel: string;
11
- categoryLabel: string;
8
+ pretty: boolean;
9
+ filteredIds: string[];
12
10
  }
package/dist/options.js CHANGED
@@ -3,18 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setOptions = exports.getPluginOptions = void 0;
4
4
  const DEFAULT_PLUGIN_OPTIONS = {
5
5
  id: 'default',
6
- docsRoot: 'docs',
7
- out: 'api',
6
+ out: './docs/api',
8
7
  hideInPageTOC: true,
9
8
  hideBreadcrumbs: true,
10
9
  hidePageHeader: true,
11
- githubPages: false,
12
- includeFileNumberPrefixes: true,
13
10
  entryFileName: 'index.md',
14
11
  sidebar: {
15
12
  autoConfiguration: true,
13
+ pretty: false,
14
+ filteredIds: [],
16
15
  },
17
- plugin: ['typedoc-plugin-markdown', 'typedoc-plugin-frontmatter'],
16
+ plugin: ['typedoc-plugin-markdown'],
18
17
  };
19
18
  function getPluginOptions(opts) {
20
19
  const options = {
package/dist/plugin.d.ts CHANGED
@@ -6,3 +6,4 @@ export default function pluginDocusaurus(context: any, opts: Partial<PluginOptio
6
6
  };
7
7
  export declare function writeFileSync(fileName: string, data: string): void;
8
8
  export declare function normalizePath(path: string): string;
9
+ export declare function removeDir(path: string): void;
package/dist/plugin.js CHANGED
@@ -23,12 +23,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.normalizePath = exports.writeFileSync = void 0;
26
+ exports.removeDir = exports.normalizePath = exports.writeFileSync = void 0;
27
27
  const fs = __importStar(require("fs"));
28
28
  const path = __importStar(require("path"));
29
29
  const typedoc_1 = require("typedoc");
30
- const frontmatter_1 = require("./frontmatter");
31
30
  const options_1 = require("./options");
31
+ const sidebar_1 = require("./sidebar");
32
32
  // store list of plugin ids when running multiple instances
33
33
  const apps = [];
34
34
  function pluginDocusaurus(context, opts) {
@@ -63,10 +63,31 @@ exports.default = pluginDocusaurus;
63
63
  async function generateTypedoc(context, opts) {
64
64
  const { siteDir } = context;
65
65
  const options = (0, options_1.getPluginOptions)(opts);
66
- const { id, docsRoot, sidebar, ...optionsPassedToTypeDoc } = options;
67
- const outputDir = path.resolve(siteDir, options.docsRoot, options.out);
66
+ const { id, sidebar, ...optionsPassedToTypeDoc } = options;
68
67
  const app = await typedoc_1.Application.bootstrapWithPlugins(optionsPassedToTypeDoc);
69
- (0, frontmatter_1.loadFrontmatter)(app, options.sidebar);
68
+ const outputDir = app.options.getValue('out');
69
+ if (options.cleanOutputDir) {
70
+ removeDir(outputDir);
71
+ }
72
+ app.renderer.on(typedoc_1.PageEvent.END, (event) => {
73
+ var _a;
74
+ event.contents = (_a = event.contents) === null || _a === void 0 ? void 0 : _a.replace(/\\</g, '<');
75
+ });
76
+ if (sidebar === null || sidebar === void 0 ? void 0 : sidebar.autoConfiguration) {
77
+ app.renderer.postRenderAsyncJobs.push(async (output) => {
78
+ const sidebarPath = path.resolve(outputDir, 'typedoc-sidebar.cjs');
79
+ const baseDir = path
80
+ .relative(siteDir, outputDir)
81
+ .split('/')
82
+ .slice(1)
83
+ .join('/');
84
+ const sidebarJson = (0, sidebar_1.getSidebar)(output.navigation, baseDir, sidebar.filteredIds);
85
+ fs.writeFileSync(sidebarPath, `// @ts-check
86
+ /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
87
+ const typedocSidebar = { items: ${JSON.stringify(sidebarJson, null, sidebar.pretty ? 2 : 0)}};
88
+ module.exports = typedocSidebar.items;`);
89
+ });
90
+ }
70
91
  const project = await app.convert();
71
92
  // if project is undefined typedoc has a problem - error logging will be supplied by typedoc.
72
93
  if (!project) {
@@ -94,3 +115,23 @@ function normalizePath(path) {
94
115
  return path.replace(/\\/g, '/');
95
116
  }
96
117
  exports.normalizePath = normalizePath;
118
+ function removeDir(path) {
119
+ if (fs.existsSync(path)) {
120
+ const files = fs.readdirSync(path);
121
+ if (files.length > 0) {
122
+ files.forEach(function (filename) {
123
+ if (fs.statSync(path + '/' + filename).isDirectory()) {
124
+ removeDir(path + '/' + filename);
125
+ }
126
+ else {
127
+ fs.unlinkSync(path + '/' + filename);
128
+ }
129
+ });
130
+ fs.rmdirSync(path);
131
+ }
132
+ else {
133
+ fs.rmdirSync(path);
134
+ }
135
+ }
136
+ }
137
+ exports.removeDir = removeDir;
@@ -0,0 +1,2 @@
1
+ import { NavigationItem } from 'typedoc-plugin-markdown';
2
+ export declare function getSidebar(navigation: NavigationItem[], basePath: string, filteredIds?: string[]): any;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSidebar = void 0;
4
+ function getSidebar(navigation, basePath, filteredIds = []) {
5
+ return navigation
6
+ .map((navigationItem) => getNavigationItem(navigationItem, basePath, filteredIds))
7
+ .filter((navItem) => Boolean(navItem));
8
+ }
9
+ exports.getSidebar = getSidebar;
10
+ function getNavigationItem(navigationItem, basePath, filteredIds) {
11
+ var _a;
12
+ const id = navigationItem.url
13
+ ? `${basePath}/${navigationItem.url}`.replace(/(.*).md/, '$1')
14
+ : null;
15
+ if ((_a = navigationItem.children) === null || _a === void 0 ? void 0 : _a.length) {
16
+ return {
17
+ type: 'category',
18
+ label: navigationItem.title,
19
+ items: getSidebar(navigationItem.children, basePath, filteredIds),
20
+ ...(id && { link: { type: 'doc', id } }),
21
+ };
22
+ }
23
+ return id && !filteredIds.includes(id)
24
+ ? {
25
+ type: 'doc',
26
+ id,
27
+ label: navigationItem.title,
28
+ }
29
+ : null;
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-typedoc",
3
- "version": "1.0.0-next.15",
3
+ "version": "1.0.0-next.17",
4
4
  "description": "A Docusaurus v2 plugin to build API documentation with TypeDoc.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -16,12 +16,13 @@
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.19"
19
+ "typedoc-plugin-markdown": ">=4.0.0-next.22"
20
20
  },
21
21
  "scripts": {
22
22
  "lint": "eslint ./src --ext .ts",
23
23
  "prepublishOnly": "npm run lint && npm run build",
24
- "build": "rm -rf ./dist && tsc"
24
+ "build": "rm -rf ./dist && tsc",
25
+ "task:docs": "node ./tasks/docs.mjs"
25
26
  },
26
27
  "author": "Thomas Grey",
27
28
  "license": "MIT",
@@ -1,3 +0,0 @@
1
- import { Application } from 'typedoc';
2
- import { SidebarOptions } from './models';
3
- export declare function loadFrontmatter(app: Application, sidebar: SidebarOptions): void;
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadFrontmatter = void 0;
4
- const typedoc_plugin_frontmatter_1 = require("typedoc-plugin-frontmatter");
5
- function loadFrontmatter(app, sidebar) {
6
- app.renderer.on(typedoc_plugin_frontmatter_1.FrontmatterEvent.PREPARE_FRONTMATTER, (event) => {
7
- var _a, _b, _c, _d, _e, _f;
8
- const hasReadme = !app.options.getValue('readme').endsWith('none');
9
- const entryPage = app.options.getValue('entryFileName');
10
- const indexPage = app.options.getValue('indexFileName');
11
- const model = (_a = event.page) === null || _a === void 0 ? void 0 : _a.model;
12
- const sidebarLabel = model === null || model === void 0 ? void 0 : model.name;
13
- let pluginFrontmatter = {};
14
- if (sidebar.autoConfiguration) {
15
- if (((_b = event.page) === null || _b === void 0 ? void 0 : _b.url) === app.options.getValue('entryFileName')) {
16
- if (sidebar.categoryLabel) {
17
- pluginFrontmatter = {
18
- ...pluginFrontmatter,
19
- sidebar_label: sidebar.categoryLabel,
20
- };
21
- }
22
- }
23
- if (hasReadme) {
24
- if (((_c = event.page) === null || _c === void 0 ? void 0 : _c.url) === entryPage) {
25
- pluginFrontmatter = {
26
- ...pluginFrontmatter,
27
- ...(sidebar.readmeLabel && {
28
- sidebar_label: sidebar.readmeLabel,
29
- }),
30
- sidebar_position: 0,
31
- };
32
- }
33
- if (((_d = event.page) === null || _d === void 0 ? void 0 : _d.url) === `01-${indexPage}`) {
34
- pluginFrontmatter = {
35
- ...pluginFrontmatter,
36
- ...(sidebar.indexLabel && { sidebar_label: sidebar.indexLabel }),
37
- };
38
- }
39
- }
40
- // Add sidebar labels to all pages
41
- if (!(((_e = event.page) === null || _e === void 0 ? void 0 : _e.url) === entryPage) &&
42
- !(((_f = event.page) === null || _f === void 0 ? void 0 : _f.url) === `01-${indexPage}`)) {
43
- pluginFrontmatter = {
44
- ...pluginFrontmatter,
45
- sidebar_label: sidebarLabel,
46
- };
47
- }
48
- }
49
- event.frontmatter = {
50
- ...pluginFrontmatter,
51
- ...event.frontmatter,
52
- };
53
- });
54
- }
55
- exports.loadFrontmatter = loadFrontmatter;