summaryrefslogtreecommitdiff
path: root/app/build.js
blob: 9d9b8fc9bfeec4de778226366e0fd3501915acc1 (plain)
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
const fs = require('fs');
let original = fs.readFileSync("./sw.src.js").toString();

let fileList = [
    "/app/",
    "/-/demo",
    "https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css",
    "https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js",
    "/assets/logo/logo.png",
    "/assets/icons/right.svg"
];
function files(dir, sdir) {
    for (let file of fs.readdirSync(dir)) {
        if (file.startsWith(".")) continue;

        if (fs.lstatSync(dir + "/" + file).isDirectory()) {
            files(dir + "/" + file, sdir + "/" + file);
        } else {
            if (sdir + "/" + file !== "/app/build.js" && sdir + "/" + file !== "/app/fronters/dl.js" && sdir + "/" + file !== "/app/sw.src.js" && !file.endsWith(".php")) {
                fileList.push(sdir + "/" + file);
            }
        }
    }
}

files(".", "/app");
console.log(JSON.stringify(fileList, null, 2));
let fileList1 = fileList;

fileList = [];
files("../assets/uploads", "/assets/uploads");
console.log(JSON.stringify(fileList, null, 2));
let fileList2 = fileList;

original = original.replace('[["%CacheData%"]]', JSON.stringify([...fileList1, ...fileList2], null, 4));

fs.writeFileSync("./sw.js", fs.readFileSync("./localforage.js") + "\n\n" + original);