-
-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathconvertify.js
More file actions
107 lines (90 loc) · 2.97 KB
/
Copy pathconvertify.js
File metadata and controls
107 lines (90 loc) · 2.97 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"use strict";
// convertify -- use "convert" instead of "magick" (magick v6),
// and patch functions for node v5
let major = -1
try {
major = parseInt(process.version.replace("v", "").split(".")[0])
}
catch(error) {}
if(major >= 6 && process.argv.indexOf("--bypass-version-check") == -1) {
console.log(`
=======
[!] your nodejs version appears to be
new enough to not need those patches,
and they will most likely cause more
trouble than use.
heavily not recommended, but you can use
--bypass-version-check to get around
this message.
======`)
process.exit()
return;
}
console.log("// applying magick->convert patches")
const fs = require("fs")
const convertFiles = [
"post_config_setup.js",
"back/backend.js",
"back/detect_default_avatar.js",
"back/dominant_color.js",
"back/yt2009charts.js",
"back/yt2009mobile.js"
]
convertFiles.forEach(f => {
let content = fs.readFileSync(f).toString()
content = content.split(`, "magick --help"`).join("")
content = content.split(`, "convert --help"`).join("")
content = content.split("magick convert").join("convert")
content = content.split("\"magick").join("\"convert")
content = content.split("`magick").join("`convert")
fs.writeFileSync(f, content)
console.log(`processed ${f}`)
})
// trimStart() and trimEnd() exist in node v5 but crash the whole process
// replace with trimLeft() and trimRight()
console.log("\n\n\n// applying string trim fixes (es6)")
const trimFiles = [
"post_config_setup.js",
"back/"
]
function trimFix(content) {
return content
.split("trimStart(").join("trimLeft(")
.split("trimEnd(").join("trimRight(")
.split("trim()").join("trimLeft().trimRight()")
}
trimFiles.forEach(f => {
if(f.endsWith("/")) {
// is a directory
fs.readdirSync(f).forEach(file => {
if(file.endsWith(".js")) {
let path = f + file
let content = fs.readFileSync(path).toString()
content = trimFix(content)
fs.writeFileSync(path, content)
console.log(`processed ${path}`)
}
})
} else {
// is a file
let content = fs.readFileSync(f).toString()
content = trimFix(content)
fs.writeFileSync(f, content)
console.log(`processed ${f}`)
}
})
try {fs.unlinkSync(__dirname + "/Dockerfile")}catch(error){}
// bigint patchout
console.log("\n\n\napplying bigint nuke")
let htmlCode = fs.readFileSync("./back/yt2009html.js").toString()
htmlCode = htmlCode.split("BigInt").join("")
fs.writeFileSync("./back/yt2009html.js", htmlCode)
console.log("..done!")
// regex fixup
console.log("\n\n\napplying regex patch")
htmlCode = htmlCode.split("/gui").join("/gi")
fs.writeFileSync("./back/yt2009html.js", htmlCode)
let utilsCode = fs.readFileSync("./back/yt2009utils.js").toString()
utilsCode = utilsCode.split("/gui").join("/gi")
fs.writeFileSync("./back/yt2009utils.js", utilsCode)
console.log("..done!")