Skip to content

Commit

Permalink
fix: remove hacky MarkdownToSummary
Browse files Browse the repository at this point in the history
  • Loading branch information
GerkinDev committed Jul 19, 2022
1 parent bc588b2 commit 2edc787
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 95 deletions.
7 changes: 3 additions & 4 deletions packages/plugin-monorepo-readmes/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import assert from 'assert';
import { readFileSync } from 'fs';

import { Application, DeclarationReflection, DefaultTheme, JSX, PageEvent, ProjectReflection, ReflectionKind, RendererEvent } from 'typedoc';
import { Application, DeclarationReflection, DefaultTheme, JSX, MinimalSourceFile, PageEvent, ProjectReflection, ReflectionKind, RendererEvent } from 'typedoc';

import { ABasePlugin, CurrentPageMemo, EventsExtra, MarkdownToSummary, reflectionSourceUtils } from '@knodes/typedoc-pluginutils';
import { ABasePlugin, CurrentPageMemo, EventsExtra, reflectionSourceUtils } from '@knodes/typedoc-pluginutils';

import { findReadmeFile } from './find-readme-file';
import { buildOptions } from './options';
import { isMonorepoReadmesPluginTheme } from './output/theme';

export class MonorepoReadmePlugin extends ABasePlugin {
public readonly markdownToSummary = MarkdownToSummary.for( this );
public readonly pluginOptions = buildOptions( this );
private readonly _currentPageMemo = CurrentPageMemo.for( this );
public constructor( application: Application ){
Expand Down Expand Up @@ -70,7 +69,7 @@ export class MonorepoReadmePlugin extends ABasePlugin {
source,
];
const fakePageEvent = new PageEvent<ProjectReflection>( props.name );
fakeProject.readme = this.markdownToSummary.processFromString( readFileSync( absReadme, 'utf-8' ) );
fakeProject.readme = this.application.converter.parseRawComment( new MinimalSourceFile( readFileSync( absReadme, 'utf-8' ), absReadme ) ).summary;
fakePageEvent.filename = props.filename;
fakePageEvent.project = props.project;
fakePageEvent.url = props.url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { resolve } from 'path';

import { isString, noop, omit } from 'lodash';
import { Class } from 'type-fest';
import { Comment, DeclarationReflection, LogLevel, ProjectReflection, Reflection, ReflectionKind, SourceReference, normalizePath } from 'typedoc';

import { MarkdownToSummary } from '@knodes/typedoc-pluginutils';
import { DeclarationReflection, LogLevel, ProjectReflection, Reflection, ReflectionKind, SourceReference, normalizePath } from 'typedoc';

import { MockPlugin, createMockProjectWithPackage, mockPlugin, restoreFs, setVirtualFs } from '#plugintestbed';

Expand All @@ -26,11 +24,7 @@ const opts = ( pages: IRootPageNode[] ) => ( {
source: '',
} as IPluginOptions );
beforeEach( () => {
plugin = mockPlugin<PagesPlugin>( {
markdownToSummary: {
processFromString: jest.fn().mockImplementation( v => new Comment( [ { kind: 'text', text: v } ] ) ),
} as jest.MockedObject<MarkdownToSummary>,
} );
plugin = mockPlugin<PagesPlugin>();
pageTreeBuilder = new PageTreeBuilder( plugin );
project = createMockProjectWithPackage();
} );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from 'assert';

import { Comment, DeclarationReflection, ProjectReflection, Reflection, normalizePath } from 'typedoc';
import { DeclarationReflection, MinimalSourceFile, ProjectReflection, Reflection, normalizePath } from 'typedoc';

import { IPluginComponent, getWorkspaces, miscUtils, resolveNamedPath } from '@knodes/typedoc-pluginutils';

Expand Down Expand Up @@ -164,7 +164,7 @@ export class PageTreeBuilder implements IPluginComponent<PagesPlugin> {
nodePath,
normalizePath( join( io.output, getNodeUrl( node ) ) ) ),
`Could not generate a page reflection for ${getNodePath( node, actualParent )}` );
page.comment = new Comment( this.plugin.markdownToSummary.processFromString ( page.content ) ?? [] );
page.comment = this.plugin.application.converter.parseRawComment( new MinimalSourceFile( page.content, page.sourceFilePath ) );
return page;
}
return new MenuReflection(
Expand Down
3 changes: 1 addition & 2 deletions packages/plugin-pages/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Application, Context, Converter, Reflection, RendererEvent } from 'typedoc';

import { ABasePlugin, EventsExtra, MarkdownToSummary, ReflectionCommentReplacer } from '@knodes/typedoc-pluginutils';
import { ABasePlugin, EventsExtra, ReflectionCommentReplacer } from '@knodes/typedoc-pluginutils';

import { PageTreeBuilder } from './converter/page-tree';
import { ANodeReflection } from './models/reflections';
import { buildOptions } from './options';
import { IPagesPluginThemeMethods, bindReplaceMarkdown, getPagesPluginThemeMethods } from './output';

export class PagesPlugin extends ABasePlugin {
public readonly markdownToSummary = MarkdownToSummary.for( this.application );
public readonly pluginOptions = buildOptions( this );
private readonly _reflectionCommentReplacer = new ReflectionCommentReplacer( this );
private _themeMethods?: IPagesPluginThemeMethods;
Expand Down
1 change: 1 addition & 0 deletions packages/plugintestbed/src/mock-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const mockPlugin = <T extends ABasePlugin>( props: Partial<MockPlugin<T>>
};
application.converter = new Converter( application );
application.renderer = new Renderer( application );
application.application = application;
const plugin = Object.create( ABasePlugin.prototype, Object.fromEntries( Object.entries( {
application,
rootDir: process.cwd(),
Expand Down
1 change: 0 additions & 1 deletion packages/pluginutils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export * from './autoload';
export * from './base-plugin';
export * from './current-page-memo';
export * from './events-extra';
export * from './markdown-to-summary';
export * from './options';
export * from './plugin-logger';
export * from './reflection-accessor';
Expand Down
78 changes: 0 additions & 78 deletions packages/pluginutils/src/markdown-to-summary.ts

This file was deleted.

0 comments on commit 2edc787

Please sign in to comment.