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