-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (33 loc) · 1.18 KB
/
index.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
const ob = require('javascript-obfuscator'),
path = require('path'),
fs = require('fs');
function obfuscator(obj, options) {
const self = this,
start = new Date(),
pluginName = path.basename(path.dirname(__filename));
let msg;
options = options || {};
return (solve, reject) => {
try {
obj.content = ob.obfuscate(obj.content, options).getObfuscatedCode();
fs.writeFile(obj.name, obj.content, err => {
if (err == null) {
msg = 'plugin ' + pluginName.white() + ' wrote ' + obj.name +' (' + self.getSize(obj.name) + ')';
} else {
self.doErr(err, obj, pluginName);
}
err
? reject(`Plugin ${pluginName} write error:\n${err}`)
: solve(obj);
self.notifyAndUnlock(start, msg);
})
} catch(err) {
err
? reject(`Plugin ${pluginName} minification error:\n${err}`)
: solve(obj);
self.notifyAndUnlock(start, msg);
}
}
}
obfuscator.ext = ['js', 'coffee', 'ts'];
module.exports = obfuscator;