mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-10-03 20:13:15 +00:00
93 lines
2.5 KiB
JavaScript
93 lines
2.5 KiB
JavaScript
import fs from "fs";
|
|
import path from "path";
|
|
|
|
import internal from "./internal.json" with { type: "json" };
|
|
import reserved from "./reserved.json" with { type: "json" };
|
|
|
|
const directoryPath = "./domains";
|
|
const outputDir = "./raw-api";
|
|
const domainsOutputDir = path.join(outputDir, "v2", "domains");
|
|
|
|
if (!fs.existsSync(outputDir)) {
|
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
}
|
|
if (!fs.existsSync(domainsOutputDir)) {
|
|
fs.mkdirSync(domainsOutputDir, { recursive: true });
|
|
}
|
|
|
|
function writeDomainFile(entry) {
|
|
fs.writeFileSync(
|
|
path.join(domainsOutputDir, `${entry.subdomain}.json`),
|
|
JSON.stringify(entry)
|
|
);
|
|
}
|
|
|
|
const v2 = [];
|
|
|
|
for (const subdomain of internal) {
|
|
const entry = {
|
|
domain: `${subdomain}.is-a.dev`,
|
|
subdomain: subdomain,
|
|
owner: { username: "is-a-dev" },
|
|
records: { CNAME: "internal.is-a.dev" },
|
|
internal: true
|
|
};
|
|
v2.push(entry);
|
|
writeDomainFile(entry);
|
|
}
|
|
|
|
for (const subdomain of reserved) {
|
|
const entry = {
|
|
domain: `${subdomain}.is-a.dev`,
|
|
subdomain: subdomain,
|
|
owner: { username: "is-a-dev" },
|
|
records: { URL: "https://is-a.dev/reserved" },
|
|
reserved: true
|
|
};
|
|
v2.push(entry);
|
|
writeDomainFile(entry);
|
|
}
|
|
|
|
fs.readdir(directoryPath, function (err, files) {
|
|
if (err) throw err;
|
|
|
|
let processedCount = 0;
|
|
|
|
files.forEach(function (file) {
|
|
const filePath = path.join(directoryPath, file);
|
|
|
|
fs.readFile(filePath, "utf8", (err, data) => {
|
|
if (err) throw err;
|
|
|
|
const item = JSON.parse(data);
|
|
const name = path.parse(file).name;
|
|
|
|
item.domain = `${name}.is-a.dev`;
|
|
item.subdomain = name;
|
|
delete item.owner.email;
|
|
|
|
const itemV2 = {
|
|
domain: item.domain,
|
|
subdomain: item.subdomain,
|
|
owner: item.owner,
|
|
records: item.records
|
|
};
|
|
if (item.redirect_config) itemV2.redirect_config = item.redirect_config;
|
|
if (item.proxied) itemV2.proxied = item.proxied;
|
|
|
|
v2.push(itemV2);
|
|
writeDomainFile(itemV2);
|
|
|
|
processedCount++;
|
|
if (processedCount === files.length) {
|
|
v2.sort((a, b) => a.domain.localeCompare(b.subdomain));
|
|
fs.writeFile(
|
|
path.join(outputDir, "v2.json"),
|
|
JSON.stringify(v2),
|
|
(err) => { if (err) throw err; }
|
|
);
|
|
}
|
|
});
|
|
});
|
|
});
|