Created
January 24, 2019 08:27
-
-
Save dontcallmedom/535094bbaa8f456f010696bfe0423a07 to your computer and use it in GitHub Desktop.
MDN BCD / W3C status comparator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const specData = JSON.parse(fs.readFileSync("macros/SpecData.json", "utf-8")); | |
const w3cSpecData = JSON.parse(fs.readFileSync("../spec-dashboard/spec-list.json", "utf-8")); | |
const not = f => x => !f(x); | |
const isW3CDomain = function(url) { | |
const w3cDomains = [ | |
/w3\.org/, | |
/w3c\.github\.io/, | |
/drafts\.csswg\.org/, | |
/webaudio\.github\.io/, | |
/svgwg\.org/, | |
/drafts\.fxtf\.org/, | |
/heycam\.github\.io/, | |
/drafts\.css-houdini\.org/, | |
/webassembly\.github\.io/ | |
]; | |
for (const domain of w3cDomains) { | |
if (url.match(domain)) return true; | |
} | |
return false; | |
}; | |
const w3cStatuses = ["ED", "WD", "CR", "PR", "REC", "Obsolete"]; | |
const otherStatuses = ["Draft", "Living", "Obsolete", "Standard", "RFC"]; | |
const cleanspaces = s => s.replace(/ /g, " "); | |
const shortStatuses = { | |
"Working Draft": "WD", | |
"Candidate Recommendation": "CR", | |
"Proposed Recommendation": "PR" | |
} | |
const specDataByUrl = Object.keys(specData).reduce( | |
(acc, name) => {acc[specData[name].url] = {...specData[name], shortname: name}; return acc;}, {} | |
); | |
const specUrls = Object.keys(specDataByUrl); | |
const httpize = u => u.replace(/^https:/, "http:"); | |
const unversion = u => u.replace(/-[0-9]\/$/, "/"); | |
const matchW3cSpec = (u, unversioning = true) => { | |
if (w3cSpecData[u]) return w3cSpecData[u]; | |
if (w3cSpecData[httpize(u)]) return w3cSpecData[httpize(u)]; | |
if (unversioning) { | |
if (w3cSpecData[unversion(u)]) return w3cSpecData[unversion(u)]; | |
if (w3cSpecData[unversion(httpize(u))]) return w3cSpecData[unversion(httpize(u))]; | |
} | |
}; | |
console.log("Non-W3C specs with W3C statuses"); | |
console.log(specUrls.filter(not(isW3CDomain)).filter(u => !otherStatuses.includes(specDataByUrl[u].status)).map(u => u + ": " + specDataByUrl[u].status).join("\n")); | |
console.log(); | |
console.log("W3C specs with non-W3C statuses"); | |
console.log(specUrls.filter(isW3CDomain).filter(u => !w3cStatuses.includes(specDataByUrl[u].status)).join("\n")); | |
console.log(); | |
console.log("W3C specs with wrong status"); | |
for (const url of specUrls.filter(isW3CDomain)) { | |
if (!["ED", "REC", "Obsolete"].includes(specDataByUrl[url].status)) { | |
if (!matchW3cSpec(url)) { | |
console.log("Unknown Rec-track work on " + url + " (marked as " + specDataByUrl[url].status + ")"); | |
} else { | |
const w3cStatus = shortStatuses[matchW3cSpec(url).status]; | |
if (specDataByUrl[url].status != w3cStatus) { | |
console.log("Spec " + url + " is marked as " + specDataByUrl[url].status + " instead of " + w3cStatus); | |
} | |
} | |
} else { | |
if (specDataByUrl[url].status == "ED" && matchW3cSpec(url, false)) { | |
console.log("Spec " + url + " is marked as ED but has been published as " + shortStatuses[matchW3cSpec(url).status]); | |
} else if (specDataByUrl[url].status == "ED") { | |
console.log("Is " + url + " an ED or a CG draft?"); | |
} | |
} | |
if (matchW3cSpec(url) && matchW3cSpec(url).title !== cleanspaces(specDataByUrl[url].name)) { | |
console.log("Spec " + url + " is known as “" + cleanspaces(specDataByUrl[url].name) + "” instead of “" + matchW3cSpec(url).title + "”"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment