diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-03-24 02:18:31 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-24 02:18:31 +0800 |
commit | f30353087f9c4ec4fa5e096a065c9749e1164984 (patch) | |
tree | 4d7968160890b5efa358593e743411c7b8652556 /packages/react-docs/src/utils | |
parent | 7ef6bd4b14b7502617c6929010d4a9991e1d577d (diff) | |
parent | bed7d87b7ff64989051e6b2115a1c77e1e72ff55 (diff) | |
download | dexon-sol-tools-f30353087f9c4ec4fa5e096a065c9749e1164984.tar dexon-sol-tools-f30353087f9c4ec4fa5e096a065c9749e1164984.tar.gz dexon-sol-tools-f30353087f9c4ec4fa5e096a065c9749e1164984.tar.bz2 dexon-sol-tools-f30353087f9c4ec4fa5e096a065c9749e1164984.tar.lz dexon-sol-tools-f30353087f9c4ec4fa5e096a065c9749e1164984.tar.xz dexon-sol-tools-f30353087f9c4ec4fa5e096a065c9749e1164984.tar.zst dexon-sol-tools-f30353087f9c4ec4fa5e096a065c9749e1164984.zip |
Merge branch 'development' into feature/deployer-improvements
Diffstat (limited to 'packages/react-docs/src/utils')
-rw-r--r-- | packages/react-docs/src/utils/doxity_utils.ts | 1 | ||||
-rw-r--r-- | packages/react-docs/src/utils/typedoc_utils.ts | 71 |
2 files changed, 64 insertions, 8 deletions
diff --git a/packages/react-docs/src/utils/doxity_utils.ts b/packages/react-docs/src/utils/doxity_utils.ts index 26dea6966..1b91690e0 100644 --- a/packages/react-docs/src/utils/doxity_utils.ts +++ b/packages/react-docs/src/utils/doxity_utils.ts @@ -116,6 +116,7 @@ export const doxityUtils = { methods, properties, types: [], + functions: [], events, }; docAgnosticFormat[contractName] = docSection; diff --git a/packages/react-docs/src/utils/typedoc_utils.ts b/packages/react-docs/src/utils/typedoc_utils.ts index e4cea1e40..02f5b4049 100644 --- a/packages/react-docs/src/utils/typedoc_utils.ts +++ b/packages/react-docs/src/utils/typedoc_utils.ts @@ -15,6 +15,7 @@ import { TypeDocNode, TypeDocType, TypeParameter, + TypescriptFunction, TypescriptMethod, } from '../types'; import { utils } from '../utils/utils'; @@ -81,17 +82,22 @@ export const typeDocUtils = { } } - // Since the `types.ts` file is the only file that does not export a module/class but - // instead has each type export itself, we do not need to go down two levels of nesting - // for it. let entities; let packageComment = ''; - if (sectionName === docsInfo.sections.types) { - entities = packageDefinitionWithMergedChildren.children; - } else { + // HACK: We assume 1 exported class per file + const classChildren = _.filter(packageDefinitionWithMergedChildren.children, (child: TypeDocNode) => { + return child.kindString === KindString.Class; + }); + if (classChildren.length > 1 && sectionName !== 'types') { + throw new Error('`react-docs` only supports projects with 1 exported class per file'); + } + const isClassExport = packageDefinitionWithMergedChildren.children[0].kindString === KindString.Class; + if (isClassExport) { entities = packageDefinitionWithMergedChildren.children[0].children; const commentObj = packageDefinitionWithMergedChildren.children[0].comment; packageComment = !_.isUndefined(commentObj) ? commentObj.shortText : packageComment; + } else { + entities = packageDefinitionWithMergedChildren.children; } const docSection = typeDocUtils._convertEntitiesToDocSection(entities, docsInfo, sectionName); @@ -105,6 +111,7 @@ export const typeDocUtils = { comment: '', constructors: [], methods: [], + functions: [], properties: [], types: [], }; @@ -124,6 +131,13 @@ export const typeDocUtils = { docSection.constructors.push(constructor); break; + case KindString.Function: + if (entity.flags.isExported) { + const func = typeDocUtils._convertFunction(entity, docsInfo.sections, sectionName, docsInfo.id); + docSection.functions.push(func); + } + break; + case KindString.Method: if (entity.flags.isPublic) { isConstructor = false; @@ -151,7 +165,6 @@ export const typeDocUtils = { break; case KindString.Interface: - case KindString.Function: case KindString.Variable: case KindString.Enumeration: case KindString.TypeAlias: @@ -162,10 +175,20 @@ export const typeDocUtils = { sectionName, docsInfo.id, ); - docSection.types.push(customType); + const seenTypeNames = _.map(docSection.types, t => t.name); + const isUnseen = !_.includes(seenTypeNames, customType.name); + if (isUnseen) { + docSection.types.push(customType); + } } break; + case KindString.Class: + // We currently do not support more then a single class per file + // except for the types section, where we ignore classes since we + // only want to render type definitions. + break; + default: throw utils.spawnSwitchErr('kindString', entity.kindString); } @@ -303,6 +326,38 @@ export const typeDocUtils = { }; return method; }, + _convertFunction( + entity: TypeDocNode, + sections: SectionsMap, + sectionName: string, + docId: string, + ): TypescriptFunction { + const signature = entity.signatures[0]; + const source = entity.sources[0]; + const hasComment = !_.isUndefined(signature.comment); + + const parameters = _.map(signature.parameters, param => { + return typeDocUtils._convertParameter(param, sections, sectionName, docId); + }); + const returnType = typeDocUtils._convertType(signature.type, sections, sectionName, docId); + const typeParameter = _.isUndefined(signature.typeParameter) + ? undefined + : typeDocUtils._convertTypeParameter(signature.typeParameter[0], sections, sectionName, docId); + + const func = { + name: signature.name, + comment: hasComment ? signature.comment.shortText : undefined, + returnComment: hasComment && signature.comment.returns ? signature.comment.returns : undefined, + source: { + fileName: source.fileName, + line: source.line, + }, + parameters, + returnType, + typeParameter, + }; + return func; + }, _convertTypeParameter( entity: TypeDocNode, sections: SectionsMap, |