forked from Slimefun/Wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
missing.js
88 lines (69 loc) · 2.33 KB
/
missing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const fs = require('fs');
const http = require("https");
const url = "https://github.com/TheBusyBiscuit/Slimefun4/wiki/";
const regex = /\(https:\/\/github\.com\/TheBusyBiscuit\/Slimefun4\/wiki\/[A-Za-z-]+\)/g;
const options = {
method: "PATCH",
hostname: "api.github.com",
path: "/repos/Slimefun/Slimefun-wiki/issues/2",
headers: {
"User-Agent": "Slimefun-wiki Action",
"authorization": "token " + process.env.ACCESS_TOKEN,
"content-type": "application/x-www-form-urlencoded"
}
}
const promises = [];
const pages = [];
const missing = [];
const missingPage = fs.readFileSync("missing.md", "UTF-8");
fs.promises.readdir("pages").then((files) => {
for (var i in files) {
promises.push(fs.promises.readFile("pages/" + files[i], "UTF-8").then((content) => {
var match;
do {
match = regex.exec(content);
if (match) {
var page = match[0].substring(1 + url.length, match[0].length - 1) + ".md";
findFile(page);
}
} while(match);
}));
}
Promise.all(promises).then(() => {
var request = http.request(options, (response) => {
var body = [];
response.on("data", (data) => {
body.push(data);
});
response.on("end", function () {
console.log(Buffer.concat(body).toString());
});
});
var content = "The following pages are still missing!\n\n";
for (var i in missing) {
content += "* " + missing[i] + " \n";
fs.writeFile("pages/" + missing[i], missingPage, (err) => {
if (err) throw err;
});
}
content += "\nIt would be really nice if someone added them and made a Pull Request.\n";
content += url + "pulls";
request.write(JSON.stringify({
title: "Missing Pages: " + missing.length,
body: content,
state: "open"
}));
request.end();
});
});
function findFile(page) {
if (pages.includes(page)) return;
pages.push(page);
if (fs.existsSync("pages/" + page)) {
console.log(page + " : OK");
}
else {
console.log(page + " : MISSING");
missing.push(page);
};
}