]> git.ipfire.org Git - thirdparty/blocklistproject/lists.git/commitdiff
Adding generate-adguard script
authorCharlie Fish <fishcharlie@me.com>
Tue, 6 Jul 2021 01:10:09 +0000 (19:10 -0600)
committerCharlie Fish <fishcharlie@me.com>
Tue, 6 Jul 2021 01:10:09 +0000 (19:10 -0600)
.github/workflows/run-automations.yml
scripts/generate-adguard.js [new file with mode: 0644]

index 0941acab1679036d46a6886b1b464fe420064d59..78a49b9933313b20b60de864ad2803c2caac0c81 100644 (file)
@@ -18,6 +18,7 @@ jobs:
       - run: node scripts/update-number-of-domains.js
       - run: node scripts/generate-noip.js
       - run: node scripts/generate-dnsmasq.js
+      - run: node scripts/generate-adguard.js
       - name: Commit & Push
         uses: actions-x/commit@v2
         with:
diff --git a/scripts/generate-adguard.js b/scripts/generate-adguard.js
new file mode 100644 (file)
index 0000000..6bf7bce
--- /dev/null
@@ -0,0 +1,15 @@
+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 fileContents = await fs.readFile(path.join(__dirname, "..", file), "utf8"); // Get file contents as a string
+               const adGuardFileContents = fileContents
+               .replace(/^# Title: (.*?)$/gmu, "# Title: $1 (adguard)") // Add (adguard) to end of title
+               .replaceAll(/^# 0\.0\.0\.0 (.*?) (.*)/gmu, "@@||$1^! $2")
+               .replaceAll(/0\.0\.0\.0 (.*?)$/gmu, "||$1^")
+               .replaceAll(/^#/gmu, "!");
+               await fs.writeFile(path.join(__dirname, "..", "adguard", file.replace(".txt", "-ags.txt")), adGuardFileContents, "utf8"); // Write new file to `adguard` directory
+       }));
+})();