Skip to content

Instantly share code, notes, and snippets.

@gero3
Created January 3, 2018 22:04
Show Gist options
  • Save gero3/e76d8925a72a848c51a133ba0879e100 to your computer and use it in GitHub Desktop.
Save gero3/e76d8925a72a848c51a133ba0879e100 to your computer and use it in GitHub Desktop.
var fs = require("fs");
function getMethods(obj) {
var allPages = {};
for (var category in obj) {
var pages = obj[category];
for (var page in pages) {
var filterItems = pages[page];
if (typeof filterItems === "string") {
filterItems = { "#URL": filterItems };
} else {
filterItems = { "#URL": filterItems["#URL"] };
}
var url = filterItems["#URL"];
var HTMLFile = fs.readFileSync(url + ".html", "utf8");
var regex = /\[page:([\w\.]+) ?([\w\.\s]+)?\]\s+→/gi
var matches = [];
do {
match = regex.exec(HTMLFile);
if (match) {
filterItems["#PARENT"] = match[1];
}
} while (match);
regex = /\[(?:member|property|method):([\w]+) ?([\w\.\s]+)?\]/gi;
var matches = [];
do {
match = regex.exec(HTMLFile);
if (match && match[2]) {
matches.push(match[2]);
} else if (match && match[1]) {
matches.push(match[1]);
}
} while (match);
matches.forEach(function (match) {
filterItems[match] = page + "." + match
});
pages[page] = JSON.sort(filterItems);
allPages[page] = filterItems;
console.log(pages[page]);
};
};
/*
for (var pageToCheck in allPages) {
var parent = allPages[pageToCheck]["#PARENT"];
while (parent) {
if (allPages[parent]) {
for (parentFilters in allPages[parent]) {
if (!parentFilters.startsWith("#") && !allPages[pageToCheck][parentFilters]) {
allPages[pageToCheck][parentFilters] = allPages[parent][parentFilters];
}
}
parent = allPages[parent]["#PARENT"];
} else {
parent = undefined;
}
}
}*/
}
JSON.sort = function (o) {
const isObject = (v) => ('[object Object]' === Object.prototype.toString.call(v));
if (Array.isArray(o)) {
return o.sort().map(v => isObject(v) ? JSON.sort(v) : v);
} else if (isObject(o)) {
return Object
.keys(o)
.sort()
.reduce((a, k) => {
if (isObject(o[k])) {
a[k] = JSON.sort(o[k]);
} else if (Array.isArray(o[k])) {
a[k] = o[k].map(v => isObject(v) ? JSON.sort(v) : v);
} else {
a[k] = o[k];
}
return a;
}, {});
}
return o;
}
var list = (new Function(fs.readFileSync("list.js", "utf8") + ";return list;"))();
getMethods(list.Reference);
getMethods(list.Examples);
fs.writeFileSync("list.js", "var list = " + JSON.stringify(list, undefined, 4).replace(/ /g, "\t").replace(/\r\n/g, "\n").replace(/{\n/g, "{\n\n").replace(/(\s+)}\n/g, "\n$1}\n\n").replace(/(\s+)},\n/g, "\n$1},\n\n"), "utf8");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment