diff --git a/scripts/update-registry/shared/updateRegistry.ts b/scripts/update-registry/shared/updateRegistry.ts index 90809f7f2..0a989e5c5 100644 --- a/scripts/update-registry/shared/updateRegistry.ts +++ b/scripts/update-registry/shared/updateRegistry.ts @@ -37,7 +37,6 @@ export const registryUpdate = (missingTypesAsDescribeResult: DescribeEntry[]) => registry.suffixes[suffix] = typeId; } }); - console.log('Updated registry with new types:'); const jsonData = JSON.stringify(registry, null, 2); fs.writeFileSync('./src/registry/metadataRegistry.json', jsonData); }; diff --git a/scripts/update-registry/updateRegistryFromCoreMetadata.ts b/scripts/update-registry/updateRegistryFromCoreMetadata.ts index c9020102b..ae77dbe34 100644 --- a/scripts/update-registry/updateRegistryFromCoreMetadata.ts +++ b/scripts/update-registry/updateRegistryFromCoreMetadata.ts @@ -22,8 +22,9 @@ const getMissingTypesFromDescribe = async (missingTypes: string[]): Promise (typeName: string): DescribeEntry | undefined => { - if (describe[typeName]) { - return describe[typeName]; + const [, found] = Object.entries(describe).find(([key]) => key.toLowerCase() === typeName.toLowerCase()) ?? []; + if (found !== undefined) { + return found; } console.warn(`No entry for ${typeName}`); }; @@ -31,6 +32,9 @@ const logMissingEntry = (async () => { const missingTypes = await whatTypesNeedDescribe(); const missingTypesAsDescribeEntry = await getMissingTypesFromDescribe(missingTypes); - console.log(missingTypesAsDescribeEntry); + (missingTypesAsDescribeEntry.length + ? [`Updating types in the registry`, missingTypesAsDescribeEntry] + : ['No metadata changes made'] + ).map((i) => console.log(i)); registryUpdate(missingTypesAsDescribeEntry); })(); diff --git a/scripts/update-registry/updateRegistryFromOrg.ts b/scripts/update-registry/updateRegistryFromOrg.ts index 1bb3f1019..0a65830aa 100644 --- a/scripts/update-registry/updateRegistryFromOrg.ts +++ b/scripts/update-registry/updateRegistryFromOrg.ts @@ -9,12 +9,12 @@ const getMissingTypesAsDescribeResult = async (missingTypes: string[]): Promise< const describeResult = await execProm('sf org list metadata-types -o registryBuilder --json'); const metadataObjectsByName = new Map( (JSON.parse(describeResult.stdout).result.metadataObjects as DescribeResult[]).map((describeObj) => [ - describeObj.xmlName, + describeObj.xmlName.toLowerCase(), describeObj, ]) ); // get the missingTypes from the describe - return missingTypes.map((key) => metadataObjectsByName.get(key)).filter(isDefined); + return missingTypes.map(lowercaseFn).map(getOrWarn(metadataObjectsByName)).filter(isDefined); }; /** massage for slight differences between the 2 types */ @@ -33,6 +33,18 @@ const describeResultToDescribeEntry = (describeResult: DescribeResult): Describe const missingTypes = await whatTypesNeedDescribe(); const missingTypesAsDescribeResult = await getMissingTypesAsDescribeResult(missingTypes); - console.log(missingTypesAsDescribeResult); registryUpdate(missingTypesAsDescribeResult.map(describeResultToDescribeEntry)); })(); + +const lowercaseFn = (s: string) => s.toLowerCase(); + +const getOrWarn = + (map: Map) => + (key: string): T | undefined => { + const result = map.get(key); + if (result === undefined) { + console.warn(`No entry for ${key}`); + return; + } + return result; + };