diff options
Diffstat (limited to 'shared/core-utils')
-rw-r--r-- | shared/core-utils/logs/logs.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/shared/core-utils/logs/logs.ts b/shared/core-utils/logs/logs.ts new file mode 100644 index 000000000..d0996cf55 --- /dev/null +++ b/shared/core-utils/logs/logs.ts | |||
@@ -0,0 +1,25 @@ | |||
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 | } | ||