All files index.js

76.19% Statements 16/21
41.67% Branches 5/12
100% Functions 2/2
76.19% Lines 16/21
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 391x 1x 1x 1x   1x 1x 1x     1x   1x       1x 1x 1x 1x 1x 1x               1x                  
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!');
		}
	});
};