all-node-versions
Version:
List all available Node.js versions
46 lines (26 loc) • 662 B
JavaScript
import{pathExists}from"path-exists";
import{
getCacheFile,
getCacheFileContent,
setCacheFileContent}from
"./file.js";
export const readCachedVersions=async(fetchOpt)=>{
if(fetchOpt===true){
return
}
const cacheFile=await getCacheFile();
if(!(await pathExists(cacheFile))){
return
}
const{versionsInfo,age}=await getCacheFileContent(cacheFile);
if(isOldCache(age,fetchOpt)){
return
}
return versionsInfo
};
const isOldCache=(age,fetchOpt)=>age>MAX_AGE_MS&&fetchOpt!==false;
const MAX_AGE_MS=36e5;
export const writeCachedVersions=async(versionsInfo)=>{
const cacheFile=await getCacheFile();
await setCacheFileContent(cacheFile,versionsInfo)
};