Skip to content

Commit e1b3424

Browse files
authored
Update generate-noip.js
1 parent e2e5c7a commit e1b3424

1 file changed

Lines changed: 31 additions & 11 deletions

File tree

scripts/generate-noip.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1-
const fs = require("fs").promises;
2-
const path = require("path");
1+
const fs = require("node:fs").promises;
2+
const path = require("node:path");
33

44
(async () => {
5-
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`
6-
await Promise.all(files.map(async (file) => { // For each file
7-
const fileContents = await fs.readFile(path.join(__dirname, "..", file), "utf8"); // Get file contents as a string
8-
const noIPFileContents = fileContents
9-
.replaceAll(/^0\.0\.0\.0 /gmu, "") // Replace all occurances of "0.0.0.0 " at the beginning of the line with "" (nothing)
10-
.replaceAll(/^# 0\.0\.0\.0 /gmu, "# ") // Replace all occurances of "# 0.0.0.0 " at the beginning of the line with "# "
11-
.replace(/^# Title: (.*?)$/gmu, "# Title: $1 (NL)"); // Add (NL) to end of title
12-
await fs.writeFile(path.join(__dirname, "..", "alt-version", file.replace(".txt", "-nl.txt")), noIPFileContents, "utf8"); // Write new file to `alt-version` directory
13-
}));
5+
try {
6+
const files = (await fs.readdir(path.join(__dirname, ".."))).filter(
7+
(file) => file.endsWith(".txt"),
8+
);
9+
await Promise.all(
10+
files.map(async (file) => {
11+
const fileContents = await fs.readFile(
12+
path.join(__dirname, "..", file),
13+
"utf8",
14+
);
15+
const noIPFileContents = fileContents
16+
.replaceAll(/^0\.0\.0\.0 /gmu, "")
17+
.replaceAll(/^# 0\.0\.0\.0 /gmu, "# ")
18+
.replace(/^# Title: (.*?)$/gmu, "# Title: $1 (NL)");
19+
await fs.writeFile(
20+
path.join(
21+
__dirname,
22+
"..",
23+
"alt-version",
24+
file.replace(".txt", "-nl.txt"),
25+
),
26+
noIPFileContents,
27+
"utf8",
28+
);
29+
}),
30+
);
31+
} catch (error) {
32+
console.error("Error processing files:", error);
33+
}
1434
})();

0 commit comments

Comments
 (0)