Render external dep exports

This commit is contained in:
Fabio Berger
2018-08-16 14:57:45 -07:00
parent bf9ee82d9f
commit 8e3df2b5ae
5 changed files with 50 additions and 6 deletions

View File

@@ -221,7 +221,7 @@ export async function generateAndUploadDocsAsync(packageName: string, isStaging:
); );
} }
const externalExportsToLink: { [externalExport: string]: string } = {}; const externalExportToLink: { [externalExport: string]: string } = {};
const externalExportsWithoutLinks: string[] = []; const externalExportsWithoutLinks: string[] = [];
_.each(externalExports, externalExport => { _.each(externalExports, externalExport => {
const linkIfExists = EXTERNAL_EXPORT_TO_LINK[externalExport]; const linkIfExists = EXTERNAL_EXPORT_TO_LINK[externalExport];
@@ -229,7 +229,7 @@ export async function generateAndUploadDocsAsync(packageName: string, isStaging:
externalExportsWithoutLinks.push(externalExport); externalExportsWithoutLinks.push(externalExport);
return; return;
} }
externalExportsToLink[externalExport] = linkIfExists; externalExportToLink[externalExport] = linkIfExists;
}); });
if (!_.isEmpty(externalExportsWithoutLinks)) { if (!_.isEmpty(externalExportsWithoutLinks)) {
throw new Error( throw new Error(
@@ -246,7 +246,7 @@ export async function generateAndUploadDocsAsync(packageName: string, isStaging:
exportPathToTypedocNames, exportPathToTypedocNames,
exportPathOrder, exportPathOrder,
externalTypeToLink: EXTERNAL_TYPE_TO_LINK, externalTypeToLink: EXTERNAL_TYPE_TO_LINK,
externalExportsToLink, externalExportToLink,
}, },
typedocJson: finalTypeDocOutput, typedocJson: finalTypeDocOutput,
}; };

View File

@@ -19,6 +19,7 @@ import {
AddressByContractName, AddressByContractName,
DocAgnosticFormat, DocAgnosticFormat,
Event, Event,
ExternalExportToLink,
Property, Property,
SolidityMethod, SolidityMethod,
SupportedDocJson, SupportedDocJson,
@@ -26,6 +27,7 @@ import {
TypescriptFunction, TypescriptFunction,
TypescriptMethod, TypescriptMethod,
} from '../types'; } from '../types';
import { constants } from '../utils/constants';
import { Badge } from './badge'; import { Badge } from './badge';
import { Comment } from './comment'; import { Comment } from './comment';
@@ -300,6 +302,8 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
<div>{eventDefs}</div> <div>{eventDefs}</div>
</div> </div>
)} )}
{!_.isUndefined(docSection.externalExportToLink) &&
this._renderExternalExports(docSection.externalExportToLink)}
{!_.isUndefined(typeDefs) && {!_.isUndefined(typeDefs) &&
typeDefs.length > 0 && ( typeDefs.length > 0 && (
<div> <div>
@@ -309,6 +313,22 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
</div> </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 { private _renderNetworkBadgesIfExists(sectionName: string): React.ReactNode {
if (this.props.docsInfo.type !== SupportedDocJson.Doxity) { if (this.props.docsInfo.type !== SupportedDocJson.Doxity) {
return null; return null;

View File

@@ -105,8 +105,9 @@ export interface DocSection {
methods: Array<TypescriptMethod | SolidityMethod>; methods: Array<TypescriptMethod | SolidityMethod>;
properties: Property[]; properties: Property[];
types: CustomType[]; types: CustomType[];
functions?: TypescriptFunction[]; functions: TypescriptFunction[];
events?: Event[]; events?: Event[];
externalExportToLink?: ExternalExportToLink;
} }
export interface TypescriptMethod extends BaseMethod { export interface TypescriptMethod extends BaseMethod {
@@ -296,10 +297,15 @@ export interface ExternalTypeToLink {
[externalTypeName: string]: string; [externalTypeName: string]: string;
} }
export interface ExternalExportToLink {
[externalExport: string]: string;
}
export interface Metadata { export interface Metadata {
exportPathToTypedocNames: ExportNameToTypedocNames; exportPathToTypedocNames: ExportNameToTypedocNames;
exportPathOrder: string[]; exportPathOrder: string[];
externalTypeToLink: ExternalTypeToLink; externalTypeToLink: ExternalTypeToLink;
externalExportToLink: ExternalExportToLink;
} }
export interface GeneratedDocJson { export interface GeneratedDocJson {

View File

@@ -2,6 +2,7 @@ import { SupportedDocJson } from '../types';
export const constants = { export const constants = {
TYPES_SECTION_NAME: 'types', TYPES_SECTION_NAME: 'types',
EXTERNAL_EXPORTS_SECTION_NAME: 'externalExports',
TYPE_TO_SYNTAX: { TYPE_TO_SYNTAX: {
[SupportedDocJson.Doxity]: 'solidity', [SupportedDocJson.Doxity]: 'solidity',
[SupportedDocJson.TypeDoc]: 'typescript', [SupportedDocJson.TypeDoc]: 'typescript',

View File

@@ -7,13 +7,13 @@ import {
CustomTypeChild, CustomTypeChild,
DocAgnosticFormat, DocAgnosticFormat,
DocSection, DocSection,
ExternalExportToLink,
ExternalTypeToLink, ExternalTypeToLink,
GeneratedDocJson, GeneratedDocJson,
IndexSignature, IndexSignature,
KindString, KindString,
Parameter, Parameter,
Property, Property,
SectionsMap,
Type, Type,
TypeDocNode, TypeDocNode,
TypeDocType, TypeDocType,
@@ -28,6 +28,7 @@ import { constants } from './constants';
export class TypeDocUtils { export class TypeDocUtils {
private _typeDocNameOrder: string[]; private _typeDocNameOrder: string[];
private _externalTypeToLink: ExternalTypeToLink; private _externalTypeToLink: ExternalTypeToLink;
private _externalExportToLink: ExternalExportToLink;
private _docsInfo: DocsInfo; private _docsInfo: DocsInfo;
private _typeDocJson: TypeDocNode; private _typeDocJson: TypeDocNode;
private _classNames: string[]; private _classNames: string[];
@@ -36,6 +37,7 @@ export class TypeDocUtils {
const exportPathOrder = generatedDocJson.metadata.exportPathOrder; const exportPathOrder = generatedDocJson.metadata.exportPathOrder;
const exportPathToTypedocNames = generatedDocJson.metadata.exportPathToTypedocNames; const exportPathToTypedocNames = generatedDocJson.metadata.exportPathToTypedocNames;
this._externalTypeToLink = generatedDocJson.metadata.externalTypeToLink; this._externalTypeToLink = generatedDocJson.metadata.externalTypeToLink;
this._externalExportToLink = generatedDocJson.metadata.externalExportToLink;
this._typeDocJson = generatedDocJson.typedocJson; this._typeDocJson = generatedDocJson.typedocJson;
// TODO: Extract the non typeDoc exports, and render them somehow // TODO: Extract the non typeDoc exports, and render them somehow
@@ -88,6 +90,22 @@ export class TypeDocUtils {
} }
public convertToDocAgnosticFormat(): DocAgnosticFormat { public convertToDocAgnosticFormat(): DocAgnosticFormat {
const docAgnosticFormat: 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[] = []; const typeEntities: TypeDocNode[] = [];
_.each(this._typeDocNameOrder, typeDocName => { _.each(this._typeDocNameOrder, typeDocName => {
const fileChildIndex = _.findIndex(this._typeDocJson.children, child => child.name === typeDocName); const fileChildIndex = _.findIndex(this._typeDocJson.children, child => child.name === typeDocName);
@@ -458,7 +476,6 @@ export class TypeDocUtils {
method: methodIfExists, method: methodIfExists,
indexSignature: indexSignatureIfExists, indexSignature: indexSignatureIfExists,
}; };
console.log('this._externalTypeToLink', this._externalTypeToLink);
const externalLinkIfExists = this._externalTypeToLink[entity.name]; const externalLinkIfExists = this._externalTypeToLink[entity.name];
if (!_.isUndefined(externalLinkIfExists)) { if (!_.isUndefined(externalLinkIfExists)) {
type.externalLink = externalLinkIfExists; type.externalLink = externalLinkIfExists;