|
const fs = require("fs").promises; |
|
const path = require("path"); |
|
|
|
(async () => { |
|
let hasError = false; |
|
|
|
const files = (await fs.readdir(path.join(__dirname, ".."))).filter((file) => file.endsWith(".txt")); |
|
await Promise.all(files.filter((file) => file !== "everything.txt").map(async (file) => { |
|
const fileContents = await fs.readFile(path.join(__dirname, "..", file), "utf8"); |
|
|
|
const commentedURLs = fileContents.split("\n").map((line) => { |
|
if (line.startsWith("# 0.0.0.0")) { |
|
return line.split(" ")[2].trim(); |
|
} |
|
|
|
return null; |
|
}).filter((a) => a !== null && !!a); |
|
|
|
let isHeaderComplete = false; |
|
fileContents.split("\n").forEach((line, index) => { |
|
if (line.startsWith("0.0.0.0")) { |
|
isHeaderComplete = true; |
|
} |
|
|
|
|
|
if (line.length > 0 && !line.indexOf("Version")) { |
|
console.error(`Line ${index + 1} in ${file} must not contain a Version/Date.`); |
|
hasError = true; |
|
} |
|
|
|
|
|
if (line.length > 0 && !line.startsWith("#") && !line.startsWith("0.0.0.0 ")) { |
|
console.error(`Line ${index + 1} in ${file} must start with "#" or "0.0.0.0 ".`); |
|
hasError = true; |
|
} |
|
|
|
|
|
if (line.startsWith("0.0.0.0 ")) { |
|
const lineNoIP = line.replace("0.0.0.0 ", ""); |
|
const url = lineNoIP.split("#")[0].trim(); |
|
if (url.toLowerCase() !== url) { |
|
console.error(`Line ${index + 1} in ${file} url ${url} must be all lowercase.`); |
|
hasError = true; |
|
} |
|
} |
|
|
|
|
|
if (line.startsWith("#") && line.length > 1 && line[1] !== " ") { |
|
console.error(`Line ${index + 1} in ${file} should have a space after #.`); |
|
hasError = true; |
|
} |
|
|
|
|
|
if (isHeaderComplete && line.startsWith("#") && !line.startsWith("# 0.0.0.0") && !line.startsWith("# NOTE:")) { |
|
console.error(`Line ${index + 1} in ${file} should start with "# 0.0.0.0" or "# NOTE:".`); |
|
hasError = true; |
|
} |
|
|
|
|
|
if (line.startsWith("0.0.0.0 ")) { |
|
const lineNoIP = line.replace("0.0.0.0 ", ""); |
|
const url = lineNoIP.split("#")[0].trim(); |
|
if (commentedURLs.includes(url)) { |
|
console.error(`Line ${index + 1} in ${file} url ${url} is commented out in this file. This suggests an error. Please either remove this line or remove the commented URL.`); |
|
hasError = true; |
|
} |
|
} |
|
|
|
|
|
if (line.startsWith("0.0.0.0 ")) { |
|
const lineNoIP = line.replace("0.0.0.0 ", ""); |
|
const url = lineNoIP.split("#")[0].trim(); |
|
if (/\s/gmu.test(url)) { |
|
console.error(`Line ${index + 1} in ${file} url ${url} contains whitespace in the URL.`); |
|
hasError = true; |
|
} |
|
} |
|
}); |
|
})); |
|
|
|
process.exit(hasError ? 1 : 0); |
|
})(); |
|
|