-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.mjs
More file actions
41 lines (31 loc) · 896 Bytes
/
utils.mjs
File metadata and controls
41 lines (31 loc) · 896 Bytes
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
37
38
39
40
41
import { resolve } from 'node:path';
import { promises, lstatSync } from 'node:fs';
const { readdir } = promises;
export async function getFiles(dir) {
if (lstatSync(dir).isFile()) {
return [dir].filter(file => file.endsWith('.svg'));
}
const dirents = await readdir(dir, { withFileTypes: true });
const files = await Promise.all(
dirents.map(dirent => {
const res = resolve(dir, dirent.name);
return dirent.isDirectory() ? getFiles(res) : res;
})
);
// @ts-ignore
return [].concat(...files).filter(file => file.endsWith('.svg'));
}
export async function getInputFiles(input) {
return !input ? [] : await getFiles(resolve(input));
}
export async function getPathsFiles(paths) {
if (paths.length === 0) {
return [];
}
let result = [];
for (const path of paths) {
const files = await getInputFiles(path);
result = [...result, ...files];
}
return result;
}