-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
47 lines (42 loc) · 1.01 KB
/
build.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
const path = require("path");
const fs = require("fs");
const { log } = require("console");
function walkSync(dir, res, ext) {
res = res || [];
let files = fs.readdirSync(dir);
for (let f of files) {
if (f.charAt(0) === ".") {
continue;
}
let p = path.join(dir, f);
let stat = fs.lstatSync(p);
if (stat.isDirectory()) {
walkSync(p, res, ext);
} else if (stat.isFile()) {
let extF = path.extname(f);
if (typeof ext === "string") {
if (extF !== ext) {
continue;
}
} else if (Array.isArray(ext)) {
if (ext.indexOf(extF) < 0) {
continue;
}
}
res.push(p);
}
}
return res;
}
const url = __dirname;
const replaceUrl = "https://zhengpj95.github.io/imgdepot";
const list = [];
walkSync(url, list, ".png");
const urlAry = ["# img depot\n"];
for (let item of list) {
item = path.join(item).replace(url, replaceUrl).replaceAll("\\", "/");
urlAry.push(item);
// console.log(item);
}
urlAry.push("");
fs.writeFileSync(path.join(__dirname, "README.md"), urlAry.join("\n\n"));