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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { PluginOptions } from './models';
2
- export default function pluginDocusaurus(context: any, opts: Partial<PluginOptions>): {
1
+ export default function pluginDocusaurus(context: any, opts: Record<string, any>): {
3
2
  name: string;
4
3
  loadContent(): Promise<void>;
5
4
  extendCli(cli: any): void;
package/dist/index.js CHANGED
@@ -25,8 +25,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const path = __importStar(require("path"));
27
27
  const typedoc_1 = require("typedoc");
28
+ const typedoc_plugin_frontmatter_1 = require("typedoc-plugin-frontmatter");
29
+ const typedoc_plugin_markdown_1 = require("typedoc-plugin-markdown");
28
30
  const options_1 = require("./options");
29
31
  const renderer_1 = require("./renderer");
32
+ // store list of plugin ids when running multiple instances
30
33
  const apps = [];
31
34
  function pluginDocusaurus(context, opts) {
32
35
  return {
@@ -44,6 +47,7 @@ function pluginDocusaurus(context, opts) {
44
47
  .action(async () => {
45
48
  var _a;
46
49
  (_a = context.siteConfig) === null || _a === void 0 ? void 0 : _a.plugins.forEach((pluginConfig) => {
50
+ // Check PluginConfig is typed to [string, PluginOptions]
47
51
  if (pluginConfig && typeof pluginConfig[1] === 'object') {
48
52
  generateTypedoc(context, pluginConfig[1]);
49
53
  }
@@ -53,6 +57,9 @@ function pluginDocusaurus(context, opts) {
53
57
  };
54
58
  }
55
59
  exports.default = pluginDocusaurus;
60
+ /**
61
+ * Initiates a new typedoc Application bootstraped with plugin options
62
+ */
56
63
  async function generateTypedoc(context, opts) {
57
64
  const { siteDir } = context;
58
65
  const options = (0, options_1.getPluginOptions)(opts);
@@ -61,8 +68,11 @@ async function generateTypedoc(context, opts) {
61
68
  const app = new typedoc_1.Application();
62
69
  (0, options_1.loadOptions)(app);
63
70
  (0, renderer_1.loadRenderer)(app);
71
+ (0, typedoc_plugin_markdown_1.load)(app);
72
+ (0, typedoc_plugin_frontmatter_1.load)(app);
64
73
  await app.bootstrapWithPlugins(optionsPassedToTypeDoc);
65
74
  const project = app.convert();
75
+ // if project is undefined typedoc has a problem - error logging will be supplied by typedoc.
66
76
  if (!project) {
67
77
  if (app.options.getValue('skipErrorChecking')) {
68
78
  return;
@@ -70,7 +80,7 @@ async function generateTypedoc(context, opts) {
70
80
  console.error('[docusaurus-plugin-typedoc] TypeDoc exited with an error. Use the "skipErrorChecking" option to disable TypeDoc error checking.');
71
81
  process.exit();
72
82
  }
73
- if (options.watch) {
83
+ if (app.options.getValue('watch')) {
74
84
  app.convertAndWatch(async (project) => {
75
85
  await app.generateDocs(project, outputDir);
76
86
  });
package/dist/models.d.ts CHANGED
@@ -1,23 +1,11 @@
1
- import { TypedocPluginMarkdownOptions } from 'typedoc-plugin-markdown';
2
- export interface PluginOptions extends TypedocPluginMarkdownOptions {
1
+ export interface PluginOptions {
3
2
  id: string;
4
3
  docsRoot: string;
5
4
  sidebar: SidebarOptions;
6
5
  }
7
6
  export interface SidebarOptions {
8
- categoryLabel: string;
9
- position: number | null;
10
7
  autoConfiguration: boolean;
8
+ readmeLabel: string;
9
+ indexLabel: string;
10
+ categoryLabel: string;
11
11
  }
12
- export interface SidebarCategory {
13
- type: string;
14
- label: string;
15
- items: SidebarItem[];
16
- }
17
- export interface CategoryYamlOptions {
18
- path: string;
19
- label: string;
20
- position: number | null;
21
- collapsed: boolean;
22
- }
23
- export type SidebarItem = SidebarCategory | string;
package/dist/options.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  import { Application } from 'typedoc';
2
- import { PluginOptions } from './models';
3
- export declare function getPluginOptions(opts: Partial<PluginOptions>): PluginOptions;
2
+ export declare function getPluginOptions(opts: Record<string, any>): Record<string, any>;
4
3
  export declare function loadOptions(app: Application): void;
package/dist/options.js CHANGED
@@ -6,17 +6,13 @@ const DEFAULT_PLUGIN_OPTIONS = {
6
6
  id: 'default',
7
7
  docsRoot: 'docs',
8
8
  out: 'api',
9
- watch: false,
10
- plugin: [],
11
9
  hideInPageTOC: true,
12
10
  hideBreadcrumbs: true,
13
11
  hidePageHeader: true,
12
+ githubPages: false,
14
13
  includeFileNumberPrefixes: true,
15
- skipIndexPage: true,
16
14
  entryFileName: 'index.md',
17
15
  sidebar: {
18
- categoryLabel: 'API',
19
- position: null,
20
16
  autoConfiguration: true,
21
17
  },
22
18
  };
@@ -48,12 +44,10 @@ function loadOptions(app) {
48
44
  }
49
45
  read(container) {
50
46
  const plugins = container.getValue('plugin');
51
- ['typedoc-plugin-markdown', 'typedoc-plugin-frontmatter'].forEach((defaultPlugin) => {
52
- if (!plugins.includes(defaultPlugin)) {
53
- plugins.push(defaultPlugin);
54
- }
55
- });
56
- container.setValue('plugin', plugins);
47
+ container.setValue('plugin', plugins === null || plugins === void 0 ? void 0 : plugins.filter((plugin) => ![
48
+ 'typedoc-plugin-markdown',
49
+ 'typedoc-plugin-frontmatter',
50
+ ].includes(plugin)));
57
51
  }
58
52
  })());
59
53
  }
package/dist/renderer.js CHANGED
@@ -16,52 +16,52 @@ function loadRenderer(app) {
16
16
  exports.loadRenderer = loadRenderer;
17
17
  function loadFrontmatter(app, event) {
18
18
  var _a, _b, _c, _d, _e, _f, _g;
19
- const renderContext = app.renderer.theme.getRenderContext();
19
+ const hasReadme = !app.options.getValue('readme').endsWith('none');
20
+ const entryPage = app.options.getValue('entryFileName');
21
+ const indexPage = app.options.getValue('indexFileName');
20
22
  const sidebar = app.options.getValue('sidebar');
21
- const isIndexPage = (_a = event.page) === null || _a === void 0 ? void 0 : _a.url.endsWith(renderContext.indexFileName);
22
- const isReadmePage = (_b = event.page) === null || _b === void 0 ? void 0 : _b.url.endsWith(app.options.getValue('entryFileName'));
23
- const isPackageModule = event.page.model.kindOf(typedoc_1.ReflectionKind.Module) &&
24
- !Boolean(((_c = event.page.model) === null || _c === void 0 ? void 0 : _c.parent).groups);
25
- const model = (_d = event.page) === null || _d === void 0 ? void 0 : _d.model;
23
+ const model = (_a = event.page) === null || _a === void 0 ? void 0 : _a.model;
24
+ const sidebarLabel = model === null || model === void 0 ? void 0 : model.name;
26
25
  let pluginFrontmatter = {};
27
26
  if (sidebar.autoConfiguration) {
28
- if (!isIndexPage && !isReadmePage) {
29
- const sidebarLabel = model === null || model === void 0 ? void 0 : model.name;
30
- pluginFrontmatter = {
31
- ...pluginFrontmatter,
32
- sidebar_label: sidebarLabel,
33
- };
34
- }
35
- if (((_e = event.page) === null || _e === void 0 ? void 0 : _e.url) === app.options.getValue('entryFileName')) {
27
+ if (((_b = event.page) === null || _b === void 0 ? void 0 : _b.url) === app.options.getValue('entryFileName')) {
36
28
  if (sidebar.categoryLabel) {
37
29
  pluginFrontmatter = {
38
30
  ...pluginFrontmatter,
39
31
  sidebar_label: sidebar.categoryLabel,
40
32
  };
41
33
  }
42
- if (sidebar.position !== null && !Number.isNaN(sidebar.position)) {
34
+ }
35
+ if (hasReadme) {
36
+ if (((_c = event.page) === null || _c === void 0 ? void 0 : _c.url) === entryPage) {
43
37
  pluginFrontmatter = {
44
38
  ...pluginFrontmatter,
45
- sidebar_position: sidebar.position,
39
+ ...(sidebar.readmeLabel && { sidebar_label: sidebar.readmeLabel }),
40
+ sidebar_position: 0,
41
+ };
42
+ }
43
+ if (((_d = event.page) === null || _d === void 0 ? void 0 : _d.url) === `01-${indexPage}`) {
44
+ pluginFrontmatter = {
45
+ ...pluginFrontmatter,
46
+ ...(sidebar.indexLabel && { sidebar_label: sidebar.indexLabel }),
46
47
  };
47
48
  }
48
49
  }
49
- if ((_f = event.page) === null || _f === void 0 ? void 0 : _f.url.endsWith(app.options.getValue('entryFileName'))) {
50
- pluginFrontmatter = {
51
- ...pluginFrontmatter,
52
- hide_table_of_contents: true,
53
- };
54
- }
55
- if (isPackageModule && isReadmePage) {
56
- pluginFrontmatter = {
57
- ...pluginFrontmatter,
58
- sidebar_label: event.page.model.name,
59
- };
50
+ else {
51
+ if (((_e = event.page) === null || _e === void 0 ? void 0 : _e.url) === entryPage) {
52
+ pluginFrontmatter = {
53
+ ...pluginFrontmatter,
54
+ ...(sidebar.indexLabel && { sidebar_label: sidebar.indexLabel }),
55
+ sidebar_position: 0,
56
+ };
57
+ }
60
58
  }
61
- if (isPackageModule && isIndexPage && Boolean((_g = event.page.model) === null || _g === void 0 ? void 0 : _g.readme)) {
59
+ // Add sidebar labels to all pages
60
+ if (!(((_f = event.page) === null || _f === void 0 ? void 0 : _f.url) === entryPage) &&
61
+ !(((_g = event.page) === null || _g === void 0 ? void 0 : _g.url) === `01-${indexPage}`)) {
62
62
  pluginFrontmatter = {
63
63
  ...pluginFrontmatter,
64
- sidebar_label: 'Index',
64
+ sidebar_label: sidebarLabel,
65
65
  };
66
66
  }
67
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-typedoc",
3
- "version": "1.0.0-next.10",
3
+ "version": "1.0.0-next.11",
4
4
  "description": "A Docusaurus v2 plugin to build API documentation with TypeDoc.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -15,18 +15,15 @@
15
15
  "directory": "packages/docusaurus-plugin-typedoc"
16
16
  },
17
17
  "homepage": "https://github.com/tgreyuk/typedoc-plugin-markdown/tree/master/packages/docusaurus-plugin-typedoc",
18
- "dependencies": {
19
- "typedoc-plugin-frontmatter": "^0.0.2"
20
- },
21
18
  "peerDependencies": {
22
- "typedoc-plugin-markdown": ">=4.0.0-next.12"
19
+ "typedoc-plugin-markdown": ">=4.0.0-next.13",
20
+ "typedoc-plugin-frontmatter": ">=0.0.2"
23
21
  },
24
22
  "scripts": {
25
23
  "lint": "eslint ./src --ext .ts",
26
- "prepublishOnly": "npm run lint && npm run build && npm run test",
24
+ "prepublishOnly": "npm run lint && npm run build",
27
25
  "build": "rm -rf ./dist && tsc",
28
- "build-and-test": "npm run build && npm run test",
29
- "test": "jest --colors"
26
+ "build-and-test": "npm run build && npm run test"
30
27
  },
31
28
  "author": "Thomas Grey",
32
29
  "license": "MIT",