aboutsummaryrefslogtreecommitdiffstats
path: root/packages/react-docs
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-08-17 05:57:45 +0800
committerFabio Berger <me@fabioberger.com>2018-08-17 05:57:45 +0800
commit8e3df2b5aeac9d6776640be1248863055c75cf4a (patch)
tree97fd70a5f9b821334f0590b63557b6bac39924a5 /packages/react-docs
parentbf9ee82d9f4a2fec392f0ee58342fc6b3be94dff (diff)
downloaddexon-sol-tools-8e3df2b5aeac9d6776640be1248863055c75cf4a.tar
dexon-sol-tools-8e3df2b5aeac9d6776640be1248863055c75cf4a.tar.gz
dexon-sol-tools-8e3df2b5aeac9d6776640be1248863055c75cf4a.tar.bz2
dexon-sol-tools-8e3df2b5aeac9d6776640be1248863055c75cf4a.tar.lz
dexon-sol-tools-8e3df2b5aeac9d6776640be1248863055c75cf4a.tar.xz
dexon-sol-tools-8e3df2b5aeac9d6776640be1248863055c75cf4a.tar.zst
dexon-sol-tools-8e3df2b5aeac9d6776640be1248863055c75cf4a.zip
Render external dep exports
Diffstat (limited to 'packages/react-docs')
-rw-r--r--packages/react-docs/src/components/documentation.tsx20
-rw-r--r--packages/react-docs/src/types.ts8
-rw-r--r--packages/react-docs/src/utils/constants.ts1
-rw-r--r--packages/react-docs/src/utils/typedoc_utils.ts21
4 files changed, 47 insertions, 3 deletions
diff --git a/packages/react-docs/src/components/documentation.tsx b/packages/react-docs/src/components/documentation.tsx
index 82e444018..43a1f746e 100644
--- a/packages/react-docs/src/components/documentation.tsx
+++ b/packages/react-docs/src/components/documentation.tsx
@@ -19,6 +19,7 @@ import {
AddressByContractName,
DocAgnosticFormat,
Event,
+ ExternalExportToLink,
Property,
SolidityMethod,
SupportedDocJson,
@@ -26,6 +27,7 @@ import {
TypescriptFunction,
TypescriptMethod,
} from '../types';
+import { constants } from '../utils/constants';
import { Badge } from './badge';
import { Comment } from './comment';
@@ -300,6 +302,8 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
<div>{eventDefs}</div>
</div>
)}
+ {!_.isUndefined(docSection.externalExportToLink) &&
+ this._renderExternalExports(docSection.externalExportToLink)}
{!_.isUndefined(typeDefs) &&
typeDefs.length > 0 && (
<div>
@@ -309,6 +313,22 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
</div>
);
}
+ private _renderExternalExports(externalExportToLink: ExternalExportToLink): React.ReactNode {
+ const externalExports = _.map(externalExportToLink, (link: string, exportName: string) => {
+ return (
+ <div className="pt2">
+ <code className={`hljs ${constants.TYPE_TO_SYNTAX[this.props.docsInfo.type]}`}>
+ {`import { `}
+ <a href={link} target="_blank" style={{ color: colors.lightBlueA700, textDecoration: 'none' }}>
+ {exportName}
+ </a>
+ {` } from '${this.props.docsInfo.displayName}'`}
+ </code>
+ </div>
+ );
+ });
+ return <div>{externalExports}</div>;
+ }
private _renderNetworkBadgesIfExists(sectionName: string): React.ReactNode {
if (this.props.docsInfo.type !== SupportedDocJson.Doxity) {
return null;
diff --git a/packages/react-docs/src/types.ts b/packages/react-docs/src/types.ts
index 0155685e0..8352af876 100644
--- a/packages/react-docs/src/types.ts
+++ b/packages/react-docs/src/types.ts
@@ -105,8 +105,9 @@ export interface DocSection {
methods: Array<TypescriptMethod | SolidityMethod>;
properties: Property[];
types: CustomType[];
- functions?: TypescriptFunction[];
+ functions: TypescriptFunction[];
events?: Event[];
+ externalExportToLink?: ExternalExportToLink;
}
export interface TypescriptMethod extends BaseMethod {
@@ -296,10 +297,15 @@ export interface ExternalTypeToLink {
[externalTypeName: string]: string;
}
+export interface ExternalExportToLink {
+ [externalExport: string]: string;
+}
+
export interface Metadata {
exportPathToTypedocNames: ExportNameToTypedocNames;
exportPathOrder: string[];
externalTypeToLink: ExternalTypeToLink;
+ externalExportToLink: ExternalExportToLink;
}
export interface GeneratedDocJson {
diff --git a/packages/react-docs/src/utils/constants.ts b/packages/react-docs/src/utils/constants.ts
index c3c74fd11..97bedf2db 100644
--- a/packages/react-docs/src/utils/constants.ts
+++ b/packages/react-docs/src/utils/constants.ts
@@ -2,6 +2,7 @@ import { SupportedDocJson } from '../types';
export const constants = {
TYPES_SECTION_NAME: 'types',
+ EXTERNAL_EXPORTS_SECTION_NAME: 'externalExports',
TYPE_TO_SYNTAX: {
[SupportedDocJson.Doxity]: 'solidity',
[SupportedDocJson.TypeDoc]: 'typescript',
diff --git a/packages/react-docs/src/utils/typedoc_utils.ts b/packages/react-docs/src/utils/typedoc_utils.ts
index e10493673..989485dfc 100644
--- a/packages/react-docs/src/utils/typedoc_utils.ts
+++ b/packages/react-docs/src/utils/typedoc_utils.ts
@@ -7,13 +7,13 @@ import {
CustomTypeChild,
DocAgnosticFormat,
DocSection,
+ ExternalExportToLink,
ExternalTypeToLink,
GeneratedDocJson,
IndexSignature,
KindString,
Parameter,
Property,
- SectionsMap,
Type,
TypeDocNode,
TypeDocType,
@@ -28,6 +28,7 @@ import { constants } from './constants';
export class TypeDocUtils {
private _typeDocNameOrder: string[];
private _externalTypeToLink: ExternalTypeToLink;
+ private _externalExportToLink: ExternalExportToLink;
private _docsInfo: DocsInfo;
private _typeDocJson: TypeDocNode;
private _classNames: string[];
@@ -36,6 +37,7 @@ export class TypeDocUtils {
const exportPathOrder = generatedDocJson.metadata.exportPathOrder;
const exportPathToTypedocNames = generatedDocJson.metadata.exportPathToTypedocNames;
this._externalTypeToLink = generatedDocJson.metadata.externalTypeToLink;
+ this._externalExportToLink = generatedDocJson.metadata.externalExportToLink;
this._typeDocJson = generatedDocJson.typedocJson;
// TODO: Extract the non typeDoc exports, and render them somehow
@@ -88,6 +90,22 @@ export class TypeDocUtils {
}
public convertToDocAgnosticFormat(): DocAgnosticFormat {
const docAgnosticFormat: DocAgnosticFormat = {};
+
+ if (!_.isEmpty(this._externalExportToLink)) {
+ this._docsInfo.sections[constants.EXTERNAL_EXPORTS_SECTION_NAME] = constants.EXTERNAL_EXPORTS_SECTION_NAME;
+ this._docsInfo.menu[constants.EXTERNAL_EXPORTS_SECTION_NAME] = [constants.EXTERNAL_EXPORTS_SECTION_NAME];
+ const docSection: DocSection = {
+ comment: 'This package also re-exports some third-party libraries for your convenience.',
+ constructors: [],
+ methods: [],
+ functions: [],
+ properties: [],
+ types: [],
+ externalExportToLink: this._externalExportToLink,
+ };
+ docAgnosticFormat[constants.EXTERNAL_EXPORTS_SECTION_NAME] = docSection;
+ }
+
const typeEntities: TypeDocNode[] = [];
_.each(this._typeDocNameOrder, typeDocName => {
const fileChildIndex = _.findIndex(this._typeDocJson.children, child => child.name === typeDocName);
@@ -458,7 +476,6 @@ export class TypeDocUtils {
method: methodIfExists,
indexSignature: indexSignatureIfExists,
};
- console.log('this._externalTypeToLink', this._externalTypeToLink);
const externalLinkIfExists = this._externalTypeToLink[entity.name];
if (!_.isUndefined(externalLinkIfExists)) {
type.externalLink = externalLinkIfExists;