Skip to content

Commit 3c49bad

Browse files
Adam GrawenderWain-PC
Adam Grawender
authored andcommitted
Fix deprecated gulp-util#8 (#16)
* Fixes #8 * Added package-lock.json * Cleaned up package.json * Added .gitignore template from github/gitignore repo * Updated README * Refactored code where needed * 1.1.5
1 parent 279d7f7 commit 3c49bad

File tree

5 files changed

+1037
-52
lines changed

5 files changed

+1037
-52
lines changed

.gitignore

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (https://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# TypeScript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
60+
# parcel-bundler cache (https://parceljs.org/)
61+
.cache
62+
63+
# next.js build output
64+
.next
65+
66+
# nuxt.js build output
67+
.nuxt
68+
69+
# vuepress build output
70+
.vuepress/dist
71+
72+
# Serverless directories
73+
.serverless

README.md

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
gulp-javascript-obfuscator
2-
==========================
1+
# gulp-javascript-obfuscator
32

4-
Gulp plugin for [javascript-obfuscator](https://github.com/javascript-obfuscator/javascript-obfuscator).
3+
Gulp plugin for [javascript-obfuscator](https://github.com/javascript-obfuscator/javascript-obfuscator)
54

65
## Installation
76

8-
Install the package with NPM:
7+
Install the package with npm:
98

10-
`npm install --save gulp-javascript-obfuscator`
9+
```bash
10+
$ npm install --save gulp-javascript-obfuscator
11+
```
1112

1213
## Usage
1314

1415
```javascript
15-
var gulp = require('gulp'),
16-
javascriptObfuscator = require('gulp-javascript-obfuscator');
17-
16+
const gulp = require('gulp');
17+
const javascriptObfuscator = require('gulp-javascript-obfuscator');
1818

1919
gulp.src('file.js')
2020
.pipe(javascriptObfuscator())
2121
.pipe(gulp.dest('dist'));
2222
```
2323

24-
2524
## Options
2625

27-
[Pass any options available in the obfuscator](https://github.com/javascript-obfuscator/javascript-obfuscator#javascript-obfuscator-options).
26+
[Pass any options available in the obfuscator](https://github.com/javascript-obfuscator/javascript-obfuscator#javascript-obfuscator-options)
2827

2928
```javascript
3029
gulp.src('file.js')
@@ -36,4 +35,3 @@ gulp.src('file.js')
3635
```
3736

3837
Using **sourceMap** option with value set to **true** will also output a _.map_ file to Gulp stream.
39-

index.js

+21-32
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,27 @@
1-
var through = require('through2'),
2-
gutil = require('gulp-util'),
3-
JavaScriptObfuscator = require('javascript-obfuscator'),
4-
PluginError = gutil.PluginError;
1+
const through2 = require('through2');
2+
const Vinyl = require('vinyl');
3+
const JavaScriptObfuscator = require('javascript-obfuscator');
4+
const PluginError = require('plugin-error');
55

6-
module.exports = function gulpJavaScriptObfuscator(options) {
7-
if(!options) {
8-
options = {}
9-
}
6+
module.exports = function gulpJavaScriptObfuscator (options = {}) {
7+
return through2.obj(function (file, enc, cb) {
8+
if (file.isNull()) return cb(null, file);
9+
if (!file.isBuffer()) throw new PluginError('gulp-javascript-obfuscator', 'Only Buffers are supported!');
1010

11-
return through.obj(function (file, enc, cb) {
12-
var obfuscationResult;
13-
if (file.isNull()) {
14-
return cb(null, file);
15-
}
16-
17-
if (file.isBuffer()) {
18-
try {
19-
obfuscationResult = JavaScriptObfuscator.obfuscate(String(file.contents), options);
20-
file.contents = new Buffer(obfuscationResult.getObfuscatedCode());
21-
if(options.sourceMap && options.sourceMapMode !== 'inline') {
22-
this.push(new gutil.File({
23-
cwd: file.cwd,
24-
base: file.base,
25-
path: file.path + '.map',
26-
contents: new Buffer(obfuscationResult.getSourceMap())
27-
}))
28-
}
29-
cb(null, file);
11+
try {
12+
const obfuscationResult = JavaScriptObfuscator.obfuscate(String(file.contents), options);
13+
file.contents = new Buffer(obfuscationResult.getObfuscatedCode());
14+
if (options.sourceMap && options.sourceMapMode !== 'inline') {
15+
this.push(new Vinyl({
16+
cwd: file.cwd,
17+
base: file.base,
18+
path: file.path + '.map',
19+
contents: new Buffer(obfuscationResult.getSourceMap())
20+
}))
3021
}
31-
catch (err) {
32-
throw new PluginError('gulp-javascript-obfuscator', err);
33-
}
34-
} else if (file.isStream()) {
35-
throw new PluginError('gulp-javascript-obfuscator', 'Streams are not supported!');
22+
return cb(null, file);
23+
} catch (err) {
24+
throw new PluginError('gulp-javascript-obfuscator', err);
3625
}
3726
});
3827
};

0 commit comments

Comments
 (0)