grunt-contrib-obfuscator
Advanced tools
Comparing version 1.0.2 to 1.1.0
{ | ||
"name": "grunt-contrib-obfuscator", | ||
"description": "Grunt plugin that obfuscates your JavaScript using the javascript-obfuscator library.", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Tiago Serafim" |
@@ -1,16 +0,46 @@ | ||
grunt-contrib-obfuscator | ||
======================== | ||
# grunt-contrib-obfuscator [![Build Status](https://travis-ci.org/javascript-obfuscator/grunt-contrib-obfuscator.svg?branch=master)](https://travis-ci.org/javascript-obfuscator/grunt-contrib-obfuscator) | ||
Grunt plugin for [javascript-obfuscator](https://github.com/javascript-obfuscator/javascript-obfuscator). You can try the javascript-obfuscator module and see all its options here: https://javascriptobfuscator.herokuapp.com | ||
> Obfuscate JavaScript files using [javascript-obfuscator](https://github.com/javascript-obfuscator/javascript-obfuscator) | ||
[![Build Status](https://travis-ci.org/javascript-obfuscator/grunt-contrib-obfuscator.svg?branch=master)](https://travis-ci.org/javascript-obfuscator/grunt-contrib-obfuscator) | ||
You can try the javascript-obfuscator module and see all its options here: https://javascriptobfuscator.herokuapp.com | ||
## Installation | ||
## Getting Started | ||
Install the package with NPM: | ||
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: | ||
`npm install --save grunt-contrib-obfuscator` | ||
```shell | ||
npm install grunt-contrib-obfuscator --save-dev | ||
``` | ||
## Usage | ||
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: | ||
```js | ||
grunt.loadNpmTasks('grunt-contrib-obfuscator'); | ||
``` | ||
## Obfuscator task | ||
_Run this task with the `grunt obfuscator` command._ | ||
Task targets, files and options may be specified according to the grunt [Configuring tasks](http://gruntjs.com/configuring-tasks) guide. | ||
## Options | ||
[See the options on the obfuscator repo](https://github.com/javascript-obfuscator/javascript-obfuscator#javascript-obfuscator-options). | ||
_Note that at this time the `sourceMap` isn't implemented in this plugin._ | ||
In addition the the obfuscator options, you can also use: | ||
#### banner | ||
Type: `String` | ||
Default: `''` | ||
This string will be prepended to the obfuscated output. Template strings (e.g. `<%= config.value %>` will be expanded automatically. | ||
## Usage examples | ||
#### Default options | ||
This configuration will obfuscate the input files using the default options. | ||
```javascript | ||
@@ -35,6 +65,25 @@ obfuscator: { | ||
## Options | ||
#### Debug protection and banner | ||
[See the options on the obfuscator repo](https://github.com/javascript-obfuscator/javascript-obfuscator#javascript-obfuscator-options). | ||
Here you code will be protected against debugging | ||
Note that at this time the `sourceMap` isn't implemented in this plugin. | ||
```javascript | ||
obfuscator: { | ||
options: { | ||
banner: '// obfuscated with grunt-contrib-obfuscator.\n', | ||
debugProtection: true, | ||
debugProtectionInterval: true | ||
}, | ||
task1: { | ||
options: { | ||
// options for each sub task | ||
}, | ||
files: { | ||
'dest/output.js': [ | ||
'src/js/file1.js', | ||
'src/js/file2.js' | ||
] | ||
} | ||
} | ||
} | ||
``` |
@@ -12,2 +12,7 @@ 'use strict'; | ||
// Converts \r\n to \n | ||
function normalizeLf(string) { | ||
return string.replace(/\r\n/g, '\n'); | ||
} | ||
module.exports = function (grunt) { | ||
@@ -31,4 +36,8 @@ var getAvailableFiles = function (filesArray) { | ||
this.files.forEach(function (file) { | ||
var options = this.options({}); | ||
var options = this.options({ | ||
banner: '' | ||
}); | ||
var banner = normalizeLf(options.banner); | ||
var availableFiles = getAvailableFiles(file.src); | ||
@@ -55,3 +64,5 @@ | ||
grunt.file.write(file.dest, obfuscated); | ||
var output = banner + obfuscated; | ||
grunt.file.write(file.dest, output); | ||
created.files++; | ||
@@ -58,0 +69,0 @@ |
6622
56
89