Skip to content

Commit

Permalink
Merge pull request #63 from IgniteUI/update-to-latest
Browse files Browse the repository at this point in the history
apply breaking changes of Typedoc 0.22+ v
  • Loading branch information
zdrawku authored Apr 21, 2022
2 parents 8529dd4 + fc5b21e commit 8f02813
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 597 deletions.
46 changes: 26 additions & 20 deletions components/convert-component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component, ConverterComponent } from 'typedoc/dist/lib/converter/components';
import { Converter } from 'typedoc/dist/lib/converter';
import { ReflectionKind } from 'typedoc/dist/lib/models';
import {
Application,
Converter,
ReflectionKind,
} from 'typedoc';
import { FileOperations } from '../utils/file-operations';
import { ClassFactory } from '../utils/factories/class-factory';
import { BaseFactory } from '../utils/factories/base-factory';
Expand All @@ -9,41 +11,45 @@ import { Parser } from '../utils/parser';
import { Constants } from '../utils/constants';
import { InterfaceFactory } from '../utils/factories/interface-factory';
import { FunctionFactory } from '../utils/factories/function-factory';

@Component({ name: 'convert-component' })
export class ConvertComponent extends ConverterComponent {

export class ConvertComponent {
/**
* Contains current name per every Class, Interface, Enum.
*/
jsonObjectName: string;
public jsonObjectName: string;
/**
* Contains current Object instance.
*/
factoryInstance: BaseFactory;
fileOperations: FileOperations;
public factoryInstance: BaseFactory;
public fileOperations: FileOperations;
/**
* Current @Reflection instance.
*/
reflection;
parser: Parser;
public reflection;
public parser: Parser;
/**
* Main process dir
*/
mainDirToExport: string;
public mainDirToExport: string;
/**
* Global functions data.
*/
globalFuncsJson = {};
public globalFuncsJson = {};

public application: Application

public constructor(application: Application) {
this.application = application;
this.initialize();
}

public initialize() {

this.listenTo(this.owner, {
[Converter.EVENT_RESOLVE]: this.resolve,
[Converter.EVENT_RESOLVE_BEGIN]: this.onResolveBegin,
[Converter.EVENT_RESOLVE_END]: this.onResolveEnd,
[Converter.EVENT_END]: this.onEnd,
[Converter.EVENT_BEGIN]: this.onBegin
});
this.application.converter.on(Converter.EVENT_RESOLVE, this.resolve.bind(this));
this.application.converter.on(Converter.EVENT_RESOLVE_BEGIN, this.onResolveBegin.bind(this));
this.application.converter.on(Converter.EVENT_RESOLVE_END, this.onResolveEnd.bind(this));
this.application.converter.on(Converter.EVENT_END, this.onEnd.bind(this));
this.application.converter.on(Converter.EVENT_BEGIN, this.onBegin.bind(this));

this.parser = new Parser();
this.fileOperations = new FileOperations(this.application.logger);
Expand Down
19 changes: 10 additions & 9 deletions components/render-component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import * as path from 'path';

import { Component, RendererComponent } from 'typedoc/dist/lib/output/components';
import { ReflectionKind } from 'typedoc/dist/lib/models';
import { ReflectionKind, RendererEvent, LogLevel, Application } from 'typedoc';
import { FileOperations } from '../utils/file-operations';
import { AttributeType } from '../utils/enums/json-keys';
import { Constants } from '../utils/constants';
import { RendererEvent } from 'typedoc/dist/lib/output/events';
import { Parser } from '../utils/parser';
import { LogLevel } from 'typedoc/dist/lib/utils';

@Component({ name: 'render-component'})
export class RenderComponenet extends RendererComponent {
export class RenderComponenet {
private warns: boolean;

fileOperations: FileOperations;
Expand All @@ -31,10 +27,15 @@ export class RenderComponenet extends RendererComponent {
*/
parser: Parser;

public application

public constructor(application: Application) {
this.application = application;
this.initialize();
}

public initialize() {
this.listenTo(this.owner, {
[RendererEvent.BEGIN]: this.onRenderBegin,
});
this.application.renderer.on(RendererEvent.BEGIN,this.onRenderBegin.bind(this));

this.fileOperations = new FileOperations(this.application.logger);
this.parser = new Parser();
Expand Down
56 changes: 12 additions & 44 deletions components/theme-component.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,29 @@
import * as path from 'path';

import { RendererEvent, PageEvent } from "typedoc/dist/lib/output/events";
import { Component } from 'typedoc/dist/lib/utils';
import { RendererComponent } from 'typedoc/dist/lib/output/components';
import { Constants } from '../utils/constants';
import { RendererEvent, ReflectionKind, Application } from "typedoc";
import { GlobalFuncs } from '../utils/global-funcs';
import { HardcodedStrings } from '../utils/template-strings';
import { ReflectionKind } from 'typedoc/dist/lib/models';
import { NavigationItem } from 'typedoc/dist/lib/output/models/NavigationItem';

@Component({ name: 'theme-component' })
export class ThemeComponent extends RendererComponent {
export class ThemeComponent {
public app: Application;

public constructor(app: Application) {
this.app = app
this.initialize();
}

initialize() {
this.listenTo(this.owner, {
[RendererEvent.BEGIN]: this.onRenderBegin,
[PageEvent.BEGIN]: this.onRenderingBeginPage
});
this.app.renderer.on(
RendererEvent.BEGIN, this.onRenderBegin.bind(this)
);
}

private onRenderBegin(event) {
this.registerHelpers();

if (!event.project.groups) {
return;
}

this.localizeGroupTitles(event.project.groups);
this.run(event.project.reflections);
}

private onRenderingBeginPage(event: PageEvent) {
const navigationItems: Array<NavigationItem> = event.navigation.children;
navigationItems.forEach((item: NavigationItem) => {
item.title = this.getLocaleValue(item.title);
});
}

private run(reflections) {
const keys = Object.keys(reflections);
Expand Down Expand Up @@ -103,25 +92,4 @@ export class ThemeComponent extends RendererComponent {
HardcodedStrings.getLocal(),
value);
}

/**
* Register helper function responsible
* for hardcoded template strings localization.
*/
private registerHelpers() {
let module;
try {
module = require.resolve(Constants.PROJ_NAME);
} catch(e) {
this.application.logger.error(e.message);
return;
}

const pluginDist = path.dirname(require.resolve(module));
if (pluginDist) {
this.owner.theme.resources.deactivate();
this.owner.theme.resources.helpers.addOrigin('custom-helpers', path.join(pluginDist, 'utils', 'helpers'));
this.owner.theme.resources.activate();
}
}
}
14 changes: 9 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as process from 'process';
import * as fs from 'fs-extra';

import { Application } from 'typedoc/dist/lib/application'
import { Application } from 'typedoc'
import { ConvertComponent } from './components/convert-component';
import { RenderComponenet } from './components/render-component';
import { Constants } from './utils/constants';
Expand All @@ -10,7 +10,9 @@ import { HardcodedStrings } from './utils/template-strings';
import { ThemeComponent } from './components/theme-component';
import { pluginOptions } from './utils/options';

module.exports = (PluginHost: Application) => {
export * from './utils/helpers/localize';

export function load(PluginHost: Application) {
const app = PluginHost.owner;
/**
* Add Options register Component.
Expand Down Expand Up @@ -44,20 +46,22 @@ module.exports = (PluginHost: Application) => {
/**
* Register component responsible for the convertion.
*/
app.converter.addComponent('convert-component', new ConvertComponent(app.converter));
new ConvertComponent(app);
// app.converter.('test', ConvertComponent(app));
}

if (startRenderer) {
/**
* Register component responsible for the Renderer.
*/
app.renderer.addComponent('render-component', new RenderComponenet(app.renderer));
new RenderComponenet(app)
}

/**
* Register theme component.
*/
app.renderer.addComponent('theme-component', new ThemeComponent(app.renderer));
new ThemeComponent(app);
// app.renderer.addComponent('theme-component', new ThemeComponent(app.renderer));
registerHardcodedTemplateStrings(processArgs);
}

Expand Down
Loading

0 comments on commit 8f02813

Please sign in to comment.