diff --git a/scripts/create-everything-list.js b/scripts/create-everything-list.js index 1695b619..d2409af2 100644 --- a/scripts/create-everything-list.js +++ b/scripts/create-everything-list.js @@ -1,5 +1,5 @@ -const fs = require("fs").promises; -const path = require("path"); +const fs = require("node:fs").promises; +const path = require("node:path"); const listsToIncludeInEverythingList = [ "abuse", @@ -29,29 +29,35 @@ const listsToIncludeInEverythingList = [ ]; (async () => { - const files = (await fs.readdir(path.join(__dirname, ".."))).filter((file) => file.endsWith(".txt")).filter((file) => listsToIncludeInEverythingList.some((val) => file.startsWith(val))); // Array of strings, each representing a single file that ends in `.txt` + try { + const files = (await fs.readdir(path.join(__dirname, ".."))).filter( + (file) => + file.endsWith(".txt") && + listsToIncludeInEverythingList.some((val) => file.startsWith(val)), + ); + const domains = new Set(); - const domains = new Set(); + await Promise.all( + files.map(async (file) => { + const fileContents = await fs.readFile( + path.join(__dirname, "..", file), + "utf8", + ); + for (const line of fileContents.split("\n")) { + if (line.startsWith("0.0.0.0 ")) { + domains.add(line.replace("0.0.0.0 ", "")); + } + } + }), + ); - await Promise.all(files.map(async (file) => { // For each file - - const fileContents = await fs.readFile(path.join(__dirname, "..", file), "utf8"); // Get file contents as a string - - fileContents.split("\n").forEach((line) => { - if (line.startsWith("0.0.0.0 ")) { - domains.add(line.replace("0.0.0.0 ", "")); - } - }); - })); - - let everythingListContent = -`# ------------------------------------[UPDATE]-------------------------------------- + let everythingListContent = `# ------------------------------------[UPDATE]-------------------------------------- # Title: The Block List Project - Everything List # Expires: 1 day # Homepage: https://blocklistproject.github.io/Lists/ # Help: https://github.com/blocklistproject/lists/wiki/ # License: https://unlicense.org -# Total number of network filters: +# Total number of network filters: ${domains.size} # ------------------------------------[SUPPORT]------------------------------------- # You can support by: # - reporting false positives @@ -62,7 +68,17 @@ const listsToIncludeInEverythingList = [ # Everything list # ------------------------------------[FILTERS]------------------------------------- `; - domains.forEach((val) => everythingListContent += `0.0.0.0 ${val}\n`); - await fs.writeFile(path.join(__dirname, "..", "everything.txt"), everythingListContent, "utf8"); + for (const val of domains) { + everythingListContent += `0.0.0.0 ${val}\n`; + } + + await fs.writeFile( + path.join(__dirname, "..", "everything.txt"), + everythingListContent, + "utf8", + ); + } catch (error) { + console.error("Error processing files:", error); + } })();