]> git.ipfire.org Git - thirdparty/blocklistproject/lists.git/commitdiff
Update create-everything-list.js
authorgap579137 <30596626+gap579137@users.noreply.github.com>
Fri, 20 Sep 2024 15:04:18 +0000 (10:04 -0500)
committerGitHub <noreply@github.com>
Fri, 20 Sep 2024 15:04:18 +0000 (10:04 -0500)
scripts/create-everything-list.js

index 1695b619accd916b79504bdd11bb038a68688fae..d2409af2d8544e3d119be5b46338af8e1c13d862 100644 (file)
@@ -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);
+       }
 })();