aboutsummaryrefslogtreecommitdiffstats
path: root/packages/react-docs/src/docs_info.ts
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-03-16 00:57:27 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-03-16 00:57:27 +0800
commit76029cbf0915df36266bd5e51add07755297ddda (patch)
treee1692f8cc4ea4642292c61f65ba3911ded26de8e /packages/react-docs/src/docs_info.ts
parentb9c1653c1cf6984d56b7825d8747b48d797fa39e (diff)
parent4a27a7dc581fc6c8a3d4e212ca3712c249a5b417 (diff)
downloaddexon-0x-contracts-76029cbf0915df36266bd5e51add07755297ddda.tar
dexon-0x-contracts-76029cbf0915df36266bd5e51add07755297ddda.tar.gz
dexon-0x-contracts-76029cbf0915df36266bd5e51add07755297ddda.tar.bz2
dexon-0x-contracts-76029cbf0915df36266bd5e51add07755297ddda.tar.lz
dexon-0x-contracts-76029cbf0915df36266bd5e51add07755297ddda.tar.xz
dexon-0x-contracts-76029cbf0915df36266bd5e51add07755297ddda.tar.zst
dexon-0x-contracts-76029cbf0915df36266bd5e51add07755297ddda.zip
Merge branch 'development' into feature/sra-report/collection-tests
* development: (97 commits) Keep console.log in monorepo-scripts Enable coverage for all other packages with tests Fix parallel coverage results reporting Fix linter issuesx Remove outdated comment Add script copying to build command Add postpublish script to sol-cov Move configuration into package.json configs section Transform input data before encoding for callAsync and getABIEncodedTransactionData Update CHANGELOGs Consolidate all console.log into the @0xproject/utils package Update coverage badge to show development coverage Configure post build hook Notify coveralls after all tasks have finished Address feedback Revert "Report all coverage reports together" Separate published packages and typescript typings on README Consolidate docs generation and uploading logic Use async/await instead of promise syntax Move changelog entry ...
Diffstat (limited to 'packages/react-docs/src/docs_info.ts')
-rw-r--r--packages/react-docs/src/docs_info.ts123
1 files changed, 123 insertions, 0 deletions
diff --git a/packages/react-docs/src/docs_info.ts b/packages/react-docs/src/docs_info.ts
new file mode 100644
index 000000000..68bddef06
--- /dev/null
+++ b/packages/react-docs/src/docs_info.ts
@@ -0,0 +1,123 @@
+import { MenuSubsectionsBySection } from '@0xproject/react-shared';
+import compareVersions = require('compare-versions');
+import * as _ from 'lodash';
+
+import {
+ ContractsByVersionByNetworkId,
+ DocAgnosticFormat,
+ DocsInfoConfig,
+ DocsInfoTypeConfigs,
+ DocsMenu,
+ DoxityDocObj,
+ SectionsMap,
+ SupportedDocJson,
+ TypeDocNode,
+} from './types';
+import { doxityUtils } from './utils/doxity_utils';
+import { typeDocUtils } from './utils/typedoc_utils';
+
+export class DocsInfo {
+ public id: string;
+ public type: SupportedDocJson;
+ public displayName: string;
+ public packageUrl: string;
+ public menu: DocsMenu;
+ public sections: SectionsMap;
+ public sectionNameToMarkdown: { [sectionName: string]: string };
+ public contractsByVersionByNetworkId?: ContractsByVersionByNetworkId;
+ public typeConfigs: DocsInfoTypeConfigs;
+ private _docsInfo: DocsInfoConfig;
+ constructor(config: DocsInfoConfig) {
+ this.id = config.id;
+ this.type = config.type;
+ this.displayName = config.displayName;
+ this.packageUrl = config.packageUrl;
+ this.sections = config.sections;
+ this.sectionNameToMarkdown = config.sectionNameToMarkdown;
+ this.contractsByVersionByNetworkId = config.contractsByVersionByNetworkId;
+ this.typeConfigs = config.typeConfigs;
+ this._docsInfo = config;
+ }
+ public isPublicType(typeName: string): boolean {
+ if (_.isUndefined(this._docsInfo.typeConfigs.publicTypes)) {
+ return false;
+ }
+ const isPublic = _.includes(this._docsInfo.typeConfigs.publicTypes, typeName);
+ return isPublic;
+ }
+ public getModulePathsIfExists(sectionName: string): string[] {
+ const modulePathsIfExists = this._docsInfo.sectionNameToModulePath[sectionName];
+ return modulePathsIfExists;
+ }
+ public getMenu(selectedVersion?: string): { [section: string]: string[] } {
+ if (_.isUndefined(selectedVersion) || _.isUndefined(this._docsInfo.menuSubsectionToVersionWhenIntroduced)) {
+ return this._docsInfo.menu;
+ }
+
+ const finalMenu = _.cloneDeep(this._docsInfo.menu);
+ if (_.isUndefined(finalMenu.contracts)) {
+ return finalMenu;
+ }
+
+ // TODO: refactor to include more sections then simply the `contracts` section
+ finalMenu.contracts = _.filter(finalMenu.contracts, (contractName: string) => {
+ const versionIntroducedIfExists = this._docsInfo.menuSubsectionToVersionWhenIntroduced[contractName];
+ if (!_.isUndefined(versionIntroducedIfExists)) {
+ const existsInSelectedVersion = compareVersions(selectedVersion, versionIntroducedIfExists) >= 0;
+ return existsInSelectedVersion;
+ } else {
+ return true;
+ }
+ });
+ return finalMenu;
+ }
+ public getMenuSubsectionsBySection(docAgnosticFormat?: DocAgnosticFormat): MenuSubsectionsBySection {
+ const menuSubsectionsBySection = {} as MenuSubsectionsBySection;
+ if (_.isUndefined(docAgnosticFormat)) {
+ return menuSubsectionsBySection;
+ }
+
+ const docSections = _.keys(this.sections);
+ _.each(docSections, sectionName => {
+ const docSection = docAgnosticFormat[sectionName];
+ if (_.isUndefined(docSection)) {
+ return; // no-op
+ }
+
+ if (!_.isUndefined(this.sections.types) && sectionName === this.sections.types) {
+ const sortedTypesNames = _.sortBy(docSection.types, 'name');
+ const typeNames = _.map(sortedTypesNames, t => t.name);
+ menuSubsectionsBySection[sectionName] = typeNames;
+ } else {
+ let eventNames: string[] = [];
+ if (!_.isUndefined(docSection.events)) {
+ const sortedEventNames = _.sortBy(docSection.events, 'name');
+ eventNames = _.map(sortedEventNames, m => m.name);
+ }
+ const sortedMethodNames = _.sortBy(docSection.methods, 'name');
+ const methodNames = _.map(sortedMethodNames, m => m.name);
+ menuSubsectionsBySection[sectionName] = [...methodNames, ...eventNames];
+ }
+ });
+ return menuSubsectionsBySection;
+ }
+ public getTypeDefinitionsByName(docAgnosticFormat: DocAgnosticFormat) {
+ if (_.isUndefined(this.sections.types)) {
+ return {};
+ }
+
+ const typeDocSection = docAgnosticFormat[this.sections.types];
+ const typeDefinitionByName = _.keyBy(typeDocSection.types, 'name');
+ return typeDefinitionByName;
+ }
+ public isVisibleConstructor(sectionName: string): boolean {
+ return _.includes(this._docsInfo.visibleConstructors, sectionName);
+ }
+ public convertToDocAgnosticFormat(docObj: DoxityDocObj | TypeDocNode): DocAgnosticFormat {
+ if (this.type === SupportedDocJson.Doxity) {
+ return doxityUtils.convertToDocAgnosticFormat(docObj as DoxityDocObj);
+ } else {
+ return typeDocUtils.convertToDocAgnosticFormat(docObj as TypeDocNode, this);
+ }
+ }
+}