docusaurus-plugin-typedoc 1.0.0-next.2 → 1.0.0-next.21

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,26 +1,36 @@
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
+ ![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
4
 
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)
5
+ A [Docusaurus](https://v2.docusaurus.io/) plugin to build TypeScript API documentation with [TypeDoc](https://github.com/TypeStrong/typedoc).
7
6
 
8
- ## What it does?
7
+ ## Contents
9
8
 
10
- Generates static TypeDoc pages in Markdown with frontmatter as part of the Docusaurus build.
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)
16
+
17
+ ## What does it do?
18
+
19
+ - Presets relevant options of [typedoc-plugin-markdown](https://github.com/tgreyuk/typedoc-plugin-markdown/tree/master/packages/typedoc-plugin-markdown#readme).
20
+ - Runs TypeDoc from the Docusaurus CLI.
11
21
 
12
22
  ## Installation
13
23
 
14
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.
15
25
 
26
+ > [typedoc](https://github.com/TypeStrong/typedoc) and [typedoc-plugin-markdown](https://github.com/tgreyuk/typedoc-plugin-markdown) are peer dependencies.
27
+
16
28
  ```shell
17
- npm install typedoc typedoc-plugin-markdown docusaurus-plugin-typedoc --save-dev
29
+ npm install docusaurus-plugin-typedoc typedoc typedoc-plugin-markdown@next --save-dev
18
30
  ```
19
31
 
20
32
  ## Usage
21
33
 
22
- ### Config
23
-
24
34
  Add the plugin to `docusaurus.config.js` and specify the required options (see [options](#options)).
25
35
 
26
36
  ```js
@@ -46,130 +56,119 @@ TypeDoc will be bootstraped with the Docusaurus `start` and `build` [cli command
46
56
  "build": "docusaurus build",
47
57
  ```
48
58
 
49
- 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).
50
60
 
51
- ### Directory structure
61
+ Typical directory structure:
52
62
 
53
- ```
54
- ├── docusauruss-website
55
- ├── build/ (static site dir)
56
- ├── docs/
57
- ├── api/ (compiled typedoc markdown)
58
- ├── docusaurus.config.js
59
- ├── package.json
60
- ├── sidebars.js
61
- ├──package.json
62
- ├──src (typescript source files)
63
- ├──tsconfig.json
64
- ```
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
65
73
 
66
74
  ## Options
67
75
 
68
76
  ### TypeDoc options
69
77
 
70
- To configure TypeDoc, pass any relevant [TypeDoc options](https://typedoc.org/guides/options/) to the config.
78
+ Options can be declared:
71
79
 
72
- At a minimum the `entryPoints` and `tsconfig` options will need to be set.
80
+ - Passing arguments via the command line.
81
+ - Using a `typedoc.json` file.
82
+ - Under the `typedocOptions` key in `tsconfig.json`.
73
83
 
74
- ```js
75
- entryPoints: ['../src/index.ts'],
76
- tsconfig: '../tsconfig.json'
77
- ```
84
+ Please see <https://typedoc.org/options/configuration> for general TypeDoc option configuration.
78
85
 
79
- Additional TypeDoc plugins will need to be explicitly set:
86
+ The following TypeDoc / Markdown plugin options can be passed to config:
80
87
 
81
- ```js
82
- plugin: ['typedoc-plugin-xyz'];
88
+ - [typedoc](https://typedoc.org/options) options (HTML specific output options that will be ignored).
89
+ - [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).
90
+
91
+ The following typedoc-plugin-markdown options are preset with the plugin.
92
+
93
+ ```json
94
+ {
95
+ "out": "./docs/api",
96
+ "hideInPageTOC": true,
97
+ "hideBreadcrumbs": true,
98
+ "hidePageHeader": true,
99
+ "entryFileName": "index.md"
100
+ }
83
101
  ```
84
102
 
85
- #### Other config options
103
+ ### Plugin options
86
104
 
87
- TypeDoc options can also be declared:
105
+ Options specific to the plugin should also be declared in the same object.
88
106
 
89
- - Using a `typedoc.json` file.
90
- - Under the `typedocOptions` key in `tsconfig.json`.
107
+ #### `--sidebar`
91
108
 
92
- > Note: Options declared in this manner will take priority and overwrite options declared in `docusaurus.config.js`.
109
+ `sidebar.autoConfiguration`
93
110
 
94
- ### Plugin options
111
+ Set to `false` to disable sidebar generation. Defaults to `true`.
95
112
 
96
- Options specific to the plugin should also be declared in the same object.
113
+ `sidebar.filteredIds`
97
114
 
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. |
115
+ Ids of pages to be filtered from the sidebar. This would typically be used to filter README or index pages from the sidebar.
104
116
 
105
- ### An example configuration
117
+ `sidebar.pretty`
106
118
 
107
- ```js
108
- module.exports = {
109
- plugins: [
110
- [
111
- 'docusaurus-plugin-typedoc',
112
- {
113
- // TypeDoc options
114
- entryPoints: ['../src/index.ts'],
115
- tsconfig: '../tsconfig.json',
116
- plugin: ['typedoc-plugin-xyz'],
117
-
118
- // Plugin options
119
- out: 'api-xyz',
120
- sidebar: {
121
- categoryLabel: 'API XYZ',
122
- position: 0,
123
- fullNames: true,
124
- },
125
- },
126
- ],
127
- ],
128
- };
129
- ```
119
+ Pretty format the sidebar JSON.
130
120
 
131
- ## Recipes
121
+ ## Sidebar
132
122
 
133
- ### Sidebar and Navbar
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.
134
124
 
135
- #### Sidebar
125
+ A docusaurus sidebar file `typedoc-sidebar.cjs` is published to the relevant output directory along with the generated markdown documentation.
136
126
 
137
- `sidebars.js` can be configured in following ways:
127
+ This file should be referenced in `sidebars.js` using a sidebar slice and can be configured in following ways:
138
128
 
139
- 1. Generate the entire sidebar from file structure of your docs folder (default behaviour):
129
+ 1. Display sidebar on the root:
140
130
 
141
131
  ```js
142
132
  module.exports = {
143
- sidebar: [
144
- {
145
- type: 'autogenerated',
146
- dirName: '.', // '.' means the docs folder
147
- },
148
- ],
133
+ typedocSidebar: require('./docs/api/typedoc-sidebar.cjs'),
149
134
  };
150
135
  ```
151
136
 
152
- 2. Alternatively, if you wish to manually control other parts of your sidebar you can use a slice for the TypeDoc sidebar.
137
+ 2. Display the sidebar inside a category:
153
138
 
154
- > note: `sidebar.categoryLabel` and `sidebar.position` options are ignored with this implementation)
139
+ ```js
140
+ module.exports = {
141
+ typedocSidebar: {
142
+ 'Typedoc Docs': require('./docs/api/typedoc-sidebar.js'),
143
+ },
144
+ };
145
+ ```
146
+
147
+ 3. Display the sidebar inside a linked category
148
+
149
+ > Note the linked category page can be removed from sidebar using [`sidebar.filteredIds`]().
155
150
 
156
151
  ```js
157
152
  module.exports = {
158
- sidebar: {
159
- 'Category 1': ['doc1', 'doc2', 'doc3'],
160
- API: [
161
- {
162
- type: 'autogenerated',
163
- dirName: 'api', // 'api' is the 'out' directory
153
+ typedocSidebar: [
154
+ {
155
+ type: 'category',
156
+ label: 'Typedoc Docs',
157
+ link: {
158
+ type: 'doc',
159
+ id: 'api/index',
164
160
  },
165
- ],
166
- },
161
+ items: require('./docs/api/typedoc-sidebar.js'),
162
+ },
163
+ ],
167
164
  };
168
165
  ```
169
166
 
170
- Please see https://docusaurus.io/docs/sidebar for sidebar documentation.
167
+ Please see <https://docusaurus.io/docs/sidebar> for sidebar documentation.
171
168
 
172
- #### Navbar
169
+ ## Other configuration
170
+
171
+ ### Navbar
173
172
 
174
173
  A navbar item can be configured in `themeConfig` options in `docusaurus.config.js`:
175
174
 
@@ -188,28 +187,7 @@ A navbar item can be configured in `themeConfig` options in `docusaurus.config.j
188
187
  },
189
188
  ```
190
189
 
191
- Please see https://docusaurus.io/docs/api/themes/configuration#navbar-items for navbar documentation.
192
-
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
- ```
190
+ Please see <https://docusaurus.io/docs/api/themes/configuration#navbar-items> for navbar documentation.
213
191
 
214
192
  ### Multi instance
215
193
 
@@ -242,9 +220,20 @@ module.exports = {
242
220
  };
243
221
  ```
244
222
 
223
+ `sidebars.js`
224
+
225
+ ```js
226
+ module.exports = {
227
+ typedocSidebar: {
228
+ 'API 1': require('./docs/api-1/typedoc-sidebar.js'),
229
+ 'API 2': require('./docs/api-2/typedoc-sidebar.js'),
230
+ },
231
+ };
232
+ ```
233
+
245
234
  ### Watch mode
246
235
 
247
- 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>.
248
237
 
249
238
  Targetting the option in development mode only can be achieved using Node.js Environment Variables:
250
239
 
@@ -272,26 +261,9 @@ module.exports = {
272
261
  };
273
262
  ```
274
263
 
275
- ### Monorepo setup
276
-
277
- `docusaurus.config.js`
264
+ ### Frontmatter
278
265
 
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
- ```
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.
295
267
 
296
268
  ## License
297
269
 
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
+ export { PluginOptions } from './models';
1
2
  export { default } from './plugin';
@@ -0,0 +1,10 @@
1
+ import { PluginOptions as TypedocPluginMarkdownOptions } from 'typedoc-plugin-markdown';
2
+ export interface PluginOptions extends TypedocPluginMarkdownOptions {
3
+ id: string;
4
+ sidebar: Partial<SidebarOptions>;
5
+ }
6
+ export interface SidebarOptions {
7
+ autoConfiguration: boolean;
8
+ pretty: boolean;
9
+ filteredIds: string[];
10
+ }
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 setOptions(app: Application, options: any): void;
package/dist/options.js CHANGED
@@ -1,29 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPluginOptions = void 0;
3
+ exports.setOptions = exports.getPluginOptions = void 0;
4
4
  const DEFAULT_PLUGIN_OPTIONS = {
5
5
  id: 'default',
6
- docsRoot: 'docs',
7
- out: 'api',
8
- cleanOutputDir: true,
6
+ out: './docs/api',
7
+ hideInPageTOC: true,
8
+ hideBreadcrumbs: true,
9
+ hidePageHeader: true,
10
+ entryFileName: 'index.md',
9
11
  sidebar: {
10
- fullNames: false,
11
- categoryLabel: 'API',
12
- collapsed: true,
13
- indexLabel: 'Overview',
14
- position: null,
15
12
  autoConfiguration: true,
13
+ pretty: false,
14
+ filteredIds: [],
16
15
  },
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,
16
+ plugin: ['typedoc-plugin-markdown'],
25
17
  };
26
- const getPluginOptions = (opts) => {
18
+ function getPluginOptions(opts) {
27
19
  const options = {
28
20
  ...DEFAULT_PLUGIN_OPTIONS,
29
21
  ...opts,
@@ -31,7 +23,16 @@ const getPluginOptions = (opts) => {
31
23
  ...DEFAULT_PLUGIN_OPTIONS.sidebar,
32
24
  ...opts.sidebar,
33
25
  },
26
+ plugin: [
27
+ ...new Set([...DEFAULT_PLUGIN_OPTIONS.plugin, ...(opts.plugin || [])]),
28
+ ],
34
29
  };
35
30
  return options;
36
- };
31
+ }
37
32
  exports.getPluginOptions = getPluginOptions;
33
+ function setOptions(app, options) {
34
+ for (const [key, val] of Object.entries(options)) {
35
+ app.options.setValue(key, val);
36
+ }
37
+ }
38
+ exports.setOptions = setOptions;
package/dist/plugin.d.ts CHANGED
@@ -1,6 +1,9 @@
1
- import { PluginOptions } from './types';
1
+ import { PluginOptions } from '.';
2
2
  export default function pluginDocusaurus(context: any, opts: Partial<PluginOptions>): {
3
3
  name: string;
4
4
  loadContent(): Promise<void>;
5
5
  extendCli(cli: any): void;
6
6
  };
7
+ export declare function writeFileSync(fileName: string, data: string): void;
8
+ export declare function normalizePath(path: string): string;
9
+ export declare function removeDir(path: string): void;
package/dist/plugin.js CHANGED
@@ -23,12 +23,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.removeDir = exports.normalizePath = exports.writeFileSync = void 0;
27
+ const fs = __importStar(require("fs"));
26
28
  const path = __importStar(require("path"));
27
29
  const typedoc_1 = require("typedoc");
28
- const typedoc_plugin_markdown_1 = require("typedoc-plugin-markdown");
29
30
  const options_1 = require("./options");
30
- const render_1 = require("./render");
31
- const theme_1 = require("./theme");
31
+ const sidebar_1 = require("./sidebar");
32
+ // store list of plugin ids when running multiple instances
32
33
  const apps = [];
33
34
  function pluginDocusaurus(context, opts) {
34
35
  return {
@@ -36,7 +37,7 @@ function pluginDocusaurus(context, opts) {
36
37
  async loadContent() {
37
38
  if (opts.id && !apps.includes(opts.id)) {
38
39
  apps.push(opts.id);
39
- generateTypedoc(context, opts);
40
+ await generateTypedoc(context, opts);
40
41
  }
41
42
  },
42
43
  extendCli(cli) {
@@ -46,6 +47,7 @@ function pluginDocusaurus(context, opts) {
46
47
  .action(async () => {
47
48
  var _a;
48
49
  (_a = context.siteConfig) === null || _a === void 0 ? void 0 : _a.plugins.forEach((pluginConfig) => {
50
+ // Check PluginConfig is typed to [string, PluginOptions]
49
51
  if (pluginConfig && typeof pluginConfig[1] === 'object') {
50
52
  generateTypedoc(context, pluginConfig[1]);
51
53
  }
@@ -55,22 +57,52 @@ function pluginDocusaurus(context, opts) {
55
57
  };
56
58
  }
57
59
  exports.default = pluginDocusaurus;
60
+ /**
61
+ * Initiates a new typedoc Application bootstraped with plugin options
62
+ */
58
63
  async function generateTypedoc(context, opts) {
64
+ var _a, _b, _c;
59
65
  const { siteDir } = context;
60
66
  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);
67
+ const { id, sidebar, ...optionsPassedToTypeDoc } = options;
68
+ const app = await typedoc_1.Application.bootstrapWithPlugins(optionsPassedToTypeDoc);
69
+ const outputDir = app.options.getValue('out');
70
+ if (options.cleanOutputDir) {
71
+ removeDir(outputDir);
64
72
  }
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();
73
+ if (((_b = (_a = context.siteConfig) === null || _a === void 0 ? void 0 : _a.markdown) === null || _b === void 0 ? void 0 : _b.format) !== 'mdx') {
74
+ app.renderer.on(typedoc_1.PageEvent.END, (event) => {
75
+ var _a;
76
+ event.contents = (_a = event.contents) === null || _a === void 0 ? void 0 : _a.replace(/\\</g, '<');
77
+ });
78
+ }
79
+ if (sidebar === null || sidebar === void 0 ? void 0 : sidebar.autoConfiguration) {
80
+ const docsPreset = (_c = context.siteConfig) === null || _c === void 0 ? void 0 : _c.presets.find((preset) => { var _a; return Boolean((_a = preset[1]) === null || _a === void 0 ? void 0 : _a.docs); });
81
+ app.renderer.postRenderAsyncJobs.push(async (output) => {
82
+ var _a, _b;
83
+ const sidebarPath = path.resolve(outputDir, 'typedoc-sidebar.cjs');
84
+ const baseDir = path
85
+ .relative(siteDir, outputDir)
86
+ .split(path.sep)
87
+ .slice(1)
88
+ .join(path.sep);
89
+ const sidebarJson = (0, sidebar_1.getSidebar)(output.navigation, baseDir, sidebar.filteredIds, (_b = (_a = docsPreset[1]) === null || _a === void 0 ? void 0 : _a.docs) === null || _b === void 0 ? void 0 : _b.numberPrefixParser);
90
+ fs.writeFileSync(sidebarPath, `// @ts-check
91
+ /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
92
+ const typedocSidebar = { items: ${JSON.stringify(sidebarJson, null, sidebar.pretty ? 2 : 0)}};
93
+ module.exports = typedocSidebar.items;`);
94
+ });
95
+ }
96
+ const project = await app.convert();
97
+ // if project is undefined typedoc has a problem - error logging will be supplied by typedoc.
70
98
  if (!project) {
71
- return;
99
+ if (app.options.getValue('skipErrorChecking')) {
100
+ return;
101
+ }
102
+ console.error('[docusaurus-plugin-typedoc] TypeDoc exited with an error. Use the "skipErrorChecking" option to disable TypeDoc error checking.');
103
+ process.exit();
72
104
  }
73
- if (options.watch) {
105
+ if (app.options.getValue('watch')) {
74
106
  app.convertAndWatch(async (project) => {
75
107
  await app.generateDocs(project, outputDir);
76
108
  });
@@ -79,3 +111,32 @@ async function generateTypedoc(context, opts) {
79
111
  await app.generateDocs(project, outputDir);
80
112
  }
81
113
  }
114
+ function writeFileSync(fileName, data) {
115
+ fs.mkdirSync(path.dirname(normalizePath(fileName)), { recursive: true });
116
+ fs.writeFileSync(normalizePath(fileName), data);
117
+ }
118
+ exports.writeFileSync = writeFileSync;
119
+ function normalizePath(path) {
120
+ return path.replace(/\\/g, '/');
121
+ }
122
+ exports.normalizePath = normalizePath;
123
+ function removeDir(path) {
124
+ if (fs.existsSync(path)) {
125
+ const files = fs.readdirSync(path);
126
+ if (files.length > 0) {
127
+ files.forEach(function (filename) {
128
+ if (fs.statSync(path + '/' + filename).isDirectory()) {
129
+ removeDir(path + '/' + filename);
130
+ }
131
+ else {
132
+ fs.unlinkSync(path + '/' + filename);
133
+ }
134
+ });
135
+ fs.rmdirSync(path);
136
+ }
137
+ else {
138
+ fs.rmdirSync(path);
139
+ }
140
+ }
141
+ }
142
+ 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[], numberPrefixParser?: any): any;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSidebar = void 0;
4
+ function getSidebar(navigation, basePath, filteredIds = [], numberPrefixParser) {
5
+ return navigation
6
+ .map((navigationItem) => getNavigationItem(navigationItem, basePath, filteredIds, numberPrefixParser))
7
+ .filter((navItem) => Boolean(navItem));
8
+ }
9
+ exports.getSidebar = getSidebar;
10
+ function getNavigationItem(navigationItem, basePath, filteredIds, numberPrefixParser) {
11
+ var _a, _b;
12
+ const parsedUrl = numberPrefixParser === false
13
+ ? navigationItem.url
14
+ : (_a = navigationItem.url) === null || _a === void 0 ? void 0 : _a.replace(/\d+\-/g, '');
15
+ const id = navigationItem.url
16
+ ? `${basePath}/${parsedUrl}`.replace(/(.*).md/, '$1')
17
+ : null;
18
+ if ((_b = navigationItem.children) === null || _b === void 0 ? void 0 : _b.length) {
19
+ return {
20
+ type: 'category',
21
+ label: navigationItem.title,
22
+ items: getSidebar(navigationItem.children, basePath, filteredIds),
23
+ ...(id && { link: { type: 'doc', id } }),
24
+ };
25
+ }
26
+ return id && !filteredIds.includes(id)
27
+ ? {
28
+ type: 'doc',
29
+ id,
30
+ label: navigationItem.title,
31
+ }
32
+ : null;
33
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-typedoc",
3
- "version": "1.0.0-next.2",
4
- "description": "A Docusaurus v2 plugin to build API documentation with TypeDoc.",
3
+ "version": "1.0.0-next.21",
4
+ "description": "A Docusaurus plugin to build API documentation with TypeDoc.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
7
7
  "dist/"
@@ -16,15 +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": ">=0.23.0",
20
- "typedoc-plugin-markdown": ">=4.0.0-next.2"
19
+ "typedoc-plugin-markdown": ">=4.0.0-next.26"
21
20
  },
22
21
  "scripts": {
23
22
  "lint": "eslint ./src --ext .ts",
24
- "prepublishOnly": "npm run lint && npm run build && npm run test",
23
+ "prepublishOnly": "npm run lint && npm run build",
25
24
  "build": "rm -rf ./dist && tsc",
26
- "build-and-test": "npm run build && npm run test",
27
- "test": "jest --colors"
25
+ "task:docs": "node ./tasks/docs.mjs"
28
26
  },
29
27
  "author": "Thomas Grey",
30
28
  "license": "MIT",
@@ -35,5 +33,8 @@
35
33
  "markdown",
36
34
  "typescript",
37
35
  "api"
38
- ]
36
+ ],
37
+ "devDependencies": {
38
+ "@docusaurus/types": "^3.0.0"
39
+ }
39
40
  }
@@ -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/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,36 +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
- }
22
- export type FrontMatter = Record<string, string | boolean | number | null> | undefined;
23
- export interface SidebarOptions {
24
- fullNames?: boolean;
25
- categoryLabel: string;
26
- collapsed: boolean;
27
- indexLabel?: string;
28
- position: number | null;
29
- autoConfiguration: boolean;
30
- }
31
- export interface SidebarCategory {
32
- type: string;
33
- label: string;
34
- items: SidebarItem[];
35
- }
36
- export type SidebarItem = SidebarCategory | string;
File without changes