forked from tookit/vue-material-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.js
42 lines (40 loc) · 1.01 KB
/
file.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
const fs = require('fs');
const path = require('path');
const faker = require('faker');
const mime = require('mime-types');
const walkSync = (dir, filelist = [], exclude = []) => {
let files = fs.readdirSync(dir) || [];
filelist = filelist || [];
files.forEach((name) => {
let filePath = path.join(dir, name);
let file = {};
let fileStat = fs.statSync(filePath);
let fullPath = path.resolve(filePath);
let parse = path.parse(filePath);
let fileType = mime.lookup(filePath);
if (fileStat.isDirectory()) {
filelist = walkSync(filePath, filelist);
}
else {
file = {
uuid: faker.random.uuid(),
fileName: name,
fileType: fileType,
path: filePath,
fullPath: fullPath,
ext: parse.ext,
dir: parse.dir,
ctime: fileStat.ctime,
size: fileStat.size
};
filelist.push(file);
}
});
return filelist;
};
const files = walkSync('./static', [], []);
module.exports = () => {
return {
data: files
};
};