[add] filter by npm api before repo fetch

This commit is contained in:
2025-08-15 04:01:08 +01:00
parent 7f2f0b9240
commit 52d0c7b649
7 changed files with 794 additions and 157 deletions

View File

@@ -9,18 +9,18 @@ import { resolve } from "node:path";
* @param {()=>Promise<T>} asyncCallback
* @returns {Promise<T>}
*/
export async function cacheFunctionOutput(fileName, asyncCallback) {
export async function cacheFunctionOutput(fileName, asyncCallback, silent=false) {
const fileLoc = resolve('../cache-repos', fileName);
if (existsSync(fileLoc)) {
console.log("[cacher] Using cached ", fileLoc);
!silent && console.log("[cacher] Using cached ", fileLoc);
const fileContents = (await readFile(fileLoc)).toString();
return JSON.parse(fileContents);
} else {
console.log("[cacher] cache miss")
!silent && console.log("[cacher] cache miss")
const returnRes = await asyncCallback();
const fileContents = JSON.stringify(returnRes);
await writeFile(fileLoc,fileContents);
console.log("[cacher] saved ",fileLoc)
!silent && console.log("[cacher] saved ",fileLoc)
return returnRes;
}
}