const fs = require("fs");
const { resolve } = require("path");
const Content = `
ethers.js - Legacy Documentation
This link is out-of-date and has moved.
Click here to visit the updated documentation
or continue to the historic legacy documentation.
`
const redirects = require("./redirects.json");
const links = require("../docs/v5/metadata.json").links;
const result = { };
const prefix = "ethers.js/html/";
Object.keys(redirects).forEach((uri) => {
if (uri.substring(0, prefix.length) !== prefix) { return; }
const comps = uri.substring(prefix.length).split("#");
const filename = comps[0];
const hash = comps[1] || "_";
const tag = redirects[uri];
let path = null;
if (tag.path) {
path = tag.path;
} else if (tag.tag) {
path = links[tag.tag] || null;
} else {
console.log("Missing tag:", uri);
return;
}
if (!path) {
console.log("Missing path:", uri);
return;
}
if (!result[filename]) { result[filename] = {
"_legacy": `/v4/${ filename }`
}; }
result[filename][hash] = path;
});
function generateOutput(filename) {
const page = result[filename];
return Content.replace("%%DEFAULT%%", page._ || "/v5/")
.replace("%%LEGACY%%", page._legacy || "/v4/")
.replace("%%REDIRECTS%%", JSON.stringify(page));
}
Object.keys(result).forEach((filename) => {
const output = generateOutput(filename);
const path = resolve(__dirname, "../docs/ethers.js/html", filename);
fs.writeFileSync(path, output);
});