diff options
author | Fabio Berger <me@fabioberger.com> | 2018-08-01 23:36:37 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-08-01 23:36:37 +0800 |
commit | 3bdf6004ca74dd9eb380aa61cf9e69c47725116a (patch) | |
tree | 02065e5e202fdf959aa90c44eaeb25cf838540dd /packages/react-docs/src/docs_info.ts | |
parent | 11869122b4fe00c834347f9911985d7b2572bc9b (diff) | |
download | dexon-sol-tools-3bdf6004ca74dd9eb380aa61cf9e69c47725116a.tar.gz dexon-sol-tools-3bdf6004ca74dd9eb380aa61cf9e69c47725116a.tar.zst dexon-sol-tools-3bdf6004ca74dd9eb380aa61cf9e69c47725116a.zip |
Start refactoring docs to remove unnecessary configs given more concise TypeDoc JSON
Diffstat (limited to 'packages/react-docs/src/docs_info.ts')
-rw-r--r-- | packages/react-docs/src/docs_info.ts | 56 |
1 files changed, 15 insertions, 41 deletions
diff --git a/packages/react-docs/src/docs_info.ts b/packages/react-docs/src/docs_info.ts index b37942da6..dd3cb9a96 100644 --- a/packages/react-docs/src/docs_info.ts +++ b/packages/react-docs/src/docs_info.ts @@ -13,7 +13,7 @@ import { SectionsMap, SupportedDocJson, TypeDefinitionByName, - TypeDocNode, + GeneratedDocJson, } from './types'; import { doxityUtils } from './utils/doxity_utils'; import { typeDocUtils } from './utils/typedoc_utils'; @@ -32,6 +32,7 @@ export class DocsInfo { constructor(config: DocsInfoConfig) { this.id = config.id; this.type = config.type; + this.menu = config.menu; this.displayName = config.displayName; this.packageUrl = config.packageUrl; this.sections = config.sections; @@ -40,38 +41,8 @@ export class DocsInfo { 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 doesExistInSelectedVersion = compareVersions(selectedVersion, versionIntroducedIfExists) >= 0; - return doesExistInSelectedVersion; - } else { - return true; - } - }); - return finalMenu; + return this._docsInfo.menu; } public getMenuSubsectionsBySection(docAgnosticFormat?: DocAgnosticFormat): MenuSubsectionsBySection { const menuSubsectionsBySection = {} as MenuSubsectionsBySection; @@ -96,12 +67,18 @@ export class DocsInfo { 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]; + const propertiesSortedByName = _.sortBy(docSection.properties, 'name'); + const propertyNames = _.map(propertiesSortedByName, m => m.name); + const methodsSortedByName = _.sortBy(docSection.methods, 'name'); + const methodNames = _.map(methodsSortedByName, m => m.name); const sortedFunctionNames = _.sortBy(docSection.functions, 'name'); const functionNames = _.map(sortedFunctionNames, m => m.name); - menuSubsectionsBySection[sectionName] = [...eventNames, ...functionNames, ...methodNames]; + menuSubsectionsBySection[sectionName] = [ + ...eventNames, + ...propertyNames, + ...functionNames, + ...methodNames, + ]; } }); return menuSubsectionsBySection; @@ -115,14 +92,11 @@ export class DocsInfo { const typeDefinitionByName = _.keyBy(typeDocSection.types, 'name') as any; return typeDefinitionByName; } - public isVisibleConstructor(sectionName: string): boolean { - return _.includes(this._docsInfo.visibleConstructors, sectionName); - } - public convertToDocAgnosticFormat(docObj: DoxityDocObj | TypeDocNode): DocAgnosticFormat { + public convertToDocAgnosticFormat(docObj: DoxityDocObj | GeneratedDocJson): DocAgnosticFormat { if (this.type === SupportedDocJson.Doxity) { return doxityUtils.convertToDocAgnosticFormat(docObj as DoxityDocObj); } else { - return typeDocUtils.convertToDocAgnosticFormat(docObj as TypeDocNode, this); + return typeDocUtils.convertToDocAgnosticFormat(docObj as GeneratedDocJson, this); } } } |