Skip to content

Commit

Permalink
Update update-number-of-domains.js
Browse files Browse the repository at this point in the history
  • Loading branch information
gap579137 authored Sep 20, 2024
1 parent e424b49 commit 71976fe
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions scripts/update-number-of-domains.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
const fs = require("fs").promises;
const path = require("path");
const fs = require("node:fs").promises;
const path = require("node:path");

(async () => {
try {
const directoryPath = path.join(__dirname, "..");
const files = (await fs.readdir(directoryPath)).filter(file => file.endsWith(".txt"));
const files = (await fs.readdir(directoryPath)).filter((file) =>
file.endsWith(".txt"),
);

await Promise.all(files.map(async file => {
const filePath = path.join(directoryPath, file);
const fileContents = await fs.readFile(filePath, "utf8");
await Promise.all(
files.map(async (file) => {
const filePath = path.join(directoryPath, file);
const fileContents = await fs.readFile(filePath, "utf8");

// Extract unique domains
const existingDomains = new Set(
fileContents
.split("\n")
.filter(line => line.startsWith("0.0.0.0 "))
.map(line => line.replace("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 ", "")),
);

// 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}`
);
const updatedContents = fileContents.replace(
/^# Total number of network filters: ?(\d*)$/gm,
`# Total number of network filters: ${existingDomains.size}`,
);

await fs.writeFile(filePath, updatedContents, "utf8");
}));
await fs.writeFile(filePath, updatedContents, "utf8");
}),
);
} catch (error) {
console.error("Error processing files:", error);
}
Expand Down

0 comments on commit 71976fe

Please sign in to comment.