-
Notifications
You must be signed in to change notification settings - Fork 2
/
encrypt.js
29 lines (23 loc) · 881 Bytes
/
encrypt.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
const { join } = require('path');
const { readdirSync, statSync } = require('fs');
const JavaScriptObfuscator = require('javascript-obfuscator');
const fs = require('fs');
const distDirectory = './dist';
function obfuscateFile(filePath) {
const fileContents = fs.readFileSync(filePath, 'utf8');
const obfuscationResult = JavaScriptObfuscator.obfuscate(fileContents);
fs.writeFileSync(filePath, obfuscationResult.getObfuscatedCode(), 'utf8');
}
function traverseDirectory(currentPath) {
const files = readdirSync(currentPath).map(file => join(currentPath, file));
files.forEach((file) => {
console.log('encry =======> ', file);
if (statSync(file).isDirectory()) {
traverseDirectory(file);
} else if (file.endsWith('.js')) {
obfuscateFile(file);
}
});
}
traverseDirectory(distDirectory);
console.log('JavaScript obfuscation complete!');