generated from aquaticone/esm-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsHelpers.js
36 lines (33 loc) · 885 Bytes
/
fsHelpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import fs from "fs"
import readdirp from "readdirp"
export async function getAllPaths(dir) {
const allPaths = []
const readdirpOptions = {
fileFilter: "*.png",
type: "files_directories",
}
for await (const entry of readdirp(dir, readdirpOptions)) {
allPaths.push({ path: entry.path, absPath: entry.fullPath })
}
return allPaths
}
export async function cleanDir(dir) {
const readdirpOptions = {
type: "files_directories",
levels: 1,
}
const allPaths = []
for await (const entry of readdirp(dir, readdirpOptions)) {
allPaths.push({ absPath: entry.fullPath })
}
for (let i = 0; i < allPaths.length; i++) {
const { absPath } = allPaths[i]
try {
await fs.promises.rm(absPath, { recursive: true })
} catch {}
}
}
export async function isFile(path) {
const stat = await fs.promises.lstat(path)
return stat.isFile()
}