mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-05-18 15:26:00 +00:00
require lowercase file names
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const directoryPath = path.join(__dirname, "../domains");
|
||||
|
||||
(async () => {
|
||||
// Read the files in the 'domains' directory
|
||||
fs.readdirSync(directoryPath, (err, files) => {
|
||||
if (err) {
|
||||
console.error("Error reading directory:", err);
|
||||
return;
|
||||
}
|
||||
|
||||
files.forEach(async (file) => {
|
||||
const oldPath = path.join(directoryPath, file);
|
||||
const newPath = path.join(directoryPath, file.toLowerCase());
|
||||
|
||||
// Only rename if the file name is not already in lowercase
|
||||
if (oldPath !== newPath) {
|
||||
fs.renameSync(oldPath, newPath, (err) => {
|
||||
if (err) {
|
||||
console.error("Error renaming file:", err);
|
||||
} else {
|
||||
console.log(`Renamed: ${file} -> ${file.toLowerCase()}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
})();
|
||||
@@ -5,7 +5,6 @@ const path = require("path");
|
||||
const domainsPath = path.resolve("domains");
|
||||
const files = fs.readdirSync(domainsPath);
|
||||
|
||||
// Nested subdomains should not exist if the parent subdomain does not exist
|
||||
t("Nested subdomains should not exist without a parent subdomain", (t) => {
|
||||
files.forEach((file) => {
|
||||
const subdomain = file.replace(".json", "");
|
||||
@@ -23,7 +22,6 @@ t("Nested subdomains should not exist without a parent subdomain", (t) => {
|
||||
t.pass();
|
||||
});
|
||||
|
||||
// Nested subdomains should not exist if the parent subdomain has NS records
|
||||
t("Nested subdomains should not exist if the parent subdomain has NS records", (t) => {
|
||||
files.forEach((file) => {
|
||||
const subdomain = file.replace(".json", "");
|
||||
|
||||
+1
-4
@@ -50,18 +50,17 @@ const validateOptionalFields = (t, obj, optionalFields, file) => {
|
||||
});
|
||||
};
|
||||
|
||||
// Ensure all files are valid JSON
|
||||
t("All files should be valid JSON", (t) => {
|
||||
files.forEach((file) => {
|
||||
t.notThrows(() => fs.readJsonSync(path.join(domainsPath, file)), `${file}: Invalid JSON file`);
|
||||
});
|
||||
});
|
||||
|
||||
// Ensure all files have the required fields
|
||||
t("All files should have valid file names", (t) => {
|
||||
files.forEach((file) => {
|
||||
t.true(file.endsWith(".json"), `${file}: File does not have .json extension`);
|
||||
t.false(file.includes(".is-a.dev"), `${file}: File name should not contain .is-a.dev`);
|
||||
t.true(file === file.toLowerCase(), `${file}: File name should be lowercase`);
|
||||
|
||||
// Ignore root domain
|
||||
if (file !== "@.json") {
|
||||
@@ -74,7 +73,6 @@ t("All files should have valid file names", (t) => {
|
||||
});
|
||||
});
|
||||
|
||||
// Ensure all files have the required fields
|
||||
t("All files should have the required fields", (t) => {
|
||||
files.forEach((file) => {
|
||||
const data = fs.readJsonSync(path.join(domainsPath, file));
|
||||
@@ -88,7 +86,6 @@ t("All files should have the required fields", (t) => {
|
||||
});
|
||||
});
|
||||
|
||||
// Validate the optional fields
|
||||
t("All files should have valid optional fields", (t) => {
|
||||
files.forEach((file) => {
|
||||
const data = fs.readJsonSync(path.join(domainsPath, file));
|
||||
|
||||
+12
-3
@@ -16,7 +16,6 @@ const ipv6Regex =
|
||||
const domainsPath = path.resolve("domains");
|
||||
const files = fs.readdirSync(domainsPath);
|
||||
|
||||
// Validate the record object key names
|
||||
t("All files should have valid record types", (t) => {
|
||||
files.forEach((file) => {
|
||||
const data = fs.readJsonSync(path.join(domainsPath, file));
|
||||
@@ -50,7 +49,6 @@ t("All files should have valid record types", (t) => {
|
||||
});
|
||||
});
|
||||
|
||||
// Ensure there are no duplicate keys in the record object
|
||||
t("All files should not have duplicate record keys", (t) => {
|
||||
files.forEach((file) => {
|
||||
const data = fs.readJsonSync(path.join(domainsPath, file));
|
||||
@@ -62,7 +60,6 @@ t("All files should not have duplicate record keys", (t) => {
|
||||
});
|
||||
});
|
||||
|
||||
// Validate the values of the record object's keys
|
||||
t("All files should have valid record values", (t) => {
|
||||
files.forEach((file) => {
|
||||
const data = fs.readJsonSync(path.join(domainsPath, file));
|
||||
@@ -81,6 +78,7 @@ t("All files should have valid record values", (t) => {
|
||||
);
|
||||
});
|
||||
|
||||
// A records must be a valid IPv4 address
|
||||
if (key === "A") {
|
||||
value.forEach((record) => {
|
||||
t.regex(
|
||||
@@ -100,6 +98,7 @@ t("All files should have valid record values", (t) => {
|
||||
});
|
||||
}
|
||||
|
||||
// AAAA records must be a valid IPv6 address
|
||||
if (key === "AAAA") {
|
||||
value.forEach((record) => {
|
||||
t.regex(
|
||||
@@ -119,6 +118,7 @@ t("All files should have valid record values", (t) => {
|
||||
});
|
||||
}
|
||||
|
||||
// MX and NS records must be a valid hostname
|
||||
if (["MX", "NS"].includes(key)) {
|
||||
value.forEach((record) => {
|
||||
t.regex(
|
||||
@@ -139,6 +139,7 @@ t("All files should have valid record values", (t) => {
|
||||
`${file}: Record value should be a string for ${key}`
|
||||
);
|
||||
|
||||
// CNAME records must be a valid hostname
|
||||
if (key === "CNAME") {
|
||||
t.regex(
|
||||
value,
|
||||
@@ -147,6 +148,7 @@ t("All files should have valid record values", (t) => {
|
||||
);
|
||||
}
|
||||
|
||||
// URL records must be a valid URL
|
||||
if (key === "URL") {
|
||||
try {
|
||||
new URL(value);
|
||||
@@ -171,6 +173,7 @@ t("All files should have valid record values", (t) => {
|
||||
|
||||
if (key === "CAA") {
|
||||
value.forEach((record) => {
|
||||
// flags must be a number
|
||||
t.true(
|
||||
typeof record.flags === "number",
|
||||
`${file}: CAA record value should have a number for flags at index ${value.indexOf(
|
||||
@@ -178,6 +181,7 @@ t("All files should have valid record values", (t) => {
|
||||
)}`
|
||||
);
|
||||
|
||||
// tag and value must be strings
|
||||
t.true(
|
||||
typeof record.tag === "string",
|
||||
`${file}: CAA record value should have a string for tag at index ${value.indexOf(
|
||||
@@ -196,6 +200,7 @@ t("All files should have valid record values", (t) => {
|
||||
|
||||
if (key === "DS") {
|
||||
value.forEach((record) => {
|
||||
// key_tag, algorithm, and digest_type must be numbers
|
||||
t.true(
|
||||
typeof record.key_tag === "number",
|
||||
`${file}: DS record value should have a number for key_tag at index ${value.indexOf(
|
||||
@@ -217,6 +222,7 @@ t("All files should have valid record values", (t) => {
|
||||
)}`
|
||||
);
|
||||
|
||||
// digest must be a string
|
||||
t.true(
|
||||
typeof record.digest === "string",
|
||||
`${file}: DS record value should have a string for digest at index ${value.indexOf(
|
||||
@@ -228,6 +234,7 @@ t("All files should have valid record values", (t) => {
|
||||
|
||||
if (key === "SRV") {
|
||||
value.forEach((record) => {
|
||||
// priority, weight, and port must be numbers
|
||||
t.true(
|
||||
typeof record.priority === "number",
|
||||
`${file}: SRV record value should have a number for priority at index ${value.indexOf(
|
||||
@@ -249,6 +256,7 @@ t("All files should have valid record values", (t) => {
|
||||
)}`
|
||||
);
|
||||
|
||||
// target must be a string
|
||||
t.true(
|
||||
typeof record.target === "string",
|
||||
`${file}: SRV record value should have a string for target at index ${value.indexOf(
|
||||
@@ -256,6 +264,7 @@ t("All files should have valid record values", (t) => {
|
||||
)}`
|
||||
);
|
||||
|
||||
// target must be a valid hostname
|
||||
t.regex(
|
||||
value.target,
|
||||
hostnameRegex,
|
||||
|
||||
Reference in New Issue
Block a user