var through = require('through2'),
gutil = require('gulp-util'),
JavaScriptObfuscator = require('javascript-obfuscator'),
PluginError = gutil.PluginError;
module.exports = function gulpJavaScriptObfuscator(options) {
Eif(!options) {
options = {}
}
return through.obj(function (file, enc, cb) {
var obfuscationResult;
Iif (file.isNull()) {
return cb(null, file);
}
Eif (file.isBuffer()) {
try {
obfuscationResult = JavaScriptObfuscator.obfuscate(String(file.contents), options);
file.contents = new Buffer(obfuscationResult.getObfuscatedCode());
this.push(file);
Iif(options.sourceMap && options.sourceMapMode !== 'inline') {
this.push(new gutil.File({
cwd: file.cwd,
base: file.base,
path: file.path + '.map',
contents: new Buffer(obfuscationResult.getSourceMap())
}))
}
cb();
}
catch (err) {
throw new PluginError('gulp-javascript-obfuscator', err);
}
} else if (file.isStream()) {
throw new PluginError('gulp-javascript-obfuscator', 'Streams are not supported!');
}
});
}; |