From 34fdcee12adb6789f8d40a62872d8a3265025e7a Mon Sep 17 00:00:00 2001 From: Charlie Fish Date: Sun, 27 Jun 2021 18:41:14 -0600 Subject: [PATCH] Adding script to automate updating number of domains in list --- .github/workflows/run-automations.yml | 1 + scripts/update-number-of-domains.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 scripts/update-number-of-domains.js diff --git a/.github/workflows/run-automations.yml b/.github/workflows/run-automations.yml index e594d96..0941aca 100644 --- a/.github/workflows/run-automations.yml +++ b/.github/workflows/run-automations.yml @@ -15,6 +15,7 @@ jobs: node-version: 15.x - run: node scripts/create-everything-list.js - run: node scripts/remove-duplicates.js + - run: node scripts/update-number-of-domains.js - run: node scripts/generate-noip.js - run: node scripts/generate-dnsmasq.js - name: Commit & Push diff --git a/scripts/update-number-of-domains.js b/scripts/update-number-of-domains.js new file mode 100644 index 0000000..5f50f79 --- /dev/null +++ b/scripts/update-number-of-domains.js @@ -0,0 +1,20 @@ +const fs = require("fs").promises; +const path = require("path"); + +(async () => { + const files = (await fs.readdir(path.join(__dirname, ".."))).filter((file) => file.endsWith(".txt")); // Array of strings, each representing a single file that ends in `.txt` + + await Promise.all(files.map(async (file) => { // For each file + const existingDomains = new Set(); + + 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 ")) { + existingDomains.add(line.replace("0.0.0.0 ", "")); + } + }); + + await fs.writeFile(path.join(__dirname, "..", file), fileContents.replace(/^# Total number of network filters: ?(\d*)$/gmu, `# Total number of network filters: ${existingDomains.size}`), "utf8"); + })); +})(); -- 2.47.2