Move external types to link mapping to doc generation util and refactor typedocUtils to be a class to avoid excessive param passing

This commit is contained in:
Fabio Berger 2018-08-15 11:36:45 -07:00
parent 3b8a343711
commit a8d44ccc48
17 changed files with 138 additions and 322 deletions

View File

@ -27,6 +27,7 @@ const EXTERNAL_TYPE_TO_LINK: { [externalType: string]: string } = {
'solc.StandardContractOutput': 'solc.StandardContractOutput':
'https://solidity.readthedocs.io/en/v0.4.24/using-the-compiler.html#output-description', 'https://solidity.readthedocs.io/en/v0.4.24/using-the-compiler.html#output-description',
'solc.CompilerSettings': 'https://solidity.readthedocs.io/en/v0.4.24/using-the-compiler.html#input-description', 'solc.CompilerSettings': 'https://solidity.readthedocs.io/en/v0.4.24/using-the-compiler.html#input-description',
Schema: 'https://github.com/tdegrunt/jsonschema/blob/5c2edd4baba149964aec0f23c87ad12c25a50dfb/lib/index.d.ts#L49',
}; };
const CLASSES_WITH_HIDDEN_CONSTRUCTORS: string[] = [ const CLASSES_WITH_HIDDEN_CONSTRUCTORS: string[] = [

View File

@ -5,7 +5,6 @@ import * as React from 'react';
import { DocsInfo } from '../docs_info'; import { DocsInfo } from '../docs_info';
import { Parameter, SolidityMethod, TypeDefinitionByName, TypescriptFunction, TypescriptMethod } from '../types'; import { Parameter, SolidityMethod, TypeDefinitionByName, TypescriptFunction, TypescriptMethod } from '../types';
import { constants } from '../utils/constants'; import { constants } from '../utils/constants';
import { typeDocUtils } from '../utils/typedoc_utils';
import { Comment } from './comment'; import { Comment } from './comment';
import { Signature } from './signature'; import { Signature } from './signature';

View File

@ -179,17 +179,8 @@ export const Type: React.SFC<TypeProps> = (props: TypeProps): any => {
return [prev, ', ', curr]; return [prev, ', ', curr];
}); });
let typeNameUrlIfExists;
let typePrefixIfExists;
if (!_.isUndefined(props.docsInfo.typeConfigs)) {
typeNameUrlIfExists = !_.isUndefined(props.docsInfo.typeConfigs.typeNameToExternalLink)
? props.docsInfo.typeConfigs.typeNameToExternalLink[typeName as string]
: undefined;
typePrefixIfExists = !_.isUndefined(props.docsInfo.typeConfigs.typeNameToPrefix)
? props.docsInfo.typeConfigs.typeNameToPrefix[typeName as string]
: undefined;
}
const isExportedClassReference = !!props.type.isExportedClassReference; const isExportedClassReference = !!props.type.isExportedClassReference;
const typeNameUrlIfExists = !_.isUndefined(props.type.externalLink) ? props.type.externalLink : undefined;
if (!_.isUndefined(typeNameUrlIfExists)) { if (!_.isUndefined(typeNameUrlIfExists)) {
typeName = ( typeName = (
<a <a
@ -198,7 +189,6 @@ export const Type: React.SFC<TypeProps> = (props: TypeProps): any => {
className="text-decoration-none" className="text-decoration-none"
style={{ color: colors.lightBlueA700 }} style={{ color: colors.lightBlueA700 }}
> >
{!_.isUndefined(typePrefixIfExists) ? `${typePrefixIfExists}.` : ''}
{typeName} {typeName}
</a> </a>
); );

View File

@ -6,17 +6,16 @@ import {
ContractsByVersionByNetworkId, ContractsByVersionByNetworkId,
DocAgnosticFormat, DocAgnosticFormat,
DocsInfoConfig, DocsInfoConfig,
DocsInfoTypeConfigs,
DocsMenu, DocsMenu,
DoxityDocObj, DoxityDocObj,
GeneratedDocJson,
SectionNameToMarkdownByVersion, SectionNameToMarkdownByVersion,
SectionsMap, SectionsMap,
SupportedDocJson, SupportedDocJson,
TypeDefinitionByName, TypeDefinitionByName,
GeneratedDocJson,
} from './types'; } from './types';
import { doxityUtils } from './utils/doxity_utils'; import { doxityUtils } from './utils/doxity_utils';
import { typeDocUtils } from './utils/typedoc_utils'; import { TypeDocUtils } from './utils/typedoc_utils';
export class DocsInfo { export class DocsInfo {
public id: string; public id: string;
@ -27,7 +26,6 @@ export class DocsInfo {
public sections: SectionsMap; public sections: SectionsMap;
public sectionNameToMarkdownByVersion: SectionNameToMarkdownByVersion; public sectionNameToMarkdownByVersion: SectionNameToMarkdownByVersion;
public contractsByVersionByNetworkId?: ContractsByVersionByNetworkId; public contractsByVersionByNetworkId?: ContractsByVersionByNetworkId;
public typeConfigs: DocsInfoTypeConfigs;
constructor(config: DocsInfoConfig) { constructor(config: DocsInfoConfig) {
this.id = config.id; this.id = config.id;
this.type = config.type; this.type = config.type;
@ -37,7 +35,6 @@ export class DocsInfo {
this.sections = config.markdownSections; this.sections = config.markdownSections;
this.sectionNameToMarkdownByVersion = config.sectionNameToMarkdownByVersion; this.sectionNameToMarkdownByVersion = config.sectionNameToMarkdownByVersion;
this.contractsByVersionByNetworkId = config.contractsByVersionByNetworkId; this.contractsByVersionByNetworkId = config.contractsByVersionByNetworkId;
this.typeConfigs = config.typeConfigs;
} }
public getMenuSubsectionsBySection(docAgnosticFormat?: DocAgnosticFormat): MenuSubsectionsBySection { public getMenuSubsectionsBySection(docAgnosticFormat?: DocAgnosticFormat): MenuSubsectionsBySection {
const menuSubsectionsBySection = {} as MenuSubsectionsBySection; const menuSubsectionsBySection = {} as MenuSubsectionsBySection;
@ -101,7 +98,8 @@ export class DocsInfo {
if (this.type === SupportedDocJson.Doxity) { if (this.type === SupportedDocJson.Doxity) {
return doxityUtils.convertToDocAgnosticFormat(docObj as DoxityDocObj); return doxityUtils.convertToDocAgnosticFormat(docObj as DoxityDocObj);
} else { } else {
return typeDocUtils.convertToDocAgnosticFormat(docObj as GeneratedDocJson, this); const typeDocUtils = new TypeDocUtils(docObj as GeneratedDocJson, this);
return typeDocUtils.convertToDocAgnosticFormat();
} }
} }
} }

View File

@ -11,12 +11,6 @@ export interface DocsInfoConfig {
markdownSections: SectionsMap; markdownSections: SectionsMap;
sectionNameToMarkdownByVersion: SectionNameToMarkdownByVersion; sectionNameToMarkdownByVersion: SectionNameToMarkdownByVersion;
contractsByVersionByNetworkId?: ContractsByVersionByNetworkId; contractsByVersionByNetworkId?: ContractsByVersionByNetworkId;
typeConfigs?: DocsInfoTypeConfigs;
}
export interface DocsInfoTypeConfigs {
typeNameToExternalLink?: { [typeName: string]: string };
typeNameToPrefix?: { [typeName: string]: string };
} }
export interface DocsMenu { export interface DocsMenu {
@ -160,6 +154,7 @@ export interface Type {
types?: Type[]; types?: Type[];
method?: TypescriptMethod; method?: TypescriptMethod;
indexSignature?: IndexSignature; indexSignature?: IndexSignature;
externalLink?: string;
} }
export interface ElementType { export interface ElementType {
@ -297,9 +292,14 @@ export interface ExportNameToTypedocNames {
[exportName: string]: string[]; [exportName: string]: string[];
} }
export interface ExternalTypeToLink {
[externalTypeName: string]: string;
}
export interface Metadata { export interface Metadata {
exportPathToTypedocNames: ExportNameToTypedocNames; exportPathToTypedocNames: ExportNameToTypedocNames;
exportPathOrder: string[]; exportPathOrder: string[];
externalTypeToLink: ExternalTypeToLink;
} }
export interface GeneratedDocJson { export interface GeneratedDocJson {

View File

@ -7,6 +7,7 @@ import {
CustomTypeChild, CustomTypeChild,
DocAgnosticFormat, DocAgnosticFormat,
DocSection, DocSection,
ExternalTypeToLink,
GeneratedDocJson, GeneratedDocJson,
IndexSignature, IndexSignature,
KindString, KindString,
@ -24,8 +25,39 @@ import {
import { constants } from './constants'; import { constants } from './constants';
export const typeDocUtils = { export class TypeDocUtils {
isType(entity: TypeDocNode): boolean { private _typeDocNameOrder: string[];
private _externalTypeToLink: ExternalTypeToLink;
private _docsInfo: DocsInfo;
private _typeDocJson: TypeDocNode;
private _classNames: string[];
constructor(generatedDocJson: GeneratedDocJson, docsInfo: DocsInfo) {
this._docsInfo = docsInfo;
console.log('generatedDocJson.metadata', generatedDocJson.metadata);
const exportPathOrder = generatedDocJson.metadata.exportPathOrder;
const exportPathToTypedocNames = generatedDocJson.metadata.exportPathToTypedocNames;
this._externalTypeToLink = generatedDocJson.metadata.externalTypeToLink;
this._typeDocJson = generatedDocJson.typedocJson;
// TODO: Extract the non typeDoc exports, and render them somehow
this._typeDocNameOrder = _.compact(
_.flatten(
_.map(exportPathOrder, exportPath => {
return exportPathToTypedocNames[exportPath];
}),
),
);
this._classNames = [];
_.each(this._typeDocJson.children, file => {
_.each(file.children, child => {
if (child.kindString === KindString.Class) {
this._classNames.push(child.name);
}
});
});
}
public isType(entity: TypeDocNode): boolean {
return ( return (
entity.kindString === KindString.Interface || entity.kindString === KindString.Interface ||
entity.kindString === KindString.Function || entity.kindString === KindString.Function ||
@ -33,17 +65,17 @@ export const typeDocUtils = {
entity.kindString === KindString.Variable || entity.kindString === KindString.Variable ||
entity.kindString === KindString.Enumeration entity.kindString === KindString.Enumeration
); );
}, }
isMethod(entity: TypeDocNode): boolean { public isMethod(entity: TypeDocNode): boolean {
return entity.kindString === KindString.Method; return entity.kindString === KindString.Method;
}, }
isConstructor(entity: TypeDocNode): boolean { public isConstructor(entity: TypeDocNode): boolean {
return entity.kindString === KindString.Constructor; return entity.kindString === KindString.Constructor;
}, }
isProperty(entity: TypeDocNode): boolean { public isProperty(entity: TypeDocNode): boolean {
return entity.kindString === KindString.Property; return entity.kindString === KindString.Property;
}, }
getModuleDefinitionsBySectionName(versionDocObj: TypeDocNode, configModulePaths: string[]): TypeDocNode[] { public getModuleDefinitionsBySectionName(versionDocObj: TypeDocNode, configModulePaths: string[]): TypeDocNode[] {
const moduleDefinitions: TypeDocNode[] = []; const moduleDefinitions: TypeDocNode[] = [];
const jsonModules = versionDocObj.children; const jsonModules = versionDocObj.children;
_.each(jsonModules, jsonMod => { _.each(jsonModules, jsonMod => {
@ -54,52 +86,28 @@ export const typeDocUtils = {
}); });
}); });
return moduleDefinitions; return moduleDefinitions;
}, }
convertToDocAgnosticFormat(generatedDocJson: GeneratedDocJson, docsInfo: DocsInfo): DocAgnosticFormat { public convertToDocAgnosticFormat(): DocAgnosticFormat {
const exportPathOrder = generatedDocJson.metadata.exportPathOrder;
const exportPathToTypedocNames = generatedDocJson.metadata.exportPathToTypedocNames;
const typeDocJson = generatedDocJson.typedocJson;
// TODO: Extract the non typeDoc exports, and render them somehow
const typeDocNameOrder = _.compact(
_.flatten(
_.map(exportPathOrder, exportPath => {
return exportPathToTypedocNames[exportPath];
}),
),
);
const classNames: string[] = [];
_.each(typeDocJson.children, file => {
_.each(file.children, child => {
if (child.kindString === KindString.Class) {
classNames.push(child.name);
}
});
});
const docAgnosticFormat: DocAgnosticFormat = {}; const docAgnosticFormat: DocAgnosticFormat = {};
const typeEntities: TypeDocNode[] = []; const typeEntities: TypeDocNode[] = [];
_.each(typeDocNameOrder, typeDocName => { _.each(this._typeDocNameOrder, typeDocName => {
const fileChildIndex = _.findIndex(typeDocJson.children, child => child.name === typeDocName); const fileChildIndex = _.findIndex(this._typeDocJson.children, child => child.name === typeDocName);
const fileChild = typeDocJson.children[fileChildIndex]; const fileChild = this._typeDocJson.children[fileChildIndex];
let sectionName: string; let sectionName: string;
_.each(fileChild.children, child => { _.each(fileChild.children, child => {
switch (child.kindString) { switch (child.kindString) {
case KindString.Class: case KindString.Class:
case KindString.ObjectLiteral: { case KindString.ObjectLiteral: {
sectionName = child.name; sectionName = child.name;
docsInfo.sections[sectionName] = sectionName; this._docsInfo.sections[sectionName] = sectionName;
docsInfo.menu[sectionName] = [sectionName]; this._docsInfo.menu[sectionName] = [sectionName];
const entities = child.children; const entities = child.children;
const commentObj = child.comment; const commentObj = child.comment;
const sectionComment = !_.isUndefined(commentObj) ? commentObj.shortText : ''; const sectionComment = !_.isUndefined(commentObj) ? commentObj.shortText : '';
const isClassOrObjectLiteral = true; const isClassOrObjectLiteral = true;
const docSection = typeDocUtils._convertEntitiesToDocSection( const docSection = this._convertEntitiesToDocSection(
entities, entities,
docsInfo,
sectionName, sectionName,
classNames,
isClassOrObjectLiteral, isClassOrObjectLiteral,
); );
docSection.comment = sectionComment; docSection.comment = sectionComment;
@ -108,17 +116,12 @@ export const typeDocUtils = {
} }
case KindString.Function: { case KindString.Function: {
sectionName = child.name; sectionName = child.name;
docsInfo.sections[sectionName] = sectionName; this._docsInfo.sections[sectionName] = sectionName;
docsInfo.menu[sectionName] = [sectionName]; this._docsInfo.menu[sectionName] = [sectionName];
const entities = [child]; const entities = [child];
const commentObj = child.comment; const commentObj = child.comment;
const SectionComment = !_.isUndefined(commentObj) ? commentObj.shortText : ''; const SectionComment = !_.isUndefined(commentObj) ? commentObj.shortText : '';
const docSection = typeDocUtils._convertEntitiesToDocSection( const docSection = this._convertEntitiesToDocSection(entities, sectionName);
entities,
docsInfo,
sectionName,
classNames,
);
docSection.comment = SectionComment; docSection.comment = SectionComment;
docAgnosticFormat[sectionName] = docSection; docAgnosticFormat[sectionName] = docSection;
break; break;
@ -135,24 +138,17 @@ export const typeDocUtils = {
}); });
}); });
if (!_.isEmpty(typeEntities)) { if (!_.isEmpty(typeEntities)) {
docsInfo.sections[constants.TYPES_SECTION_NAME] = constants.TYPES_SECTION_NAME; this._docsInfo.sections[constants.TYPES_SECTION_NAME] = constants.TYPES_SECTION_NAME;
docsInfo.menu[constants.TYPES_SECTION_NAME] = [constants.TYPES_SECTION_NAME]; this._docsInfo.menu[constants.TYPES_SECTION_NAME] = [constants.TYPES_SECTION_NAME];
const docSection = typeDocUtils._convertEntitiesToDocSection( const docSection = this._convertEntitiesToDocSection(typeEntities, constants.TYPES_SECTION_NAME);
typeEntities,
docsInfo,
constants.TYPES_SECTION_NAME,
classNames,
);
docAgnosticFormat[constants.TYPES_SECTION_NAME] = docSection; docAgnosticFormat[constants.TYPES_SECTION_NAME] = docSection;
} }
return docAgnosticFormat; return docAgnosticFormat;
}, }
_convertEntitiesToDocSection( private _convertEntitiesToDocSection(
entities: TypeDocNode[], entities: TypeDocNode[],
docsInfo: DocsInfo,
sectionName: string, sectionName: string,
classNames: string[],
isClassOrObjectLiteral: boolean = false, isClassOrObjectLiteral: boolean = false,
): DocSection { ): DocSection {
const docSection: DocSection = { const docSection: DocSection = {
@ -169,14 +165,7 @@ export const typeDocUtils = {
switch (entity.kindString) { switch (entity.kindString) {
case KindString.Constructor: case KindString.Constructor:
isConstructor = true; isConstructor = true;
const constructor = typeDocUtils._convertMethod( const constructor = this._convertMethod(entity, isConstructor, sectionName);
entity,
isConstructor,
docsInfo.sections,
sectionName,
docsInfo.id,
classNames,
);
docSection.constructors.push(constructor); docSection.constructors.push(constructor);
break; break;
@ -185,14 +174,7 @@ export const typeDocUtils = {
const funcName = (entity as TypeDocNode).signatures[0].name; const funcName = (entity as TypeDocNode).signatures[0].name;
const isPublicFunc = !_.startsWith(funcName, '_'); const isPublicFunc = !_.startsWith(funcName, '_');
if (isPublicFunc) { if (isPublicFunc) {
const func = typeDocUtils._convertFunction( const func = this._convertFunction(entity, sectionName, isClassOrObjectLiteral);
entity,
docsInfo.sections,
sectionName,
docsInfo.id,
isClassOrObjectLiteral,
classNames,
);
docSection.functions.push(func); docSection.functions.push(func);
} }
} }
@ -201,49 +183,25 @@ export const typeDocUtils = {
case KindString.Method: case KindString.Method:
if (entity.flags.isPublic) { if (entity.flags.isPublic) {
isConstructor = false; isConstructor = false;
const method = typeDocUtils._convertMethod( const method = this._convertMethod(entity, isConstructor, sectionName);
entity,
isConstructor,
docsInfo.sections,
sectionName,
docsInfo.id,
classNames,
);
docSection.methods.push(method); docSection.methods.push(method);
} }
break; break;
case KindString.Property: case KindString.Property: {
const property = typeDocUtils._convertProperty( const property = this._convertProperty(entity, sectionName);
entity,
docsInfo.sections,
sectionName,
docsInfo.id,
classNames,
);
docSection.properties.push(property); docSection.properties.push(property);
break; break;
}
case KindString.Variable: case KindString.Variable:
if (isClassOrObjectLiteral) { if (isClassOrObjectLiteral) {
// Render as a property // Render as a property
const property = typeDocUtils._convertProperty( const property = this._convertProperty(entity, sectionName);
entity,
docsInfo.sections,
sectionName,
docsInfo.id,
classNames,
);
docSection.properties.push(property); docSection.properties.push(property);
} else { } else {
// Otherwise, render as a type // Otherwise, render as a type
const customType = typeDocUtils._convertCustomType( const customType = this._convertCustomType(entity, sectionName);
entity,
docsInfo.sections,
sectionName,
docsInfo.id,
classNames,
);
const seenTypeNames = _.map(docSection.types, t => t.name); const seenTypeNames = _.map(docSection.types, t => t.name);
const isUnseen = !_.includes(seenTypeNames, customType.name); const isUnseen = !_.includes(seenTypeNames, customType.name);
if (isUnseen) { if (isUnseen) {
@ -255,13 +213,7 @@ export const typeDocUtils = {
case KindString.Interface: case KindString.Interface:
case KindString.Enumeration: case KindString.Enumeration:
case KindString.TypeAlias: { case KindString.TypeAlias: {
const customType = typeDocUtils._convertCustomType( const customType = this._convertCustomType(entity, sectionName);
entity,
docsInfo.sections,
sectionName,
docsInfo.id,
classNames,
);
const seenTypeNames = _.map(docSection.types, t => t.name); const seenTypeNames = _.map(docSection.types, t => t.name);
const isUnseen = !_.includes(seenTypeNames, customType.name); const isUnseen = !_.includes(seenTypeNames, customType.name);
if (isUnseen) { if (isUnseen) {
@ -281,25 +233,17 @@ export const typeDocUtils = {
} }
}); });
return docSection; return docSection;
}, }
_convertCustomType( private _convertCustomType(entity: TypeDocNode, sectionName: string): CustomType {
entity: TypeDocNode, const typeIfExists = !_.isUndefined(entity.type) ? this._convertType(entity.type, sectionName) : undefined;
sections: SectionsMap,
sectionName: string,
docId: string,
classNames: string[],
): CustomType {
const typeIfExists = !_.isUndefined(entity.type)
? typeDocUtils._convertType(entity.type, sections, sectionName, docId, classNames)
: undefined;
const isConstructor = false; const isConstructor = false;
const methodIfExists = !_.isUndefined(entity.declaration) const methodIfExists = !_.isUndefined(entity.declaration)
? typeDocUtils._convertMethod(entity.declaration, isConstructor, sections, sectionName, docId, classNames) ? this._convertMethod(entity.declaration, isConstructor, sectionName)
: undefined; : undefined;
const doesIndexSignatureExist = !_.isUndefined(entity.indexSignature); const doesIndexSignatureExist = !_.isUndefined(entity.indexSignature);
const indexSignature = entity.indexSignature as TypeDocNode; const indexSignature = entity.indexSignature as TypeDocNode;
const indexSignatureIfExists = doesIndexSignatureExist const indexSignatureIfExists = doesIndexSignatureExist
? typeDocUtils._convertIndexSignature(indexSignature, sections, sectionName, docId, classNames) ? this._convertIndexSignature(indexSignature, sectionName)
: undefined; : undefined;
const commentIfExists = const commentIfExists =
!_.isUndefined(entity.comment) && !_.isUndefined(entity.comment.shortText) !_.isUndefined(entity.comment) && !_.isUndefined(entity.comment.shortText)
@ -309,20 +253,13 @@ export const typeDocUtils = {
const childrenIfExist = !_.isUndefined(entity.children) const childrenIfExist = !_.isUndefined(entity.children)
? _.map(entity.children, (child: TypeDocNode) => { ? _.map(entity.children, (child: TypeDocNode) => {
let childTypeIfExists = !_.isUndefined(child.type) let childTypeIfExists = !_.isUndefined(child.type)
? typeDocUtils._convertType(child.type, sections, sectionName, docId, classNames) ? this._convertType(child.type, sectionName)
: undefined; : undefined;
if (child.kindString === KindString.Method) { if (child.kindString === KindString.Method) {
childTypeIfExists = { childTypeIfExists = {
name: child.name, name: child.name,
typeDocType: TypeDocTypes.Reflection, typeDocType: TypeDocTypes.Reflection,
method: typeDocUtils._convertMethod( method: this._convertMethod(child, isConstructor, sectionName),
child,
isConstructor,
sections,
sectionName,
docId,
classNames,
),
}; };
} }
const c: CustomTypeChild = { const c: CustomTypeChild = {
@ -345,37 +282,25 @@ export const typeDocUtils = {
children: childrenIfExist, children: childrenIfExist,
}; };
return customType; return customType;
}, }
_convertIndexSignature( private _convertIndexSignature(entity: TypeDocNode, sectionName: string): IndexSignature {
entity: TypeDocNode,
sections: SectionsMap,
sectionName: string,
docId: string,
classNames: string[],
): IndexSignature {
const key = entity.parameters[0]; const key = entity.parameters[0];
const indexSignature = { const indexSignature = {
keyName: key.name, keyName: key.name,
keyType: typeDocUtils._convertType(key.type, sections, sectionName, docId, classNames), keyType: this._convertType(key.type, sectionName),
valueName: entity.type.name, valueName: entity.type.name,
}; };
return indexSignature; return indexSignature;
}, }
_convertProperty( private _convertProperty(entity: TypeDocNode, sectionName: string): Property {
entity: TypeDocNode,
sections: SectionsMap,
sectionName: string,
docId: string,
classNames: string[],
): Property {
const source = entity.sources[0]; const source = entity.sources[0];
const commentIfExists = !_.isUndefined(entity.comment) ? entity.comment.shortText : undefined; const commentIfExists = !_.isUndefined(entity.comment) ? entity.comment.shortText : undefined;
const isConstructor = false; const isConstructor = false;
const isStatic = _.isUndefined(entity.flags.isStatic) ? false : entity.flags.isStatic; const isStatic = _.isUndefined(entity.flags.isStatic) ? false : entity.flags.isStatic;
const callPath = typeDocUtils._getCallPath(sectionName, isStatic, isConstructor, entity.name); const callPath = this._getCallPath(sectionName, isStatic, isConstructor, entity.name);
const property = { const property = {
name: entity.name, name: entity.name,
type: typeDocUtils._convertType(entity.type, sections, sectionName, docId, classNames), type: this._convertType(entity.type, sectionName),
source: { source: {
fileName: source.fileName, fileName: source.fileName,
line: source.line, line: source.line,
@ -384,29 +309,22 @@ export const typeDocUtils = {
callPath, callPath,
}; };
return property; return property;
}, }
_convertMethod( private _convertMethod(entity: TypeDocNode, isConstructor: boolean, sectionName: string): TypescriptMethod {
entity: TypeDocNode,
isConstructor: boolean,
sections: SectionsMap,
sectionName: string,
docId: string,
classNames: string[],
): TypescriptMethod {
const signature = entity.signatures[0]; const signature = entity.signatures[0];
const source = entity.sources[0]; const source = entity.sources[0];
const hasComment = !_.isUndefined(signature.comment); const hasComment = !_.isUndefined(signature.comment);
const isStatic = _.isUndefined(entity.flags.isStatic) ? false : entity.flags.isStatic; const isStatic = _.isUndefined(entity.flags.isStatic) ? false : entity.flags.isStatic;
const parameters = _.map(signature.parameters, param => { const parameters = _.map(signature.parameters, param => {
return typeDocUtils._convertParameter(param, sections, sectionName, docId, classNames); return this._convertParameter(param, sectionName);
}); });
const returnType = typeDocUtils._convertType(signature.type, sections, sectionName, docId, classNames); const returnType = this._convertType(signature.type, sectionName);
const typeParameter = _.isUndefined(signature.typeParameter) const typeParameter = _.isUndefined(signature.typeParameter)
? undefined ? undefined
: typeDocUtils._convertTypeParameter(signature.typeParameter[0], sections, sectionName, docId, classNames); : this._convertTypeParameter(signature.typeParameter[0], sectionName);
const callPath = typeDocUtils._getCallPath(sectionName, isStatic, isConstructor, entity.name); const callPath = this._getCallPath(sectionName, isStatic, isConstructor, entity.name);
const method = { const method = {
isConstructor, isConstructor,
isStatic, isStatic,
@ -416,6 +334,10 @@ export const typeDocUtils = {
source: { source: {
fileName: source.fileName, fileName: source.fileName,
line: source.line, line: source.line,
callPath,
parameters,
returnType,
typeParameter,
}, },
callPath, callPath,
parameters, parameters,
@ -423,8 +345,8 @@ export const typeDocUtils = {
typeParameter, typeParameter,
}; };
return method; return method;
}, }
_getCallPath(sectionName: string, isStatic: boolean, isConstructor: boolean, entityName: string): string { private _getCallPath(sectionName: string, isStatic: boolean, isConstructor: boolean, entityName: string): string {
// HACK: we use the fact that the sectionName is the same as the property name at the top-level // HACK: we use the fact that the sectionName is the same as the property name at the top-level
// of the public interface. In the future, we shouldn't use this hack but rather get it from the JSON. // of the public interface. In the future, we shouldn't use this hack but rather get it from the JSON.
let callPath; let callPath;
@ -435,32 +357,25 @@ export const typeDocUtils = {
callPath = `${prefix}.`; callPath = `${prefix}.`;
} }
return callPath; return callPath;
}, }
_convertFunction( private _convertFunction(entity: TypeDocNode, sectionName: string, isObjectLiteral: boolean): TypescriptFunction {
entity: TypeDocNode,
sections: SectionsMap,
sectionName: string,
docId: string,
isObjectLiteral: boolean,
classNames: string[],
): TypescriptFunction {
const signature = entity.signatures[0]; const signature = entity.signatures[0];
const source = entity.sources[0]; const source = entity.sources[0];
const hasComment = !_.isUndefined(signature.comment); const hasComment = !_.isUndefined(signature.comment);
const parameters = _.map(signature.parameters, param => { const parameters = _.map(signature.parameters, param => {
return typeDocUtils._convertParameter(param, sections, sectionName, docId, classNames); return this._convertParameter(param, sectionName);
}); });
const returnType = typeDocUtils._convertType(signature.type, sections, sectionName, docId, classNames); const returnType = this._convertType(signature.type, sectionName);
const typeParameter = _.isUndefined(signature.typeParameter) const typeParameter = _.isUndefined(signature.typeParameter)
? undefined ? undefined
: typeDocUtils._convertTypeParameter(signature.typeParameter[0], sections, sectionName, docId, classNames); : this._convertTypeParameter(signature.typeParameter[0], sectionName);
let callPath = ''; let callPath = '';
if (isObjectLiteral) { if (isObjectLiteral) {
const isConstructor = false; const isConstructor = false;
const isStatic = false; const isStatic = false;
callPath = typeDocUtils._getCallPath(sectionName, isStatic, isConstructor, entity.name); callPath = this._getCallPath(sectionName, isStatic, isConstructor, entity.name);
} }
const func = { const func = {
name: signature.name, name: signature.name,
@ -476,28 +391,16 @@ export const typeDocUtils = {
typeParameter, typeParameter,
}; };
return func; return func;
}, }
_convertTypeParameter( private _convertTypeParameter(entity: TypeDocNode, sectionName: string): TypeParameter {
entity: TypeDocNode, const type = this._convertType(entity.type, sectionName);
sections: SectionsMap,
sectionName: string,
docId: string,
classNames: string[],
): TypeParameter {
const type = typeDocUtils._convertType(entity.type, sections, sectionName, docId, classNames);
const parameter = { const parameter = {
name: entity.name, name: entity.name,
type, type,
}; };
return parameter; return parameter;
}, }
_convertParameter( private _convertParameter(entity: TypeDocNode, sectionName: string): Parameter {
entity: TypeDocNode,
sections: SectionsMap,
sectionName: string,
docId: string,
classNames: string[],
): Parameter {
let comment = '<No comment>'; let comment = '<No comment>';
if (entity.comment && entity.comment.shortText) { if (entity.comment && entity.comment.shortText) {
comment = entity.comment.shortText; comment = entity.comment.shortText;
@ -507,7 +410,7 @@ export const typeDocUtils = {
const isOptional = !_.isUndefined(entity.flags.isOptional) ? entity.flags.isOptional : false; const isOptional = !_.isUndefined(entity.flags.isOptional) ? entity.flags.isOptional : false;
const type = typeDocUtils._convertType(entity.type, sections, sectionName, docId, classNames); const type = this._convertType(entity.type, sectionName);
const parameter = { const parameter = {
name: entity.name, name: entity.name,
@ -517,19 +420,13 @@ export const typeDocUtils = {
type, type,
}; };
return parameter; return parameter;
}, }
_convertType( private _convertType(entity: TypeDocType, sectionName: string): Type {
entity: TypeDocType,
sections: SectionsMap,
sectionName: string,
docId: string,
classNames: string[],
): Type {
const typeArguments = _.map(entity.typeArguments, typeArgument => { const typeArguments = _.map(entity.typeArguments, typeArgument => {
return typeDocUtils._convertType(typeArgument, sections, sectionName, docId, classNames); return this._convertType(typeArgument, sectionName);
}); });
const types = _.map(entity.types, t => { const types = _.map(entity.types, t => {
return typeDocUtils._convertType(t, sections, sectionName, docId, classNames); return this._convertType(t, sectionName);
}); });
let indexSignatureIfExists; let indexSignatureIfExists;
@ -538,23 +435,10 @@ export const typeDocUtils = {
!_.isUndefined(entity.declaration) && !_.isUndefined(entity.declaration.indexSignature); !_.isUndefined(entity.declaration) && !_.isUndefined(entity.declaration.indexSignature);
if (doesIndexSignatureExist) { if (doesIndexSignatureExist) {
const indexSignature = entity.declaration.indexSignature as TypeDocNode; const indexSignature = entity.declaration.indexSignature as TypeDocNode;
indexSignatureIfExists = typeDocUtils._convertIndexSignature( indexSignatureIfExists = this._convertIndexSignature(indexSignature, sectionName);
indexSignature,
sections,
sectionName,
docId,
classNames,
);
} else if (!_.isUndefined(entity.declaration)) { } else if (!_.isUndefined(entity.declaration)) {
const isConstructor = false; const isConstructor = false;
methodIfExists = typeDocUtils._convertMethod( methodIfExists = this._convertMethod(entity.declaration, isConstructor, sectionName);
entity.declaration,
isConstructor,
sections,
sectionName,
docId,
classNames,
);
} }
const elementTypeIfExists = !_.isUndefined(entity.elementType) const elementTypeIfExists = !_.isUndefined(entity.elementType)
@ -564,10 +448,10 @@ export const typeDocUtils = {
} }
: undefined; : undefined;
const type = { const type: Type = {
name: entity.name, name: entity.name,
value: entity.value, value: entity.value,
isExportedClassReference: _.includes(classNames, entity.name), isExportedClassReference: _.includes(this._classNames, entity.name),
typeDocType: entity.type, typeDocType: entity.type,
typeArguments, typeArguments,
elementType: elementTypeIfExists, elementType: elementTypeIfExists,
@ -575,6 +459,11 @@ export const typeDocUtils = {
method: methodIfExists, method: methodIfExists,
indexSignature: indexSignatureIfExists, indexSignature: indexSignatureIfExists,
}; };
console.log('this._externalTypeToLink', this._externalTypeToLink);
const externalLinkIfExists = this._externalTypeToLink[entity.name];
if (!_.isUndefined(externalLinkIfExists)) {
type.externalLink = externalLinkIfExists;
}
return type; return type;
}, }
}; }

View File

@ -34,13 +34,7 @@ const docsInfoConfig: DocsInfoConfig = {
[markdownSections.installation]: InstallationMarkdownV1, [markdownSections.installation]: InstallationMarkdownV1,
}, },
}, },
markdownSections: markdownSections, markdownSections,
typeConfigs: {
typeNameToExternalLink: {
Provider: constants.URL_WEB3_PROVIDER_DOCS,
BigNumber: constants.URL_BIGNUMBERJS_GITHUB,
},
},
}; };
const docsInfo = new DocsInfo(docsInfoConfig); const docsInfo = new DocsInfo(docsInfoConfig);

View File

@ -35,12 +35,6 @@ const docsInfoConfig: DocsInfoConfig = {
}, },
}, },
markdownSections, markdownSections,
typeConfigs: {
typeNameToPrefix: {},
typeNameToExternalLink: {
BigNumber: constants.URL_BIGNUMBERJS_GITHUB,
},
},
}; };
const docsInfo = new DocsInfo(docsInfoConfig); const docsInfo = new DocsInfo(docsInfoConfig);

View File

@ -36,12 +36,7 @@ const docsInfoConfig: DocsInfoConfig = {
[markdownSections.installation]: InstallationMarkdown, [markdownSections.installation]: InstallationMarkdown,
}, },
}, },
markdownSections: markdownSections, markdownSections,
typeConfigs: {
typeNameToExternalLink: {
BigNumber: constants.URL_BIGNUMBERJS_GITHUB,
},
},
}; };
const docsInfo = new DocsInfo(docsInfoConfig); const docsInfo = new DocsInfo(docsInfoConfig);

View File

@ -43,13 +43,7 @@ const docsInfoConfig: DocsInfoConfig = {
[markdownSections.usage]: UsageMarkdownV1, [markdownSections.usage]: UsageMarkdownV1,
}, },
}, },
markdownSections: markdownSections, markdownSections,
typeConfigs: {
typeNameToExternalLink: {
Schema:
'https://github.com/tdegrunt/jsonschema/blob/5c2edd4baba149964aec0f23c87ad12c25a50dfb/lib/index.d.ts#L49',
},
},
}; };
const docsInfo = new DocsInfo(docsInfoConfig); const docsInfo = new DocsInfo(docsInfoConfig);

View File

@ -35,11 +35,6 @@ const docsInfoConfig: DocsInfoConfig = {
}, },
}, },
markdownSections, markdownSections,
typeConfigs: {
typeNameToExternalLink: {
BigNumber: constants.URL_BIGNUMBERJS_GITHUB,
},
},
}; };
const docsInfo = new DocsInfo(docsInfoConfig); const docsInfo = new DocsInfo(docsInfoConfig);

View File

@ -35,11 +35,6 @@ const docsInfoConfig: DocsInfoConfig = {
}, },
}, },
markdownSections, markdownSections,
typeConfigs: {
typeNameToExternalLink: {
BigNumber: constants.URL_BIGNUMBERJS_GITHUB,
},
},
}; };
const docsInfo = new DocsInfo(docsInfoConfig); const docsInfo = new DocsInfo(docsInfoConfig);

View File

@ -37,11 +37,7 @@ const docsInfoConfig: DocsInfoConfig = {
[markdownSections.usage]: UsageMarkdown, [markdownSections.usage]: UsageMarkdown,
}, },
}, },
markdownSections: markdownSections, markdownSections,
typeConfigs: {
typeNameToExternalLink: {},
typeNameToPrefix: {},
},
}; };
const docsInfo = new DocsInfo(docsInfoConfig); const docsInfo = new DocsInfo(docsInfoConfig);

View File

@ -37,11 +37,7 @@ const docsInfoConfig: DocsInfoConfig = {
[markdownSections.usage]: UsageMarkdown, [markdownSections.usage]: UsageMarkdown,
}, },
}, },
markdownSections: markdownSections, markdownSections,
typeConfigs: {
typeNameToExternalLink: {},
typeNameToPrefix: {},
},
}; };
const docsInfo = new DocsInfo(docsInfoConfig); const docsInfo = new DocsInfo(docsInfoConfig);

View File

@ -39,13 +39,6 @@ const docsInfoConfig: DocsInfoConfig = {
}, },
}, },
markdownSections: docSections, markdownSections: docSections,
typeConfigs: {
typeNameToExternalLink: {
Web3: constants.URL_WEB3_DOCS,
BigNumber: constants.URL_BIGNUMBERJS_GITHUB,
},
typeNameToPrefix: {},
},
}; };
const docsInfo = new DocsInfo(docsInfoConfig); const docsInfo = new DocsInfo(docsInfoConfig);

View File

@ -35,13 +35,6 @@ const docsInfoConfig: DocsInfoConfig = {
}, },
}, },
markdownSections: docSections, markdownSections: docSections,
typeConfigs: {
typeNameToExternalLink: {
Web3: constants.URL_WEB3_DOCS,
BigNumber: constants.URL_BIGNUMBERJS_GITHUB,
},
typeNameToPrefix: {},
},
}; };
const docsInfo = new DocsInfo(docsInfoConfig); const docsInfo = new DocsInfo(docsInfoConfig);

View File

@ -56,13 +56,7 @@ const docsInfoConfig: DocsInfoConfig = {
[markdownSections.errors]: ErrorsMarkdownV1, [markdownSections.errors]: ErrorsMarkdownV1,
}, },
}, },
markdownSections: markdownSections, markdownSections,
typeConfigs: {
typeNameToPrefix: {},
typeNameToExternalLink: {
BigNumber: constants.URL_BIGNUMBERJS_GITHUB,
},
},
}; };
const docsInfo = new DocsInfo(docsInfoConfig); const docsInfo = new DocsInfo(docsInfoConfig);