-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanDir.js
42 lines (35 loc) · 890 Bytes
/
scanDir.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
37
38
39
40
41
42
import { walk } from "@root/walk";
import path from "path";
import fs from 'fs';
const root = "./";
const filesList = [];
const generatedList = [];
const walkFunc = async (err, pathname, dirent) => {
if (err) {
throw err;
}
if (dirent.isDirectory() && dirent.name.startsWith(".")) {
return false;
}
if (path.parse(root + pathname).ext == '.asy') {
filesList.push(root + pathname);
}
};
export async function getFileList() {
await walk(root, walkFunc);
return(filesList);
}
export function getAllFileList() {
return new Promise((resolve,reject) => {
fs.readdir(root, (err, files) => {
files.forEach(file => {
const parsedFile = path.parse(file);
if ((parsedFile.ext == '.asy') &&
(file != 'config.asy')) {
generatedList.push(parsedFile.name);
}
});
resolve(generatedList);
});
})
}