docusaurus-plugin-typedoc 1.0.0-next.4 → 1.0.0-next.7

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.
@@ -0,0 +1,18 @@
1
+ import { TypedocPluginMarkdownOptions } from 'typedoc-plugin-markdown';
2
+ export interface PluginOptions extends TypedocPluginMarkdownOptions {
3
+ id: string;
4
+ docsRoot: string;
5
+ sidebar: SidebarOptions;
6
+ }
7
+ export interface SidebarOptions {
8
+ categoryLabel: string;
9
+ collapsed: boolean;
10
+ position: number | null;
11
+ autoConfiguration: boolean;
12
+ }
13
+ export interface SidebarCategory {
14
+ type: string;
15
+ label: string;
16
+ items: SidebarItem[];
17
+ }
18
+ export type SidebarItem = SidebarCategory | string;
package/dist/options.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { PluginOptions } from './types';
1
+ import { PluginOptions } from './models';
2
2
  export declare const getPluginOptions: (opts: Partial<PluginOptions>) => PluginOptions;
package/dist/options.js CHANGED
@@ -5,12 +5,9 @@ const DEFAULT_PLUGIN_OPTIONS = {
5
5
  id: 'default',
6
6
  docsRoot: 'docs',
7
7
  out: 'api',
8
- cleanOutputDir: true,
9
8
  sidebar: {
10
- fullNames: false,
11
9
  categoryLabel: 'API',
12
10
  collapsed: true,
13
- indexLabel: 'Overview',
14
11
  position: null,
15
12
  autoConfiguration: true,
16
13
  },
@@ -18,10 +15,10 @@ const DEFAULT_PLUGIN_OPTIONS = {
18
15
  hideBreadcrumbs: true,
19
16
  hidePageTitle: false,
20
17
  entryDocument: 'index.md',
21
- plugin: ['none'],
22
18
  watch: false,
23
- theme: 'docusaurus',
24
19
  enableFrontmatter: true,
20
+ numberPrefixOutput: true,
21
+ theme: 'docusaurus',
25
22
  };
26
23
  const getPluginOptions = (opts) => {
27
24
  const options = {
package/dist/plugin.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PluginOptions } from './types';
1
+ import { PluginOptions } from './models';
2
2
  export default function pluginDocusaurus(context: any, opts: Partial<PluginOptions>): {
3
3
  name: string;
4
4
  loadContent(): Promise<void>;
package/dist/plugin.js CHANGED
@@ -59,13 +59,12 @@ async function generateTypedoc(context, opts) {
59
59
  const { siteDir } = context;
60
60
  const options = (0, options_1.getPluginOptions)(opts);
61
61
  const outputDir = path.resolve(siteDir, options.docsRoot, options.out);
62
- if (opts.cleanOutputDir) {
63
- (0, render_1.removeDir)(outputDir);
64
- }
65
62
  const app = new typedoc_1.Application();
66
63
  app.renderer.defineTheme('docusaurus', theme_1.DocusaurusTheme);
67
64
  (0, typedoc_plugin_markdown_1.load)(app);
68
- (0, render_1.bootstrap)(app, options);
65
+ (0, render_1.addTypedocReaders)(app);
66
+ (0, render_1.addTypedocDeclarations)(app);
67
+ await app.bootstrapWithPlugins(options);
69
68
  const project = app.convert();
70
69
  if (!project) {
71
70
  return;
package/dist/render.d.ts CHANGED
@@ -1,5 +1,3 @@
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;
1
+ import { Application } from 'typedoc';
2
+ export declare function addTypedocReaders(app: Application): void;
3
+ export declare function addTypedocDeclarations(app: Application): void;
package/dist/render.js CHANGED
@@ -1,72 +1,19 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.removeDir = exports.render = exports.bootstrap = void 0;
27
- const fs = __importStar(require("fs"));
3
+ exports.addTypedocDeclarations = exports.addTypedocReaders = void 0;
28
4
  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) => {
5
+ function addTypedocReaders(app) {
57
6
  app.options.addReader(new typedoc_1.TypeDocReader());
58
7
  app.options.addReader(new typedoc_1.TSConfigReader());
59
- };
60
- const addTypedocDeclarations = (app) => {
8
+ }
9
+ exports.addTypedocReaders = addTypedocReaders;
10
+ function addTypedocDeclarations(app) {
61
11
  app.options.addDeclaration({
62
12
  name: 'id',
63
13
  });
64
14
  app.options.addDeclaration({
65
15
  name: 'docsRoot',
66
16
  });
67
- app.options.addDeclaration({
68
- name: 'siteDir',
69
- });
70
17
  app.options.addDeclaration({
71
18
  name: 'globalsTitle',
72
19
  });
@@ -74,8 +21,5 @@ const addTypedocDeclarations = (app) => {
74
21
  name: 'sidebar',
75
22
  type: typedoc_1.ParameterType.Mixed,
76
23
  });
77
- };
78
- function removeDir(path) {
79
- fs.rmSync(path, { recursive: true, force: true });
80
24
  }
81
- exports.removeDir = removeDir;
25
+ exports.addTypedocDeclarations = addTypedocDeclarations;
package/dist/theme.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { DeclarationReflection, PageEvent, Renderer, RendererEvent } from 'typedoc';
2
2
  import { MarkdownTheme } from 'typedoc-plugin-markdown';
3
- import { SidebarOptions } from './types';
3
+ import { SidebarOptions } from './models';
4
4
  export declare class DocusaurusTheme extends MarkdownTheme {
5
5
  sidebar: SidebarOptions;
6
6
  constructor(renderer: Renderer);
7
7
  onPageEnd(page: PageEvent<DeclarationReflection>): void;
8
8
  onRendererEnd(renderer: RendererEvent): void;
9
- loopAndWriteCategories(path: string): void;
10
- writeCategoryYaml: (categoryPath: string, label: string, position: number | null, collapsed: boolean) => void;
9
+ loopAndWriteCategories(path: string, level?: number): void;
10
+ writeCategoryYaml: (categoryPath: string, label: string, position: number | null, collapsed: boolean, generatedIndex: boolean) => void;
11
11
  }
package/dist/theme.js CHANGED
@@ -33,11 +33,10 @@ exports.DocusaurusTheme = void 0;
33
33
  const fs = __importStar(require("fs"));
34
34
  const typedoc_1 = require("typedoc");
35
35
  const typedoc_plugin_markdown_1 = require("typedoc-plugin-markdown");
36
- const navigation_1 = require("./navigation");
37
36
  class DocusaurusTheme extends typedoc_plugin_markdown_1.MarkdownTheme {
38
37
  constructor(renderer) {
39
38
  super(renderer);
40
- this.writeCategoryYaml = (categoryPath, label, position, collapsed) => {
39
+ this.writeCategoryYaml = (categoryPath, label, position, collapsed, generatedIndex) => {
41
40
  const yaml = [`label: "${label}"`];
42
41
  if (position !== null) {
43
42
  yaml.push(`position: ${position}`);
@@ -45,6 +44,11 @@ class DocusaurusTheme extends typedoc_plugin_markdown_1.MarkdownTheme {
45
44
  if (!collapsed) {
46
45
  yaml.push(`collapsed: false`);
47
46
  }
47
+ if (generatedIndex) {
48
+ yaml.push(`link:
49
+ type: "generated-index"
50
+ title: "${label}"`);
51
+ }
48
52
  if (fs.existsSync(categoryPath)) {
49
53
  fs.writeFileSync(categoryPath + '/_category_.yml', yaml.join('\n'));
50
54
  }
@@ -61,16 +65,11 @@ class DocusaurusTheme extends typedoc_plugin_markdown_1.MarkdownTheme {
61
65
  }
62
66
  onRendererEnd(renderer) {
63
67
  if (this.sidebar.autoConfiguration) {
64
- this.writeCategoryYaml(renderer.outputDirectory, this.sidebar.categoryLabel, this.sidebar.position, this.sidebar.collapsed);
68
+ this.writeCategoryYaml(renderer.outputDirectory, this.sidebar.categoryLabel, this.sidebar.position, this.sidebar.collapsed, false);
65
69
  this.loopAndWriteCategories(renderer.outputDirectory);
66
- const globalsFile = this.getRenderContext().globalsFile;
67
- const globalsPath = `${renderer.outputDirectory}/${this.getRenderContext().globalsFile}`;
68
- if (fs.existsSync(globalsPath)) {
69
- fs.renameSync(globalsPath, `${renderer.outputDirectory}/01-${globalsFile}`);
70
- }
71
70
  }
72
71
  }
73
- loopAndWriteCategories(path) {
72
+ loopAndWriteCategories(path, level = 0) {
74
73
  const directory = fs.readdirSync(path);
75
74
  directory.forEach((segment) => {
76
75
  const fullPath = `${path}/${segment}`;
@@ -78,14 +77,12 @@ class DocusaurusTheme extends typedoc_plugin_markdown_1.MarkdownTheme {
78
77
  if (isDirectory) {
79
78
  const mapping = Object.entries(this.mappings)
80
79
  .filter((entry) => {
81
- return entry[1].directory === segment;
80
+ return entry[1].directory === segment.slice(3);
82
81
  })
83
82
  .map((entry) => entry[1])[0];
84
83
  const subdirectory = fs.readdirSync(fullPath);
85
- const containsDir = subdirectory.some((item) => fs.lstatSync(`${fullPath}/${item}`).isDirectory());
86
- if ((mapping && !containsDir) ||
87
- (mapping === null || mapping === void 0 ? void 0 : mapping.kind) === typedoc_1.ReflectionKind.Namespace) {
88
- this.writeCategoryYaml(fullPath, (0, navigation_1.getKindPlural)(mapping.kind), navigation_1.CATEGORY_POSITION[mapping.kind], true);
84
+ if (mapping && !subdirectory.includes(`${mapping === null || mapping === void 0 ? void 0 : mapping.directory}.md`)) {
85
+ this.writeCategoryYaml(fullPath, typedoc_1.ReflectionKind.pluralString(mapping.kind), null, true, true);
89
86
  }
90
87
  this.loopAndWriteCategories(fullPath);
91
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-typedoc",
3
- "version": "1.0.0-next.4",
3
+ "version": "1.0.0-next.7",
4
4
  "description": "A Docusaurus v2 plugin to build API documentation with TypeDoc.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "homepage": "https://github.com/tgreyuk/typedoc-plugin-markdown/tree/master/packages/docusaurus-plugin-typedoc",
18
18
  "peerDependencies": {
19
- "typedoc-plugin-markdown": ">=4.0.0-next.5"
19
+ "typedoc-plugin-markdown": ">=4.0.0-next.8"
20
20
  },
21
21
  "scripts": {
22
22
  "lint": "eslint ./src --ext .ts",
@@ -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,37 +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.Namespace]: 'Namespaces',
11
- [typedoc_1.ReflectionKind.TypeAlias]: 'Type aliases',
12
- };
13
- exports.CATEGORY_POSITION = {
14
- [typedoc_1.ReflectionKind.Module]: 1,
15
- [typedoc_1.ReflectionKind.Namespace]: 1,
16
- [typedoc_1.ReflectionKind.Enum]: 2,
17
- [typedoc_1.ReflectionKind.Class]: 3,
18
- [typedoc_1.ReflectionKind.Interface]: 4,
19
- [typedoc_1.ReflectionKind.TypeAlias]: 5,
20
- [typedoc_1.ReflectionKind.Variable]: 6,
21
- [typedoc_1.ReflectionKind.Function]: 7,
22
- [typedoc_1.ReflectionKind.ObjectLiteral]: 8,
23
- };
24
- function getKindPlural(kind) {
25
- if (kind in PLURALS) {
26
- return PLURALS[kind];
27
- }
28
- else {
29
- return getKindString(kind) + 's';
30
- }
31
- }
32
- exports.getKindPlural = getKindPlural;
33
- function getKindString(kind) {
34
- let str = typedoc_1.ReflectionKind[kind];
35
- str = str.replace(/(.)([A-Z])/g, (_m, a, b) => a + ' ' + b.toLowerCase());
36
- return str;
37
- }
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