diff options
author | Fabio Berger <me@fabioberger.com> | 2018-08-16 07:50:23 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-08-16 07:50:23 +0800 |
commit | baab0f27b543f8f17bad0e3a40b803763236edb9 (patch) | |
tree | 2aa92c6c8ef0c979950041e01746c76b9840bba0 /packages/monorepo-scripts | |
parent | 9e7657ac5db596ff8dacf1c37784be2e9e7f87a6 (diff) | |
download | dexon-0x-contracts-baab0f27b543f8f17bad0e3a40b803763236edb9.tar dexon-0x-contracts-baab0f27b543f8f17bad0e3a40b803763236edb9.tar.gz dexon-0x-contracts-baab0f27b543f8f17bad0e3a40b803763236edb9.tar.bz2 dexon-0x-contracts-baab0f27b543f8f17bad0e3a40b803763236edb9.tar.lz dexon-0x-contracts-baab0f27b543f8f17bad0e3a40b803763236edb9.tar.xz dexon-0x-contracts-baab0f27b543f8f17bad0e3a40b803763236edb9.tar.zst dexon-0x-contracts-baab0f27b543f8f17bad0e3a40b803763236edb9.zip |
Check for superfluous types in a packages index.ts and throw if they exist
Diffstat (limited to 'packages/monorepo-scripts')
-rw-r--r-- | packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts b/packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts index b51b17db1..b236c299f 100644 --- a/packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts +++ b/packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts @@ -185,6 +185,16 @@ export async function generateAndUploadDocsAsync(packageName: string, isStaging: const referenceNamesWithDuplicates = getAllReferenceNames(propertyName, finalTypeDocOutput, []); const referenceNames = _.uniq(referenceNamesWithDuplicates); + const exportedTypes = getAllTypeNames(finalTypeDocOutput, []); + const excessiveReferences = _.difference(exportedTypes, referenceNames); + if (!_.isEmpty(excessiveReferences)) { + throw new Error( + `${packageName} package exports BUT does not need: \n${excessiveReferences.join( + '\n', + )} \nin it\'s index.ts. Remove them then try again.`, + ); + } + const missingReferences: string[] = []; _.each(referenceNames, referenceName => { if (!_.includes(allExportedItems, referenceName) && _.isUndefined(EXTERNAL_TYPE_TO_LINK[referenceName])) { @@ -230,6 +240,27 @@ export async function generateAndUploadDocsAsync(packageName: string, isStaging: }); } +function getAllTypeNames(node: any, typeNames: string[]): string[] { + if (!_.isObject(node)) { + return typeNames; + } + const typeKindStrings = ['Interface', 'Enumeration', 'Type alias']; + if (_.includes(typeKindStrings, node.kindString)) { + return [...typeNames, node.name]; + } + let updatedTypeNames = typeNames; + _.each(node, nodeValue => { + if (_.isArray(nodeValue)) { + _.each(nodeValue, aNode => { + updatedTypeNames = getAllTypeNames(aNode, updatedTypeNames); + }); + } else if (_.isObject(nodeValue)) { + updatedTypeNames = getAllTypeNames(nodeValue, updatedTypeNames); + } + }); + return updatedTypeNames; +} + function getAllReferenceNames(propertyName: string, node: any, referenceNames: string[]): string[] { let updatedReferenceNames = referenceNames; if (!_.isObject(node)) { |