From 9b28ae14fb06044a03da494db9b826bfdd5b3fed Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Tue, 26 Apr 2022 21:35:19 -0500 Subject: [PATCH] Throw when file count is off --- build-lists.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/build-lists.js b/build-lists.js index c298bba..196af81 100644 --- a/build-lists.js +++ b/build-lists.js @@ -241,7 +241,10 @@ class BuildLists { return } - saveApiEndpoints = async function ( listOptions ) { + saveApiEndpoints = async ( listOptions ) => { + + const apiDirectory = './static/api' + const apiListDirectory = `${ apiDirectory }/${ listOptions.endpointPrefix }` const poolSize = 1000 @@ -265,7 +268,7 @@ class BuildLists { } = listEntry - const endpointPath = `./static/api${endpoint}.json` + const endpointPath = `${ apiDirectory }${ endpoint }.json` const endpointDirectory = dirname(endpointPath) // Add related videos @@ -297,6 +300,15 @@ class BuildLists { throw new Error( errors ) } + // Count saved files + const fileCount = fs.readdirSync( apiListDirectory ).length + + console.log( fileCount, 'Files saved in', apiListDirectory ) + console.log( this.lists[listOptions.name].size, 'Entries' ) + + if ( fileCount !== this.lists[listOptions.name].size ) { + throw new Error( `Files don\'t match list count in ${ apiListDirectory }` ) + } } // Save app lists to JSON