-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
31 lines (27 loc) · 912 Bytes
/
index.ts
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
import JavaScriptObfuscator from "javascript-obfuscator"
import path from "path"
import fs from "fs"
function Obfuscator(content:string):string {
let obfuscationResult = JavaScriptObfuscator.obfuscate(content,
{
compact: true,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1
}
)
return obfuscationResult.getObfuscatedCode()
}
async function ExchangeJS(dir: string, output: string) {
const files = fs.readdirSync(dir)
for (const file of files) {
if (fs.statSync(path.join(dir, file)).isDirectory()) {
await ExchangeJS(path.join(dir, file), path.join(output, file))
} else {
const contents = Obfuscator(fs.readFileSync(path.join(dir, file), "utf-8"))
fs.writeFileSync(path.join(output, file), contents)
}
}
}
(async () => {
await ExchangeJS(path.join(__dirname, "./js/"), path.join(__dirname, "./public/"))
})()