-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (57 loc) · 1.91 KB
/
index.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const fs = require('fs');
const path = require('path');
let components = [];
let i = 1;
let walk = function (modelPath) {
fs.readdirSync(modelPath)
.forEach(function (file) {
let filePath = path.join(modelPath, '/' + file)
let stat = fs.statSync(filePath);
if (stat.isFile()) {
if (/(.*)\.(jpg|png)/.test(file)) {
// require(filePath)
let imgObj = {
title: '超能APP',
images: `cartoon/${filePath}`,
name: file,
episode: `第${i}集`,
id: i
}
components.push(imgObj);
// let newPath = path.join(modelPath, '/' + `${i}.jpg`);
// // 如果文件名称不一致修改
// fs.rename(filePath, newPath, function (err) {
// if (err) {
// console.log(err);
// throw err;
// }
// });
i++;
}
} else if (stat.isDirectory()) {
walk(filePath)
}
})
};
walk('./');
fs.writeFile('./cartoon.js', JSON.stringify(components), { flag: 'a', encoding: 'utf-8', mode: '0666' }, function (err) {
if (err) {
console.log("文件写入失败")
} else {
console.log("文件写入成功");
}
})
return;
files.forEach(function (item, index) {
console.log(item.isDirectory());
// console.log(item);
let stat = fs.lstatSync("./" + item)
if (stat.isDirectory() === true) {
components.push(item)
}
})
console.log(components);
// let str = JSON.stringify(components)
// fs.writeFile('./extension.json', str, function (err) {
// if (err) { res.status(500).send('Server is error...') }
// })