const fs = require('fs'); let original = fs.readFileSync("./sw.src.js").toString(); let fileList = [ "/app/" ]; 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)); original = original.replace('[["%CacheData%"]]', JSON.stringify(fileList, null, 4)); fs.writeFileSync("./sw.js", fs.readFileSync("./localforage.js") + "\n\n" + original);