aboutsummaryrefslogtreecommitdiffstats
path: root/packages/react-docs/src/utils
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-04-02 20:23:07 +0800
committerFabio Berger <me@fabioberger.com>2018-04-02 20:23:07 +0800
commit8162394797342cef268cc8072fc860326974e269 (patch)
tree2826b02715a8cb794571be6c7dccdb395329361c /packages/react-docs/src/utils
parentfd001186dd281a11920246c6b9afcefe1d55bc23 (diff)
parent695b697cdf6c73bb4b5f920869ce128f9a9e7523 (diff)
downloaddexon-0x-contracts-8162394797342cef268cc8072fc860326974e269.tar
dexon-0x-contracts-8162394797342cef268cc8072fc860326974e269.tar.gz
dexon-0x-contracts-8162394797342cef268cc8072fc860326974e269.tar.bz2
dexon-0x-contracts-8162394797342cef268cc8072fc860326974e269.tar.lz
dexon-0x-contracts-8162394797342cef268cc8072fc860326974e269.tar.xz
dexon-0x-contracts-8162394797342cef268cc8072fc860326974e269.tar.zst
dexon-0x-contracts-8162394797342cef268cc8072fc860326974e269.zip
Merge branch 'development'
* development: (175 commits) small README fixes Update docs list in README Add manual postpublish command to all public packages and update CHANGELOG.json Fix postpublish util to ignore namespace Fix release notes bug Should print out `lerna publish` stdout so we can see if anything went wrong Publish Updated CHANGELOGS Generate CHANGELOG.json files Fix hasty find/replace Default to 4sp Update moment, no longer need separate moment types Move prettify command to utils and also call it on CHANGELOG.md Add prettier run on generated CHANGELOG.json and fix scripts Remove semi-colons from monorepo-scripts package.json Get rid of ; in top-level package.json Fix TSLint error Make dry-run configurable from top-level package.json Improve naming Run prettier, update deployer CHANGELOG ...
Diffstat (limited to 'packages/react-docs/src/utils')
-rw-r--r--packages/react-docs/src/utils/doxity_utils.ts1
-rw-r--r--packages/react-docs/src/utils/typedoc_utils.ts71
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,