-
Notifications
You must be signed in to change notification settings - Fork 14
/
v14-Upgrader.js
47 lines (40 loc) · 1.75 KB
/
v14-Upgrader.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
// const { Embed, ButtonComponent, SelectMenuComponent } = require("discord.js");
const { readFileSync, writeFileSync } = require("fs");
const readdirRecursive = require("recursive-readdir");
readdirRecursive(process.cwd()).then(async (paths) => {
paths = paths.filter(x => !x.includes("jsconfig") && !x.includes("package") && !x.includes("LICENSE") && !x.includes("v14-") && !x.includes("yarn.lock") && !x.includes("node_modules") && !x.includes(".git"));
firstLoop: for (let i = 0; i < paths.length; i++) {
let path = paths[i];
let content = readFileSync(path).toString();
let upperCaseList = content.match(/\"[A-Z_]+\"|\'[A-Z_]+\'|\`[A-Z_]+\`/g);
let fixSize = 0;
secondLoop: for (let j = 0; j < upperCaseList?.length; j++) {
fixSize++;
let oldWord = upperCaseList[j];
let newWord = "\"" + upperToCamel(oldWord.match(/[A-Z_]+/)?.shift()) + "\"";
content = content.replace(oldWord, newWord);
}
content = content.replace(/PermissionString/g, "PermissionResolvable");
content = content.replace(/MessageEmbed|EmbedBuilder|Embed/g, "EmbedBuilder");
content = content.replace(/MessageButton|ButtonBuilder|ButtonComponent/g, "ButtonBuilder");
content = content.replace(/MessageSelectMenu|SelectMenuBuilder|SelectMenuComponent/g, "SelectMenuBuilder");
writeFileSync(path, content);
console.log(path.replace(process.cwd(), ""), `${i}/${paths.length}`, fixSize)
}
});
function upperToCamel(word) {
let nextUp = true;
let newWord = "";
for (let i = 0; i < word.length; i++) {
let char = word[i];
if (char == "_") {
nextUp = true;
} else if (nextUp) {
newWord += char.toUpperCase();
nextUp = false;
} else {
newWord += char.toLowerCase();
}
}
return newWord
}