]> git.ipfire.org Git - thirdparty/blocklistproject/lists.git/commitdiff
Update update-number-of-domains.js
authorgap579137 <30596626+gap579137@users.noreply.github.com>
Tue, 5 Nov 2024 03:42:09 +0000 (21:42 -0600)
committerGitHub <noreply@github.com>
Tue, 5 Nov 2024 03:42:09 +0000 (21:42 -0600)
scripts/update-number-of-domains.js

index fcb3e31767ecd7bd2664861593a696d72dcc7022..584b0e6d01aeab65ceca5880d023b59d7705833a 100644 (file)
@@ -3,31 +3,42 @@ const path = require("node:path");
 
 (async () => {
        try {
+               // Define the base directory containing .txt files
                const directoryPath = path.join(__dirname, "..");
+
+               // Retrieve all .txt files from the directory
                const files = (await fs.readdir(directoryPath)).filter((file) =>
-                       file.endsWith(".txt"),
+                       file.endsWith(".txt")
                );
 
+               // Process each file concurrently
                await Promise.all(
                        files.map(async (file) => {
                                const filePath = path.join(directoryPath, file);
                                const fileContents = await fs.readFile(filePath, "utf8");
 
+                               // Extract unique domains starting with "0.0.0.0"
                                const existingDomains = new Set(
                                        fileContents
                                                .split("\n")
                                                .filter((line) => line.startsWith("0.0.0.0 "))
-                                               .map((line) => line.replace("0.0.0.0 ", "")),
+                                               .map((line) => line.slice(8)) // Extract domain after "0.0.0.0 "
                                );
 
+                               // Update the total number of network filters
                                const updatedContents = fileContents.replace(
-                                       /^# Total number of network filters: ?(\d*)$/gm,
-                                       `# Total number of network filters: ${existingDomains.size}`,
+                                       /^# Total number of network filters: ?\d*$/m,
+                                       `# Total number of network filters: ${existingDomains.size}`
                                );
 
+                               // Write the updated content back to the file
                                await fs.writeFile(filePath, updatedContents, "utf8");
-                       }),
+
+                               console.log(`Updated domain count for: ${file}`);
+                       })
                );
+
+               console.log("All files processed successfully.");
        } catch (error) {
                console.error("Error processing files:", error);
        }