docusaurus-plugin-typedoc 1.0.0-next.3 → 1.0.0-next.30

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,298 +1,15 @@
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=next)](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)
7
-
8
- ## What it does?
9
-
10
- Generates static TypeDoc pages in Markdown with frontmatter as part of the Docusaurus build.
5
+ A Docusaurus plugin to integrate TypeDoc ( + typedoc-plugin-markdown ) into a Docusaurus project.
11
6
 
12
7
  ## Installation
13
8
 
14
- > 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
-
16
9
  ```shell
17
- npm install typedoc typedoc-plugin-markdown docusaurus-plugin-typedoc --save-dev
18
- ```
19
-
20
- ## Usage
21
-
22
- ### Config
23
-
24
- Add the plugin to `docusaurus.config.js` and specify the required options (see [options](#options)).
25
-
26
- ```js
27
- module.exports = {
28
- plugins: [
29
- [
30
- 'docusaurus-plugin-typedoc',
31
-
32
- // Plugin / TypeDoc options
33
- {
34
- entryPoints: ['../src/index.ts'],
35
- tsconfig: '../tsconfig.json',
36
- },
37
- ],
38
- ],
39
- };
40
- ```
41
-
42
- TypeDoc will be bootstraped with the Docusaurus `start` and `build` [cli commands](https://v2.docusaurus.io/docs/cli):
43
-
44
- ```javascript
45
- "start": "docusaurus start",
46
- "build": "docusaurus build",
47
- ```
48
-
49
- Once built the docs will be available at `/docs/api` (or equivalent out directory).
50
-
51
- ### Directory structure
52
-
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
- ```
65
-
66
- ## Options
67
-
68
- ### TypeDoc options
69
-
70
- To configure TypeDoc, pass any relevant [TypeDoc options](https://typedoc.org/guides/options/) to the config.
71
-
72
- At a minimum the `entryPoints` and `tsconfig` options will need to be set.
73
-
74
- ```js
75
- entryPoints: ['../src/index.ts'],
76
- tsconfig: '../tsconfig.json'
77
- ```
78
-
79
- Additional TypeDoc plugins will need to be explicitly set:
80
-
81
- ```js
82
- plugin: ['typedoc-plugin-xyz'];
83
- ```
84
-
85
- #### Other config options
86
-
87
- TypeDoc options can also be declared:
88
-
89
- - Using a `typedoc.json` file.
90
- - Under the `typedocOptions` key in `tsconfig.json`.
91
-
92
- > Note: Options declared in this manner will take priority and overwrite options declared in `docusaurus.config.js`.
93
-
94
- ### Plugin options
95
-
96
- Options specific to the plugin should also be declared in the same object.
97
-
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. |
104
-
105
- ### An example configuration
106
-
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
- ```
130
-
131
- ## Recipes
132
-
133
- ### Sidebar and Navbar
134
-
135
- #### Sidebar
136
-
137
- `sidebars.js` can be configured in following ways:
138
-
139
- 1. Generate the entire sidebar from file structure of your docs folder (default behaviour):
140
-
141
- ```js
142
- module.exports = {
143
- sidebar: [
144
- {
145
- type: 'autogenerated',
146
- dirName: '.', // '.' means the docs folder
147
- },
148
- ],
149
- };
150
- ```
151
-
152
- 2. Alternatively, if you wish to manually control other parts of your sidebar you can use a slice for the TypeDoc sidebar.
153
-
154
- > note: `sidebar.categoryLabel` and `sidebar.position` options are ignored with this implementation)
155
-
156
- ```js
157
- module.exports = {
158
- sidebar: {
159
- 'Category 1': ['doc1', 'doc2', 'doc3'],
160
- API: [
161
- {
162
- type: 'autogenerated',
163
- dirName: 'api', // 'api' is the 'out' directory
164
- },
165
- ],
166
- },
167
- };
168
- ```
169
-
170
- Please see https://docusaurus.io/docs/sidebar for sidebar documentation.
171
-
172
- #### Navbar
173
-
174
- A navbar item can be configured in `themeConfig` options in `docusaurus.config.js`:
175
-
176
- ```js
177
- themeConfig: {
178
- navbar: {
179
- items: [
180
- {
181
- to: 'docs/api/', // 'api' is the 'out' directory
182
- activeBasePath: 'docs',
183
- label: 'API',
184
- position: 'left',
185
- },
186
- ],
187
- },
188
- },
189
- ```
190
-
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
- ```
213
-
214
- ### Multi instance
215
-
216
- It is possible to build multi TypeDoc instances by passing in multiple configs with unique ids:
217
-
218
- `docusaurus.config.js`
219
-
220
- ```js
221
- module.exports = {
222
- plugins: [
223
- [
224
- 'docusaurus-plugin-typedoc',
225
- {
226
- id: 'api-1',
227
- entryPoints: ['../api-1/src/index.ts'],
228
- tsconfig: '../api-1/tsconfig.json',
229
- out: 'api-1',
230
- },
231
- ],
232
- [
233
- 'docusaurus-plugin-typedoc',
234
- {
235
- id: 'api-2',
236
- entryPoints: ['../api-2/src/index.ts'],
237
- tsconfig: '../api-2/tsconfig.json',
238
- out: 'api-2',
239
- },
240
- ],
241
- ],
242
- };
243
- ```
244
-
245
- ### Watch mode
246
-
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).
248
-
249
- Targetting the option in development mode only can be achieved using Node.js Environment Variables:
250
-
251
- `package.json`
252
-
253
- ```json
254
- "start": "TYPEDOC_WATCH=true docusaurus start",
255
- "build": "TYPEDOC_WATCH=false docusaurus build",
256
- ```
257
-
258
- `docusaurus.config.js`
259
-
260
- ```js
261
- module.exports = {
262
- plugins: [
263
- [
264
- 'docusaurus-plugin-typedoc',
265
- {
266
- entryPoints: ['../src/index.ts'],
267
- tsconfig: '../tsconfig.json',
268
- watch: process.env.TYPEDOC_WATCH,
269
- },
270
- ],
271
- ],
272
- };
273
- ```
274
-
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
- ```
10
+ npm install docusaurus-plugin-typedoc --save-dev
11
+ ```
295
12
 
296
- ## License
13
+ ## Documentation
297
14
 
298
- [MIT](https://github.com/tgreyuk/typedoc-plugin-markdown/blob/master/packages/docusaurus-plugin-typedoc/LICENSE)
15
+ Please visit [typedoc-plugin-markdown.org](https://typedoc-plugin-markdown.org/plugins/docusaurus) for comprehensive documentation, including options and usage guides.
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
+ export { PluginOptions } from './models';
1
2
  export { default } from './plugin';
@@ -0,0 +1,5 @@
1
+ import { PluginOptions as TypedocPluginMarkdownOptions } from 'typedoc-plugin-markdown';
2
+ import { PluginOptions as DocusaurusOptions } from './options/option-types';
3
+ export interface PluginOptions extends TypedocPluginMarkdownOptions, DocusaurusOptions {
4
+ id: string;
5
+ }
@@ -0,0 +1,21 @@
1
+ import { ParameterType } from 'typedoc';
2
+ /**
3
+ * **sidebar.autoConfiguration**
4
+ *
5
+ * Set to `false` to disable sidebar generation. Defaults to `true`.
6
+ *
7
+ * **sidebar.pretty**
8
+ *
9
+ * Pretty format the sidebar JSON.
10
+ *
11
+ * Please see the [sidebar guide](/plugins/docusaurus/guide/sidebar) for additional information on sidebar setup.
12
+ *
13
+ */
14
+ export declare const sidebar: {
15
+ help: string;
16
+ type: ParameterType;
17
+ defaultValue: {
18
+ autoConfiguration: boolean;
19
+ pretty: boolean;
20
+ };
21
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sidebar = void 0;
4
+ const typedoc_1 = require("typedoc");
5
+ const options_1 = require("../options");
6
+ /**
7
+ * **sidebar.autoConfiguration**
8
+ *
9
+ * Set to `false` to disable sidebar generation. Defaults to `true`.
10
+ *
11
+ * **sidebar.pretty**
12
+ *
13
+ * Pretty format the sidebar JSON.
14
+ *
15
+ * Please see the [sidebar guide](/plugins/docusaurus/guide/sidebar) for additional information on sidebar setup.
16
+ *
17
+ */
18
+ exports.sidebar = {
19
+ help: 'Configures the autogenerated Docusaurus sidebar.',
20
+ type: typedoc_1.ParameterType.Mixed,
21
+ defaultValue: options_1.DEFAULT_SIDEBAR_OPTIONS,
22
+ };
@@ -0,0 +1,26 @@
1
+ import { ManuallyValidatedOption } from 'typedoc';
2
+ declare module 'typedoc' {
3
+ interface TypeDocOptionMap {
4
+ sidebar: ManuallyValidatedOption<Sidebar>;
5
+ }
6
+ }
7
+ /**
8
+ * Describes the options declared by the plugin.
9
+ *
10
+ * @category Options
11
+ */
12
+ export interface PluginOptions {
13
+ /**
14
+ * Configures the autogenerated Docusaurus sidebar.
15
+ */
16
+ sidebar: Sidebar;
17
+ }
18
+ /**
19
+ *
20
+ *
21
+ * @category Options
22
+ */
23
+ export interface Sidebar {
24
+ autoConfiguration: boolean;
25
+ pretty: boolean;
26
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // THIS FILE IS AUTO GENERATED FROM THE OPTIONS CONFIG. DO NOT EDIT DIRECTLY.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ declare const _default: {
2
+ out: string;
3
+ hideBreadcrumbs: boolean;
4
+ hidePageHeader: boolean;
5
+ entryFileName: string;
6
+ plugin: string[];
7
+ };
8
+ export default _default;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ out: './docs/api',
5
+ hideBreadcrumbs: true,
6
+ hidePageHeader: true,
7
+ entryFileName: 'index.md',
8
+ plugin: ['typedoc-plugin-markdown'],
9
+ };
package/dist/options.d.ts CHANGED
@@ -1,2 +1,5 @@
1
- import { PluginOptions } from './types';
2
- export declare const getPluginOptions: (opts: Partial<PluginOptions>) => PluginOptions;
1
+ export declare const DEFAULT_SIDEBAR_OPTIONS: {
2
+ autoConfiguration: boolean;
3
+ pretty: boolean;
4
+ };
5
+ export declare function getPluginOptions(opts: Record<string, any>): Record<string, any>;
package/dist/options.js CHANGED
@@ -1,29 +1,22 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPluginOptions = void 0;
6
+ exports.getPluginOptions = exports.DEFAULT_SIDEBAR_OPTIONS = void 0;
7
+ const presets_1 = __importDefault(require("./options/presets"));
8
+ exports.DEFAULT_SIDEBAR_OPTIONS = {
9
+ autoConfiguration: true,
10
+ pretty: false,
11
+ };
4
12
  const DEFAULT_PLUGIN_OPTIONS = {
13
+ ...presets_1.default,
5
14
  id: 'default',
6
- docsRoot: 'docs',
7
- out: 'api',
8
- cleanOutputDir: true,
9
15
  sidebar: {
10
- fullNames: false,
11
- categoryLabel: 'API',
12
- collapsed: true,
13
- indexLabel: 'Overview',
14
- position: null,
15
- autoConfiguration: true,
16
+ ...exports.DEFAULT_SIDEBAR_OPTIONS,
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
18
  };
26
- const getPluginOptions = (opts) => {
19
+ function getPluginOptions(opts) {
27
20
  const options = {
28
21
  ...DEFAULT_PLUGIN_OPTIONS,
29
22
  ...opts,
@@ -31,7 +24,10 @@ const getPluginOptions = (opts) => {
31
24
  ...DEFAULT_PLUGIN_OPTIONS.sidebar,
32
25
  ...opts.sidebar,
33
26
  },
27
+ plugin: [
28
+ ...new Set([...DEFAULT_PLUGIN_OPTIONS.plugin, ...(opts.plugin || [])]),
29
+ ],
34
30
  };
35
31
  return options;
36
- };
32
+ }
37
33
  exports.getPluginOptions = getPluginOptions;
package/dist/plugin.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { PluginOptions } from './types';
2
- export default function pluginDocusaurus(context: any, opts: Partial<PluginOptions>): {
1
+ import { PluginOptions } from '.';
2
+ export default function pluginDocusaurus(context: any, opts: Partial<PluginOptions>): Promise<{
3
3
  name: string;
4
- loadContent(): Promise<void>;
5
4
  extendCli(cli: any): void;
6
- };
5
+ }>;
package/dist/plugin.js CHANGED
@@ -23,29 +23,29 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
+ const fs = __importStar(require("fs"));
26
27
  const path = __importStar(require("path"));
27
28
  const typedoc_1 = require("typedoc");
28
- const typedoc_plugin_markdown_1 = require("typedoc-plugin-markdown");
29
29
  const options_1 = require("./options");
30
- const render_1 = require("./render");
31
- const theme_1 = require("./theme");
30
+ const options = __importStar(require("./options/declarations"));
31
+ const sidebar_1 = require("./sidebar");
32
+ // store list of plugin ids when running multiple instances
32
33
  const apps = [];
33
- function pluginDocusaurus(context, opts) {
34
+ async function pluginDocusaurus(context, opts) {
35
+ const PLUGIN_NAME = 'docusaurus-plugin-typedoc';
36
+ if (opts.id && !apps.includes(opts.id)) {
37
+ apps.push(opts.id);
38
+ await generateTypedoc(context, opts);
39
+ }
34
40
  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
- },
41
+ name: PLUGIN_NAME,
42
42
  extendCli(cli) {
43
43
  cli
44
44
  .command('generate-typedoc')
45
- .description('(docusaurus-plugin-typedoc) Generate TypeDoc docs independently of the Docusaurus build process.')
45
+ .description(`[${PLUGIN_NAME}] Generate TypeDoc docs independently of the Docusaurus build process.`)
46
46
  .action(async () => {
47
- var _a;
48
- (_a = context.siteConfig) === null || _a === void 0 ? void 0 : _a.plugins.forEach((pluginConfig) => {
47
+ context.siteConfig?.plugins.forEach((pluginConfig) => {
48
+ // Check PluginConfig is typed to [string, PluginOptions]
49
49
  if (pluginConfig && typeof pluginConfig[1] === 'object') {
50
50
  generateTypedoc(context, pluginConfig[1]);
51
51
  }
@@ -55,22 +55,49 @@ function pluginDocusaurus(context, opts) {
55
55
  };
56
56
  }
57
57
  exports.default = pluginDocusaurus;
58
+ /**
59
+ * Initiates a new typedoc Application bootstrapped with plugin options
60
+ */
58
61
  async function generateTypedoc(context, opts) {
59
62
  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);
63
+ const pluginOptions = (0, options_1.getPluginOptions)(opts);
64
+ const { id, sidebar, ...optionsPassedToTypeDoc } = pluginOptions;
65
+ const app = await typedoc_1.Application.bootstrapWithPlugins(optionsPassedToTypeDoc);
66
+ Object.entries(options).forEach(([name, option]) => {
67
+ app.options.addDeclaration({
68
+ name,
69
+ ...option,
70
+ });
71
+ });
72
+ const outputDir = app.options.getValue('out');
73
+ if (sidebar?.autoConfiguration) {
74
+ const docsPreset = context.siteConfig?.presets?.find((preset) => Boolean(preset[1]?.docs));
75
+ app.renderer.postRenderAsyncJobs.push(async (output) => {
76
+ if (output.navigation) {
77
+ const sidebarPath = path.resolve(outputDir, 'typedoc-sidebar.cjs');
78
+ const baseDir = path
79
+ .relative(siteDir, outputDir)
80
+ .split(path.sep)
81
+ .slice(1)
82
+ .join(path.sep);
83
+ const sidebarJson = (0, sidebar_1.getSidebar)(output.navigation, baseDir, docsPreset ? docsPreset[1]?.docs?.numberPrefixParser : null);
84
+ fs.writeFileSync(sidebarPath, `// @ts-check
85
+ /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
86
+ const typedocSidebar = { items: ${JSON.stringify(sidebarJson, null, sidebar.pretty ? 2 : 0)}};
87
+ module.exports = typedocSidebar.items;`);
88
+ }
89
+ });
64
90
  }
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();
91
+ const project = await app.convert();
92
+ // if project is undefined typedoc has a problem - error logging will be supplied by typedoc.
70
93
  if (!project) {
71
- return;
94
+ if (app.options.getValue('skipErrorChecking')) {
95
+ return;
96
+ }
97
+ console.error('[docusaurus-plugin-typedoc] TypeDoc exited with an error. Use the "skipErrorChecking" option to disable TypeDoc error checking.');
98
+ process.exit(1);
72
99
  }
73
- if (options.watch) {
100
+ if (app.options.getValue('watch')) {
74
101
  app.convertAndWatch(async (project) => {
75
102
  await app.generateDocs(project, outputDir);
76
103
  });
@@ -0,0 +1,2 @@
1
+ import { NavigationItem } from 'typedoc-plugin-markdown';
2
+ export declare function getSidebar(navigation: NavigationItem[], basePath: string, numberPrefixParser?: any): any;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSidebar = void 0;
4
+ function getSidebar(navigation, basePath, numberPrefixParser) {
5
+ return navigation
6
+ .map((navigationItem) => getNavigationItem(navigationItem, basePath, numberPrefixParser))
7
+ .filter((navItem) => Boolean(navItem));
8
+ }
9
+ exports.getSidebar = getSidebar;
10
+ function getNavigationItem(navigationItem, basePath, numberPrefixParser) {
11
+ const parsedUrl = numberPrefixParser === false
12
+ ? navigationItem.path
13
+ : navigationItem.path?.replace(/\d+\-/g, '');
14
+ const getId = () => {
15
+ const idParts = [];
16
+ if (basePath.length > 0) {
17
+ idParts.push(basePath);
18
+ }
19
+ if (parsedUrl) {
20
+ idParts.push(parsedUrl.replace(/\\/g, '/'));
21
+ }
22
+ if (navigationItem.path) {
23
+ return idParts.join('/').replace(/(.*)\.\w+$/, '$1');
24
+ }
25
+ return null;
26
+ };
27
+ const id = getId();
28
+ if (navigationItem.children?.length) {
29
+ return {
30
+ type: 'category',
31
+ label: `${navigationItem.title}`,
32
+ items: getSidebar(navigationItem.children, basePath, numberPrefixParser),
33
+ ...(id && {
34
+ link: {
35
+ type: 'doc',
36
+ id,
37
+ },
38
+ }),
39
+ };
40
+ }
41
+ return id
42
+ ? {
43
+ type: 'doc',
44
+ id,
45
+ label: `${navigationItem.title}`,
46
+ }
47
+ : null;
48
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-typedoc",
3
- "version": "1.0.0-next.3",
4
- "description": "A Docusaurus v2 plugin to build API documentation with TypeDoc.",
3
+ "version": "1.0.0-next.30",
4
+ "description": "A Docusaurus plugin to integrate TypeDoc ( + typedoc-plugin-markdown ) into a Docusaurus project.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
7
7
  "dist/"
@@ -16,15 +16,16 @@
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.4"
19
+ "typedoc-plugin-markdown": ">=4.0.0-next.45"
21
20
  },
22
21
  "scripts": {
23
22
  "lint": "eslint ./src --ext .ts",
24
- "prepublishOnly": "npm run lint && npm run build && npm run test",
25
- "build": "rm -rf ./dist && tsc",
26
- "build-and-test": "npm run build && npm run test",
27
- "test": "jest --colors"
23
+ "prebuild": "rm -rf dist && prebuild-options",
24
+ "prepublishOnly": "npm run lint && npm run build",
25
+ "build": "tsc",
26
+ "pretest": "rm -rf ./test/out && docusaurus generate-typedoc",
27
+ "test": "jest",
28
+ "test:update": "npm run build && npm test -- -u"
28
29
  },
29
30
  "author": "Thomas Grey",
30
31
  "license": "MIT",
@@ -35,5 +36,9 @@
35
36
  "markdown",
36
37
  "typescript",
37
38
  "api"
38
- ]
39
+ ],
40
+ "devDependencies": {
41
+ "@docusaurus/core": "^3.2.1",
42
+ "@docusaurus/types": "^3.2.1"
43
+ }
39
44
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2016 Thomas Grey
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -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,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
- 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
- await Promise.all(this.preRenderAsyncJobs.map((job) => job(output)));
45
- this.preRenderAsyncJobs = [];
46
- if (!output.isDefaultPrevented) {
47
- (_a = output.urls) === null || _a === void 0 ? void 0 : _a.forEach((mapping) => {
48
- this.renderDocument(...output.createPageEvent(mapping));
49
- });
50
- await Promise.all(this.postRenderAsyncJobs.map((job) => job(output)));
51
- this.postRenderAsyncJobs = [];
52
- this.trigger(typedoc_1.RendererEvent.END, output);
53
- }
54
- }
55
- exports.render = render;
56
- const addTypedocReaders = (app) => {
57
- app.options.addReader(new typedoc_1.TypeDocReader());
58
- app.options.addReader(new typedoc_1.TSConfigReader());
59
- };
60
- const addTypedocDeclarations = (app) => {
61
- app.options.addDeclaration({
62
- name: 'id',
63
- });
64
- app.options.addDeclaration({
65
- name: 'docsRoot',
66
- });
67
- app.options.addDeclaration({
68
- name: 'siteDir',
69
- });
70
- app.options.addDeclaration({
71
- name: 'globalsTitle',
72
- });
73
- app.options.addDeclaration({
74
- name: 'sidebar',
75
- type: typedoc_1.ParameterType.Mixed,
76
- });
77
- };
78
- function removeDir(path) {
79
- fs.rmSync(path, { recursive: true, force: true });
80
- }
81
- 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