-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
73 lines (63 loc) · 2.17 KB
/
index.js
File metadata and controls
73 lines (63 loc) · 2.17 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
const fs = require('fs');
const path = require('path');
const uglifycss = require('uglifycss');
const JavaScriptObfuscator = require('javascript-obfuscator');
const chokidar = require('chokidar');
const suffix = "-preugly";
// Function to obfuscate JavaScript files
function obfuscateJS(file) {
const inputFile = file;
const outputFile = file.replace(suffix, "");
const code = fs.readFileSync(inputFile, 'utf8');
const result = JavaScriptObfuscator.obfuscate(code, {
compact: true,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 0.75,
deadCodeInjection: true,
deadCodeInjectionThreshold: 0.4,
debugProtection: false,
debugProtectionInterval: 0,
disableConsoleOutput: true,
identifierNamesGenerator: 'hexadecimal',
log: false,
renameGlobals: false,
rotateStringArray: true,
selfDefending: true,
stringArray: true,
stringArrayEncoding: [],
stringArrayThreshold: 0.75,
unicodeEscapeSequence: false
});
fs.writeFileSync(outputFile, result.getObfuscatedCode());
}
// Function to minify CSS files
function minifyCSS(file) {
const inputFile = file;
const outputFile = file.replace(suffix, "");
const code = fs.readFileSync(inputFile, 'utf8');
const result = uglifycss.processString(code);
fs.writeFileSync(outputFile, result);
}
// Main function to process files
function processFile(file) {
if (file.endsWith('.js')) {
obfuscateJS(file);
} else if (file.endsWith('.css')) {
minifyCSS(file);
}
}
// Watch all JS and CSS files on the server
const serverDirectory = 'path/to/server/directory'; // Update this with your server directory
const watcher = chokidar.watch(serverDirectory, {
ignored: /(^|[\/\\])\../, // ignore dotfiles
persistent: true,
depth: 99 // Set depth to watch nested directories
});
watcher.on('change', (filePath) => {
if (filePath.search(suffix) == -1) return;
const ext = path.extname(filePath);
if (ext === '.js' || ext === '.css') {
console.log(`File ${filePath} has been changed!`);
processFile(filePath);
}
});