fix(build): prune stale generated api endpoints

Clean list-specific JSON endpoint directories before rewriting them so local and deploy-style API builds do not fail on leftover files from older runs.

Keep the count check, but count only generated JSON outputs so the verification reflects the actual endpoint set.
This commit is contained in:
ThatGuySam 2026-03-15 12:55:06 -05:00
parent 7dfb03bb31
commit 747e564e17

View file

@ -1,4 +1,4 @@
import { dirname, basename } from 'path' import { dirname, basename, extname, join } from 'path'
import os from 'os' import os from 'os'
import fs from 'fs-extra' import fs from 'fs-extra'
@ -448,6 +448,14 @@ class BuildLists {
const apiListDirectory = `${ apiDirectory }/${ listOptions.endpointPrefix }` const apiListDirectory = `${ apiDirectory }/${ listOptions.endpointPrefix }`
await fs.ensureDir( apiListDirectory )
for ( const existingFile of await fs.readdir( apiListDirectory ) ) {
if ( extname( existingFile ) !== '.json' ) continue
await fs.remove( join( apiListDirectory, existingFile ) )
}
// const poolSize = 1000 // const poolSize = 1000
// Store app bundles to memory // Store app bundles to memory
@ -516,14 +524,18 @@ class BuildLists {
} }
// Count saved files // Count saved files
const fileCount = fs.readdirSync( apiListDirectory ).length const fileCount = fs.readdirSync( apiListDirectory )
.filter( fileName => extname( fileName ) === '.json' )
.length
console.log( fileCount, 'Files saved in', apiListDirectory ) console.log( fileCount, 'Files saved in', apiListDirectory )
console.log( this.lists[listOptions.name].size, 'Entries' ) console.log( this.lists[listOptions.name].size, 'Entries' )
if ( fileCount !== this.lists[listOptions.name].size ) { if ( fileCount !== this.lists[listOptions.name].size ) {
const listSlugs = Array.from( this.lists[listOptions.name] ).map( listEntry => listEntry.slug ) const listSlugs = Array.from( this.lists[listOptions.name] ).map( listEntry => listEntry.slug )
const fileNames = fs.readdirSync( apiListDirectory ).map( fileName => basename(fileName).split('.')[0] ) const fileNames = fs.readdirSync( apiListDirectory )
.filter( fileName => extname( fileName ) === '.json' )
.map( fileName => basename(fileName).split('.')[0] )
logArraysDifference( listSlugs, fileNames ) logArraysDifference( listSlugs, fileNames )