UNPKG

@applitools/execution-grid-tunnel

Version:

Allows user to run tests with exection-grid and navigate to private hosts and ips

29 lines (23 loc) 777 B
const path = require('path') const {promises: fs} = require('fs') module.exports = deleteOldFiles /* // TODO: remove files in subdirectory path - The directory path age - The maximun age of files in miliseconds we want to save */ async function deleteOldFiles({directoryPath, maximunFileAge}) { const time = Date.now() const filenames = await fs.readdir(directoryPath) const files = await Promise.all( filenames.map(async (name) => { const filePath = path.join(directoryPath, name) const data = await fs.stat(filePath) return {path: filePath, data} }), ) const oldFiles = files.filter( ({data}) => !data.isDirectory() && time - data.ctimeMs > maximunFileAge, ) await Promise.all(oldFiles.map((file) => fs.unlink(file.path))) }