diff --git a/build-lists.js b/build-lists.js index 2ab4a15..128a439 100644 --- a/build-lists.js +++ b/build-lists.js @@ -16,6 +16,7 @@ import buildDeviceList from '~/helpers/build-device-list.js' import { saveSitemap } from '~/helpers/api/sitemap/build.js' import { deviceSupportsApp } from '~/helpers/devices.js' import getListSummaryNumbers from '~/helpers/get-list-summary-numbers.js' +import { logArraysDifference } from '~/helpers/arrays.js' import { getRelatedVideos @@ -55,12 +56,7 @@ dotenv.config() let timeRunGetListArray = 0 let timeRunGetListByCategories = 0 -function getSymmetricDifference (a, b) { - return [ - a.filter(x => !b.includes(x)), - b.filter(x => !a.includes(x)) - ] -} + function normalizeVersion ( rawVersion ) { const containsNumbers = /\d+/.test( rawVersion ) @@ -528,10 +524,8 @@ class BuildLists { if ( fileCount !== this.lists[listOptions.name].size ) { const listSlugs = Array.from( this.lists[listOptions.name] ).map( listEntry => listEntry.slug ) const fileNames = fs.readdirSync( apiListDirectory ).map( fileName => basename(fileName).split('.')[0] ) - const difference = getSymmetricDifference( listSlugs, fileNames ) - console.log( 'List difference', difference ) - console.log( `List difference Count ${ difference[0].length } / ${ difference[1].length }`, ) + logArraysDifference( listSlugs, fileNames ) throw new Error( `Files (${ fileCount }) don\'t match list count in ${ apiListDirectory }(${ this.lists[listOptions.name].size }).` ) } diff --git a/helpers/array.js b/helpers/array.js new file mode 100644 index 0000000..3ae2e52 --- /dev/null +++ b/helpers/array.js @@ -0,0 +1,21 @@ +export function getSymmetricDifference (a, b) { + return [ + a.filter(x => !b.includes(x)), + b.filter(x => !a.includes(x)) + ] +} + +export function logArraysDifference (a, b) { + const [ aOnly, bOnly ] = getSymmetricDifference(a, b) + + + console.log( 'Missing from first list:', aOnly ) + console.log( 'Missing from second list:', bOnly ) + + console.log( `List difference Count ${ aOnly.length } / ${ bOnly.length }`, ) + + return { + aOnly, + bOnly, + } +}