docusaurus-plugin-typedoc 0.16.1 → 0.16.5

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
@@ -7,14 +7,11 @@ A [Docusaurus v2](https://v2.docusaurus.io/) plugin to build documentation with
7
7
 
8
8
  ## What it does?
9
9
 
10
- - Generates static TypeDoc pages in Markdown as part of the build.
11
- - Adds frontmatter to pages.
10
+ Generates static TypeDoc pages in Markdown with frontmatter as part of the Docusaurus build.
12
11
 
13
12
  ## Installation
14
13
 
15
- > Install in the same location as the Docusaurus website directory.
16
-
17
- This guide assumes that a Docusaurus project has already been setup. See [installation docs](https://v2.docusaurus.io/docs/installation).
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.
18
15
 
19
16
  ```shell
20
17
  npm install typedoc typedoc-plugin-markdown docusaurus-plugin-typedoc --save-dev
@@ -49,61 +46,23 @@ TypeDoc will be bootstraped with the Docusaurus `start` and `build` [cli command
49
46
  "build": "docusaurus build",
50
47
  ```
51
48
 
52
- Once built the docs will be available at `/docs/api` or equivalent out directory.
53
-
54
- ```
55
- website/ (docusaururs website root)
56
- ├── build/ (static site dir)
57
- ├── docs/
58
- │ ├── api/ (compiled typedoc markdown)
59
- ├── docusaurus.config.js
60
- ├── package.json
61
- ├── sidebars.js
62
- ```
63
-
64
- ### Sidebar
65
-
66
- `sidebars.js` can be configured in following ways:
49
+ Once built the docs will be available at `/docs/api` (or equivalent out directory).
67
50
 
68
- 1 ) Generate the entire sidebar from file structure of your docs folder (default behaviour):
51
+ ### Directory structure
69
52
 
70
- ```js
71
- module.exports = {
72
- someSidebar: [
73
- {
74
- type: 'autogenerated',
75
- dirName: '.', // '.' means the docs folder
76
- },
77
- ],
78
- };
79
53
  ```
80
-
81
- 2 ) Alternatively, if you wish to manually control other parts of your sidebar you can use a slice for the TypeDoc sidebar.
82
- (note:`sidebar.categoryLabel` and `sidebar.position` options are ignored with this implementation)
83
-
84
-
85
- ```js
86
- module.exports = {
87
- someSidebar: {
88
- 'Category 1': ['doc1', 'doc2', 'doc3'],
89
-
90
- // use seperate generated file
91
- 'API': require('./typedoc-sidebar.js'),
92
-
93
- // or write inline
94
- 'API': [
95
- {
96
- type: 'autogenerated',
97
- dirName: 'api', // 'api' is the 'out' directory
98
- },
99
- ],
100
- },
101
- };
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
102
64
  ```
103
65
 
104
- > To maintain backward compatibility with previous versions a `./typedoc-sidebar.js` is created by default. Pass `sidebar.sidebarFile:null` to prevent this.
105
-
106
- Please see https://docusaurus.io/docs/sidebar for sidebar documentation.
107
66
 
108
67
  ## Options
109
68
 
@@ -131,18 +90,18 @@ TypeDoc options can also be declared:
131
90
  - Using a `typedoc.json` file.
132
91
  - Under the `typedocOptions` key in `tsconfig.json`.
133
92
 
134
- Note: Options declared in this manner will take priority and overwrite options declared in `docusaurus.config.js`.
93
+ > Note: Options declared in this manner will take priority and overwrite options declared in `docusaurus.config.js`.
135
94
 
136
95
  ### Plugin options
137
96
 
138
- | Name | Default | Description |
139
- | :---------------------- | :------ | :------------------------------------------- |
140
- | `out` | `"api"` | Output directory relative to docs directory. |
141
- | `sidebar.categoryLabel` | `API` | The sidebar parent category label. |
142
- | `sidebar.fullNames` | `false` | Display full names with module path. |
143
- | `sidebar.position` | `null` | The position of the sidebar in the tree. |
97
+ Options specific to the plugin should also be declared in the same object.
144
98
 
145
- If the manual sidebar is not required pass `sidebar.sidebarFile: null` to skip sidebar generation.
99
+ | Name | Default | Description |
100
+ | :---------------------- | :------ | :------------------------------------------------------- |
101
+ | `out` | `"api"` | Output dir relative to docs dir (use `.` for no subdir). | |
102
+ | `sidebar.categoryLabel` | `API` | The sidebar parent category label. |
103
+ | `sidebar.fullNames` | `false` | Display full names with module path. |
104
+ | `sidebar.position` | `auto` | The position of the sidebar in the tree. |
146
105
 
147
106
  ### An example configuration
148
107
 
@@ -172,7 +131,68 @@ module.exports = {
172
131
  ```
173
132
 
174
133
 
175
- ## Additional config
134
+ ## Recipes
135
+
136
+ ### Sidebar and Navbar
137
+
138
+ #### Sidebar
139
+
140
+ `sidebars.js` can be configured in following ways:
141
+
142
+ 1) Generate the entire sidebar from file structure of your docs folder (default behaviour):
143
+
144
+ ```js
145
+ module.exports = {
146
+ sidebar: [
147
+ {
148
+ type: 'autogenerated',
149
+ dirName: '.', // '.' means the docs folder
150
+ },
151
+ ],
152
+ };
153
+ ```
154
+
155
+ 2) Alternatively, if you wish to manually control other parts of your sidebar you can use a slice for the TypeDoc sidebar.
156
+
157
+ > note: `sidebar.categoryLabel` and `sidebar.position` options are ignored with this implementation)
158
+
159
+ ```js
160
+ module.exports = {
161
+ sidebar: {
162
+ 'Category 1': ['doc1', 'doc2', 'doc3'],
163
+ 'API': [
164
+ {
165
+ type: 'autogenerated',
166
+ dirName: 'api', // 'api' is the 'out' directory
167
+ },
168
+ ],
169
+ },
170
+ };
171
+ ```
172
+
173
+ Please see https://docusaurus.io/docs/sidebar for sidebar documentation.
174
+
175
+ #### Navbar
176
+
177
+ A navbar item can be configured in `themeConfig` options in `docusaurus.config.js`:
178
+
179
+ ```js
180
+ themeConfig: {
181
+ navbar: {
182
+ items: [
183
+ {
184
+ to: 'docs/api/', // 'api' is the 'out' directory
185
+ activeBasePath: 'docs',
186
+ label: 'API',
187
+ position: 'left',
188
+ },
189
+ ],
190
+ },
191
+ },
192
+ ```
193
+
194
+ Please see https://docusaurus.io/docs/api/themes/configuration#navbar-items for navbar documentation.
195
+
176
196
 
177
197
  ### Multi instance
178
198
 
@@ -232,6 +252,27 @@ module.exports = {
232
252
  };
233
253
  ```
234
254
 
255
+ ### Monorepo setup
256
+
257
+ `docusaurus.config.js`
258
+
259
+ ```js
260
+ module.exports = {
261
+ plugins: [
262
+ [
263
+ 'docusaurus-plugin-typedoc',
264
+ {
265
+ entryPoints: ['../packages/package-a', '../packages/package-b'],
266
+ entryPointStrategy: 'packages',
267
+ sidebar: {
268
+ fullNames: true
269
+ },
270
+ },
271
+ ],
272
+ ],
273
+ };
274
+ ```
275
+
235
276
  ## License
236
277
 
237
278
  [MIT](https://github.com/tgreyuk/typedoc-plugin-markdown/blob/master/packages/docusaurus-plugin-typedoc/LICENSE)
package/dist/options.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  import { PluginOptions } from './types';
2
2
  export declare const getPluginOptions: (opts: Partial<PluginOptions>) => PluginOptions;
3
- export declare const getOutputDirectory: (siteDir: string, options: PluginOptions) => string;
package/dist/options.js CHANGED
@@ -1,44 +1,24 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.getOutputDirectory = exports.getPluginOptions = void 0;
23
- const path = __importStar(require("path"));
3
+ exports.getPluginOptions = void 0;
24
4
  const DEFAULT_PLUGIN_OPTIONS = {
25
5
  id: 'default',
26
6
  docsRoot: 'docs',
27
7
  out: 'api',
28
8
  sidebar: {
29
9
  fullNames: false,
30
- sidebarFile: 'typedoc-sidebar.js',
31
10
  categoryLabel: 'API',
32
11
  indexLabel: undefined,
33
12
  readmeLabel: 'Readme',
34
13
  position: null,
35
14
  },
36
- plugin: ['none'],
37
- watch: false,
38
15
  hideInPageTOC: true,
39
16
  hideBreadcrumbs: true,
40
17
  hidePageTitle: true,
41
18
  entryDocument: 'index.md',
19
+ plugin: ['none'],
20
+ watch: false,
21
+ indexSlug: undefined,
42
22
  };
43
23
  const getPluginOptions = (opts) => {
44
24
  const options = {
@@ -52,7 +32,3 @@ const getPluginOptions = (opts) => {
52
32
  return options;
53
33
  };
54
34
  exports.getPluginOptions = getPluginOptions;
55
- const getOutputDirectory = (siteDir, options) => {
56
- return path.resolve(siteDir, options.docsRoot, path.relative(process.cwd(), options.out));
57
- };
58
- exports.getOutputDirectory = getOutputDirectory;
package/dist/plugin.js CHANGED
@@ -24,30 +24,29 @@ const typedoc_1 = require("typedoc");
24
24
  const typedoc_plugin_markdown_1 = require("typedoc-plugin-markdown");
25
25
  const options_1 = require("./options");
26
26
  const render_1 = require("./render");
27
- const sidebar_1 = require("./sidebar");
28
27
  const apps = [];
29
28
  async function pluginDocusaurus(context, opts) {
30
29
  if (opts.id && !apps.includes(opts.id)) {
31
30
  apps.push(opts.id);
32
31
  const { siteDir } = context;
32
+ const options = (0, options_1.getPluginOptions)(opts);
33
+ const outputDir = path.resolve(siteDir, options.docsRoot, options.out);
34
+ (0, render_1.removeDir)(outputDir);
33
35
  const app = new typedoc_1.Application();
34
36
  app.options.setValue('theme', path.resolve(__dirname));
35
37
  (0, typedoc_plugin_markdown_1.load)(app);
36
- const options = (0, render_1.bootstrap)(app, opts);
37
- if (options.sidebar.sidebarFile) {
38
- (0, sidebar_1.writeSidebar)(siteDir, options);
39
- }
38
+ (0, render_1.bootstrap)(app, options);
40
39
  const project = app.convert();
41
40
  if (!project) {
42
41
  return;
43
42
  }
44
43
  if (options.watch) {
45
44
  app.convertAndWatch(async (project) => {
46
- await app.generateDocs(project, (0, options_1.getOutputDirectory)(siteDir, options));
45
+ await app.generateDocs(project, outputDir);
47
46
  });
48
47
  }
49
48
  else {
50
- await app.generateDocs(project, (0, options_1.getOutputDirectory)(siteDir, options));
49
+ await app.generateDocs(project, outputDir);
51
50
  }
52
51
  }
53
52
  return {
package/dist/render.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { Application } from 'typedoc';
2
2
  import { PluginOptions } from './types';
3
- export declare const bootstrap: (app: Application, opts: Partial<PluginOptions>) => PluginOptions;
3
+ export declare const bootstrap: (app: Application, options: PluginOptions) => void;
4
+ export declare function removeDir(path: string): void;
package/dist/render.js CHANGED
@@ -1,15 +1,46 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bootstrap = void 0;
22
+ exports.removeDir = exports.bootstrap = void 0;
23
+ const fs = __importStar(require("fs"));
4
24
  const typedoc_1 = require("typedoc");
5
- const options_1 = require("./options");
6
- const bootstrap = (app, opts) => {
25
+ const bootstrap = (app, options) => {
7
26
  addTypedocReaders(app);
8
27
  addTypedocDeclarations(app);
9
- app.bootstrap({ ...(0, options_1.getPluginOptions)(opts) });
10
- return app.options.getRawValues();
28
+ app.renderer.render = render;
29
+ app.bootstrap(options);
11
30
  };
12
31
  exports.bootstrap = bootstrap;
32
+ async function render(project, outputDirectory) {
33
+ var _a;
34
+ const output = new typedoc_1.RendererEvent(typedoc_1.RendererEvent.BEGIN, outputDirectory, project);
35
+ output.urls = this.theme.getUrls(project);
36
+ this.trigger(output);
37
+ if (!output.isDefaultPrevented) {
38
+ (_a = output === null || output === void 0 ? void 0 : output.urls) === null || _a === void 0 ? void 0 : _a.forEach((mapping) => {
39
+ this.renderDocument(output.createPageEvent(mapping));
40
+ });
41
+ this.trigger(typedoc_1.RendererEvent.END, output);
42
+ }
43
+ }
13
44
  const addTypedocReaders = (app) => {
14
45
  app.options.addReader(new typedoc_1.TypeDocReader());
15
46
  app.options.addReader(new typedoc_1.TSConfigReader());
@@ -30,8 +61,31 @@ const addTypedocDeclarations = (app) => {
30
61
  app.options.addDeclaration({
31
62
  name: 'readmeTitle',
32
63
  });
64
+ app.options.addDeclaration({
65
+ name: 'indexSlug',
66
+ });
33
67
  app.options.addDeclaration({
34
68
  name: 'sidebar',
35
69
  type: typedoc_1.ParameterType.Mixed,
36
70
  });
37
71
  };
72
+ function removeDir(path) {
73
+ if (fs.existsSync(path)) {
74
+ const files = fs.readdirSync(path);
75
+ if (files.length > 0) {
76
+ files.forEach(function (filename) {
77
+ if (fs.statSync(path + '/' + filename).isDirectory()) {
78
+ removeDir(path + '/' + filename);
79
+ }
80
+ else {
81
+ fs.unlinkSync(path + '/' + filename);
82
+ }
83
+ });
84
+ fs.rmdirSync(path);
85
+ }
86
+ else {
87
+ fs.rmdirSync(path);
88
+ }
89
+ }
90
+ }
91
+ exports.removeDir = removeDir;
package/dist/theme.d.ts CHANGED
@@ -4,6 +4,7 @@ import { SidebarOptions } from './types';
4
4
  export declare class DocusaurusTheme extends MarkdownTheme {
5
5
  sidebar: SidebarOptions;
6
6
  readmeTitle: string;
7
+ indexSlug: string;
7
8
  constructor(renderer: Renderer);
8
9
  getRelativeUrl(url: string): string;
9
10
  onPageEnd(page: PageEvent<DeclarationReflection>): void;
@@ -13,6 +14,7 @@ export declare class DocusaurusTheme extends MarkdownTheme {
13
14
  getSidebarPosition(page: PageEvent<DeclarationReflection>): "0.5" | "0" | null;
14
15
  getId(page: PageEvent): string;
15
16
  getTitle(page: PageEvent): any;
17
+ getSlug(): string;
16
18
  get mappings(): {
17
19
  kind: ReflectionKind[];
18
20
  isLeaf: boolean;
package/dist/theme.js CHANGED
@@ -83,10 +83,7 @@ class DocusaurusTheme extends theme_1.MarkdownTheme {
83
83
  title: pageTitle,
84
84
  };
85
85
  if (page.url === this.entryDocument) {
86
- items = {
87
- ...items,
88
- slug: '/' + path.relative(process.cwd(), this.out).replace(/\\/g, '/') + '/',
89
- };
86
+ items = { ...items, slug: this.getSlug() };
90
87
  }
91
88
  if (sidebarLabel && sidebarLabel !== pageTitle) {
92
89
  items = { ...items, sidebar_label: sidebarLabel };
@@ -137,6 +134,15 @@ class DocusaurusTheme extends theme_1.MarkdownTheme {
137
134
  }
138
135
  return (0, front_matter_1.getPageTitle)(page);
139
136
  }
137
+ getSlug() {
138
+ if (this.indexSlug) {
139
+ return this.indexSlug;
140
+ }
141
+ if (this.out === process.cwd()) {
142
+ return '/';
143
+ }
144
+ return `/${path.relative(process.cwd(), this.out).replace(/\\/g, '/')}/`;
145
+ }
140
146
  get mappings() {
141
147
  return super.mappings.map((mapping) => {
142
148
  if (mapping.kind.includes(typedoc_1.ReflectionKind.Namespace)) {
@@ -158,6 +164,9 @@ __decorate([
158
164
  __decorate([
159
165
  (0, typedoc_1.BindOption)('readmeTitle')
160
166
  ], DocusaurusTheme.prototype, "readmeTitle", void 0);
167
+ __decorate([
168
+ (0, typedoc_1.BindOption)('indexSlug')
169
+ ], DocusaurusTheme.prototype, "indexSlug", void 0);
161
170
  exports.DocusaurusTheme = DocusaurusTheme;
162
171
  const writeCategoryYaml = (categoryPath, label, position) => {
163
172
  const yaml = [`label: "${label}"`];
package/dist/types.d.ts CHANGED
@@ -14,6 +14,7 @@ export interface PluginOptions {
14
14
  hideBreadcrumbs: boolean;
15
15
  hidePageTitle: boolean;
16
16
  entryDocument: string;
17
+ indexSlug?: string;
17
18
  }
18
19
  export interface FrontMatter {
19
20
  id: string;
@@ -26,7 +27,6 @@ export interface FrontMatter {
26
27
  }
27
28
  export interface SidebarOptions {
28
29
  fullNames?: boolean;
29
- sidebarFile: string;
30
30
  categoryLabel: string;
31
31
  indexLabel?: string;
32
32
  readmeLabel?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-typedoc",
3
- "version": "0.16.1",
3
+ "version": "0.16.5",
4
4
  "description": "A Docusaurus v2 plugin to build API documentation with TypeDoc.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -28,8 +28,8 @@
28
28
  "build": "rm -rf ./dist && tsc",
29
29
  "build-and-test": "yarn run build && yarn run test",
30
30
  "test:init": "rm -rf test/site && npx @docusaurus/init@latest init test/site classic",
31
- "test:demo:start": "yarn run build && cd test/site && yarn run clear && yarn run start",
32
- "test:demo:build": "yarn run build && cd test/site && yarn run clear && yarn run build && yarn run serve",
31
+ "test:demo:start": "yarn run build && cd test/site && yarn run start",
32
+ "test:demo:build": "yarn run build && cd test/site && yarn run build && yarn run serve",
33
33
  "test": "jest --colors"
34
34
  },
35
35
  "author": "Thomas Grey",
@@ -42,5 +42,5 @@
42
42
  "typescript",
43
43
  "api"
44
44
  ],
45
- "gitHead": "54ab24b8b655e3c401469ea95c841b5a969bb40a"
45
+ "gitHead": "eb289daac347deea984351f04ec7d5f82896d281"
46
46
  }
package/dist/sidebar.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { PluginOptions } from './types';
2
- export declare const writeSidebar: (siteDir: string, options: PluginOptions) => void;
package/dist/sidebar.js DELETED
@@ -1,32 +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
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.writeSidebar = void 0;
23
- const fs = __importStar(require("fs"));
24
- const path = __importStar(require("path"));
25
- const writeSidebar = (siteDir, options) => {
26
- const sidebarPath = path.resolve(siteDir, options.sidebar.sidebarFile);
27
- if (!fs.existsSync(path.dirname(sidebarPath))) {
28
- fs.mkdirSync(path.dirname(sidebarPath));
29
- }
30
- fs.writeFileSync(sidebarPath, `module.exports=[{type:'autogenerated',dirName:'${path.relative(process.cwd(), options.out)}'}];`);
31
- };
32
- exports.writeSidebar = writeSidebar;