grunt-javascript-obfuscator
Advanced tools
Comparing version 1.0.4 to 1.1.0
{ | ||
"name": "grunt-javascript-obfuscator", | ||
"description": "Obfuscates JavaScript files using amazing javascript-obfuscator.", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"main": "tasks/javascript_obfuscator.js", | ||
@@ -6,0 +6,0 @@ "files": ["tasks"], |
@@ -11,20 +11,22 @@ # grunt-javascript-obfuscator | ||
(function(){ | ||
var variable = 'abc'; | ||
console.log(variable); | ||
})(); | ||
```js | ||
(function(){ | ||
var variable = 'abc'; | ||
console.log(variable); | ||
})(); | ||
``` | ||
Protected code: | ||
var _0xabf1 = [ | ||
'\x61\x62\x63', | ||
'\x6c\x6f\x67' | ||
]; | ||
(function() { | ||
var _0xe6fab6 = _0xabf1[0x0]; | ||
console[_0xabf1[0x1]](_0xe6fab6); | ||
}()); | ||
```js | ||
var _0xabf1 = [ | ||
'\x61\x62\x63', | ||
'\x6c\x6f\x67' | ||
]; | ||
(function() { | ||
var _0xe6fab6 = _0xabf1[0x0]; | ||
console[_0xabf1[0x1]](_0xe6fab6); | ||
}()); | ||
``` | ||
Special thanks for [@sanex3339](https://github.com/sanex3339) for his outstanding [javascript-obfuscator](https://github.com/javascript-obfuscator/javascript-obfuscator) library. | ||
@@ -112,2 +114,19 @@ | ||
#### Obfuscate and overwrite | ||
In this example, source files are obfuscated and overwritten: | ||
```js | ||
grunt.initConfig({ | ||
javascript_obfuscator: { | ||
options: { | ||
/* Default options */ | ||
}, | ||
main: { | ||
src: ['src/module1.js', 'src/module2.js'] | ||
} | ||
}, | ||
}); | ||
``` | ||
## Contributing | ||
@@ -118,2 +137,3 @@ In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). | ||
* 2016-12-23 / v1.1.0 / Obfuscate and overwrite files without destination. | ||
* 2016-11-11 / v1.0.4 / Updated README. | ||
@@ -120,0 +140,0 @@ * 2016-11-09 / v1.0.3 / Updated README. |
@@ -19,4 +19,2 @@ /* | ||
return paths.map(function(path) { | ||
// Read file source. | ||
return grunt.file.read(path); | ||
@@ -26,2 +24,27 @@ }).join(grunt.util.normalizelf(';')); | ||
function obfuscate(grunt, originalSource, destFile, options) { | ||
var obfuscatedSource = JavaScriptObfuscator.obfuscate(originalSource, options).getObfuscatedCode(); | ||
grunt.file.write(destFile, obfuscatedSource); | ||
grunt.log.writeln('File "' + destFile + '" obfuscated.'); | ||
} | ||
function obfuscateSingleTarget(grunt, srcFiles, destFile, options) { | ||
var source; | ||
try { | ||
source = concat(grunt, srcFiles); | ||
} catch (error) { | ||
return grunt.fail.warn(error); | ||
} | ||
obfuscate(grunt, source, destFile, options); | ||
} | ||
function obfuscateMultiplesTargets(grunt, destFiles, options) { | ||
destFiles.forEach(function (destFile) { | ||
var source = grunt.file.read(destFile); | ||
obfuscate(grunt, source, destFile, options); | ||
}); | ||
} | ||
module.exports = function(grunt) { | ||
@@ -38,20 +61,10 @@ grunt.registerMultiTask('javascript_obfuscator', 'Obfuscates JavaScript files.', function() { | ||
files.forEach(function(f) { | ||
var src; | ||
try { | ||
src = concat(grunt, f.src); | ||
} catch (e) { | ||
return grunt.fail.warn(e); | ||
files.forEach(function(file) { | ||
if (file.dest) { | ||
obfuscateSingleTarget(grunt, file.src, file.dest, options); | ||
} else { | ||
obfuscateMultiplesTargets(grunt, file.src, options); | ||
} | ||
src = JavaScriptObfuscator.obfuscate(src, options).getObfuscatedCode(); | ||
// Write the destination file. | ||
grunt.file.write(f.dest, src); | ||
// Print a success message. | ||
grunt.log.writeln('File "' + f.dest + '" created.'); | ||
}); | ||
}); | ||
}; |
7137
54
141
521