Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add extend property #1115

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/lib/utils/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ export class DiscoverEvent extends Event {
* Responsible for loading options via child components that read options
* from various sources.
*/
@Component({name: 'options', internal: true, childClass: OptionsComponent})
@Component({ name: 'options', internal: true, childClass: OptionsComponent })
export class Options extends ChildableComponent<Application, OptionsComponent> {
private declarations!: {[name: string]: OptionDeclaration};
private declarations!: { [name: string]: OptionDeclaration };

private values!: {[name: string]: any};
private values!: { [name: string]: any };

private compilerOptions!: ts.CompilerOptions;

Expand All @@ -81,7 +81,22 @@ export class Options extends ChildableComponent<Application, OptionsComponent> {
}

read(data: any = {}, mode: OptionsReadMode = OptionsReadMode.Fetch): OptionsReadResult {
const event = new DiscoverEvent(DiscoverEvent.DISCOVER, mode);
if (typeof data.extends === 'string') {
const tryLoad = (name: string) => {
try {
data = {
...data,
...require(name)
};
return true;
} catch (e) {
return false;
}
};
if (data.extends.startsWith('@') && !data.extends.split('/')[1]) { tryLoad(`${data.extends}/typedoc-config`); } else { tryLoad(`typedoc-config-${data.extends}`) || tryLoad(data.extends); }
Richienb marked this conversation as resolved.
Show resolved Hide resolved
}

const event = new DiscoverEvent(DiscoverEvent.DISCOVER, mode);
event.data = data;

this.trigger(event);
Expand Down Expand Up @@ -162,7 +177,7 @@ export class Options extends ChildableComponent<Application, OptionsComponent> {
}
}

addDeclaration(declaration: OptionDeclaration|DeclarationOption) {
addDeclaration(declaration: OptionDeclaration | DeclarationOption) {
const decl = declaration instanceof OptionDeclaration
? declaration
: new OptionDeclaration(declaration);
Expand All @@ -178,7 +193,7 @@ export class Options extends ChildableComponent<Application, OptionsComponent> {
}
}

addDeclarations(declarations: (OptionDeclaration|DeclarationOption)[]) {
addDeclarations(declarations: (OptionDeclaration | DeclarationOption)[]) {
for (let declaration of declarations) {
this.addDeclaration(declaration);
}
Expand Down