From: gap579137 <30596626+gap579137@users.noreply.github.com> Date: Fri, 20 Sep 2024 15:05:22 +0000 (-0500) Subject: Update generate-noip.js X-Git-Tag: aggregated-20250518~31 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=e1b3424017d1bead1c9c3cefaf52538f11af59ea;p=thirdparty%2Fblocklistproject%2Flists.git Update generate-noip.js --- diff --git a/scripts/generate-noip.js b/scripts/generate-noip.js index c998e9d..7f4f8c1 100644 --- a/scripts/generate-noip.js +++ b/scripts/generate-noip.js @@ -1,14 +1,34 @@ -const fs = require("fs").promises; -const path = require("path"); +const fs = require("node:fs").promises; +const path = require("node: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 noIPFileContents = fileContents - .replaceAll(/^0\.0\.0\.0 /gmu, "") // Replace all occurances of "0.0.0.0 " at the beginning of the line with "" (nothing) - .replaceAll(/^# 0\.0\.0\.0 /gmu, "# ") // Replace all occurances of "# 0.0.0.0 " at the beginning of the line with "# " - .replace(/^# Title: (.*?)$/gmu, "# Title: $1 (NL)"); // Add (NL) to end of title - await fs.writeFile(path.join(__dirname, "..", "alt-version", file.replace(".txt", "-nl.txt")), noIPFileContents, "utf8"); // Write new file to `alt-version` directory - })); + try { + const files = (await fs.readdir(path.join(__dirname, ".."))).filter( + (file) => file.endsWith(".txt"), + ); + await Promise.all( + files.map(async (file) => { + const fileContents = await fs.readFile( + path.join(__dirname, "..", file), + "utf8", + ); + const noIPFileContents = fileContents + .replaceAll(/^0\.0\.0\.0 /gmu, "") + .replaceAll(/^# 0\.0\.0\.0 /gmu, "# ") + .replace(/^# Title: (.*?)$/gmu, "# Title: $1 (NL)"); + await fs.writeFile( + path.join( + __dirname, + "..", + "alt-version", + file.replace(".txt", "-nl.txt"), + ), + noIPFileContents, + "utf8", + ); + }), + ); + } catch (error) { + console.error("Error processing files:", error); + } })();