-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (29 loc) · 919 Bytes
/
index.js
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
39
40
41
42
'use strict';
var through = require('through2');
var gutil=require('gulp-util');
var PluginError = gutil.PluginError;
var path = require('path');
var fs = require('fs');
var NEGPacker = require('./Lib/NEGPacker');
var PLUGIN_NAME = 'gulp-negpacker';
module.exports = function (options) {
// returning the file stream
return through.obj(function(file, enc, cb) {
if (file.isBuffer()) {
var negPacker = NEGPacker(options);
negPacker.doParse(file.contents.toString());
var packlst = negPacker.PackageList;
var buffer = new Buffer('');
for(var i = 0, length = packlst.length ; i< length ; i++ ){
buffer = Buffer.concat([buffer ,packlst[i].buffer]);
}
file.contents = Buffer.concat([buffer, file.contents]);
}
if (file.isStream()) {
this.emit('error', new PluginError(PLUGIN_NAME, 'Streams are not supported!'));
this.cb();
}
this.push(file);
return cb();
});
};