logs.ts 508 B

12345678910111213141516171819202122232425
  1. import { stat } from 'fs-extra'
  2. async function mtimeSortFilesDesc (files: string[], basePath: string) {
  3. const promises = []
  4. const out: { file: string, mtime: number }[] = []
  5. for (const file of files) {
  6. const p = stat(basePath + '/' + file)
  7. .then(stats => {
  8. if (stats.isFile()) out.push({ file, mtime: stats.mtime.getTime() })
  9. })
  10. promises.push(p)
  11. }
  12. await Promise.all(promises)
  13. out.sort((a, b) => b.mtime - a.mtime)
  14. return out
  15. }
  16. export {
  17. mtimeSortFilesDesc
  18. }